Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
testHall.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 "testHall.h"
34
35using namespace std;
36
37namespace projects {
40
42 bool success = Project::initialize();
43 this->constBgB[0] = 0.0;
44 this->constBgB[1] = 0.0;
45 this->constBgB[2] = 0.0;
46 this->dipoleScalingFactor = 1.0;
47 this->dipoleTilt = 0.0;
48 this->noDipoleInSW = 0;
49 return success;
50 }
51
53 typedef Readparameters RP;
54 RP::add("TestHall.BX0", "Magnetic field x (T)", 1.0e-9);
55 RP::add("TestHall.BY0", "Magnetic field y (T)", 1.0e-9);
56 RP::add("TestHall.BZ0", "Magnetic field z (T)", 1.0e-9);
57 RP::add("TestHall.VX0", "velocity x (m/s)", -1.0e3);
58 RP::add("TestHall.VY0", "velocity y (m/s)", 1.0e3);
59 RP::add("TestHall.VZ0", "velocity z (m/s)", 1.0e3);
60 RP::add("TestHall.Temperature", "Temperature (K)", 1.0e6);
61 RP::add("TestHall.rho", "Number density (m^-3)", 1.0e6);
62 }
63
66 typedef Readparameters RP;
67
68 if(getObjectWrapper().particleSpecies.size() > 1) {
69 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
70 abort();
71 }
72 RP::get("TestHall.BX0", this->BX0);
73 RP::get("TestHall.BY0", this->BY0);
74 RP::get("TestHall.BZ0", this->BZ0);
75 RP::get("TestHall.VX0", this->VX0);
76 RP::get("TestHall.VY0", this->VY0);
77 RP::get("TestHall.VZ0", this->VZ0);
78 RP::get("TestHall.Temperature", this->TEMPERATURE);
79 RP::get("TestHall.rho", this->DENSITY);
80 }
81
83 const uint popID,
84 const uint nRequested
85 ) const {
86 //const speciesParameters& sP = this->speciesParams[popID];
87 // Fetch spatial cell center coordinates
88 // const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
89 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
90 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
91
92 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
93 Real initRho = this->DENSITY;
94 Real initT = this->TEMPERATURE;
95 const Real initV0X = this->VX0;
96 const Real initV0Y = this->VY0;
97 const Real initV0Z = this->VZ0;
98
99 #ifdef USE_GPU
102 #else
105 #endif
106 // Loop over blocks
107 Realf rhosum = 0;
109 {WID, WID, WID, nRequested},
110 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
111 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
112 Realf* bufferData = VBC->getData();
113 const vmesh::GlobalID blockGID = GIDlist[initIndex];
114 // Calculate parameters for new 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 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
124 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
125 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
126 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
127 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
128 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
129 //lsum[0] += value;
130 };
131 }, rhosum);
132 return rhosum;
133 }
134
136
140 setBackgroundFieldToZero(fsgrid, technical, bgb);
141
142 if(!P::isRestart) {
143 // local copies for lambda capture
144 const auto BX0_l = this->BX0;
145 const auto BY0_l = this->BY0;
146 const auto BZ0_l = this->BZ0;
147 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
148 phiprof::initializeTimer("setProjectBField-loop"), technical,
149 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
150 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
151 auto& cell = perb[stencil.ooo()];
152
153 cell[fsgrids::bfield::PERBX] = BX0_l * cos(2.0 * M_PI * 1.0 * xyz[0] / (P::xmax - P::xmin)) *
154 cos(2.0 * M_PI * 1.0 * xyz[1] / (P::ymax - P::ymin)) *
155 cos(2.0 * M_PI * 1.0 * xyz[2] / (P::zmax - P::zmin));
156 cell[fsgrids::bfield::PERBY] = BY0_l * cos(2.0 * M_PI * 1.0 * xyz[0] / (P::xmax - P::xmin)) *
157 cos(2.0 * M_PI * 1.0 * xyz[1] / (P::ymax - P::ymin)) *
158 cos(2.0 * M_PI * 1.0 * xyz[2] / (P::zmax - P::zmin));
159 cell[fsgrids::bfield::PERBZ] = BZ0_l * cos(2.0 * M_PI * 1.0 * xyz[0] / (P::xmax - P::xmin)) *
160 cos(2.0 * M_PI * 1.0 * xyz[1] / (P::ymax - P::ymin)) *
161 cos(2.0 * M_PI * 1.0 * xyz[2] / (P::zmax - P::zmin));
162 });
163 }
164 }
165
166} // 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)
virtual bool initialize()
Definition project.cpp:113
virtual void getParameters()
Definition project.cpp:103
virtual ~TestHall()
Definition testHall.cpp:39
virtual bool initialize(void) override
Definition testHall.cpp:41
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition testHall.cpp:135
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition testHall.cpp:137
Real dipoleScalingFactor
Definition testHall.h:48
static void addParameters(void)
Definition testHall.cpp:52
virtual void getParameters(void) override
Definition testHall.cpp:64
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition testHall.cpp:82
vmesh::VelocityMesh * get_velocity_mesh(const size_t &popID)
vmesh::VelocityBlockContainer * get_velocity_blocks(const size_t &popID)
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 Real ymax
Definition parameters.h:41
static Real xmax
Definition parameters.h:39
static Real zmax
Definition parameters.h:43
static Real ymin
Definition parameters.h:40
static Real xmin
Definition parameters.h:38
static bool isRestart
Definition parameters.h:176
static Real zmin
Definition parameters.h:42