bmad-sim / AtomicAndPhysicalConstants.jl

Julia package for handling particle identification in simulations.
MIT License
0 stars 1 forks source link

Changing units #15

Closed rot4te closed 2 months ago

rot4te commented 6 months ago

We need to add functionality to change the units of all the constants to any other common unit. The plan is to have all the constants stored in consistent units, (base eV), and use conversion to create temporary copies of the units in local memory. Since this total a few hundred Float64 objects, it won't take up more than a few kB

DavidSagan commented 6 months ago

I'm imagining a system where there is a function to set the units set_units(who) where who can be something like "MKS", "CGS", "ParticlePhysicsStandard" (is there a better name?), etc. I'm not sure of the best way to specify custom units.

lllx125 commented 6 months ago

I want to clarify how this function works. Suppose someone uses the AtomicAndPhysicalConstants package and uses some variable, say print(m_electron). And it will print 0.51099895000e6 (in eV/c^2). And say if they call the function set_units(Mev/c^2), then print(m_electron). It will print 0.51099895000 (in MeV/c^2). Is this what we are looking for?

rot4te commented 6 months ago

Yes, but that's the simple part. You want to be able to convert to any unit of the same dimension: eg eV/c^2 to kg, with order (kilo, mega, giga, etc.) freedom as well.

For example the anomalous magnetic moments are expressed in nuclear magnetons, but can also be thought of in Joule/Tesla or eV/Tesla, so it would be nice to be able to express anomalous moments in MeV/Tesla

On Mon, Mar 18, 2024, 23:16 Lixing Li @.***> wrote:

I want to clarify how this function works. Suppose someone uses the AtomicAndPhysicalConstants package and uses some variable, say print(m_electron). And it will print 0.51099895000e6 (in eV/c^2). And say if they call the function set_units(Mev/c^2), then print(m_electron). It will print 0.51099895000 (in MeV/c^2). Is this what we are looking for?

— Reply to this email directly, view it on GitHub https://github.com/bmad-sim/AtomicAndPhysicalConstants.jl/issues/15#issuecomment-2005677766, or unsubscribe https://github.com/notifications/unsubscribe-auth/APVF2CEASOVZB44YTEEAQJ3YY6UZLAVCNFSM6AAAAABE3T64DKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBVGY3TONZWGY . You are receiving this because you authored the thread.Message ID: @.***>

lllx125 commented 6 months ago

ok

DavidSagan commented 6 months ago

@lllx125 Suggestion: Before coding, it's best to formulate the API (what the User sees) first. One thing to do is make a list of all the units for the physical constants. For example, some constants have units of speed (c_light for example), etc. Then for each type come up with the different normalization that a User may want. For example, for velocities the User may want to normalize by the speed of light.

mattsignorelli commented 5 months ago

Also start with the more generic units like @DavidSagan said earlier (MKS, CGS, "ParticlePhysicsStandard" etc) because doing custom units (e.g. keV/c^2) will require parsing the units expression and we should all discuss the best way to do that when the time comes

ChristopherMayes commented 5 months ago

Also look at how openPMD stores units: https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#unit-systems-and-dimensionality This is completely general.

lllx125 commented 5 months ago

Thanks

DavidSagan commented 5 months ago

What is wanted here is a system where it is a) simple to set what units are wanted and 2) makes it obvious by looking at the set_units(...) arguments what is happening. For example, normalizing momentum by c should not involve having to type in the value of c. And I would have set_units have multiple optional arguments rather than one string argument.