Fusion-Power-Plant-Framework / bluemira

Bluemira is an integrated inter-disciplinary design tool for future fusion reactors. It incorporates several modules, some of which rely on other codes, to carry out a range of typical conceptual fusion reactor design activities.
https://bluemira.readthedocs.io/
GNU Lesser General Public License v2.1
59 stars 16 forks source link

Agree, document, and enforce a `bluemira` unit convention #323

Closed CoronelBuendia closed 2 years ago

CoronelBuendia commented 3 years ago

Description of issue / requirement to address

We are not fully consistent in units across bluemira. We've had some discussion regarding unit conventions, but we need to actually agree, document, and enforce a unit convention.

We've already resolved the topic of degrees vs radians: degrees as inputs and outputs to user-facing functionality

We also need to agree on units, e.g. SI or whatever, but sadly there are some pretty weird ones in the plasma physics and neutronics worlds. So plasma densities in 10^19/m^2 or neutron fluxes in n/cm^2/s. I don't condone such units... but we do need to strike a balance between consistency and usability.

Proposed solution

The latter will probably need to happen progressively...

Alternative solutions

Live with unit quirks forever.

Proposed Unit Convention

SI unit convention, (C or K), degrees not radians, no mega-milli-kilo-centi-pico stuff, except for kilogram..

We'll probably encounter some weird ones.

je-cook commented 3 years ago

A time to consider some use of Pint?

CoronelBuendia commented 3 years ago

A time to consider some use of Pint?

Everywhere? Or just in the user interface?

I fear passing that metadata around everywhere will break as soon as you hit a numba-accelerated block

je-cook commented 3 years ago

Just for conversion from the user interface to our units (whatever they may be) then just use the raw numbers, say in the setup of a parameter.

If we want to be really fancy we could do a conversion back to the users units at the end, but thats probably a nicety that is cared less about

CoronelBuendia commented 3 years ago

Yeah I'd be happy with that. Just going through their docs and there's also a fair amount of computational overhead, so avoid that in the main body of code would be good.

We still need to make sure about all our units internally though... cough [MA] cough [A]. That will probably be the hard part.

CoronelBuendia commented 3 years ago

Just an additional thought, this kind of feeds into the data/interfacing task. For example, in PROCESS, I'm pretty sure there are something like plasma density that will come out in plasma physicist units.

CoronelBuendia commented 3 years ago

Thoughts @fabrizio-franza @ivanmaione @jmorris-uk ?

je-cook commented 3 years ago

yep, we can maybe do the same sort of conversion, if we know the units going between the codes. Semi treating it like another user

DanShort12 commented 3 years ago

This would be great at our interfacing levels - our Parameters are already unit-aware, so if we use those at the interfacing level (or at least use their json equivalents) then it could be fairly straightforward to convert when reading in external data. We should definitely keep that conversion only at the interfacing level, and just be consistent about our internal units once something has landed in bluemira.

DanShort12 commented 3 years ago

Perhaps we could add a unit to the ParameterMapping class - that way if we know the external source and how they treat the units then we (or better yet, the users) have a single point of record for the inbound unit and then can see what conversion will take place.

fabrizio-franza commented 2 years ago

Thoughts @fabrizio-franza @ivanmaione @jmorris-uk ?

Here is how I coped with this problem in MIRA. Anywhere in the core classes (solvers, geometry builder, etc.), the SI units are used, meaning that any class properties or input parameters to each method are implicitly meant to feature and operate with SI units. However, there are few exceptions to evaluate case by case, such as:

Finally, from the user side, I use ad-hoc methods or multiplications constants, to perform units conversion. But that occurs from the user-interface (or main) script, i.e. the one that runs the full configurations.