Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Firehose.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 "Firehose.h"
34
35using namespace std;
36
37namespace projects {
40
42
44 typedef Readparameters RP;
45
46 RP::add("Firehose.Bx", "Magnetic field x component (T)", 0.0);
47 RP::add("Firehose.By", "Magnetic field y component (T)", 0.0);
48 RP::add("Firehose.Bz", "Magnetic field z component (T)", 0.0);
49 RP::add("Firehose.lambda", "Initial perturbation wavelength (m)", 0.0);
50 RP::add("Firehose.amp", "Initial perturbation amplitude (m)", 0.0);
51
52 // Per-population parameters
53 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
54 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
55 RP::add(pop + "_Firehose.rho1", "Number density, first peak (m^-3)", 0.0);
56 RP::add(pop + "_Firehose.rho2", "Number density, second peak (m^-3)", 0.0);
57 RP::add(pop + "_Firehose.Tx1", "Temperature x, first peak (K)", 0.0);
58 RP::add(pop + "_Firehose.Tx2", "Temperature x, second peak (K)", 0.0);
59 RP::add(pop + "_Firehose.Ty1", "Temperature y, first peak (K)", 0.0);
60 RP::add(pop + "_Firehose.Ty2", "Temperature y, second peak (K)", 0.0);
61 RP::add(pop + "_Firehose.Tz1", "Temperature z, first peak (K)", 0.0);
62 RP::add(pop + "_Firehose.Tz2", "Temperature z, second peak (K)", 0.0);
63 RP::add(pop + "_Firehose.Vx1", "Bulk velocity x component, first peak (m/s)", 0.0);
64 RP::add(pop + "_Firehose.Vx2", "Bulk velocity x component, second peak (m/s)", 0.0);
65 RP::add(pop + "_Firehose.Vy1", "Bulk velocity y component, first peak (m/s)", 0.0);
66 RP::add(pop + "_Firehose.Vy2", "Bulk velocity y component, second peak (m/s)", 0.0);
67 RP::add(pop + "_Firehose.Vz1", "Bulk velocity z component, first peak (m/s)", 0.0);
68 RP::add(pop + "_Firehose.Vz2", "Bulk velocity z component, second peak (m/s)", 0.0);
69 }
70 }
71
74 typedef Readparameters RP;
75 RP::get("Firehose.Bx", this->Bx);
76 RP::get("Firehose.By", this->By);
77 RP::get("Firehose.Bz", this->Bz);
78 RP::get("Firehose.lambda", this->lambda);
79 RP::get("Firehose.amp", this->amp);
80
81 // Per-population parameters
82 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
83 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
85 RP::get(pop + "_Firehose.rho1", sP.rho[0]);
86 RP::get(pop + "_Firehose.rho2", sP.rho[1]);
87 RP::get(pop + "_Firehose.Tx1", sP.Tx[0]);
88 RP::get(pop + "_Firehose.Tx2", sP.Tx[1]);
89 RP::get(pop + "_Firehose.Ty1", sP.Ty[0]);
90 RP::get(pop + "_Firehose.Ty2", sP.Ty[1]);
91 RP::get(pop + "_Firehose.Tz1", sP.Tz[0]);
92 RP::get(pop + "_Firehose.Tz2", sP.Tz[1]);
93 RP::get(pop + "_Firehose.Vx1", sP.Vx[0]);
94 RP::get(pop + "_Firehose.Vx2", sP.Vx[1]);
95 RP::get(pop + "_Firehose.Vy1", sP.Vy[0]);
96 RP::get(pop + "_Firehose.Vy2", sP.Vy[1]);
97 RP::get(pop + "_Firehose.Vz1", sP.Vz[0]);
98 RP::get(pop + "_Firehose.Vz2", sP.Vz[1]);
99
100 speciesParams.push_back(sP);
101 }
102 }
103
104 Real Firehose::profile(creal top, creal bottom, creal x) const {
105 return top * (1.0 + this->amp*cos(2.0*M_PI*x/this->lambda));
106 }
107
109 const uint popID,
110 const uint nRequested
111 ) const {
112 const FirehoseSpeciesParameters& sP = speciesParams[popID];
113 // Fetch spatial cell center coordinates
114 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
115 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
116 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
117
118 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
119 Real initRho = sP.rho[0];
120 Real initTx = sP.Tx[0];
121 Real initTy = sP.Ty[0];
122 Real initTz = sP.Tz[0];
123 Real initV0X = profile(sP.Vx[0],sP.Vx[1], x);
124 Real initV0Y = profile(sP.Vy[0],sP.Vy[1], x);
125 Real initV0Z = profile(sP.Vz[0],sP.Vz[1], x);
126
127 #ifdef USE_GPU
130 #else
133 #endif
134 // Loop over blocks
135 Realf rhosum = 0;
137 {WID, WID, WID, nRequested},
138 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
139 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
140 Realf* bufferData = VBC->getData();
141 const vmesh::GlobalID blockGID = GIDlist[initIndex];
142 // Calculate parameters for new block
143 Real blockCoords[6];
144 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
145 creal vxBlock = blockCoords[0];
146 creal vyBlock = blockCoords[1];
147 creal vzBlock = blockCoords[2];
148 creal dvxCell = blockCoords[3];
149 creal dvyCell = blockCoords[4];
150 creal dvzCell = blockCoords[5];
151 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
152 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
153 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
154 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
155 const Realf value = TriMaxwellianPhaseSpaceDensity(vx,vy,vz,initTx,initTy,initTz,initRho,mass);
156 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
157 //lsum[0] += value;
158 };
159 }, rhosum);
160 return rhosum;
161 }
162
164
168 ConstantField bgField;
169 bgField.initialize(this->Bx,
170 this->By,
171 this->Bz);
172
173 setBackgroundField(bgField, bgb, technical, fsgrid);
174 }
175
176} // 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 void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Firehose.cpp:165
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Firehose.cpp:108
std::vector< FirehoseSpeciesParameters > speciesParams
Definition Firehose.h:67
virtual bool initialize(void) override
Definition Firehose.cpp:41
virtual void getParameters(void) override
Definition Firehose.cpp:72
static void addParameters(void)
Definition Firehose.cpp:43
Real profile(creal top, creal bottom, creal x) const
Definition Firehose.cpp:104
virtual ~Firehose()
Definition Firehose.cpp:39
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition Firehose.cpp:163
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
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
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 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