Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Flowthrough.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"
32
33#include "Flowthrough.h"
34
35using namespace std;
36
37
41
49
51
52namespace projects {
55
57 return Project::initialize();
58 }
59
61 typedef Readparameters RP;
62 RP::add("Flowthrough.emptyBox","Is the simulation domain empty initially?",false);
63 RP::add("Flowthrough.densityModel","Plasma density model, 'Maxwellian' or 'SheetMaxwellian'",string("Maxwellian"));
64 RP::add("Flowthrough.densityWidth","Width of signal around origin",6.e7);
65 RP::add("Flowthrough.rescaleDensity","Rescale VDF to match spatial ",false);
66 RP::add("Flowthrough.Bx", "Magnetic field x component (T)", 0.0);
67 RP::add("Flowthrough.By", "Magnetic field y component (T)", 0.0);
68 RP::add("Flowthrough.Bz", "Magnetic field z component (T)", 0.0);
69
70 // Per-population parameters
71 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
72 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
73 RP::add(pop + "_Flowthrough.rho", "Number density (m^-3)", 0.0);
74 RP::add(pop + "_Flowthrough.rhoBase", "Background number density (m^-3)", 0.0);
75 RP::add(pop + "_Flowthrough.T", "Temperature (K)", 0.0);
76 RP::add(pop + "_Flowthrough.VX0", "Initial bulk velocity in x-direction", 0.0);
77 RP::add(pop + "_Flowthrough.VY0", "Initial bulk velocity in y-direction", 0.0);
78 RP::add(pop + "_Flowthrough.VZ0", "Initial bulk velocity in z-direction", 0.0);
79 }
80 }
81
84 int myRank;
85 MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
86 typedef Readparameters RP;
87
88 RP::get("Flowthrough.emptyBox",emptyBox);
89 RP::get("Flowthrough.Bx", this->Bx);
90 RP::get("Flowthrough.By", this->By);
91 RP::get("Flowthrough.Bz", this->Bz);
92 string densityModelString;
93 RP::get("Flowthrough.densityModel",densityModelString);
94 if (densityModelString == "Maxwellian") densityModel = Maxwellian;
95 else if (densityModelString == "SheetMaxwellian") densityModel = SheetMaxwellian;
96 else if (densityModelString == "Square") densityModel = Square;
97 else if (densityModelString == "Triangle") densityModel = Triangle;
98 else if (densityModelString == "Sinewave") densityModel = Sinewave;
99 else {
100 if (myRank == MASTER_RANK) cerr << __FILE__ << ":" << __LINE__ << " ERROR: Unknown option value!" << endl;
101 exit(1);
102 }
103 RP::get("Flowthrough.densityWidth",this->densityWidth);
104 RP::get("Flowthrough.rescaleDensity",this->rescaleDensityFlag);
105
106 // Per-population parameters
107 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
108 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
110
111 RP::get(pop + "_Flowthrough.rho", sP.rho);
112 RP::get(pop + "_Flowthrough.rhoBase", sP.rhoBase);
113 RP::get(pop + "_Flowthrough.T", sP.T);
114 RP::get(pop + "_Flowthrough.VX0", sP.V0[0]);
115 RP::get(pop + "_Flowthrough.VY0", sP.V0[1]);
116 RP::get(pop + "_Flowthrough.VZ0", sP.V0[2]);
117
118 speciesParams.push_back(sP);
119 }
120 }
123 Real rvalue;
124 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
125 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
126 const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
127 switch (densityModel) {
128 case Maxwellian:
129 rvalue = sP.rho;
130 break;
131 case SheetMaxwellian:
132 rvalue = sqrt(x*x + y*y + z*z);
133 if (rvalue <= 0.5*densityWidth) {
134 rvalue = 4*sP.rho;
135 } else {
136 rvalue = 0;
137 }
138 break;
139 case Square:
140 if (abs(x) < 0.5*densityWidth) {
141 rvalue = 4*sP.rho;
142 } else {
143 rvalue = 4*sP.rhoBase;
144 //rvalue = 0;
145 }
146 break;
147 case Triangle:
148 if (abs(x) < 0.5*densityWidth) {
149 rvalue = 4;
150 rvalue *= ( sP.rhoBase + (sP.rho-sP.rhoBase) * (1.-abs(x) / (0.5*densityWidth)));
151 } else {
152 rvalue = 4*sP.rhoBase;
153 //rvalue = 0;
154 }
155 break;
156 case Sinewave:
157 if (abs(x) < 0.5*densityWidth) {
158 rvalue = 4;
159 rvalue *= ( sP.rhoBase + (sP.rho-sP.rhoBase) * (0.5 + 0.5*cos(M_PI * x / (0.5*densityWidth))));
160 } else {
161 rvalue = 4*sP.rhoBase;
162 //rvalue = 0;
163 }
164 break;
165 default:
166 rvalue = sP.rho;
167 break;
168 }
169 return rvalue;
170 }
171
173 const uint popID,
174 const uint nRequested
175 ) const {
177
178 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
179 Real initRho = this->getCorrectNumberDensity(cell, popID);
180 Real initT = sP.T;
181 const Real initV0X = sP.V0[0];
182 const Real initV0Y = sP.V0[1];
183 const Real initV0Z = sP.V0[2];
184
185 #ifdef USE_GPU
188 #else
191 #endif
192
193 if (emptyBox == true) {
194 Realf* bufferData = cell->get_velocity_blocks(popID)->getData();
195 std::memset(bufferData, 0, nRequested*WID3*sizeof(Realf));
196 return 0;
197 }
198
199 // Loop over blocks
200 Realf rhosum = 0;
202 {WID, WID, WID, nRequested},
203 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
204 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
205 Realf* bufferData = VBC->getData();
206 const vmesh::GlobalID blockGID = GIDlist[initIndex];
207 // Calculate parameters for new block
208 Real blockCoords[6];
209 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
210 creal vxBlock = blockCoords[0];
211 creal vyBlock = blockCoords[1];
212 creal vzBlock = blockCoords[2];
213 creal dvxCell = blockCoords[3];
214 creal dvyCell = blockCoords[4];
215 creal dvzCell = blockCoords[5];
216 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
217 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
218 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
219 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
220 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
221 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
222 //lsum[0] += value;
223 };
224 }, rhosum);
225 return rhosum;
226 }
227
228 /* Evaluates local SpatialCell properties for the project and population,
229 then evaluates the phase-space density at the given coordinates.
230 Used as a probe for projectTriAxisSearch.
231 */
233 const uint popID,
234 Real vx_in, Real vy_in, Real vz_in
235 ) const {
237 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
238 Real initRho = this->getCorrectNumberDensity(cell, popID);
239 Real initT = sP.T;
240 const Real initV0X = sP.V0[0];
241 const Real initV0Y = sP.V0[1];
242 const Real initV0Z = sP.V0[2];
243
244 if (emptyBox == true) {
245 return 0;
246 }
247 creal vx = vx_in - initV0X;
248 creal vy = vy_in - initV0Y;
249 creal vz = vz_in - initV0Z;
250 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
251 return value;
252 }
253
255
259 ConstantField bgField;
260 bgField.initialize(Bx,By,Bz); //bg bx, by,bz
261 setBackgroundField(bgField, bgb, technical, fsgrid);
262 }
263
264 std::vector<std::array<Real, 3> > Flowthrough::getV0(
265 creal x,
266 creal y,
267 creal z,
268 const uint popID
269 ) const {
271 vector<std::array<Real, 3>> centerPoints;
272 std::array<Real, 3> point {{sP.V0[0], sP.V0[1], sP.V0[2]}};
273 centerPoints.push_back(point);
274 return centerPoints;
275 }
276
277} //namespace projects
for i
Definition Dispersion.m:24
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
static DensityModel densityModel
DensityModel
@ Square
@ SheetMaxwellian
@ Triangle
@ Sinewave
@ Maxwellian
#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 fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
virtual void getParameters(void) 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 Realf probePhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, Real vx_in, Real vy_in, Real vz_in) const override
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
virtual Real getCorrectNumberDensity(spatial_cell::SpatialCell *cell, const uint popID) const override
std::vector< FlowthroughSpeciesParameters > speciesParams
Definition Flowthrough.h:77
static void addParameters(void)
virtual bool initialize(void) override
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
virtual bool initialize()
Definition project.cpp:113
virtual void getParameters()
Definition project.cpp:103
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
#define MASTER_RANK
Definition common.h:67
const int WID3
Definition common.h:517
const int WID2
Definition common.h:516
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
int myRank
Definition gpu_base.cpp:48
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
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 ARCH_HOSTDEV VecSimple< T > abs(const VecSimple< T > &l)