Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
verificationLarmor.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"
34#include "verificationLarmor.h"
35
36using namespace std;
37using namespace spatial_cell;
38
39namespace projects {
43
45 typedef Readparameters RP;
46 RP::add("VerificationLarmor.BX0", "Background field value (T)", 0.0);
47 RP::add("VerificationLarmor.BY0", "Background field value (T)", 0.0);
48 RP::add("VerificationLarmor.BZ0", "Background field value (T)", 0.0);
49 RP::add("VerificationLarmor.VX0", "Bulk velocity in x", 0.0);
50 RP::add("VerificationLarmor.VY0", "Bulk velocity in y", 0.0);
51 RP::add("VerificationLarmor.VZ0", "Bulk velocity in z", 0.0);
52 RP::add("VerificationLarmor.X0", "Initial Position", 0.0);
53 RP::add("VerificationLarmor.Y0", "Initial Position", 0.0);
54 RP::add("VerificationLarmor.Z0", "Initial Position", 0.0);
55 RP::add("VerificationLarmor.rho", "Number density (m^-3)", 1.0e7);
56 }
57
60 typedef Readparameters RP;
61
62 if(getObjectWrapper().particleSpecies.size() > 1) {
63 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
64 abort();
65 }
66 RP::get("VerificationLarmor.BX0", this->BX0);
67 RP::get("VerificationLarmor.BY0", this->BY0);
68 RP::get("VerificationLarmor.BZ0", this->BZ0);
69 RP::get("VerificationLarmor.VX0", this->VX0);
70 RP::get("VerificationLarmor.VY0", this->VY0);
71 RP::get("VerificationLarmor.VZ0", this->VZ0);
72 RP::get("VerificationLarmor.X0", this->X0);
73 RP::get("VerificationLarmor.Y0", this->Y0);
74 RP::get("VerificationLarmor.Z0", this->Z0);
75 RP::get("VerificationLarmor.rho", this->DENSITY);
76 }
77
79 const uint popID,
80 const uint nRequested
81 ) const {
82 // Fetch spatial cell low corner coordinates
83 const Real x = cell->parameters[CellParams::XCRD];
84 const Real dx = cell->parameters[CellParams::DX];
85 const Real y = cell->parameters[CellParams::YCRD];
86 const Real dy = cell->parameters[CellParams::DY];
87 const Real z = cell->parameters[CellParams::ZCRD];
88 const Real dz = cell->parameters[CellParams::DZ];
89 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
90 Real initRho = this->DENSITY;
91
92 // NOTE: This fill function does not have a GPU-supported version.
95 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
96 Realf* bufferData = VBC->getData();
97
98 // Values are only set in cell at X0,Y0,Z0. Otherwise return empty.
99 if (fabs(x-this->X0)>=dx ||
100 fabs(y-this->Y0)>=dy ||
101 fabs(z-this->Z0)>=dz) {
102 std::memset(bufferData, 0, nRequested*WID3*sizeof(Realf));
103 return 0;
104 }
105
106 static bool isSet=false;
107 //static variables should be threadprivate
108 #pragma omp threadprivate(isSet)
109
110 // Loop over blocks
111 Realf rhosum = 0;
112 for (uint blockLID=0; blockLID<nRequested; ++blockLID) {
113 vmesh::GlobalID blockGID = GIDlist[blockLID];
114 // Calculate parameters for block
115 Real blockCoords[6];
116 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
117 creal vxBlock = blockCoords[0];
118 creal vyBlock = blockCoords[1];
119 creal vzBlock = blockCoords[2];
120 creal dvxCell = blockCoords[3];
121 creal dvyCell = blockCoords[4];
122 creal dvzCell = blockCoords[5];
123 for (uint kc=0; kc<WID; ++kc) {
124 for (uint jc=0; jc<WID; ++jc) {
125 for (uint ic=0; ic<WID; ++ic) {
126 creal vx = vxBlock + (ic+0.5)*dvxCell - this->VX0;
127 creal vy = vyBlock + (jc+0.5)*dvyCell - this->VY0;
128 creal vz = vzBlock + (kc+0.5)*dvzCell - this->VZ0;
129 Realf value=0;
130 if (isSet) {
131 continue;
132 }
133 if (fabs(vx)<dvxCell &&
134 fabs(vy)<dvyCell &&
135 fabs(vz)<dvzCell) {
136 isSet = true;
137 value = initRho/(dvxCell*dvyCell*dvzCell);
138 }
139 bufferData[blockLID*WID3 + kc*WID2 + jc*WID + ic] = value;
140 rhosum += value;
141 }
142 }
143 }
144 } // End loop over blocks
145 return rhosum;
146 }
147
149
153 ConstantField bgField;
154 bgField.initialize(this->BX0,
155 this->BY0,
156 this->BZ0);
157
158 setBackgroundField(bgField, bgb, technical, fsgrid);
159 }
160
161} //namespace projects
dx
Definition Dispersion.m:38
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 bool initialize()
Definition project.cpp:113
virtual void getParameters()
Definition project.cpp:103
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
virtual void getParameters(void) override
virtual bool initialize(void) override
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
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
#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
ObjectWrapper & getObjectWrapper()
Definition main.cpp:33
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
uint32_t GlobalID
Definition definitions.h:59
std::vector< species::Species > particleSpecies