Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Shocktest.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Vlasiator.
3 * Copyright 2010-2016 Finnish Meteorological Institute
4 *
5 * For details of usage, see the COPYING file and read the "Rules of the Road"
6 * at http://www.physics.helsinki.fi/vlasiator/
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include <cstdlib>
24#include <iostream>
25#include <cmath>
29
30#include "Shocktest.h"
31#include "../../common.h"
32#include "../project.h"
33#include "../../parameters.h"
36
37using namespace std;
38using namespace spatial_cell;
39
40namespace projects {
41
42 Shocktest::Shocktest() : TriAxisSearch() {} // Constructor
43 Shocktest::~Shocktest() {} // Destructor
44
45
47
49 typedef Readparameters RP;
50 RP::add("Shocktest.rho1", "Number density, left state (m^-3)", 0.0);
51 RP::add("Shocktest.rho2", "Number density, right state (m^-3)", 0.0);
52 RP::add("Shocktest.T1", "Temperature, left state (K)", 0.0);
53 RP::add("Shocktest.T2", "Temperature, right state (K)", 0.0);
54 RP::add("Shocktest.Vx1", "Bulk velocity x component, left state (m/s)", 0.0);
55 RP::add("Shocktest.Vx2", "Bulk velocity x component, right state (m/s)", 0.0);
56 RP::add("Shocktest.Vy1", "Bulk velocity y component, left state (m/s)", 0.0);
57 RP::add("Shocktest.Vy2", "Bulk velocity y component, right state (m/s)", 0.0);
58 RP::add("Shocktest.Vz1", "Bulk velocity z component, left state (m/s)", 0.0);
59 RP::add("Shocktest.Vz2", "Bulk velocity z component, right state (m/s)", 0.0);
60 RP::add("Shocktest.Bx1", "Magnetic field x component, left state (T)", 0.0);
61 RP::add("Shocktest.Bx2", "Magnetic field x component, right state (T)", 0.0);
62 RP::add("Shocktest.By1", "Magnetic field y component, left state (T)", 0.0);
63 RP::add("Shocktest.By2", "Magnetic field y component, right state (T)", 0.0);
64 RP::add("Shocktest.Bz1", "Magnetic field z component, left state (T)", 0.0);
65 RP::add("Shocktest.Bz2", "Magnetic field z component, right state (T)", 0.0);
66 }
67
70
71 if(getObjectWrapper().particleSpecies.size() > 1) {
72 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
73 abort();
74 }
75 this->rho[this->LEFT] = {NAN};
76 this->T[this->LEFT] = {NAN};
77 this->Vx[this->LEFT] = {NAN};
78 this->Vy[this->LEFT] = {NAN};
79 this->Vz[this->LEFT] = {NAN};
80 this->Bx[this->LEFT] = {NAN};
81 this->By[this->LEFT] = {NAN};
82 this->Bz[this->LEFT] = {NAN};
83 this->rho[this->RIGHT] = {NAN};
84 this->T[this->RIGHT] = {NAN};
85 this->Vx[this->RIGHT] = {NAN};
86 this->Vy[this->RIGHT] = {NAN};
87 this->Vz[this->RIGHT] = {NAN};
88 this->Bx[this->RIGHT] = {NAN};
89 this->By[this->RIGHT] = {NAN};
90 this->Bz[this->RIGHT] = {NAN};
91
92 typedef Readparameters RP;
93 RP::get("Shocktest.rho1", this->rho[this->LEFT]);
94 RP::get("Shocktest.rho2", this->rho[this->RIGHT]);
95 RP::get("Shocktest.T1", this->T[this->LEFT]);
96 RP::get("Shocktest.T2", this->T[this->RIGHT]);
97 RP::get("Shocktest.Vx1", this->Vx[this->LEFT]);
98 RP::get("Shocktest.Vx2", this->Vx[this->RIGHT]);
99 RP::get("Shocktest.Vy1", this->Vy[this->LEFT]);
100 RP::get("Shocktest.Vy2", this->Vy[this->RIGHT]);
101 RP::get("Shocktest.Vz1", this->Vz[this->LEFT]);
102 RP::get("Shocktest.Vz2", this->Vz[this->RIGHT]);
103 RP::get("Shocktest.Bx1", this->Bx[this->LEFT]);
104 RP::get("Shocktest.Bx2", this->Bx[this->RIGHT]);
105 RP::get("Shocktest.By1", this->By[this->LEFT]);
106 RP::get("Shocktest.By2", this->By[this->RIGHT]);
107 RP::get("Shocktest.Bz1", this->Bz[this->LEFT]);
108 RP::get("Shocktest.Bz2", this->Bz[this->RIGHT]);
109 }
110
112 const uint popID,
113 const uint nRequested
114 ) const {
115 //const speciesParameters& sP = this->speciesParams[popID];
116 // Fetch spatial cell center coordinates
117 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
118 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
119 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
120
121 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
122 cint side = (x < 0.0) ? this->LEFT : this->RIGHT;
123 Real initRho = this->rho[side];
124 Real initT = this->T[side];
125 const Real initV0X = this->Vx[side];
126 const Real initV0Y = this->Vy[side];
127 const Real initV0Z = this->Vz[side];
128
129 #ifdef USE_GPU
132 #else
135 #endif
136 // Loop over blocks
137 Realf rhosum = 0;
139 {WID, WID, WID, nRequested},
140 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
141 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
142 Realf* bufferData = VBC->getData();
143 const vmesh::GlobalID blockGID = GIDlist[initIndex];
144 // Calculate parameters for new block
145 Real blockCoords[6];
146 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
147 creal vxBlock = blockCoords[0];
148 creal vyBlock = blockCoords[1];
149 creal vzBlock = blockCoords[2];
150 creal dvxCell = blockCoords[3];
151 creal dvyCell = blockCoords[4];
152 creal dvzCell = blockCoords[5];
153 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
154 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
155 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
156 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
157 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
158 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
159 //lsum[0] += value;
160 };
161 }, rhosum);
162 return rhosum;
163 }
164
165 /* Evaluates local SpatialCell properties for the project and population,
166 then evaluates the phase-space density at the given coordinates.
167 Used as a probe for projectTriAxisSearch.
168 */
170 const uint popID,
171 Real vx_in, Real vy_in, Real vz_in
172 ) const {
173 //const speciesParameters& sP = this->speciesParams[popID];
174 // Fetch spatial cell center coordinates
175 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
176 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
177 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
178
179 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
180 cint side = (x < 0.0) ? this->LEFT : this->RIGHT;
181 Real initRho = this->rho[side];
182 Real initT = this->T[side];
183 const Real initV0X = this->Vx[side];
184 const Real initV0Y = this->Vy[side];
185 const Real initV0Z = this->Vz[side];
186
187 creal vx = vx_in - initV0X;
188 creal vy = vy_in - initV0Y;
189 creal vz = vz_in - initV0Z;
190 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
191 return value;
192 }
193
199 vector<std::array<Real, 3>> Shocktest::getV0(
200 creal x,
201 creal y,
202 creal z,
203 const uint popID
204 ) const {
205 vector<std::array<Real, 3>> centerPoints;
206 cint side = (x < 0.0) ? this->LEFT : this->RIGHT;
207 std::array<Real, 3> V0 {{this->Vx[side], this->Vy[side], this->Vz[side]}};
208 centerPoints.push_back(V0);
209 return centerPoints;
210 }
211
218
222 setBackgroundFieldToZero(fsgrid, technical, bgb);
223
224 if(!P::isRestart) {
225 // local copies for lambda capture
226 const auto Bx_l = this->Bx;
227 const auto By_l = this->By;
228 const auto Bz_l = this->Bz;
229 const auto LEFT_l = this->LEFT;
230 const auto RIGHT_l = this->RIGHT;
231 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
232 phiprof::initializeTimer("setProjectBField-loop"), technical,
233 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
234 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
235 auto& cell = perb[stencil.ooo()];
236
237 cell[fsgrids::bfield::PERBX] = (xyz[0] < 0.0) ? Bx_l[LEFT_l] : Bx_l[RIGHT_l];
238 cell[fsgrids::bfield::PERBY] = (xyz[0] < 0.0) ? By_l[LEFT_l] : By_l[RIGHT_l];
239 cell[fsgrids::bfield::PERBZ] = (xyz[0] < 0.0) ? Bz_l[LEFT_l] : Bz_l[RIGHT_l];
240 });
241 }
242 }
243
244} // Namespace projects
for i
Definition Dispersion.m:24
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void setBackgroundFieldToZero(FieldSolverGrid &fsgrid, fsgrids::technicalspan technical, fsgrids::bgbspan bgb)
virtual bool initialize()
Definition project.cpp:113
virtual void getParameters()
Definition project.cpp:103
static void addParameters(void)
Definition Shocktest.cpp:48
virtual bool initialize(void) override
Definition Shocktest.cpp:46
virtual std::vector< std::array< Real, 3 > > getV0(creal x, creal y, creal z, const uint popID) const override
virtual void getParameters(void) override
Definition Shocktest.cpp:68
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
virtual Realf probePhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, Real vx_in, Real vy_in, Real vz_in) const override
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
vmesh::VelocityBlockContainer * dev_get_velocity_blocks(const size_t &popID)
vmesh::VelocityMesh * dev_get_velocity_mesh(const size_t &popID)
#define WID
Definition common.h:514
const int WID3
Definition common.h:517
const int WID2
Definition common.h:516
const uint32_t cuint
Definition definitions.h:50
float Real
Definition definitions.h:41
const int cint
Definition definitions.h:45
float Realf
Definition definitions.h:33
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
const float creal
Definition definitions.h:42
const int j
const int k
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
static void parallel_reduce(const uint(&limits)[NDim], Lambda loop_body, T &sum)
std::span< std::array< Real, fsgrids::bfield::N_BFIELD > > perbspan
Definition common.h:434
std::span< technical > technicalspan
Definition common.h:452
std::span< std::array< Real, bgbfield::N_BGB > > bgbspan
Definition common.h:444
@ PERBY
Definition common.h:276
@ PERBZ
Definition common.h:277
@ PERBX
Definition common.h:275
ARCH_HOSTDEV Realf MaxwellianPhaseSpaceDensity(creal &vx, creal &vy, creal &vz, creal &T, creal &rho, creal &mass)
Definition project.h:45
uint32_t GlobalID
Definition definitions.h:59
#define NAN
std::vector< species::Species > particleSpecies
static bool isRestart
Definition parameters.h:176