Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Shock.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
34#include "Shock.h"
35
36namespace projects {
39
41
43 typedef Readparameters RP;
44 RP::add("Shock.BX0", "Background field value (T)", 1.0e-9);
45 RP::add("Shock.BY0", "Background field value (T)", 2.0e-9);
46 RP::add("Shock.BZ0", "Background field value (T)", 3.0e-9);
47 RP::add("Shock.EX0", "Background electric field", 0.0);
48 RP::add("Shock.VX0", "Bulk velocity in x", 0.0);
49 RP::add("Shock.VY0", "Bulk velocity in y", 0.0);
50 RP::add("Shock.VZ0", "Bulk velocuty in z", 0.0);
51 RP::add("Shock.rho", "Number density (m^-3)", 1.0e7);
52 RP::add("Shock.Temperature", "Temperature (K)", 2.0e6);
53 RP::add("Shock.magPertAmp", "Amplitude of the magnetic perturbation", 1.0e-9);
54 RP::add("Shock.densityPertAmp", "Amplitude factor of the density perturbation", 0.1);
55 RP::add("Shock.velocityPertAmp", "Amplitude of the velocity perturbation", 1.0e6);
56 RP::add("Shock.maxwCutoff", "Cutoff for the maxwellian distribution", 1e-12);
57 RP::add("Shock.Scale_x", "Scale length in x (m)", 2.0e6);
58 RP::add("Shock.Scale_y", "Scale length in y (m)", 2.0e6);
59 RP::add("Shock.Sharp_Y", "Sharpness of tannh", 0.1);
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 RP::get("Shock.BX0", this->BX0);
71 RP::get("Shock.BY0", this->BY0);
72 RP::get("Shock.BZ0", this->BZ0);
73 RP::get("Shock.EX0", this->EX0);
74 RP::get("Shock.VX0", this->VX0);
75 RP::get("Shock.VY0", this->VY0);
76 RP::get("Shock.VZ0", this->VZ0);
77 RP::get("Shock.rho", this->DENSITY);
78 RP::get("Shock.Temperature", this->TEMPERATURE);
79 RP::get("Shock.magPertAmp", this->magPertAmp);
80 RP::get("Shock.densityPertAmp", this->densityPertAmp);
81 RP::get("Shock.velocityPertAmp", this->velocityPertAmp);
82 RP::get("Shock.maxwCutoff", this->maxwCutoff);
83 RP::get("Shock.Scale_x", this->SCA_X);
84 RP::get("Shock.Scale_y", this->SCA_Y);
85 RP::get("Shock.Sharp_Y", this->Sharp_Y);
86 }
87
89 const uint popID,
90 const uint nRequested
91 ) const {
92 //const speciesParameters& sP = this->speciesParams[popID];
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
101 #ifdef USE_GPU
104 #else
107 #endif
108 // Loop over blocks
109 Realf rhosum = 0;
111 {WID, WID, WID, nRequested},
112 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
113 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
114 Realf* bufferData = VBC->getData();
115 const vmesh::GlobalID blockGID = GIDlist[initIndex];
116 // Calculate parameters for new block
117 Real blockCoords[6];
118 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
119 creal vxBlock = blockCoords[0];
120 creal vyBlock = blockCoords[1];
121 creal vzBlock = blockCoords[2];
122 creal dvxCell = blockCoords[3];
123 creal dvyCell = blockCoords[4];
124 creal dvzCell = blockCoords[5];
125 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
126 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
127 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
128 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
129 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
130 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
131 //lsum[0] += value;
132 };
133 }, rhosum);
134 return rhosum;
135 }
136
138
142 setBackgroundFieldToZero(fsgrid, technical, bgb);
143
144 if(!P::isRestart) {
145 // local copies for lambda capture
146 const auto BZ0_l = this->BZ0;
147 const auto Sharp_Y_l = this->Sharp_Y;
148 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
149 phiprof::initializeTimer("setProjectBField-loop"), technical,
150 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
151 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
152 auto& cell = perb[stencil.ooo()];
153
154 cell[fsgrids::bfield::PERBX] = 0.0;
155 cell[fsgrids::bfield::PERBY] = 0.0;
157 BZ0_l *
158 (3.0 + 2.0 * tanh((xyz[1] - Parameters::ymax / 2.0) / (Sharp_Y_l * Parameters::ymax)));
159 });
160 }
161 }
162}//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 void getParameters(void) override
Definition Shock.cpp:62
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Shock.cpp:139
static void addParameters(void)
Definition Shock.cpp:42
Real maxwCutoff
Definition Shock.h:58
Real DENSITY
Definition Shock.h:53
Real densityPertAmp
Definition Shock.h:56
Real TEMPERATURE
Definition Shock.h:54
Real velocityPertAmp
Definition Shock.h:57
virtual ~Shock()
Definition Shock.cpp:38
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition Shock.cpp:137
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Shock.cpp:88
virtual bool initialize(void) override
Definition Shock.cpp:40
Real Sharp_Y
Definition Shock.h:61
Real magPertAmp
Definition Shock.h:55
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 bool isRestart
Definition parameters.h:176