Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
grid_enum.h
1#pragma once
2
3// An enum which holds offsets for grid quantities
4// In the final form of this approach, this file will also set nfields (not yet)
5// and NSCALARS (done) so that adding a field only requires registering it here:
6// grid knows to allocate memory based on nfields and NSCALARS
7// and values can be accessed with density[id + ncells*grid_enum::enum_name]
8// example: C.device[id + H.n_cells*grid_enum::basic_scalar]
9
10// enum notes:
11// For advanced devs: to be implicitly treated as int,
12// The enum cannot use "enum class" or "enum struct."
13// This is referred to as an "unscoped enum:" grid_enum is "unscoped"
14// Though we give it an effective scope by wrapping it in a namespace.
15
16// Enum is wrapped in namespace to give
17// it an effective scope to prevent collisions.
18
19// Enum values (i.e. density) belong
20// to their enclosing scope, which necessitates the namespace wrapping
21// --otherwise "density" would be available in global scope.
22
23// The ": int" forces underlying type to be int.
24
25// if you update this enum, make sure that you also update the pack_arr_ variable from
26// field_info.cpp
27
28namespace grid_enum
29{
30enum : int {
31
32 // Don't change order of hydro quantities until all of hydro is made
33 // consistent with grid_enum (if ever) because enum values depend on order
34 density,
35 momentum_x,
36 momentum_y,
37 momentum_z,
38 Energy,
39
40 // Code assumes scalars are a contiguous block
41 // Always define scalar, scalar_minus_1, finalscalar_plus_1, finalscalar to
42 // compute NSCALARS
43 scalar,
44 scalar_minus_1 = scalar - 1, // so that next enum item starts at same index as scalar
45
46#ifdef SCALAR
47 // Add scalars here, wrapped appropriately with ifdefs:
48 #ifdef BASIC_SCALAR
49 basic_scalar,
50 #endif
51
52 #if defined(COOLING_GRACKLE) || defined(CHEMISTRY_GPU)
53 HI_density,
54 HII_density,
55 HeI_density,
56 HeII_density,
57 HeIII_density,
58 e_density,
59 #ifdef GRACKLE_METALS
60 metal_density,
61 #endif
62 #endif
63
64 #ifdef DUST
65 dust_density,
66 #endif // DUST
67
68#endif // SCALAR
69
70 finalscalar_plus_1, // needed to calculate NSCALARS
71 finalscalar = finalscalar_plus_1 - 1, // resets enum to finalscalar so fields afterwards are correct
72// so that anything after starts with scalar + NSCALARS
73
74#ifdef MHD
75 magnetic_x,
76 magnetic_y,
77 magnetic_z,
78#endif
79#ifdef DE
80 GasEnergy,
81#endif
82 num_fields,
83
84 // Aliases and manually computed enums
85 nscalars = finalscalar_plus_1 - scalar,
86
87#ifdef MHD
88 num_flux_fields = num_fields - 1,
89 num_interface_fields = num_fields - 1,
90#else
91 num_flux_fields = num_fields,
92 num_interface_fields = num_fields,
93#endif // MHD
94
95#ifdef MHD
96 magnetic_start = magnetic_x,
97 magnetic_end = magnetic_z,
98
99 ct_elec_x = 0,
100 ct_elec_y = 1,
101 ct_elec_z = 2,
102
103 // Note that the direction of the flux, the suffix _? indicates the direction
104 // of the electric field, not the magnetic flux
105 fluxX_magnetic_z = magnetic_start,
106 fluxX_magnetic_y = magnetic_start + 1,
107 fluxY_magnetic_x = magnetic_start,
108 fluxY_magnetic_z = magnetic_start + 1,
109 fluxZ_magnetic_y = magnetic_start,
110 fluxZ_magnetic_x = magnetic_start + 1,
111
112 Q_x_magnetic_y = magnetic_start,
113 Q_x_magnetic_z = magnetic_start + 1,
114 Q_y_magnetic_z = magnetic_start,
115 Q_y_magnetic_x = magnetic_start + 1,
116 Q_z_magnetic_x = magnetic_start,
117 Q_z_magnetic_y = magnetic_start + 1
118#endif // MHD
119
120};
121} // namespace grid_enum
122
123#define NSCALARS grid_enum::nscalars