Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Distributions.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 <iomanip>
26#include <cmath>
27
28#include "../../common.h"
33
34#include "Distributions.h"
35
36using namespace std;
37using namespace spatial_cell;
38
39namespace projects {
42
43
45
47 typedef Readparameters RP;
48 RP::add("Distributions.rho1", "Number density, first peak (m^-3)", 0.0);
49 RP::add("Distributions.rho2", "Number density, second peak (m^-3)", 0.0);
50 RP::add("Distributions.Tx1", "Temperature, first peak (K)", 0.0);
51 RP::add("Distributions.Tx2", "Temperature, second peak (K)", 0.0);
52 RP::add("Distributions.Ty1", "Temperature, first peak (K)", 0.0);
53 RP::add("Distributions.Ty2", "Temperature, second peak (K)", 0.0);
54 RP::add("Distributions.Tz1", "Temperature, first peak (K)", 0.0);
55 RP::add("Distributions.Tz2", "Temperature, second peak (K)", 0.0);
56 RP::add("Distributions.Vx1", "Bulk velocity x component, first peak (m/s)", 0.0);
57 RP::add("Distributions.Vx2", "Bulk velocity x component, second peak (m/s)", 0.0);
58 RP::add("Distributions.Vy1", "Bulk velocity y component, first peak (m/s)", 0.0);
59 RP::add("Distributions.Vy2", "Bulk velocity y component, second peak (m/s)", 0.0);
60 RP::add("Distributions.Vz1", "Bulk velocity z component, first peak (m/s)", 0.0);
61 RP::add("Distributions.Vz2", "Bulk velocity z component, second peak (m/s)", 0.0);
62 RP::add("Distributions.Bx", "Magnetic field x component (T)", 0.0);
63 RP::add("Distributions.By", "Magnetic field y component (T)", 0.0);
64 RP::add("Distributions.Bz", "Magnetic field z component (T)", 0.0);
65 RP::add("Distributions.dBx", "Magnetic field x component cosine perturbation amplitude (T)", 0.0);
66 RP::add("Distributions.dBy", "Magnetic field y component cosine perturbation amplitude (T)", 0.0);
67 RP::add("Distributions.dBz", "Magnetic field z component cosine perturbation amplitude (T)", 0.0);
68 RP::add("Distributions.magXPertAbsAmp", "Absolute amplitude of the random magnetic perturbation along x (T)", 1.0e-9);
69 RP::add("Distributions.magYPertAbsAmp", "Absolute amplitude of the random magnetic perturbation along y (T)", 1.0e-9);
70 RP::add("Distributions.magZPertAbsAmp", "Absolute amplitude of the random magnetic perturbation along z (T)", 1.0e-9);
71 RP::add("Distributions.rho1PertAbsAmp", "Absolute amplitude of the density perturbation, first peak", 0.1);
72 RP::add("Distributions.rho2PertAbsAmp", "Absolute amplitude of the density perturbation, second peak", 0.1);
73// RP::add("Distributions.Vx1PertAbsAmp", "Absolute amplitude of the Vx perturbation, first peak", 1.0e6);
74// RP::add("Distributions.Vy1PertAbsAmp", "Absolute amplitude of the Vy perturbation, first peak", 1.0e6);
75// RP::add("Distributions.Vz1PertAbsAmp", "Absolute amplitude of the Vz perturbation, first peak", 1.0e6);
76// RP::add("Distributions.Vx2PertAbsAmp", "Absolute amplitude of the Vx perturbation, second peak", 1.0e6);
77// RP::add("Distributions.Vy2PertAbsAmp", "Absolute amplitude of the Vy perturbation, second peak", 1.0e6);
78// RP::add("Distributions.Vz2PertAbsAmp", "Absolute amplitude of the Vz perturbation, second peak", 1.0e6);
79 RP::add("Distributions.lambda", "B cosine perturbation wavelength (m)", 0.0);
80 }
81
84 typedef Readparameters RP;
86
87 if(getObjectWrapper().particleSpecies.size() > 1) {
88 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
89 abort();
90 }
91
92 RP::get("Distributions.rho1", this->rho[0]);
93 RP::get("Distributions.rho2", this->rho[1]);
94 RP::get("Distributions.Tx1", this->Tx[0]);
95 RP::get("Distributions.Tx2", this->Tx[1]);
96 RP::get("Distributions.Ty1", this->Ty[0]);
97 RP::get("Distributions.Ty2", this->Ty[1]);
98 RP::get("Distributions.Tz1", this->Tz[0]);
99 RP::get("Distributions.Tz2", this->Tz[1]);
100 RP::get("Distributions.Vx1", this->Vx[0]);
101 RP::get("Distributions.Vx2", this->Vx[1]);
102 RP::get("Distributions.Vy1", this->Vy[0]);
103 RP::get("Distributions.Vy2", this->Vy[1]);
104 RP::get("Distributions.Vz1", this->Vz[0]);
105 RP::get("Distributions.Vz2", this->Vz[1]);
106 RP::get("Distributions.Bx", this->Bx);
107 RP::get("Distributions.By", this->By);
108 RP::get("Distributions.Bz", this->Bz);
109 RP::get("Distributions.magXPertAbsAmp", this->magXPertAbsAmp);
110 RP::get("Distributions.magYPertAbsAmp", this->magYPertAbsAmp);
111 RP::get("Distributions.magZPertAbsAmp", this->magZPertAbsAmp);
112 RP::get("Distributions.rho1PertAbsAmp", this->rhoPertAbsAmp[0]);
113 RP::get("Distributions.rho2PertAbsAmp", this->rhoPertAbsAmp[1]);
114// RP::get("Distributions.Vx1PertAbsAmp", this->Vx1PertAbsAmp);
115// RP::get("Distributions.Vy1PertAbsAmp", this->Vy1PertAbsAmp);
116// RP::get("Distributions.Vz1PertAbsAmp", this->Vz1PertAbsAmp);
117// RP::get("Distributions.Vx2PertAbsAmp", this->Vx2PertAbsAmp);
118// RP::get("Distributions.Vy2PertAbsAmp", this->Vy2PertAbsAmp);
119// RP::get("Distributions.Vz2PertAbsAmp", this->Vz2PertAbsAmp);
120 RP::get("Distributions.dBx", this->dBx);
121 RP::get("Distributions.dBy", this->dBy);
122 RP::get("Distributions.dBz", this->dBz);
123 RP::get("Distributions.lambda", this->lambda);
124 }
125
127 const uint popID,
128 const uint nRequested
129 ) const {
130 // Fetch spatial cell center coordinates
131 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
132 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
133 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
137 creal scaledVx1 = this->Vx[1] * relx;
138 creal scaledVy1 = this->Vy[1] * rely;
139 creal scaledVz1 = this->Vz[1] * relz;
140
141 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
142 const Real initRho0 = this->rhoRnd[0];
143 const Real initRho1 = this->rhoRnd[1];
144 const Real initT0x = this->Tx[0];
145 const Real initT0y = this->Ty[0];
146 const Real initT0z = this->Tz[0];
147 const Real initT1x = this->Tx[1];
148 const Real initT1y = this->Ty[1];
149 const Real initT1z = this->Tz[1];
150 const Real initV0X = this->Vx[0];
151 const Real initV0Y = this->Vy[0];
152 const Real initV0Z = this->Vz[0];
153 const Real initV1X = this->Vx[1];
154 const Real initV1Y = this->Vy[1];
155 const Real initV1Z = this->Vz[1];
156
157 #ifdef USE_GPU
160 #else
163 #endif
164 // Loop over blocks
165 Realf rhosum = 0;
167 {WID, WID, WID, nRequested},
168 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
169 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
170 Realf* bufferData = VBC->getData();
171 const vmesh::GlobalID blockGID = GIDlist[initIndex];
172 // Calculate parameters for new block
173 Real blockCoords[6];
174 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
175 creal vxBlock = blockCoords[0];
176 creal vyBlock = blockCoords[1];
177 creal vzBlock = blockCoords[2];
178 creal dvxCell = blockCoords[3];
179 creal dvyCell = blockCoords[4];
180 creal dvzCell = blockCoords[5];
181 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
182 Real vx = vxBlock + (i+0.5)*dvxCell - initV0X;
183 Real vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
184 Real vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
185 Realf value = TriMaxwellianPhaseSpaceDensity(vx,vy,vz,initT0x,initT0y,initT0z,initRho0,mass);
186 vx = vxBlock + (i+0.5)*dvxCell - initV1X;
187 vy = vyBlock + (j+0.5)*dvyCell - initV1Y;
188 vz = vzBlock + (k+0.5)*dvzCell - initV1Z;
189 value += TriMaxwellianPhaseSpaceDensity(vx,vy,vz,initT1x,initT1y,initT1z,initRho1,mass);
190 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
191 //lsum[0] += value;
192 };
193 }, rhosum);
194 return rhosum;
195 }
196
197 /* Evaluates local SpatialCell properties for the project and population,
198 then evaluates the phase-space density at the given coordinates.
199 Used as a probe for projectTriAxisSearch.
200 */
202 const uint popID,
203 Real vx_in, Real vy_in, Real vz_in
204 ) const {
205 // Fetch spatial cell center coordinates
206 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
207 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
208 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
212 creal scaledVx1 = this->Vx[1] * relx;
213 creal scaledVy1 = this->Vy[1] * rely;
214 creal scaledVz1 = this->Vz[1] * relz;
215
216 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
217 const Real initRho0 = this->rhoRnd[0];
218 const Real initRho1 = this->rhoRnd[1];
219 const Real initT0x = this->Tx[0];
220 const Real initT0y = this->Ty[0];
221 const Real initT0z = this->Tz[0];
222 const Real initT1x = this->Tx[1];
223 const Real initT1y = this->Ty[1];
224 const Real initT1z = this->Tz[1];
225 const Real initV0X = this->Vx[0];
226 const Real initV0Y = this->Vy[0];
227 const Real initV0Z = this->Vz[0];
228 const Real initV1X = this->Vx[1];
229 const Real initV1Y = this->Vy[1];
230 const Real initV1Z = this->Vz[1];
231
232 Realf value = 0;
233 Real vx = vx_in - initV0X;
234 Real vy = vy_in - initV0Y;
235 Real vz = vz_in - initV0Z;
236 value = TriMaxwellianPhaseSpaceDensity(vx,vy,vz,initT0x,initT0y,initT0z,initRho0,mass);
237 vx = vx_in - initV1X;
238 vy = vy_in - initV1Y;
239 vz = vz_in - initV1Z;
240 value += TriMaxwellianPhaseSpaceDensity(vx,vy,vz,initT1x,initT1y,initT1z,initRho1,mass);
241 return value;
242 }
243
245 std::default_random_engine rndState;
246 setRandomCellSeed(cell,rndState);
247 for (uint i=0; i<2; i++) {
248 this->rhoRnd[i] = this->rho[i] + this->rhoPertAbsAmp[i] * (0.5 - getRandomNumber(rndState));
249 }
250 }
251
255 fsgrids::technicalspan technical,
257 ) {
258 ConstantField bgField;
259 bgField.initialize(this->Bx,
260 this->By,
261 this->Bz);
262
263 setBackgroundField(bgField, bgb, technical, fsgrid);
264
265 if(!P::isRestart && this->lambda != 0.0) {
266 // local copies for lambda capture
267 const auto dBx_l = this->dBx;
268 const auto dBy_l = this->dBy;
269 const auto dBz_l = this->dBz;
270 const auto lambda_l = this->lambda;
271 const auto magXPertAbsAmp_l = this->magXPertAbsAmp;
272 const auto magYPertAbsAmp_l = this->magYPertAbsAmp;
273 const auto magZPertAbsAmp_l = this->magZPertAbsAmp;
274 const auto seed = this->seed;
275
276 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
277 phiprof::initializeTimer("setProjectBField-loop"), technical,
278 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
279 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
280 auto& cell = perb[stencil.ooo()];
281
282 const auto seedmodifier = coordinates.globalIDFromLocalCoordinates(stencil.i, stencil.j, stencil.k);
283 std::default_random_engine rndState_l;
284 rndState_l.seed(seed+seedmodifier);
285 Real rndBuffer[3];
286 rndBuffer[0] = std::uniform_real_distribution<>(-0.5,0.5)(rndState_l);
287 rndBuffer[1] = std::uniform_real_distribution<>(-0.5,0.5)(rndState_l);
288 rndBuffer[2] = std::uniform_real_distribution<>(-0.5,0.5)(rndState_l);
289
290 cell[fsgrids::bfield::PERBX] = dBx_l * cos(2.0 * M_PI * xyz[0] / lambda_l) + magXPertAbsAmp_l * rndBuffer[0];
291 cell[fsgrids::bfield::PERBY] = dBy_l * sin(2.0 * M_PI * xyz[0] / lambda_l) + magYPertAbsAmp_l * rndBuffer[1];
292 cell[fsgrids::bfield::PERBZ] = dBz_l * cos(2.0 * M_PI * xyz[0] / lambda_l) + magZPertAbsAmp_l * rndBuffer[2];
293 });
294 }
295 }
296
297 vector<std::array<Real, 3>> Distributions::getV0(
298 creal x,
299 creal y,
300 creal z,
301 const uint popID
302 ) const {
303 vector<std::array<Real, 3>> centerPoints;
307 creal scaledVx1 = this->Vx[1] * relx;
308 creal scaledVy1 = this->Vy[1] * rely;
309 creal scaledVz1 = this->Vz[1] * relz;
310 std::array<Real, 3> point0 {{this->Vx[0], this->Vy[0], this->Vz[0]}};
311 std::array<Real, 3> point1 {{scaledVx1, scaledVy1, scaledVz1}};
312 centerPoints.push_back(point0);
313 centerPoints.push_back(point1);
314 return centerPoints;
315 }
316
317}// namespace projects
for i
Definition Dispersion.m:24
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void setBackgroundField(const FieldFunction &bgFunction, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, bool append)
void initialize(const double Bx, const double By, const double Bz)
virtual Realf probePhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, Real vx_in, Real vy_in, Real vz_in) const override
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...
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
virtual void getParameters(void) override
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
virtual bool initialize(void) override
static void addParameters(void)
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Real getRandomNumber(std::default_random_engine &randGen) const
Definition project.cpp:317
virtual bool initialize()
Definition project.cpp:113
virtual void getParameters()
Definition project.cpp:103
void setRandomCellSeed(spatial_cell::SpatialCell *cell, std::default_random_engine &randGen) const
Definition project.cpp:336
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 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 TriMaxwellianPhaseSpaceDensity(creal &vx, creal &vy, creal &vz, creal &Tx, creal &Ty, creal &Tz, creal &rho, creal &mass)
Definition project.h:66
uint32_t GlobalID
Definition definitions.h:59
std::vector< species::Species > particleSpecies
static Real ymax
Definition parameters.h:41
static Real xmax
Definition parameters.h:39
static Real zmax
Definition parameters.h:43
static Real ymin
Definition parameters.h:40
static Real xmin
Definition parameters.h:38
static bool isRestart
Definition parameters.h:176
static Real zmin
Definition parameters.h:42