-
Notifications
You must be signed in to change notification settings - Fork 17
Polymorphic injectors, external currents, and diagnostics #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
f62ec7c
+injector_base: InjectorBase, InjectorFromLambda
JamesMcClung 496ad5c
boundary_injector: inherit from InjectorBase
JamesMcClung 7a35b95
psc: have a list of InjectorBase ptrs
JamesMcClung a175f13
*: add injectors to the list
JamesMcClung 99beaf1
psc; *: rm templated injector
JamesMcClung 1be2d52
psc: -InjectParticlesNone
JamesMcClung 1c2ddfb
-composite_injector; *
JamesMcClung 3931fad
+external_current_base
JamesMcClung 0e6f2a5
psc; *: use vec of ExternalCurrents
JamesMcClung ddc197a
psc: -ExternalCurrentNone
JamesMcClung bc43fb1
psc; *: make vecs private
JamesMcClung 358a042
boundary_injector: don't impl op()
JamesMcClung c3fbc68
psc; *: initialize -> pre_first_step
JamesMcClung f4a58a6
+diagnostic_base
JamesMcClung 7ee609c
OutputFieldsDefault: make diagnostic
JamesMcClung dceac22
output_particles*; *: make diagnostic
JamesMcClung ad80822
DiagEnergies; *: make diagnostic
JamesMcClung 95256de
psc; *: abstract diagnostics
JamesMcClung 77fa1a5
psc: update stat in perform_diagnostics
JamesMcClung 119a734
-DiagnosticsDefault; *
JamesMcClung 17fe7ab
tests: don't make diagnostics
JamesMcClung 70c54da
psc: fix capture by ref -> segfault
JamesMcClung bb1298b
injector_base: lambda_
JamesMcClung dc5cf86
*_base: more lambda_
JamesMcClung 3c16414
psc: assert pointers
JamesMcClung 79e444a
_*base: include functional
JamesMcClung 9707ee8
*_base: add virtual dtors
JamesMcClung 88e83fe
*_base: don't use templated types
JamesMcClung 02902d0
psc: solve the problem with a todo
JamesMcClung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #pragma once | ||
|
|
||
| template <typename MPARTICLES, typename MFIELDS_STATE> | ||
| struct InjectorBase | ||
| { | ||
| using Mparticles = MPARTICLES; | ||
| using MfieldsState = MFIELDS_STATE; | ||
|
|
||
| virtual void inject(Mparticles& mprts, MfieldsState& mflds) = 0; | ||
| }; | ||
|
|
||
| template <typename MPARTICLES, typename MFIELDS_STATE> | ||
| struct InjectFromLambda : InjectorBase<MPARTICLES, MFIELDS_STATE> | ||
| { | ||
| using Mparticles = MPARTICLES; | ||
| using MfieldsState = MFIELDS_STATE; | ||
|
|
||
| InjectFromLambda(std::function<void(Mparticles&, MfieldsState&)> lambda) | ||
| : lambda{lambda} | ||
| {} | ||
|
|
||
| void inject(Mparticles& mprts, MfieldsState& mflds) override | ||
| { | ||
| return lambda(mprts, mflds); | ||
| } | ||
|
|
||
| private: | ||
| std::function<void(Mparticles&, MfieldsState&)> lambda; | ||
|
JamesMcClung marked this conversation as resolved.
Outdated
|
||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may learn more as I go through more commits, but at this point I'm wondering, why not stick with
operator()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say explicit method names helps with discoverability: one can search for implementations of named methods, but not for
operator(). That's also a benefit of using polymorphism rather than templates or outright type erasure (à lastd::function).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following my own logic, I should get rid of the lambda wrappers and force users to make their own subclasses. That would be better future-proofed against more methods, too (such as requiring subclasses to provide logging-related information).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm not entirely clear on my own thinking here, though I think it's nice isolating users from having to do their own subclasses -- though admittedly lambda functions are likely an even more unfamiliar feature to a casual user...
Anyway, I guess what's there currently (class from lambda) is fine for the time being.