-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for unit systems: CGS, CONSTANTS, CUSTOM #782
Conversation
for more information, see https://pre-commit.ci
I think it would make sense to move all of the constants to |
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.
Looks good, except I'd move the definition of all constants into Physics_Traits
.
You could also define the dimensionless parameter chat_over_c
for RadSystem_Traits
instead of chat
itself.
I like both ideas: move all of the constants to |
3ba7764
to
25d6c44
Compare
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
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.
Looks like there is one unresolved conversation with @BenWibking. Once that is resolved, this LGTM.
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
|
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@BenWibking 'Disk quota exceeded' on moth. Can you fix that? |
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
@markkrumholz All issues resolved. Can you approve this? |
Description
In this PR we add the ability to allow the user to choose from one of the three unit systems:
CGS
,CUSTOM
, andCONSTANTS
.CGS:
By setting
unit_system = UnitSystem::CGS
, the user opt to use the CGS units and no constants definition are required. Ifis_radiation_enabled = true
, the user need to also specifyc_hat_over_c
. See examples in HydroShuOsher and RadTube tests.CONSTANTS:
By setting
unit_system = UnitSystem::CONSTANTS
, the user need to defineboltzmann_constant
andgravitational_constant
for hydro simulations. Ifis_radiation_enabled = true
, the user need to also definec_light
,c_hat_over_c
, andradiation_constant
. See examples in theRadhydroShock
test.CUSTOM:
By setting
unit_system = UnitSystem::CUSTOM
, the user opt to use a custom unit system. The values of the following variables need to be given in cgs units:unit_length, unit_mass, unit_time, unit_temperature
. Ifis_radiation_enabled = true
, the user need to also definec_hat
in code units. See examples in theRadLineCooling
andRadhydroShockCGS
tests.Other changes include:
AMRSimulation
class:unit_length, unit_mass, unit_time, unit_temperature
. They give the unit length, mass, time, and temperature in CGS units (cm, g, s, and K).metadata.yaml
located inside every plotfile and checkpoint outputs:unit_length, unit_mass, unit_time, unit_temperature, c, c_hat, k_B, a_rad, G
. The values ofunit_xxx
are given in CGS units and the values ofc, c_hat, k_B, a_rad, G
are given in code units.Physics_Traits::gravitational_constant
.A typical
metadata.yaml
file looks like this:Footnote: When
CONSTANTS
is chosen, I setunit_xxx
toNAN
for two reasons. First, when radiation is turned off, the units are unconstrained because it's not possible to deriveunit_xxx
from only two constants,boltzmann_constant
andgravitational_constant
. Second, theCONSTANTS
unit system is only used for testing purpose and we don't care about the physical dimensions of the variables.Related issues
Resolves #780
Checklist
Before this pull request can be reviewed, all of these tasks should be completed. Denote completed tasks with an
x
inside the square brackets[ ]
in the Markdown source below:/azp run
.Appendix: Units conversion
Here I show how to convert between CGS, CONSTANTS, and CUSTOM unit system.
Let the code units of length, mass, time, and temperature expressed in CGS units be$u_l, u_m, u_t, u_T$ . Let $G$ , $k_B$ , $c$ , and $a_R$ be the values of the gravitational constant, Boltzmann constant, speed of light, and radiation constant in CGS units, respectively. Assume the values of those constants in code units are $\hat{G}, \hat{k}_B, \hat{c}, \hat{a}_R$ . The following relations apply:
To convert from$\hat{G}$ etc into $u_l$ etc, we want to solve for $u_l$ etc from this set of four equations. By taking logarithm on both sides of the equations, we can turn them into a system of linear equations:
A simple matrix inversion gives
or, expressing explicitly,
where$\bar{d} \equiv \left(\bar{k}^4 / \bar{a}_R\right)^{1 / 6}$ . These equations are used to derive
unit_length
etc in theRadLineCooling
test.