Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Larmor.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
35#include "Larmor.h"
36
37using namespace std;
38using namespace spatial_cell;
39
40namespace projects {
43
44
46
48 typedef Readparameters RP;
49 RP::add("Larmor.BX0", "Background field value (T)", 0.0);
50 RP::add("Larmor.BY0", "Background field value (T)", 0.0);
51 RP::add("Larmor.BZ0", "Background field value (T)", 3.0e-9);
52 RP::add("Larmor.VX0", "Bulk velocity in x", 0.0);
53 RP::add("Larmor.VY0", "Bulk velocity in y", 0.0);
54 RP::add("Larmor.VZ0", "Bulk velocuty in z", 0.0);
55 RP::add("Larmor.rho", "Number density (m^-3)", 1.0e7);
56 RP::add("Larmor.Temperature", "Temperature (K)", 2.0e6);
57 RP::add("Larmor.maxwCutoff", "Cutoff for the maxwellian distribution", 1e-12);
58 RP::add("Larmor.Scale_x", "Scale length in x (m)", 2.0e6);
59 RP::add("Larmor.Scale_y", "Scale length in y (m)", 2.0e6);
60 }
61
64 typedef Readparameters RP;
65
66 if(getObjectWrapper().particleSpecies.size() > 1) {
67 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
68 abort();
69 }
70
71 RP::get("Larmor.BX0", this->BX0);
72 RP::get("Larmor.BY0", this->BY0);
73 RP::get("Larmor.BZ0", this->BZ0);
74 RP::get("Larmor.VX0", this->VX0);
75 RP::get("Larmor.VY0", this->VY0);
76 RP::get("Larmor.VZ0", this->VZ0);
77 RP::get("Larmor.rho", this->DENSITY);
78 RP::get("Larmor.Temperature", this->TEMPERATURE);
79 RP::get("Larmor.maxwCutoff", this->maxwCutoff);
80 RP::get("Larmor.Scale_x", this->SCA_X);
81 RP::get("Larmor.Scale_y", this->SCA_Y);
82 }
83
85 const uint popID,
86 const uint nRequested
87 ) const {
88 //const speciesParameters& sP = this->speciesParams[popID];
89 // Fetch spatial cell center coordinates
90 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
91 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
92 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
93
94 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
95 Real initRho = this->DENSITY;
96 Real initT = this->TEMPERATURE;
97 const Real initV0X = this->VX0;
98 const Real initV0Y = this->VY0;
99 const Real initV0Z = this->VZ0;
100 initRho = initRho * exp(-pow(x-Parameters::xmax/2.5, 2.0)/pow(this->SCA_X, 2.0)) * exp(-pow(y-Parameters::ymax/2.0, 2.0)/pow(this->SCA_Y, 2.0));
101
102 #ifdef USE_GPU
105 #else
108 #endif
109 // Loop over blocks
110 Realf rhosum = 0;
112 {WID, WID, WID, nRequested},
113 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
114 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
115 Realf* bufferData = VBC->getData();
116 const vmesh::GlobalID blockGID = GIDlist[initIndex];
117 // Calculate parameters for new block
118 Real blockCoords[6];
119 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
120 creal vxBlock = blockCoords[0];
121 creal vyBlock = blockCoords[1];
122 creal vzBlock = blockCoords[2];
123 creal dvxCell = blockCoords[3];
124 creal dvyCell = blockCoords[4];
125 creal dvzCell = blockCoords[5];
126 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
127 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
128 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
129 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
130 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
131 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
132 //lsum[0] += value;
133 };
134 }, rhosum);
135 return rhosum;
136 }
137
139
143 ConstantField bgField;
144 bgField.initialize(this->BX0, this->BY0, this->BZ0);
145
146 setBackgroundField(bgField, bgb, technical, fsgrid);
147 }
148} //namespace projects
149
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)
static void addParameters(void)
Definition Larmor.cpp:47
virtual bool initialize(void) override
Definition Larmor.cpp:45
virtual ~Larmor()
Definition Larmor.cpp:42
virtual void getParameters(void) override
Definition Larmor.cpp:62
Real maxwCutoff
Definition Larmor.h:57
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition Larmor.cpp:138
Real TEMPERATURE
Definition Larmor.h:56
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Larmor.cpp:140
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Larmor.cpp:84
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 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