Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
ct_electric_fields.h
Go to the documentation of this file.
1
10#pragma once
11
12// STL Includes
13
14// External Includes
15
16// Local Includes
17#include "../global/global.h"
18#include "../global/global_cuda.h"
19#include "../utils/cuda_utilities.h"
20#include "../utils/gpu.hpp"
21
22#ifdef MHD
23namespace mhd
24{
31namespace internal
32{
33// =====================================================================
66inline __host__ __device__ Real _ctSlope(Real const *flux, Real const *dev_conserved, Real const &fluxSign,
67 int const &ctDirection, int const &conservedQuadrent1,
68 int const &conservedQuadrent2, int const &fluxQuadrent1,
69 int const &fluxQuadrent2, int const &xid, int const &yid, int const &zid,
70 int const &nx, int const &ny, int const &n_cells)
71{
72 // Compute the various required indices
73
74 // Get the shifted modulos of the ctDirection.
75 int const modPlus1 = (ctDirection + 1) % 3;
76 int const modPlus2 = (ctDirection + 2) % 3;
77
78 // Indices for the cell centered values
79 int const xidCentered = xid - int(conservedQuadrent1 == 0) - int(conservedQuadrent2 == 0);
80 int const yidCentered = yid - int(conservedQuadrent1 == 1) - int(conservedQuadrent2 == 1);
81 int const zidCentered = zid - int(conservedQuadrent1 == 2) - int(conservedQuadrent2 == 2);
82 int const idxCentered = cuda_utilities::compute1DIndex(xidCentered, yidCentered, zidCentered, nx, ny);
83
84 // Index for the flux
85 int const idxFlux = cuda_utilities::compute1DIndex(xid - int(fluxQuadrent1 == 0) - int(fluxQuadrent2 == 0),
86 yid - int(fluxQuadrent1 == 1) - int(fluxQuadrent2 == 1),
87 zid - int(fluxQuadrent1 == 2) - int(fluxQuadrent2 == 2), nx, ny);
88
89 // Indices for the face centered magnetic fields that need to be averaged
90 int const idxB2Shift = cuda_utilities::compute1DIndex(
91 xidCentered - int(modPlus1 == 0), yidCentered - int(modPlus1 == 1), zidCentered - int(modPlus1 == 2), nx, ny);
92 int const idxB3Shift = cuda_utilities::compute1DIndex(
93 xidCentered - int(modPlus2 == 0), yidCentered - int(modPlus2 == 1), zidCentered - int(modPlus2 == 2), nx, ny);
94
95 // Load values for cell centered electric field. B1 (not present) is
96 // the magnetic field in the same direction as the `ctDirection`
97 // variable, B2 and B3 are the next two fields cyclically. i.e. if
98 // B1=Bx then B2=By and B3=Bz, if B1=By then B2=Bz and B3=Bx. The
99 // same rules apply for the momentum
100 Real const density = dev_conserved[idxCentered + grid_enum::density * n_cells];
101 Real const Momentum2 = dev_conserved[idxCentered + (modPlus1 + grid_enum::momentum_x) * n_cells];
102 Real const Momentum3 = dev_conserved[idxCentered + (modPlus2 + grid_enum::momentum_x) * n_cells];
103 Real const B2Centered = 0.5 * (dev_conserved[idxCentered + (modPlus1 + grid_enum::magnetic_start) * n_cells] +
104 dev_conserved[idxB2Shift + (modPlus1 + grid_enum::magnetic_start) * n_cells]);
105 Real const B3Centered = 0.5 * (dev_conserved[idxCentered + (modPlus2 + grid_enum::magnetic_start) * n_cells] +
106 dev_conserved[idxB3Shift + (modPlus2 + grid_enum::magnetic_start) * n_cells]);
107
108 // Compute the electric field in the center with a cross product
109 Real const electric_centered = (Momentum3 * B2Centered - Momentum2 * B3Centered) / density;
110
111 // Load face centered electric field, note fluxSign to correctly do
112 // the shift from magnetic flux to EMF/electric field and to choose
113 // which field to use
114 Real const electric_face = fluxSign * flux[idxFlux + (int(fluxSign == 1) + grid_enum::magnetic_start) * n_cells];
115
116 // Compute the slope and return it
117 // S&G 2009 equation 24
118 return electric_face - electric_centered;
119}
120// =====================================================================
121} // namespace internal
122
123// =========================================================================
139__global__ void Calculate_CT_Electric_Fields(Real const *fluxX, Real const *fluxY, Real const *fluxZ,
140 Real const *dev_conserved, Real *ctElectricFields, int const nx,
141 int const ny, int const nz, int const n_cells);
142// =========================================================================
143} // end namespace mhd
144#endif // MHD
Namespace for MHD code.
Definition magnetic_divergence.h:26