1+ .. role :: python(code)
2+ :language: python
3+ :class: highlight
4+
15.. _units :
26
37Units in EXP and pyEXP
@@ -6,23 +10,26 @@ Units in EXP and pyEXP
610Overview
711--------
812
9- The EXP N-body code assumes the gravitational constant is unity,
10- `` G=1 ``, and that mass, position and velocity units can have any
11- value defined by the user. In other words, EXP does not enforce any
12- particular unit set.
13+ The EXP N-body code assumes the gravitational constant is unity and
14+ that mass, position and velocity units can have any value defined by
15+ the user. In other words, the EXP N-body code does not enforce any
16+ particular unit set consistent with `` G=1 `` .
1317
1418pyEXP will also accept mass, position, time, and velocity with any
1519unit set defined by the imported simulation as well as an arbitrary
1620value of the gravitational constant. Explicit units types and the
1721gravitational constant ``G `` may be set at construction time as we
1822will describe below in :ref: `unit-schema `. pyEXP **requires ** the
1923user to set units explicitly when coefficient sets are
20- constructed. See :ref: `intro-pyEXP-tutorial `. There is no default.
24+ constructed. There is no default. See :ref: `intro-pyEXP-tutorial ` for
25+ an end-to-end example of coefficient computation.
2126
2227All unit information is written into the EXP coefficient files as HDF5
23- attributes. Also see :ref: `hdf5-unit-attributes ` for details.
28+ attributes. Also see :ref: `hdf5-unit-attributes ` for details. You
29+ may add units to previously computed coefficient files using the
30+ script described in :ref: `units_old `.
2431
25- .. _unit-scheme :
32+ .. _unit-schema :
2633
2734The EXP unit schema
2835-------------------
@@ -34,7 +41,12 @@ EXP requires one of the following two sequences of 4 unit types:
34412. Mass, Length, Velocity, gravitational constant (G)
3542
3643
37- Each unit is a ``tuple `` which takes the form::
44+ Other combinations are possible in principle, such as Mass, Length,
45+ Velocity and Time. However, this would require an automatic deduction
46+ of the gravitational constant. EXP does not current know about
47+ physical unit conversion. This feature may be added in the future.
48+
49+ Each separate unit is defined as a ``tuple `` which takes the form::
3850
3951 ('unit type', 'unit name', <float value>)
4052
@@ -57,8 +69,8 @@ The type and name strings are checked against the allowed values as follows:
5769 The value can be any valid floating-point number.
5870
5971The allowed types and names may be queried interactively in pyEXP
60- using the `` getAllowedUnitTypes() ` ` and
61- `` getAllowedUnitNames(type) ` `, see :ref: `units-interface `. For
72+ using the :python: ` getAllowedUnitTypes() ` and
73+ :python: ` getAllowedUnitNames(type) `, see :ref: `units-interface `. For
6274development reference, these allowed strings are defined in
6375``expui/UnitValidator.cc `` in the EXP source tree.
6476
@@ -67,13 +79,14 @@ As an example, a Gadget user might define mass units as::
6779 ('mass', 'Msun', 1.0e10)
6880
6981The full units specification is a list of tuples that includes one of
70- the four sequences. In C++, the list is a ``std::vector `` of tuples.
82+ the four sequences. In C++, the list is a :cpp:any: `std::vector<> ` of
83+ tuples.
7184
7285As an example, all native EXP simulations have the following unit
73- lists::
86+ lists:
7487
75- [('mass', 'none', 1.0f), ('length', 'none', 1.0f), ('time', 'none',
76- 1.0f), ('G', 'none', 1.0f)]
88+ .. code-block :: python
89+ [( ' mass ' , ' none ' , 1. 0f ), ( ' length ' , ' none ' , 1. 0f ), ( ' time ' , ' none ' , 1. 0f ), (' G' , ' none' , 1. 0f )]
7790
7891
7992 Units in pyEXP
@@ -119,24 +132,28 @@ is called ``coefs``. The following command will register the unit set:
119132 (' velocity' , ' km/s' , 1.0 ), (' G' , ' mixed' , 43007.1 ) ])
120133
121134 These units will be in the HDF5 that you create using
122- `` coefs.WriteH5Coefs('filename') `` . You can query, for example, the
123- allowed 'mass' units with the call
124- `` coefs.getAllowedUnitNames('mass') ` ` which returns:
135+ :python: ` coefs.WriteH5Coefs('filename') `. You can query, for example,
136+ the allowed 'mass' units with the call
137+ :python: ` coefs.getAllowedUnitNames('mass') ` which returns:
125138
126139 .. code-block :: python
127140
128141 [' gram' , ' earth_mass' , ' solar_mass' , ' kilograms' , ' kg' , ' g' , ' Mearth' , ' Msun' , ' None' , ' none' ]
129142
130- A quick note: 'mixed' is an allowed alias when dealing with
131- gravitational constants that have physical units. You can see all
132- unit types with ``getAllowedUnitTypes() ``; this returns ``['mass',
133- 'length', 'time', 'velocity', 'G'] ``. You can see the recognized
134- aliases for each type using ``getAllowedTypeAliases(type) ``. For
135- example, the recognized aliases for 'G' are:
143+ The allowed mass units for 'G' are:
136144
137145 .. code-block :: python
138146
139- [' G' , ' Grav' , ' Grav_constant' , ' Gravitational_constant' , ' grav' , ' grav_constant' , ' gravitational_constant' ]
147+ [' gram' , ' earth_mass' , ' solar_mass' , ' kilograms' , ' kg' , ' g' , ' Mearth' , ' Msun' , ' None' , ' none' ]
148+
149+
150+ A quick note: 'mixed' is an allowed alias when dealing with
151+ gravitational constants that have physical units. You can see all
152+ unit types with :python: `getAllowedUnitTypes() `; this returns
153+ :python: `['mass', 'length', 'time', 'velocity', 'G'] `. You can see
154+ the recognized aliases for each type using
155+ :python: `getAllowedTypeAliases(type) `. The gravitational constant is
156+ a special case. The recognized unit names for 'G' are: :python: `['','mixed', 'none', 'unitless']` `.
140157
141158The C++ UI echos the functions above and adds functions to retrieve
142159units
@@ -167,8 +184,8 @@ developers creating new coefficient classes.
167184The HDF5 specification
168185----------------------
169186
170- .. note :: This section assumes basic familiarity with HDF5 and `h5py`
171- in particular.
187+ .. note :: This and the following sections assumes basic familiarity
188+ with HDF5 and ` h5py ` in particular.
172189
173190EXP HDF5 coefficient files contain a full set of metadata describing
174191their basis type, basis parameters, geometry, and units as attributes
@@ -226,6 +243,11 @@ group with the following hierarchy::
226243 }
227244
228245
246+ .. _units_old :
247+
248+ Backward compatibility
249+ ----------------------
250+
229251A units attribute list could be easily added to existing HDF5 files
230252using `h5py ` using the schema described above. For example, assuming
231253that you already have an open HDF5 coefficient file named `f `, the
@@ -264,3 +286,6 @@ following code:
264286
265287 # File is automatically closed on leaving the 'with' block, flush and
266288 # update saved data on disk
289+
290+ You can update the :python: `data ` array in the example above to match your
291+ unit set.
0 commit comments