-
Notifications
You must be signed in to change notification settings - Fork 183
Modification to the Units module #673
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
Open
rjtanner
wants to merge
9
commits into
PrincetonUniversity:main
Choose a base branch
from
rjtanner:unit_mod
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
794c143
Add updated units module
rjtanner 1c680f7
Update unit module
rjtanner dfeadd2
Update constant names
rjtanner 9ed723e
Add au to units
rjtanner 2060702
Merge branch 'main' into unit_mod
felker 1a62f4a
Fix some linter errors
felker 5061155
Fix style errors
felker 36724d0
update renamed unit varnames
felker 3fb4fbf
Merge branch 'main' into unit_mod
msbc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| <comment> | ||
| problem = unit test | ||
| configure = --prob=unit_test | ||
|
|
||
| <job> | ||
| problem_id = unit_test # problem ID: basename of output filenames | ||
|
|
||
| <output1> | ||
| file_type = hdf5 # Binary data dump | ||
| variable = prim # variables to be output | ||
| dt = 1.0 # time increment between outputs | ||
|
|
||
| <time> | ||
| cfl_number = 0.4 # The Courant, Friedrichs, & Lewy (CFL) Number | ||
| nlim = 0 # cycle limit | ||
| tlim = 4.0 # time limit | ||
|
|
||
| <mesh> | ||
| nx1 = 64 # Number of zones in X1-direction | ||
| x1min = -15.0 # minimum value of X1 | ||
| x1max = 15.0 # maximum value of X1 | ||
| ix1_bc = periodic # inner-X1 boundary flag | ||
| ox1_bc = periodic # outer-X1 boundary flag | ||
|
|
||
| nx2 = 64 # Number of zones in X2-direction | ||
| x2min = -12.5 # minimum value of X2 | ||
| x2max = 12.5 # maximum value of X2 | ||
| ix2_bc = periodic # inner-X2 boundary flag | ||
| ox2_bc = periodic # outer-X2 boundary flag | ||
|
|
||
| nx3 = 64 # Number of zones in X3-direction | ||
| x3min = -10.0 # minimum value of X3 | ||
| x3max = 10.0 # maximum value of X3 | ||
| ix3_bc = periodic # inner-X3 boundary flag | ||
| ox3_bc = periodic # outer-X3 boundary flag | ||
|
|
||
| <hydro> | ||
| gamma = 1.666666666667 # gamma = C_p/C_v | ||
|
|
||
| <problem> | ||
| # Values of length, time, mass, ndensity, and velocity can be in | ||
| # the units of the basis unit system. | ||
| # All other values (e.g. energy, pressure, etc.) will have to be | ||
| # in cgs units. | ||
| pamb = 1.1 # ambient pressure in **cgs** units | ||
| energy = 2.2 # energy value in **cgs** units | ||
| ndamb = 3.3 # ambient number density (ndensity) in physical units | ||
| ndin = 4.4 # number density (ndensity) inside radius in physical units | ||
| radius = 5.5 # radius of high density in physical units | ||
| mass_val = 6.6 # mass value in physical units | ||
| vel = 7.7 # velocity value in physical units | ||
|
|
||
| <units> | ||
| #Default value for the mean atomic weight is 1.4 | ||
| mean_weight = 1.4 | ||
|
|
||
| #Preset unit systems | ||
| unit_system = ism | ||
| #unit_system = galaxy | ||
| #unit_system = galaxypc | ||
| #unit_system = ism_SR | ||
| #unit_system = cgs | ||
| #unit_system = SI | ||
|
|
||
| #Examples of custom_basis unit systems | ||
| #Default units are: | ||
| # length_unit = pc | ||
| # time_unit = Myr | ||
| # velocity_unit = km/s | ||
| # ndensity_unit = n/cm^3 | ||
| # mass_unit = Msun | ||
|
|
||
| #Recreates "ism" unit system | ||
| #unit_system = custom_basis | ||
| #length = 1.0 # pc | ||
| #velocity = 1.0 # km/s | ||
| #ndensity = 1.0 # n/cm^3 | ||
|
|
||
| #Recreates "galaxy" unit system | ||
| #unit_system = custom_basis | ||
| #length = 1.0 # kpc | ||
| #length_unit = kpc | ||
| #time = 1.0 # Myr | ||
| #ndensity = 1.0 # n/cm^3 | ||
|
|
||
| #Recreates "galaxypc" unit system | ||
| #unit_system = custom_basis | ||
| #length = 1.0 # pc | ||
| #time = 1.0 # Myr | ||
| #ndensity = 1.0 # n/cm^3 | ||
|
|
||
| #Recreates "ism_SR" unit system | ||
| #unit_system = custom_basis | ||
| #length = 1.0 # pc | ||
| #velocity = 2.99792458e5 # km/s | ||
| #ndensity = 1.0 # n/cm^3 | ||
|
|
||
| #Recreates cgs unit system | ||
| #unit_system = custom_basis | ||
| #length = 1.0 | ||
| #length_unit = cm | ||
| #time = 1.0 | ||
| #time_unit = s | ||
| #mass = 1.0 | ||
| #mass_unit = g | ||
| #velocity_unit = cm/s | ||
|
|
||
| #Recreates SI unit system | ||
| #unit_system = custom_basis | ||
| #length = 1.0 | ||
| #length_unit = m | ||
| #time = 1.0 | ||
| #time_unit = s | ||
| #mass = 1.0 | ||
| #mass_unit = kg | ||
| #velocity_unit = m/s | ||
| #ndensity_unit = n/m^3 | ||
|
|
||
| #Example of a "custom" unit system | ||
| #Recreates "ism" unit system | ||
| #unit_system = custom | ||
| #mass_cgs = 6.882618e+31 # 1 n/cm^3*pc^3 | ||
| #length_cgs = 3.08567758e+18 # 1 pc | ||
| #time_cgs = 3.085678e+13 # 1 pc/1 km/s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| //======================================================================================== | ||
| // Athena++ astrophysical MHD code | ||
| // Copyright(C) 2014 James M. Stone <jmstone@princeton.edu> and other code contributors | ||
| // Licensed under the 3-clause BSD License, see LICENSE file for details | ||
| //======================================================================================== | ||
| //! \file unit_test.cpp | ||
| //! \brief Problem file to demonstrate unit module | ||
| //! | ||
|
|
||
| // C headers | ||
|
|
||
| // C++ headers | ||
| #include <algorithm> | ||
| #include <cmath> | ||
| #include <cstdio> // fopen(), fprintf(), freopen() | ||
| #include <cstring> // strcmp() | ||
| #include <sstream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| // Athena++ headers | ||
| #include "../athena.hpp" | ||
| #include "../athena_arrays.hpp" | ||
| #include "../coordinates/coordinates.hpp" | ||
| #include "../eos/eos.hpp" | ||
| #include "../field/field.hpp" | ||
| #include "../globals.hpp" | ||
| #include "../hydro/hydro.hpp" | ||
| #include "../mesh/mesh.hpp" | ||
| #include "../parameter_input.hpp" | ||
|
|
||
| void Mesh::InitUserMeshData(ParameterInput *pin) { | ||
| // Get units pointer | ||
| Units *punit = Mesh::punit; | ||
| // Print units info | ||
| punit->PrintBasisUnits(); | ||
| punit->PrintCodeUnits(); | ||
| punit->PrintConstantsInCodeUnits(); | ||
|
|
||
| std::string lunit = std::get<1>(punit->basis_length); | ||
| std::string tunit = std::get<1>(punit->basis_time); | ||
| std::string munit = std::get<1>(punit->basis_mass); | ||
| std::string vunit = std::get<1>(punit->basis_velocity); | ||
| std::string nunit = std::get<1>(punit->basis_ndensity); | ||
|
|
||
| // Convert time and mesh values from input file | ||
| Real tlim0 = pin->GetReal("time", "tlim"); | ||
| Real dt0 = pin->GetReal("output1", "dt"); | ||
| Real x1max0 = pin->GetReal("mesh", "x1max"); | ||
| punit->ConvertInputFile(pin); | ||
| Real tlim1 = pin->GetReal("time", "tlim"); | ||
| Real dt1 = pin->GetReal("output1", "dt"); | ||
| Real x1max1 = pin->GetReal("mesh", "x1max"); | ||
|
|
||
| std::cout << "=== Values from input file converted ===" << std::endl; | ||
| std::cout << "From the <time> block:" << std::endl; | ||
| std::cout << " tlim before conversion = " << tlim0 << " " << tunit << std::endl; | ||
| std::cout << " tlim after conversion = " << tlim1 << " code time" << std::endl; | ||
| std::cout << std::endl; | ||
| std::cout << "From the <output1> block:" << std::endl; | ||
| std::cout << " dt before conversion = " << dt0 << " " << tunit << std::endl; | ||
| std::cout << " dt after conversion = " << dt1 << " code time" << std::endl; | ||
| std::cout << std::endl; | ||
| std::cout << "From the <mesh> block:" << std::endl; | ||
| std::cout << " x1max before conversion = " << x1max0 << " " << lunit << std::endl; | ||
| std::cout << " x1max after conversion = " << x1max1 << " code length" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
|
|
||
| // Pressure | ||
| Real pres = pin->GetReal("problem", "pamb"); | ||
| Real pres_code = pres/punit->code_pressure_cgs; | ||
| std::cout << "Pressure value in cgs units = " << pres << " dyne" << std::endl; | ||
| std::cout << "Pressure value in code units = " << pres_code | ||
| << " code pressure" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
| // Energy | ||
| Real en = pin->GetReal("problem", "energy"); | ||
| Real en_code = en/punit->code_energy_cgs; | ||
| std::cout << "Energy value in cgs units = " << en << " erg" << std::endl; | ||
| std::cout << "Energy value in code units = " << en_code << " code energy" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
| // Mass | ||
| Real mass = pin->GetReal("problem", "mass_val"); | ||
| Real mass_code = mass/std::get<0>(punit->basis_mass); | ||
| std::cout << "Mass value in basis units = " << mass << " " << munit << std::endl; | ||
| std::cout << "Mass value in code units = " << mass_code << " code mass" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
| // Length | ||
| Real rad = pin->GetReal("problem", "radius"); | ||
| Real rad_code = rad/std::get<0>(punit->basis_length); | ||
| std::cout << "Length value in basis units = " << rad << " " << lunit << std::endl; | ||
| std::cout << "Length value in code units = " << rad_code | ||
| << " code length" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
| // Velocity | ||
| Real vel = pin->GetReal("problem", "vel"); | ||
| Real vel_code = vel/std::get<0>(punit->basis_velocity); | ||
| std::cout << "Velocity value in basis units = " << vel << " " << vunit << std::endl; | ||
| std::cout << "Velocity value in code units = " << vel_code | ||
| << " code velocity" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
| // ndensity | ||
| Real ndin = pin->GetReal("problem", "ndin"); | ||
| Real ndin_code = ndin/std::get<0>(punit->basis_ndensity); | ||
| std::cout << "ndensity value in basis units = " << ndin << " " << nunit << std::endl; | ||
| std::cout << "ndensity value in code units = " << ndin_code | ||
| << " code ndensity" << std::endl; | ||
| std::cout << std::endl; | ||
|
|
||
| std::cout << "Gravitational constant in code units = " | ||
| << punit->Gconst_code << std::endl; | ||
| return; | ||
| } | ||
|
|
||
| //======================================================================================== | ||
| //! \fn void MeshBlock::ProblemGenerator(ParameterInput *pin) | ||
| //! \brief | ||
| //======================================================================================== | ||
|
|
||
| void MeshBlock::ProblemGenerator(ParameterInput *pin) { | ||
| // Get units pointer | ||
| Units *punit = MeshBlock::pmy_mesh->punit; | ||
|
|
||
| Real pres = pin->GetReal("problem", "pamb")/punit->code_pressure_cgs; | ||
| Real da = pin->GetReal("problem", "ndamb")/std::get<0>(punit->basis_ndensity); | ||
| Real din = pin->GetReal("problem", "ndin")/std::get<0>(punit->basis_ndensity); | ||
| Real rin = pin->GetReal("problem", "radius")/std::get<0>(punit->basis_length); | ||
| Real vel = pin->GetReal("problem", "vel")/std::get<0>(punit->basis_velocity); | ||
|
|
||
| Real gamma = peos->GetGamma(); | ||
| Real gm1 = gamma - 1.0; | ||
|
|
||
| // setup uniform ambient medium with spherical over-pressured region | ||
| for (int k=ks; k<=ke; k++) { | ||
| for (int j=js; j<=je; j++) { | ||
| for (int i=is; i<=ie; i++) { | ||
| Real x = pcoord->x1v(i); | ||
| Real y = pcoord->x2v(j); | ||
| Real z = pcoord->x3v(k); | ||
| Real rad = std::sqrt(SQR(x) + SQR(y) + SQR(z)); | ||
| Real den = da; | ||
| if (rad < rin) { | ||
| den = din; | ||
| } | ||
| phydro->u(IDN,k,j,i) = den; | ||
| phydro->u(IM1,k,j,i) = vel; | ||
| phydro->u(IM2,k,j,i) = vel/2; | ||
| phydro->u(IM3,k,j,i) = vel/3; | ||
| phydro->u(IEN,k,j,i) = pres/gm1; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| //======================================================================================== | ||
| //! \fn void Mesh::UserWorkAfterLoop(ParameterInput *pin) | ||
| //! \brief Print yt units override | ||
| //======================================================================================== | ||
|
|
||
| void Mesh::UserWorkAfterLoop(ParameterInput *pin) { | ||
| Units *punit = Mesh::punit; | ||
| // Prints a Python dictionary to use units_override | ||
| // when loading hdf5 data into yt. | ||
| punit->PrintytUnitsOverride(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In C, real numbers should be written like 2.0, 3.0.