Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Alfven.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 "Alfven.h"
33
34using namespace std;
35
36namespace projects {
39
40 bool Alfven::initialize(void) {
41 bool success = Project::initialize();
42
43 Real norm = sqrt(this->Bx_guiding*this->Bx_guiding + this->By_guiding*this->By_guiding + this->Bz_guiding*this->Bz_guiding);
44 this->Bx_guiding /= norm;
45 this->By_guiding /= norm;
46 this->Bz_guiding /= norm;
47 this->ALPHA = atan(this->By_guiding/this->Bx_guiding);
48
49 return success;
50 }
51
53 typedef Readparameters RP;
54 RP::add("Alfven.B0", "Guiding field value (T)", 1.0e-10);
55 RP::add("Alfven.Bx_guiding", "Guiding field x component", 1);
56 RP::add("Alfven.By_guiding", "Guiding field y component", 0);
57 RP::add("Alfven.Bz_guiding", "Guiding field z component", 0);
58 RP::add("Alfven.Wavelength", "Wavelength (m)", 100000.0);
59 RP::add("Alfven.A_mag", "Amplitude of the magnetic perturbation", 0.1);
60
61 // Per-population parameters
62 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
63 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
64
65 RP::add(pop + "_Alfven.rho", "Number density (m^-3)", 1.0e8);
66 RP::add(pop + "_Alfven.Temperature", "Temperature (K)", 0.86456498092);
67 RP::add(pop + "_Alfven.A_vel", "Amplitude of the velocity perturbation", 0.1);
68
69 }
70 }
71
74
75 typedef Readparameters RP;
76 RP::get("Alfven.B0", this->B0);
77 RP::get("Alfven.Bx_guiding", this->Bx_guiding);
78 RP::get("Alfven.By_guiding", this->By_guiding);
79 RP::get("Alfven.Bz_guiding", this->Bz_guiding);
80 RP::get("Alfven.Wavelength", this->WAVELENGTH);
81 RP::get("Alfven.A_mag", this->A_MAG);
82
83 // Per-population parameters
84 for(uint i=0; i< getObjectWrapper().particleSpecies.size(); i++) {
85 const std::string& pop = getObjectWrapper().particleSpecies[i].name;
86
88
89 RP::get(pop + "_Alfven.rho", sP.rho);
90 RP::get(pop + "_Alfven.Temperature",sP.T);
91 RP::get(pop + "_Alfven.A_vel", sP.A_VEL);
92
93 speciesParams.push_back(sP);
94 }
95 }
96
98 const uint popID,
99 const uint nRequested
100 ) const {
101 const AlfvenSpeciesParameters& sP = this->speciesParams[popID];
102
103 // Fetch spatial cell center coordinates
104 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
105 const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
106 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
107
108 creal mass = getObjectWrapper().particleSpecies[popID].mass;
110 creal ALFVEN_VEL = this->B0 / sqrt(mu0 * sP.rho * mass);
111
112 creal ksi = (x * cos(this->ALPHA) + y * sin(this->ALPHA)) / this->WAVELENGTH;
113 creal initV0X = sP.A_VEL * ALFVEN_VEL * sin(this->ALPHA) * sin(2.0 * M_PI * ksi);
114 creal initV0Y = - sP.A_VEL * ALFVEN_VEL * cos(this->ALPHA) * sin(2.0 * M_PI * ksi);
115 creal initV0Z = - sP.A_VEL * ALFVEN_VEL * cos(2.0 * M_PI * ksi);
116
117 Real initRho = sP.rho;
118 Real initT = sP.T;
119
120 #ifdef USE_GPU
123 #else
126 #endif
127 // Loop over blocks
128 Realf rhosum = 0;
130 {WID, WID, WID, nRequested},
131 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
132 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
133 Realf* bufferData = VBC->getData();
134 const vmesh::GlobalID blockGID = GIDlist[initIndex];
135 // Calculate parameters for new block
136 Real blockCoords[6];
137 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
138 creal vxBlock = blockCoords[0];
139 creal vyBlock = blockCoords[1];
140 creal vzBlock = blockCoords[2];
141 creal dvxCell = blockCoords[3];
142 creal dvyCell = blockCoords[4];
143 creal dvzCell = blockCoords[5];
144 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
145 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
146 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
147 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
148 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
149 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
150 //lsum[0] += value;
151 };
152 }, rhosum);
153 return rhosum;
154 }
155
157 //Real* cellParams = cell->get_cell_parameters();
158 //creal x = cellParams[CellParams::XCRD];
159 //creal dx = cellParams[CellParams::DX];
160 //creal y = cellParams[CellParams::YCRD];
161 //creal dy = cellParams[CellParams::DY];
162 //
163 //Real ksi = ((x + 0.5 * dx) * cos(this->ALPHA) + (y + 0.5 * dy) * sin(this->ALPHA)) / this->WAVELENGTH;
164 //Real dBxavg = sin(2.0 * M_PI * ksi);
165 //Real dByavg = sin(2.0 * M_PI * ksi);
166 //Real dBzavg = cos(2.0 * M_PI * ksi);
167 }
168
172 setBackgroundFieldToZero(fsgrid, technical, bgb);
173
174 if (!P::isRestart) {
175 // local copies for lambda capture
176 const auto ALPHA_l = this->ALPHA;
177 const auto WAVELENGTH_l = this->WAVELENGTH;
178 const auto B0_l = this->B0;
179 const auto A_MAG_l = this->A_MAG;
180
181 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
182 phiprof::initializeTimer("setProjectBField"), technical,
183 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
184 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
185 const std::array<Real, 3> gridSpacing = coordinates.physicalGridSpacing;
186 auto& cell = perb[stencil.ooo()];
187
188 const Real dx = gridSpacing[0];
189 const Real dy = gridSpacing[1];
190 const Real ksi = ((xyz[0] + 0.5 * dx) * cos(ALPHA_l) + (xyz[1] + 0.5 * dy) * sin(ALPHA_l)) / WAVELENGTH_l;
191 const Real dBxavg = sin(2.0 * M_PI * ksi);
192 const Real dByavg = sin(2.0 * M_PI * ksi);
193 const Real dBzavg = cos(2.0 * M_PI * ksi);
194
195 cell[fsgrids::bfield::PERBX] = B0_l * cos(ALPHA_l) - A_MAG_l * B0_l * sin(ALPHA_l) * dBxavg;
196 cell[fsgrids::bfield::PERBY] = B0_l * sin(ALPHA_l) + A_MAG_l * B0_l * cos(ALPHA_l) * dByavg;
197 cell[fsgrids::bfield::PERBZ] = B0_l * A_MAG_l * dBzavg;
198 });
199 }
200 }
201
202} // namespace projects
mu0
Definition Dispersion.m:50
for i
Definition Dispersion.m:24
dx
Definition Dispersion.m:38
sqrt(1.0+vA *vA/(c *c))) % Ion-acoustic wave cS
#define ARCH_INNER_BODY(...)
#define ARCH_LOOP_LAMBDA
void setBackgroundFieldToZero(FieldSolverGrid &fsgrid, fsgrids::technicalspan technical, fsgrids::bgbspan bgb)
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition Alfven.cpp:156
Real Bx_guiding
Definition Alfven.h:57
std::vector< AlfvenSpeciesParameters > speciesParams
Definition Alfven.h:63
Real Bz_guiding
Definition Alfven.h:59
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Alfven.cpp:97
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Alfven.cpp:169
Real By_guiding
Definition Alfven.h:58
virtual bool initialize(void) override
Definition Alfven.cpp:40
static void addParameters(void)
Definition Alfven.cpp:52
virtual ~Alfven()
Definition Alfven.cpp:38
Real WAVELENGTH
Definition Alfven.h:61
virtual void getParameters(void) override
Definition Alfven.cpp:72
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
const Real MU_0
Definition common.h:570
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