Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Diffusion.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"
33#include "Diffusion.h"
34
35using namespace std;
36using namespace spatial_cell;
37
38namespace projects {
41
43 return Project::initialize();
44 }
45
47 typedef Readparameters RP;
48 RP::add("Diffusion.B0", "Background field value (T)", 1.0e-9);
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 + "_Diffusion.rho", "Number density (m^-3)", 1.0e7);
55 RP::add(pop + "_Diffusion.Temperature", "Temperature (K)", 2.0e6);
56 RP::add(pop + "_Diffusion.Scale_x", "Scale length in x (m)", 100000.0);
57 RP::add(pop + "_Diffusion.Scale_y", "Scale length in y (m)", 100000.0);
58 }
59 }
60
63
64 typedef Readparameters RP;
65 RP::get("Diffusion.B0", this->B0);
66
67 // Per-population parameters
68 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
69 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
71
72 RP::get(pop + "_Diffusion.rho", sP.DENSITY);
73 RP::get(pop + "_Diffusion.Temperature", sP.TEMPERATURE);
74 RP::get(pop + "_Diffusion.Scale_x", sP.SCA_X);
75 RP::get(pop + "_Diffusion.Scale_y", sP.SCA_Y);
76
77 speciesParams.push_back(sP);
78 }
79 }
80
82 const uint popID,
83 const uint nRequested
84 ) const {
86 creal mass = getObjectWrapper().particleSpecies[popID].mass;
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 const Real initV0X = 0;
92 const Real initV0Y = 0;
93 const Real initV0Z = 0;
95 const Real initRho = sP.DENSITY;
96 const Real initT = sP.TEMPERATURE;
97 const Real initScaY = sP.SCA_Y;
98 const Real initScaX = sP.SCA_X;
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 = initRho * pow(mass / (2.0 * M_PI * kb * initT), 1.5) * (
129 5.0 * exp(- (pow(x, 2.0) / pow(initScaX, 2.0) + pow(y, 2.0) / pow(initScaY, 2.0))) *
130 exp(- mass * (pow(vx, 2.0) + pow(vy, 2.0) + pow(vz, 2.0)) / (2.0 * kb * initT))
131 + exp(- mass * (pow(vx, 2.0) + pow(vy, 2.0) + pow(vz, 2.0)) / (2.0 * kb * initT)));
132 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
133 //lsum[0] += value;
134 };
135 }, rhosum);
136 return rhosum;
137 }
138
140
144 fsgrids::technicalspan technical,
146 ) {
147 ConstantField bgField;
148 bgField.initialize(0,0,this->B0); //bg bx, by,bz
149 setBackgroundField(bgField, bgb, technical, fsgrid);
150 }
151} // namespace projects
for i
Definition Dispersion.m:24
kb
Definition Dispersion.m:46
#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 Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Diffusion.cpp:81
std::vector< DiffusionSpeciesParameters > speciesParams
Definition Diffusion.h:60
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
static void addParameters(void)
Definition Diffusion.cpp:46
virtual void getParameters(void) override
Definition Diffusion.cpp:61
virtual bool initialize(void) override
Definition Diffusion.cpp:42
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
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
const Real K_B
Definition common.h:571
uint32_t GlobalID
Definition definitions.h:59
std::vector< species::Species > particleSpecies