-
Notifications
You must be signed in to change notification settings - Fork 32
Grid_Enum and adding passive scalars
Cholla stores all of the conserved variables in a single contiguous array (per GPU). This means that the location of a given variable will always correspond to an integer times the total number of grid cells, i.e. density is located at location 0, x momentum at location 1*ncells, etc. Because Cholla has many possible fields, not all of which are allocated for every build type, we use a C++ Enum to keep track of data field offsets in the grid. This list is defined in grid_enum.h
. In general, this can be used with a cell id to access values in the conserved variable array in either device or host code (though note that the host arrays are only updated when data is being output). For example, to access the value of the total Energy field within a kernel, one could use conserved[id + n_cells*grid_enum::Energy]
. n_cells
may be H.n_cells
or G.H.n_cells
as appropriate for the scope of the function.
Passive scalars are advected fields. To add a new scalar field, it must be included in the grid_enum.h
list of scalars, wrapped in the appropriate #ifdef
s. See the "basic_scalar" field for an example. Cholla will automatically advect the new scalar as long as it has been enrolled within the scalar block of grid_enum. To access it in code, you can then use conserved[id+n_cells*grid_enum::your_scalar_name]
.
WARNING: adding a new field in grid_enum
does NOT create Conserved objects on the host that look like C.your_scalar_name
or C.d_your_scalar_name
--if you want those, you'll have to create them yourself.
New scalar fields will not be output by default. For output, you will need to modify the appropriate function in io.cpp (Write_Grid_HDF5, as of 1-18-2024). If applicable, it also needs to be added to read appropriately when using init=Read_Grid
(e.g. for restarts).