Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
setmaxwellian.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
26
27#include <cstdlib>
28#include <iostream>
29
30#include "setmaxwellian.h"
32#include "../object_wrapper.h"
33
34#include "../projects/project.h" // for MaxwellianPhaseSpaceDensity
36
37namespace SBC {
40
43 "maxwellian.face", "List of faces on which set Maxwellian boundary conditions are to be applied ([xyz][+-]).");
44 Readparameters::add("maxwellian.precedence",
45 "Precedence value of the set Maxwellian boundary condition (integer), the higher the stronger.",
46 3);
47 Readparameters::add("maxwellian.reapplyUponRestart",
48 "If 0 (default), keep going with the state existing in the restart file. If 1, calls again "
49 "applyInitialState. Can be used to change boundary condition behaviour during a run.",
50 0);
51 Readparameters::add("maxwellian.t_interval", "Time interval in seconds for applying the varying inflow condition.",
52 0.0); // 0 = re-calculate every time
53 // Per-population parameters
54 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
55 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
56
57 Readparameters::add(pop + "_maxwellian.file_x+",
58 "Input files for the set Maxwellian inflow parameters on face x+. Data format per line: time "
59 "(s) density (p/m^3) Temperature (K) Vx Vy Vz (m/s) Bx By Bz (T).",
60 "");
61 Readparameters::add(pop + "_maxwellian.file_x-",
62 "Input files for the set Maxwellian inflow parameters on face x-. Data format per line: time "
63 "(s) density (p/m^3) Temperature (K) Vx Vy Vz (m/s) Bx By Bz (T).",
64 "");
65 Readparameters::add(pop + "_maxwellian.file_y+",
66 "Input files for the set Maxwellian inflow parameters on face y+. Data format per line: time "
67 "(s) density (p/m^3) Temperature (K) Vx Vy Vz (m/s) Bx By Bz (T).",
68 "");
69 Readparameters::add(pop + "_maxwellian.file_y-",
70 "Input files for the set Maxwellian inflow parameters on face y-. Data format per line: time "
71 "(s) density (p/m^3) Temperature (K) Vx Vy Vz (m/s) Bx By Bz (T).",
72 "");
73 Readparameters::add(pop + "_maxwellian.file_z+",
74 "Input files for the set Maxwellian inflow parameters on face z+. Data format per line: time "
75 "(s) density (p/m^3) Temperature (K) Vx Vy Vz (m/s) Bx By Bz (T).",
76 "");
77 Readparameters::add(pop + "_maxwellian.file_z-",
78 "Input files for the set Maxwellian inflow parameters on face z-. Data format per line: time "
79 "(s) density (p/m^3) Temperature (K) Vx Vy Vz (m/s) Bx By Bz (T).",
80 "");
81 Readparameters::add(pop + "_maxwellian.dynamic",
82 "Boolean value, is the set Maxwellian inflow dynamic in time or not.", 0);
83 }
84 }
85
87 Readparameters::get("maxwellian.face", faceList);
88 Readparameters::get("maxwellian.precedence", precedence);
89
90 uint reapply;
91 Readparameters::get("maxwellian.reapplyUponRestart", reapply);
92 Readparameters::get("maxwellian.t_interval", tInterval);
93 this->applyUponRestart = false;
94 if(reapply == 1) {
95 this->applyUponRestart = true;
96 }
97
98 // Per-population parameters
99 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
100 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
101
103 sP.nParams = 9;
104
105 Readparameters::get(pop + "_maxwellian.dynamic", dynamic);
106 Readparameters::get(pop + "_maxwellian.file_x+", sP.files[0]);
107 Readparameters::get(pop + "_maxwellian.file_x-", sP.files[1]);
108 Readparameters::get(pop + "_maxwellian.file_y+", sP.files[2]);
109 Readparameters::get(pop + "_maxwellian.file_y-", sP.files[3]);
110 Readparameters::get(pop + "_maxwellian.file_z+", sP.files[4]);
111 Readparameters::get(pop + "_maxwellian.file_z-", sP.files[5]);
112
113 speciesParams.push_back(sP);
114 }
115 }
116
125 void Maxwellian::generateTemplateCell(spatial_cell::SpatialCell& templateCell, Real (&B)[3], int inputDataIndex,
126 creal t) {
127 Real initRho, initT, initV0X, initV0Y, initV0Z, Bx = 0, By = 0, Bz = 0, buffer[8];
128
129 templateCell.sysBoundaryFlag = this->getIndex();
130 templateCell.sysBoundaryLayer = 1;
131
132 // Init all particle species
133 for (uint popID=0; popID<getObjectWrapper().particleSpecies.size(); ++popID) {
134 templateCell.clear(popID,false); //clear, do not de-allocate memory
135 // Interpolate is in setbyuser.cpp and .h
136 interpolate(inputDataIndex, popID, t, &buffer[0]);
137 initRho = buffer[0];
138 initT = buffer[1];
139 initV0X = buffer[2];
140 initV0Y = buffer[3];
141 initV0Z = buffer[4];
142 Bx = buffer[5];
143 By = buffer[6];
144 Bz = buffer[7];
145 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
146
147 // Find list of blocks to initialize.
148 const uint nRequested = SBC::findMaxwellianBlocksToInitialize(popID,templateCell, initRho, initT, initV0X, initV0Y, initV0Z);
149 // stores in vmesh->getGrid() (localToGlobalMap)
150 // with count in cell.get_population(popID).N_blocks
151
152 // Resize and populate mesh
153 templateCell.prepare_to_receive_blocks(popID);
154
155 // Set the reservation value (capacity is increased in add_velocity_blocks
156 const Realf minValue = templateCell.getVelocityBlockMinValue(popID);
157
158 // fills v-space into target
159
160 #ifdef USE_GPU
161 vmesh::VelocityMesh *vmesh = templateCell.dev_get_velocity_mesh(popID);
163 #else
164 vmesh::VelocityMesh *vmesh = templateCell.get_velocity_mesh(popID);
165 vmesh::VelocityBlockContainer* VBC = templateCell.get_velocity_blocks(popID);
166 #endif
167 // Loop over blocks
168 Realf rhosum = 0;
170 {WID, WID, WID, nRequested},
171 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
172 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
173 Realf* bufferData = VBC->getData();
174 const vmesh::GlobalID blockGID = GIDlist[initIndex];
175 // Calculate parameters for new block
176 Real blockCoords[6];
177 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
178 creal vxBlock = blockCoords[0];
179 creal vyBlock = blockCoords[1];
180 creal vzBlock = blockCoords[2];
181 creal dvxCell = blockCoords[3];
182 creal dvyCell = blockCoords[4];
183 creal dvzCell = blockCoords[5];
184 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
185 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
186 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
187 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
188 const Realf value = projects::MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
189 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
190 //lsum[0] += value;
191 };
192 }, rhosum);
193
194 #ifdef USE_GPU
195 // Set and apply the reservation value
196 templateCell.setReservation(popID,nRequested,true); // Force to this value
197 templateCell.applyReservation(popID);
198 #endif
199
200 //let's get rid of blocks not fulfilling the criteria here to save memory.
201 templateCell.adjustSingleCellVelocityBlocks(popID,true);
202
203 } // for-loop over particle species
204
205 B[0] = Bx;
206 B[1] = By;
207 B[2] = Bz;
208
209 calculateCellMoments(&templateCell,true,false,true);
210
211 templateCell.parameters[CellParams::RHOM_R] = templateCell.parameters[CellParams::RHOM];
212 templateCell.parameters[CellParams::VX_R] = templateCell.parameters[CellParams::VX];
213 templateCell.parameters[CellParams::VY_R] = templateCell.parameters[CellParams::VY];
214 templateCell.parameters[CellParams::VZ_R] = templateCell.parameters[CellParams::VZ];
215 templateCell.parameters[CellParams::RHOQ_R] = templateCell.parameters[CellParams::RHOQ];
216 templateCell.parameters[CellParams::P_11_R] = templateCell.parameters[CellParams::P_11];
217 templateCell.parameters[CellParams::P_22_R] = templateCell.parameters[CellParams::P_22];
218 templateCell.parameters[CellParams::P_33_R] = templateCell.parameters[CellParams::P_33];
219 templateCell.parameters[CellParams::RHOM_V] = templateCell.parameters[CellParams::RHOM];
220 templateCell.parameters[CellParams::VX_V] = templateCell.parameters[CellParams::VX];
221 templateCell.parameters[CellParams::VY_V] = templateCell.parameters[CellParams::VY];
222 templateCell.parameters[CellParams::VZ_V] = templateCell.parameters[CellParams::VZ];
223 templateCell.parameters[CellParams::RHOQ_V] = templateCell.parameters[CellParams::RHOQ];
224 templateCell.parameters[CellParams::P_11_V] = templateCell.parameters[CellParams::P_11];
225 templateCell.parameters[CellParams::P_22_V] = templateCell.parameters[CellParams::P_22];
226 templateCell.parameters[CellParams::P_33_V] = templateCell.parameters[CellParams::P_33];
227 }
228
229 std::string Maxwellian::getName() const { return "Maxwellian"; }
231
232} // namespace SBC
for i
Definition Dispersion.m:24
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void calculateCellMoments(spatial_cell::SpatialCell *cell, const bool &computeSecond, const bool &computePopulationMomentsOnly, const bool &doNotSkip)
static void addComposing(const std::string &name, const std::string &desc)
static void get(const std::string &name, std::string &value)
static void add(const std::string &name, const std::string &desc, const std::string &defValue)
void interpolate(const int inputDataIndex, const uint popID, creal t, Real *outputData)
Definition inflow.cpp:390
Real tInterval
Definition inflow.h:109
std::vector< InflowSpeciesParameters > speciesParams
Definition inflow.h:114
std::vector< std::string > faceList
Definition inflow.h:113
static void addParameters()
virtual string getName() const override
virtual ~Maxwellian()
virtual void getParameters() override
virtual uint getIndex() const override
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
void adjustSingleCellVelocityBlocks(const uint popID, bool doDeleteEmpty=false)
Real getVelocityBlockMinValue(const uint popID) const
void clear(const uint popID, bool shrink=false)
void prepare_to_receive_blocks(const uint popID)
void applyReservation(const uint popID)
std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > parameters
void setReservation(const uint popID, const vmesh::LocalID reservationsize, bool force=false)
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
float Real
Definition definitions.h:41
float Realf
Definition definitions.h:33
const float creal
Definition definitions.h:42
const int j
const int k
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
vmesh::LocalID findMaxwellianBlocksToInitialize(const uint popID, spatial_cell::SpatialCell &cell, creal &rho, creal &T, creal &VX0, creal &VY0, creal &VZ0)
SBC::findMaxwellianBlocksToInitialize returns a list of blocks to construct the VDF with.
static void parallel_reduce(const uint(&limits)[NDim], Lambda loop_body, T &sum)
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
std::string files[6]
Definition inflow.h:39