Enable TAE-EP simulations (fix several bugs)#144
Conversation
…containing the classes for the new input handling
…eplace the species dictionary in models.
…tors class was moved there becuae the .pyi file takes precedence over .py for type inference
…attribute species to each variable
- new class `Noise` in perturbations.py - added arguments `given_in_basis` and `comp` to each perturbation
spossann
left a comment
There was a problem hiding this comment.
Looks good! Have written some suggestions.
| """ | ||
|
|
||
| @abstractmethod | ||
| def vth(self, psic): |
There was a problem hiding this comment.
A type KineticBackground should be evaluated at (eta1, eta2, ...) etc. thus on the unit cube, not at psic. Wouldn't it be more consistent to have a function eta_to_psic and use it in the evaluations?
There was a problem hiding this comment.
If we do that, we need to recalculate psic_to_eta is not
There was a problem hiding this comment.
May be we should rename it to psic_to_rc.
There was a problem hiding this comment.
We have two options here:
- We keep the hierarchy
class CanonicalMaxwellian(KineticBackground):, then CanonicalMaxwellian needs to respect what the base class demands (see docstring). - Do not inherit, thus make a new class
class CanonicalMaxwellian:; then we loose some consistency with the rest of the code and have to adapt a bit.
I prefer option 1. to have a unique class for backgrounds, which can then be added/subtracted etc. If I understand correctly you say we do not need to re-evaluate the canonical Maxwellian, and just evaluate it at the beginning and then store the value in the marker array? This could be done also in eta-space and the problem is solved, right?
There was a problem hiding this comment.
I mean, in the case of control_variate=True scheme, we need to evaluate the canonical Maxwellian whenever we push particles. So far the approach was that first we evaluate constants of motion of all particles etas into an array of etas as an input argument right?
There was a problem hiding this comment.
I mean, in the case of
control_variate=Truescheme, we need to evaluate the canonical Maxwellian whenever we push particles. So far the approach was that first we evaluate constants of motion of all particles ψ c and ε with the pyccelized kernels and store them in the marker array and then use the stored values when we evaluate the canonical Maxwellian. With your suggested approach, if I understand correctly, we should implement the function which converts an array ofetasinto an array of ε and ψ c and keepetasas an input argument right?
What I don't understand is the following: When the value of the canoncial Maxwellian never changes for a particle, because the arguments are constants of motion, why not store the value of the Canonical Maxwellian in the marker array?
On the other hand, if the value does change, and we need to recompute anyway, then why have an intermediate step for storing the changed "constants of motion", and not evaluate the Maxwellian directly? In the eval we can compute the constants, as you suggested.
|
|
||
| return out | ||
|
|
||
| def __call__(self, *args): |
There was a problem hiding this comment.
Here it is not clear whether one evaluates at eta or at psic. I would opt for eta for consistency.
There was a problem hiding this comment.
Currently, args includes the canonical toroidal momentum psic and the energy
|
|
||
| return res | ||
|
|
||
| def _evaluate_moment(self, psic, *, name: str = "n", add_perturbation: bool = None): |
There was a problem hiding this comment.
In fact, we use
There was a problem hiding this comment.
Please adapt the name to rc to be clear.
There was a problem hiding this comment.
But the input argument is still psic. In the function, we calculate r_c from the psic, then evaluate at the r_c.
There was a problem hiding this comment.
Ok, so in general there is nothing wrong with having this helper function that evaluate at psic, but these should be called inside the methods demanded by the base class.
|
Hi @spossann, are you considering any further modifications for this MR? |
I still want to get some consistency for the arguments of the CanonicalMaxwellian. |
|
That is possible, but then we need to pass |
Yes I think it is fine. |
|
After implementing this, I realized that the performance degradation might be more significant than I initially expected. The current fix introduces multiple large 2D array computations (roughly number_of_particle_sizes × 6). Moreover, these calculations must be done every time the particle positions or velocities are updated when using the control variate method. |
We should definitely finish the performance testing to make sure this doesn't happen 😅 |
This comment refers specifically to the most recent commit that I made in this MR, not to the overall approach in general ;) |
Core changes:
Allow
TAE-EP simulationswith devel.CanonicalMaxwellian.n_cols_diagandn_cols_auxto the classParticles.Model-specific changes:
Bug fix in the model
LinearMHDDriftkineticCC