Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
test_fp.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>
26
27#include "../../common.h"
31
32#include "test_fp.h"
33
35
36using namespace std;
37
38namespace projects {
41
42
43 /*typedef test_fpParameters tfP;
44 Real this->B0 = NAN;
45 Real this->DENSITY = NAN;
46 Real this->TEMPERATURE = NAN;
47 Real this->ALPHA = NAN;
48 int this->CASE = 5;
49 bool this->shear = false;
50 */
51
54 this->ALPHA *= M_PI / 4.0;
55 return true;
56 }
57
59 typedef Readparameters RP;
60 RP::add("test_fp.V0", "Velocity magnitude (m/s)", 1.0e6);
61 RP::add("test_fp.B0", "Magnetic field value in the non-zero patch (T)", 1.0e-9);
62 RP::add("test_fp.rho", "Number density (m^-3)", 1.0e7);
63 RP::add("test_fp.Temperature", "Temperature (K)", 1.0e-6);
64 RP::add("test_fp.angle", "Orientation of the propagation expressed in pi/4", 0.0);
65 RP::add("test_fp.Bdirection", "Direction of the magnetic field (0:x, 1:y, 2:z, 3:all)", 0);
66 RP::add("test_fp.shear", "Add a shear (if false, V=0.5 everywhere).", true);
67 }
68
71 typedef Readparameters RP;
72
73 if(getObjectWrapper().particleSpecies.size() > 1) {
74 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
75 abort();
76 }
77 RP::get("test_fp.B0", this->B0);
78 RP::get("test_fp.V0", this->V0);
79 RP::get("test_fp.rho", this->DENSITY);
80 RP::get("test_fp.Temperature", this->TEMPERATURE);
81 RP::get("test_fp.angle", this->ALPHA);
82 RP::get("test_fp.Bdirection", this->CASE);
83 RP::get("test_fp.shear", this->shear);
84 }
85
86 Real test_fp::sign(creal value) const {
87 if (abs(value) < 1e-5) return 0.0;
88 else return value / abs(value);
89 }
90
92 const uint popID,
93 const uint nRequested
94 ) const {
95 //const speciesParameters& sP = this->speciesParams[popID];
96 // Fetch spatial cell center coordinates
97 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
98 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
99 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
100
101 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
102 Real initRho = this->DENSITY;
103 Real initT = this->TEMPERATURE;
104
105 std::array<Real, 3> initV0 = this->getV0(x, y, z, popID)[0];
106 const Real initV0X = initV0[0];
107 const Real initV0Y = initV0[1];
108 const Real initV0Z = initV0[2];
109
110 #ifdef USE_GPU
113 #else
116 #endif
117 // Loop over blocks
118 Realf rhosum = 0;
120 {WID, WID, WID, nRequested},
121 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
122 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
123 Realf* bufferData = VBC->getData();
124 const vmesh::GlobalID blockGID = GIDlist[initIndex];
125 // Calculate parameters for new block
126 Real blockCoords[6];
127 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
128 creal vxBlock = blockCoords[0];
129 creal vyBlock = blockCoords[1];
130 creal vzBlock = blockCoords[2];
131 creal dvxCell = blockCoords[3];
132 creal dvyCell = blockCoords[4];
133 creal dvzCell = blockCoords[5];
134 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
135 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
136 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
137 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
138 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
139 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
140 //lsum[0] += value;
141 };
142 }, rhosum);
143 return rhosum;
144 }
145
146 /* Evaluates local SpatialCell properties for the project and population,
147 then evaluates the phase-space density at the given coordinates.
148 Used as a probe for projectTriAxisSearch.
149 */
151 const uint popID,
152 Real vx_in, Real vy_in, Real vz_in
153 ) const {
154 // Fetch spatial cell center coordinates
155 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
156 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
157 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
158
159 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
160 Real initRho = this->DENSITY;
161 Real initT = this->TEMPERATURE;
162
163 std::array<Real, 3> initV0 = this->getV0(x, y, z, popID)[0];
164 const Real initV0X = initV0[0];
165 const Real initV0Y = initV0[1];
166 const Real initV0Z = initV0[2];
167
168 creal vx = vx_in - initV0X;
169 creal vy = vy_in - initV0Y;
170 creal vz = vz_in - initV0Z;
171 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
172 return value;
173 }
174
178 setBackgroundFieldToZero(fsgrid, technical, bgb);
179
180 if(!P::isRestart) {
181 const Real areaFactor = 1.0;
182
183 const auto B0_l = this->B0; // local copies for lambda capture
184 const auto CASE_l = this->CASE;
185
186 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
187 phiprof::initializeTimer("setProjectBField-loop"), technical,
188 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
189 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
190 const std::array<Real, 3> gridSpacing = coordinates.physicalGridSpacing;
191 auto& cell = perb[stencil.ooo()];
192
193 creal dx = gridSpacing[0] * 3.5;
194 creal dy = gridSpacing[1] * 3.5;
195 creal dz = gridSpacing[2] * 3.5;
196 creal x = xyz[0] + 0.5 * gridSpacing[0];
197 creal y = xyz[1] + 0.5 * gridSpacing[1];
198 creal z = xyz[2] + 0.5 * gridSpacing[2];
199
200 switch (CASE_l) {
201 case BXCASE:
202 cell[fsgrids::bfield::PERBX] = 0.1 * B0_l * areaFactor;
203 if (y >= -dy && y <= dy) {
204 if (z >= -dz && z <= dz) {
205 cell[fsgrids::bfield::PERBX] = B0_l * areaFactor;
206 }
207 }
208 break;
209 case BYCASE:
210 cell[fsgrids::bfield::PERBY] = 0.1 * B0_l * areaFactor;
211 if (x >= -dx && x <= dx) {
212 if (z >= -dz && z <= dz) {
213 cell[fsgrids::bfield::PERBY] = B0_l * areaFactor;
214 }
215 }
216 break;
217 case BZCASE:
218 cell[fsgrids::bfield::PERBZ] = 0.1 * B0_l * areaFactor;
219 if (x >= -dx && x <= dx) {
220 if (y >= -dy && y <= dy) {
221 cell[fsgrids::bfield::PERBZ] = B0_l * areaFactor;
222 }
223 }
224 break;
225 case BALLCASE:
226 cell[fsgrids::bfield::PERBX] = 0.1 * B0_l * areaFactor;
227 cell[fsgrids::bfield::PERBY] = 0.1 * B0_l * areaFactor;
228 cell[fsgrids::bfield::PERBZ] = 0.1 * B0_l * areaFactor;
229
230
231 if (y >= -dy && y <= dy) {
232 if (z >= -dz && z <= dz) {
233 cell[fsgrids::bfield::PERBX] = B0_l * areaFactor;
234 }
235 }
236 if (x >= -dx && x <= dx) {
237 if (z >= -dz && z <= dz) {
238 cell[fsgrids::bfield::PERBY] = B0_l * areaFactor;
239 }
240 }
241 if (x >= -dx && x <= dx) {
242 if (y >= -dy && y <= dy) {
243 cell[fsgrids::bfield::PERBZ] = B0_l * areaFactor;
244 }
245 }
246 break;
247 }
248 });
249 }
250 }
251
255
256 vector<std::array<Real, 3>> test_fp::getV0(
257 creal x,
258 creal y,
259 creal z,
260 creal dx,
261 creal dy,
262 creal dz,
263 const uint popID
264 ) const {
265 vector<std::array<Real, 3>> centerPoints;
266
267 Real VX=0.0,VY=0.0,VZ=0.0;
268 if (this->shear == true)
269 {
270 //Real ksi;
271 Real eta;
272 switch (this->CASE) {
273 case BXCASE:
274 //ksi = ((y + 0.5 * dy) * cos(this->ALPHA) + (z + 0.5 * dz) * sin(this->ALPHA)) / (2.0 * sqrt(2.0));
275 eta = (-(y + 0.5 * dy) * sin(this->ALPHA) + (z + 0.5 * dz) * cos(this->ALPHA)) / (2.0 * sqrt(2.0));
276 VX = 0.0;
277 VY = sign(cos(this->ALPHA)) * 0.5 + 0.1*cos(this->ALPHA) * sin(2.0 * M_PI * eta);
278 VZ = sign(sin(this->ALPHA)) * 0.5 + 0.1*sin(this->ALPHA) * sin(2.0 * M_PI * eta);
279 break;
280 case BYCASE:
281 //ksi = ((z + 0.5 * dz) * cos(this->ALPHA) + (x + 0.5 * dx) * sin(this->ALPHA)) / (2.0 * sqrt(2.0));
282 eta = (-(z + 0.5 * dz) * sin(this->ALPHA) + (x + 0.5 * dx) * cos(this->ALPHA)) / (2.0 * sqrt(2.0));
283 VX = sign(sin(this->ALPHA)) * 0.5 + 0.1*sin(this->ALPHA) * sin(2.0 * M_PI * eta);
284 VY = 0.0;
285 VZ = sign(cos(this->ALPHA)) * 0.5 + 0.1*cos(this->ALPHA) * sin(2.0 * M_PI * eta);
286 break;
287 case BZCASE:
288 //ksi = ((x + 0.5 * dx) * cos(this->ALPHA) + (y + 0.5 * dy) * sin(this->ALPHA)) / (2.0 * sqrt(2.0));
289 eta = (-(x + 0.5 * dx) * sin(this->ALPHA) + (y + 0.5 * dy) * cos(this->ALPHA)) / (2.0 * sqrt(2.0));
290 VX = sign(cos(this->ALPHA)) * 0.5 + 0.1*cos(this->ALPHA) * sin(2.0 * M_PI * eta);
291 VY = sign(sin(this->ALPHA)) * 0.5 + 0.1*sin(this->ALPHA) * sin(2.0 * M_PI * eta);
292 VZ = 0.0;
293 break;
294 case BALLCASE:
295 std::cerr << "not implemented in " << __FILE__ << ":" << __LINE__ << std::endl;
296 exit(1);
297 break;
298 }
299 } else {
300 switch (this->CASE) {
301 case BXCASE:
302 VX = 0.0;
303 VY = cos(this->ALPHA) * 0.5;
304 VZ = sin(this->ALPHA) * 0.5;
305 break;
306 case BYCASE:
307 VX = sin(this->ALPHA) * 0.5;
308 VY = 0.0;
309 VZ = cos(this->ALPHA) * 0.5;
310 break;
311 case BZCASE:
312 VX = cos(this->ALPHA) * 0.5;
313 VY = sin(this->ALPHA) * 0.5;
314 VZ = 0.0;
315 break;
316 case BALLCASE:
317 VX = 0.5 / sqrt(3.0);
318 VY = 0.5 / sqrt(3.0);
319 VZ = 0.5 / sqrt(3.0);
320 break;
321 }
322 }
323
324 VX *= this->V0 * 2.0;
325 VY *= this->V0 * 2.0;
326 VZ *= this->V0 * 2.0;
327
328 std::array<Real, 3> point {{VX, VY, VZ}};
329 centerPoints.push_back(point);
330 return centerPoints;
331 }
332
333 vector<std::array<Real, 3>> test_fp::getV0(
334 creal x,
335 creal y,
336 creal z,
337 const uint popID
338 ) const {
339 vector<std::array<Real, 3>> centerPoints;
340
341 creal dx = 0.0;
342 creal dy = 0.0;
343 creal dz = 0.0;
344
345 return this->getV0(x,y,z,dx,dy,dz,popID);
346 }
347
348}// namespace projects
for i
Definition Dispersion.m:24
dx
Definition Dispersion.m:38
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
#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
virtual std::vector< std::array< Real, 3 > > getV0(creal x, creal y, creal z, const uint popID) const override
Return a vector containing the velocity coordinate of the centre of each ion population in the distri...
Definition test_fp.cpp:333
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition test_fp.cpp:175
virtual bool initialize(void) override
Definition test_fp.cpp:52
virtual ~test_fp()
Definition test_fp.cpp:40
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition test_fp.cpp:252
Real sign(creal value) const
Definition test_fp.cpp:86
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition test_fp.cpp:91
static void addParameters(void)
Definition test_fp.cpp:58
virtual void getParameters(void) override
Definition test_fp.cpp:69
virtual Realf probePhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, Real vx_in, Real vy_in, Real vz_in) const override
Definition test_fp.cpp:150
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
float Realf
Definition definitions.h:33
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
const float creal
Definition definitions.h:42
const Real VY
const Real VZ
const int j
const Real VX
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
std::vector< species::Species > particleSpecies
static bool isRestart
Definition parameters.h:176
cases
Definition test_fp.cpp:34
@ BALLCASE
Definition test_fp.cpp:34
@ BXCASE
Definition test_fp.cpp:34
@ BYCASE
Definition test_fp.cpp:34
@ BZCASE
Definition test_fp.cpp:34
static ARCH_HOSTDEV VecSimple< T > abs(const VecSimple< T > &l)