Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
basic_structs.h
Go to the documentation of this file.
1
8#pragma once
9
10#include "../global/global.h"
11#include "../global/global_cuda.h"
12#include "../utils/gpu.hpp"
13
15{
16// =====================================================================================================================
17// Here are some basic structs that can be used in various places when needed
18// =====================================================================================================================
31template <typename T>
32struct VectorXYZ {
35 T arr_[3];
36
39
45 __device__ __host__ T* data() { return arr_; }
46
57 __device__ __host__ T& operator[](std::size_t i) { return arr_[i]; }
58 __device__ __host__ const T& operator[](std::size_t i) const { return arr_[i]; }
60
68 __device__ __host__ T& x() noexcept { return arr_[0]; }
69 __device__ __host__ const T& x() const noexcept { return arr_[0]; }
70 __device__ __host__ T& y() noexcept { return arr_[1]; }
71 __device__ __host__ const T& y() const noexcept { return arr_[1]; }
72 __device__ __host__ T& z() noexcept { return arr_[2]; }
73 __device__ __host__ const T& z() const noexcept { return arr_[2]; }
75};
76// =====================================================================================================================
77
78// =====================================================================================================================
83struct Conserved {
84 // Hydro variables
85 Real density, energy;
86 VectorXYZ<Real> momentum;
87
88#ifdef MHD
89 // These are all cell centered values
90 VectorXYZ<Real> magnetic;
91#endif // MHD
92
93#ifdef DE
94 Real gas_energy;
95#endif // DE
96
97#ifdef SCALAR
98 Real scalar[grid_enum::nscalars];
99#endif // SCALAR
100
102 Conserved() = default;
104 Conserved(Real const in_density, VectorXYZ<Real> const& in_momentum, Real const in_energy,
105 VectorXYZ<Real> const& in_magnetic = {0, 0, 0}, Real const in_gas_energy = 0.0)
106 : density(in_density), momentum(in_momentum), energy(in_energy)
107 {
108#ifdef MHD
109 magnetic = in_magnetic;
110#endif // mhd
111
112#ifdef DE
113 gas_energy = in_gas_energy;
114#endif // DE
115 };
116};
117// =====================================================================================================================
118
119// =====================================================================================================================
124struct Primitive {
125 // Hydro variable
126 Real density, pressure;
127 VectorXYZ<Real> velocity;
128
129#ifdef MHD
130 // These are all cell centered values
131 VectorXYZ<Real> magnetic;
132#endif // MHD
133
134#ifdef DE
136 Real gas_energy;
137#endif // DE
138
139#ifdef SCALAR
140 Real scalar[grid_enum::nscalars];
141#endif // SCALAR
142
144 Primitive() = default;
147 Primitive(Real const in_density, VectorXYZ<Real> const& in_velocity, Real const in_pressure,
148 VectorXYZ<Real> const& in_magnetic = {0, 0, 0}, Real const in_gas_energy = 0.0)
149 : density(in_density), velocity(in_velocity), pressure(in_pressure)
150 {
151#ifdef MHD
152 magnetic = in_magnetic;
153#endif // mhd
154
155#ifdef DE
156 gas_energy = in_gas_energy;
157#endif // DE
158 };
159};
160// =====================================================================================================================
161} // namespace hydro_utilities
162
163namespace reconstruction
164{
166 // Hydro variables
167 Real density, energy;
170 hydro_utilities::VectorXYZ<Real> velocity, momentum;
171
172#ifdef MHD
173 // These are all cell centered values
174 Real total_pressure;
176#endif // MHD
177
178#ifdef DE
179 Real gas_energy;
180#endif // DE
181
182#ifdef SCALAR
183 Real scalar[grid_enum::nscalars];
184#endif // SCALAR
185
186 // Define the constructors
188 InterfaceState() = default;
191 InterfaceState(Real const in_density, hydro_utilities::VectorXYZ<Real> const in_velocity, Real const in_energy,
192 Real const in_pressure, hydro_utilities::VectorXYZ<Real> const in_magnetic = {0, 0, 0},
193 Real const in_total_pressure = 0.0)
194 : density(in_density), velocity(in_velocity), energy(in_energy), pressure(in_pressure)
195 {
196 momentum.x() = velocity.x() * density;
197 momentum.y() = velocity.y() * density;
198 momentum.z() = velocity.z() * density;
199#ifdef MHD
200 magnetic = in_magnetic;
201 total_pressure = in_total_pressure;
202#endif // MHD
203#ifdef DE
204 gas_energy = 0.0;
205#endif // DE
206 };
207};
208} // namespace reconstruction
Definition basic_structs.h:15
Namespace to contain various utilities for the interface reconstruction kernels.
Definition pcm_cuda.h:23
A data only struct for the conserved variables.
Definition basic_structs.h:83
Conserved(Real const in_density, VectorXYZ< Real > const &in_momentum, Real const in_energy, VectorXYZ< Real > const &in_magnetic={0, 0, 0}, Real const in_gas_energy=0.0)
Manual constructor, mostly used for testing and doesn't init all members.
Definition basic_structs.h:104
Conserved()=default
Default constructor, should init everything to zero.
A data only struct for the primitive variables.
Definition basic_structs.h:124
Primitive(Real const in_density, VectorXYZ< Real > const &in_velocity, Real const in_pressure, VectorXYZ< Real > const &in_magnetic={0, 0, 0}, Real const in_gas_energy=0.0)
Definition basic_structs.h:147
Primitive()=default
Default constructor, should init everything to zero.
A data only struct that acts as a simple 3 element vector.
Definition basic_structs.h:32
__device__ __host__ T & x() noexcept
Directly access the x, y, and z elements. Const version is needed if the object instance is declared ...
Definition basic_structs.h:68
__device__ __host__ T & operator[](std::size_t i)
Overload for the [] operator to allow array-like access. Const version is needed if the object instan...
Definition basic_structs.h:57
__device__ __host__ T * data()
Returns the pointer to the data array.
Definition basic_structs.h:45
T arr_[3]
Definition basic_structs.h:35
Definition basic_structs.h:165
InterfaceState()=default
Default constructor, should set everything to 0.
InterfaceState(Real const in_density, hydro_utilities::VectorXYZ< Real > const in_velocity, Real const in_energy, Real const in_pressure, hydro_utilities::VectorXYZ< Real > const in_magnetic={0, 0, 0}, Real const in_total_pressure=0.0)
Definition basic_structs.h:191
Real pressure
Note that pressure here is the gas pressure not the total pressure which would include the magnetic c...
Definition basic_structs.h:169