Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Harris.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 "Harris.h"
33
34using namespace std;
35using namespace spatial_cell;
36
37namespace projects {
40
42
44 typedef Readparameters RP;
45 RP::add("Harris.Scale_size", "Harris sheet scale size (m)", 150000.0);
46 RP::add("Harris.BX0", "Magnetic field at infinity (T)", 8.33061003094e-8);
47 RP::add("Harris.BY0", "Magnetic field at infinity (T)", 8.33061003094e-8);
48 RP::add("Harris.BZ0", "Magnetic field at infinity (T)", 8.33061003094e-8);
49
50 // Per-population parameters
51 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
52 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
53
54 RP::add(pop + "_Harris.Temperature", "Temperature (K)", 2.0e6);
55 RP::add(pop + "_Harris.rho", "Number density at infinity (m^-3)", 1.0e7);
56 }
57 }
58
61 typedef Readparameters RP;
62 RP::get("Harris.Scale_size", this->SCA_LAMBDA);
63 RP::get("Harris.BX0", this->BX0);
64 RP::get("Harris.BY0", this->BY0);
65 RP::get("Harris.BZ0", this->BZ0);
66
67
68 // Per-population parameters
69 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
70 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
72
73 RP::get(pop + "_Harris.Temperature", sP.TEMPERATURE);
74 RP::get(pop + "_Harris.rho", sP.DENSITY);
75
76 speciesParams.push_back(sP);
77 }
78 }
79
81 const uint popID,
82 const uint nRequested
83 ) const {
84 const HarrisSpeciesParameters& sP = speciesParams[popID];
85 // Fetch spatial cell center coordinates
86 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
87 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
88 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
89
90 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
91 Real initRho = sP.DENSITY;
92 Real initT = sP.TEMPERATURE;
93 // Note: bulk V is zero, according to this and getV0().
94 const Real initV0X = 0;
95 const Real initV0Y = 0;
96 const Real initV0Z = 0;
97
98 initRho *= (1.0 + 5.0 / pow(cosh(x / (this->SCA_LAMBDA)), 2.0));
99
100 #ifdef USE_GPU
103 #else
106 #endif
107 // Loop over blocks
108 Realf rhosum = 0;
110 {WID, WID, WID, nRequested},
111 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
112 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
113 Realf* bufferData = VBC->getData();
114 const vmesh::GlobalID blockGID = GIDlist[initIndex];
115 // Calculate parameters for new block
116 Real blockCoords[6];
117 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
118 creal vxBlock = blockCoords[0];
119 creal vyBlock = blockCoords[1];
120 creal vzBlock = blockCoords[2];
121 creal dvxCell = blockCoords[3];
122 creal dvyCell = blockCoords[4];
123 creal dvzCell = blockCoords[5];
124 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
125 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
126 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
127 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
128 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
129 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
130 //lsum[0] += value;
131 };
132 }, rhosum);
133 return rhosum;
134 }
135
136 /* Evaluates local SpatialCell properties for the project and population,
137 then evaluates the phase-space density at the given coordinates.
138 Used as a probe for projectTriAxisSearch.
139 */
141 const uint popID,
142 Real vx_in, Real vy_in, Real vz_in
143 ) const {
144 const HarrisSpeciesParameters& sP = speciesParams[popID];
145 // Fetch spatial cell center coordinates
146 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
147 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
148 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
149
150 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
151 Real initRho = sP.DENSITY;
152 Real initT = sP.TEMPERATURE;
153 // Note: bulk V is zero, according to this and getV0().
154 const Real initV0X = 0;
155 const Real initV0Y = 0;
156 const Real initV0Z = 0;
157
158 initRho *= (1.0 + 5.0 / pow(cosh(x / (this->SCA_LAMBDA)), 2.0));
159 creal vx = vx_in - initV0X;
160 creal vy = vy_in - initV0Y;
161 creal vz = vz_in - initV0Z;
162 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
163 return value;
164 }
165
167
168 vector<std::array<Real, 3>> Harris::getV0(
169 creal x,
170 creal y,
171 creal z,
172 const uint popID
173 ) const {
174 vector<std::array<Real, 3>> V0;
175 std::array<Real, 3> v = {{0.0, 0.0, 0.0 }};
176 V0.push_back(v);
177 return V0;
178 }
179
183 setBackgroundFieldToZero(fsgrid, technical, bgb);
184
185 if(!P::isRestart) {
186 // local copies for lambda capture
187 const auto BX0_l = this->BX0;
188 const auto BY0_l = this->BY0;
189 const auto BZ0_l = this->BZ0;
190 const auto SCA_LAMBDA_l = this->SCA_LAMBDA;
191
192 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
193 phiprof::initializeTimer("setProjectBField-loop"), technical,
194 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
195 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
196 const std::array<Real, 3> gridSpacing = coordinates.physicalGridSpacing;
197 auto& cell = perb[stencil.ooo()];
198
199 cell[fsgrids::bfield::PERBX] = BX0_l * tanh((xyz[1] + 0.5 * gridSpacing[1]) / SCA_LAMBDA_l);
200 cell[fsgrids::bfield::PERBY] = BY0_l * tanh((xyz[2] + 0.5 * gridSpacing[2]) / SCA_LAMBDA_l);
201 cell[fsgrids::bfield::PERBZ] = BZ0_l * tanh((xyz[0] + 0.5 * gridSpacing[0]) / SCA_LAMBDA_l);
202 });
203 }
204 }
205
206} // namespace projects
for i
Definition Dispersion.m:24
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void setBackgroundFieldToZero(FieldSolverGrid &fsgrid, fsgrids::technicalspan technical, fsgrids::bgbspan bgb)
Real SCA_LAMBDA
Definition Harris.h:55
virtual Realf probePhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, Real vx_in, Real vy_in, Real vz_in) const override
Definition Harris.cpp:140
virtual bool initialize(void) override
Definition Harris.cpp:41
static void addParameters(void)
Definition Harris.cpp:43
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 Harris.cpp:168
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition Harris.cpp:166
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Harris.cpp:180
std::vector< HarrisSpeciesParameters > speciesParams
Definition Harris.h:57
virtual ~Harris()
Definition Harris.cpp:39
virtual void getParameters(void) override
Definition Harris.cpp:59
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Harris.cpp:80
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
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 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