Skip to content
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

Create abstract base class as interface for plasma normalizations #859

Merged
merged 30 commits into from
Jan 1, 2021

Conversation

namurphy
Copy link
Member

@namurphy namurphy commented Jun 23, 2020

This pull request includes new classes that describe standard normalizations that are used for ideal and extended MHD. The purpose of these classes is to have a standard way to represent normalization information that can be used for different codes and groups. Actually, I would have found these classes to be really helpful for a simulation benchmark project that I'm working on so that I didn't need to create them from scratch. I'm most familiar with the fluid approximation normalizations so I'm starting with those, but we'll also need to create normalizations for PIC simulation (where length is often normalized to the ion inertial length and time to the inverse of the ion gyrofrequency). I still have a lot to do for this, so it's lower priority for code review at the moment.

  • I have added a changelog entry for this pull request.
  • If adding new functionality, I have added tests and
    docstrings.
  • I have fixed any newly failing tests.

Closes #808.

namurphy added 2 commits June 22, 2020 18:25
I expect that an abstract base class will be helpful here because will be
different normalizations for different ways of representing plasma (e.g,
ideal, resistive MHD, or extended MHD normalizations are different than
normalizations used for PIC simulations.  I'll tentatively keep this in,
but we can re-evaluate how useful it will be later on.
@codecov
Copy link

codecov bot commented Jun 23, 2020

Codecov Report

Merging #859 (8eed431) into master (95aa647) will decrease coverage by 0.36%.
The diff coverage is 82.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #859      +/-   ##
==========================================
- Coverage   96.29%   95.92%   -0.37%     
==========================================
  Files          62       60       -2     
  Lines        5715     5471     -244     
==========================================
- Hits         5503     5248     -255     
- Misses        212      223      +11     
Impacted Files Coverage Δ
plasmapy/simulation/normalizations.py 82.52% <82.52%> (ø)
plasmapy/simulation/__init__.py 100.00% <100.00%> (ø)
plasmapy/formulary/collisions.py 96.75% <0.00%> (-0.44%) ⬇️
plasmapy/simulation/particletracker.py 98.30% <0.00%> (-0.03%) ⬇️
plasmapy/formulary/parameters.py 99.00% <0.00%> (-0.01%) ⬇️
plasmapy/formulary/__init__.py 100.00% <0.00%> (ø)
plasmapy/diagnostics/thomson.py 100.00% <0.00%> (ø)
plasmapy/formulary/braginskii.py 99.72% <0.00%> (ø)
plasmapy/formulary/dielectric.py 100.00% <0.00%> (ø)
plasmapy/plasma/sources/plasma3d.py 100.00% <0.00%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 81c6431...bd335bb. Read the comment docs.

@StanczakDominik
Copy link
Member

This pull request has been mentioned on PlasmaPy Community Discourse Forum. There might be relevant details there:

https://plasmapy.discourse.group/t/ideas-for-how-we-can-use-normalizations-objects/44/1

@namurphy
Copy link
Member Author

For this pull request, I'm thinking that I should focus on getting the normalizations in there in the proper form with sufficient documentation. It'll probably be best to have follow-up pull requests that deal with how an object containing normalizations can be used in operations. Best to limit the scope of pull requests, as we've learned...

  • Create an issue on dunder operations for normalizations objects after this pull request is merged.

@StanczakDominik
Copy link
Member

This pull request has been mentioned on PlasmaPy Community Discourse Forum. There might be relevant details there:

plasmapy.discourse.group/t/ideas-for-how-we-can-use-normalizations-objects/44/1

I would just like to note that this was an automation that I forgot I set up and holy wow, did I just give myself a brief moment of existential doubt.

@namurphy namurphy changed the title Create classes to represent standard normalizations for MHD Create abstract base class as interface for plasma normalizations Dec 31, 2020
@namurphy
Copy link
Member Author

I decided to downscope this pull request. This PR now creates a first attempt at an abstract base class, AbstractNormalizations, that is to be used in the creation of classes to represent normalizations for plasmas. This PR does not include tests since this is the first draft, and because I'm not sure of a meaningful way of testing abstract classes. I'm ready for this PR to be merged when it's ready.

I'm thinking it would be really helpful to have a function that takes a unit and returns a list of corresponding physical types, and a function that takes a physical type and then returns the appropriate SI unit. I'd probably use this functionality a lot since I often have to figure out what units are for a particular quantity (like thermal conduction). This is related to what I brought up in astropy/astropy#11202.

In any case, I'm still thinking about the best strategy for creating classes like MHDNormalizations, and I think it'll be better to spread the creation of new machinery out over several pull requests.

@namurphy namurphy marked this pull request as ready for review December 31, 2020 21:17
@namurphy namurphy requested a review from a team December 31, 2020 21:18
@namurphy
Copy link
Member Author

Also, you should be proud that I alphabetized the attributes contained in AbstractNormalizations. 🥇 💯 🎓 🔤

@rocco8773
Copy link
Member

Also, you should be proud that I alphabetized the attributes contained in AbstractNormalizations. 🥇 💯 🎓 🔤

It is beautifully organized! 🔤🤣

@rocco8773
Copy link
Member

Something to think about for the future... This feels like a dataclass to me and, I'm guessing, that is how it will be predominately used. I'm assuming it's basically a warehouse for normalization constants that are then used to normalize (array / norm.length) or de-normalize (array * norm.length) physical parameters.

changelog/859.feature.rst Outdated Show resolved Hide resolved
Comment on lines 102 to 109
@property
@abstractmethod
def ion(self) -> Particle:
"""
The ion in the plasma, which could be a positron in the case
of a pair plasma.
"""
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An ion isn't really a normalization. It's mass could be a normalization, or it's gyrofrequency could be. I would remove this method and leave it up to the user to manually define/calculate the other normalizations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah...I've been wondering how to handle ions in the normalization, since how to handle ion stuff make normalization stuff kind of messy...in particular for how we handle multi-component plasmas. Ultimately I'd like for there to be normalization classes that allow operations like:

>>> dimensionless_plasma = dimensional_plasma / normalizations
>>> dimensional_plasma = normalizations * dimensionless_plasma

For these to work we'd need information on the ion(s) somehow, so the choice of ion(s) do end up weirdly more or less being part of the normalization...in particular for the normalization between number density and mass density. I'll remove the ion attribute for now, and worry about how to deal with this next year.

ugh why won't 2016 just end already

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh why won't 2016 just end already

I know! Longest year eveeeeeeeeeer! Completely feels like 4+ years.


Well, that will be an interesting implementation. I like it, but I have no clue how to go about implementing it. Might be easier to have something like dimensionless_plasma.reform(normalizations) and dimensional_plasma.reform(normalizations). I only used reform to keep the name consistent across all plasma classes.

namurphy and others added 3 commits December 31, 2020 21:59
There's discussion about this in PlasmaPy#859.  Ions are a weird part of the normalization,
and we'll need to think more about how to handle them in a consistent way.
Copy link
Member

@rocco8773 rocco8773 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RTD finally finished and it looks good. I'm curious where this functionality goes and how its UI develops. I can see it being useful in several places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.simulation Related to the plasmapy.simulation subpackage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create classes to represent normalizations in simulation subpackage
3 participants