Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
Riemann1.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"
32
33#include "Riemann1.h"
34
35using namespace std;
36
37namespace projects {
40
42
44 typedef Readparameters RP;
45 RP::add("Riemann.rho1", "Number density, left state (m^-3)", 0.0);
46 RP::add("Riemann.rho2", "Number density, right state (m^-3)", 0.0);
47 RP::add("Riemann.T1", "Temperature, left state (K)", 0.0);
48 RP::add("Riemann.T2", "Temperature, right state (K)", 0.0);
49 RP::add("Riemann.Vx1", "Bulk velocity x component, left state (m/s)", 0.0);
50 RP::add("Riemann.Vx2", "Bulk velocity x component, right state (m/s)", 0.0);
51 RP::add("Riemann.Vy1", "Bulk velocity y component, left state (m/s)", 0.0);
52 RP::add("Riemann.Vy2", "Bulk velocity y component, right state (m/s)", 0.0);
53 RP::add("Riemann.Vz1", "Bulk velocity z component, left state (m/s)", 0.0);
54 RP::add("Riemann.Vz2", "Bulk velocity z component, right state (m/s)", 0.0);
55 RP::add("Riemann.Bx1", "Magnetic field x component, left state (T)", 0.0);
56 RP::add("Riemann.Bx2", "Magnetic field x component, right state (T)", 0.0);
57 RP::add("Riemann.By1", "Magnetic field y component, left state (T)", 0.0);
58 RP::add("Riemann.By2", "Magnetic field y component, right state (T)", 0.0);
59 RP::add("Riemann.Bz1", "Magnetic field z component, left state (T)", 0.0);
60 RP::add("Riemann.Bz2", "Magnetic field z component, right state (T)", 0.0);
61 }
62
65 typedef Readparameters RP;
66
67 if(getObjectWrapper().particleSpecies.size() > 1) {
68 std::cerr << "The selected project does not support multiple particle populations! Aborting in " << __FILE__ << " line " << __LINE__ << std::endl;
69 abort();
70 }
71 RP::get("Riemann.rho1", this->rho[this->LEFT]);
72 RP::get("Riemann.rho2", this->rho[this->RIGHT]);
73 RP::get("Riemann.T1", this->T[this->LEFT]);
74 RP::get("Riemann.T2", this->T[this->RIGHT]);
75 RP::get("Riemann.Vx1", this->Vx[this->LEFT]);
76 RP::get("Riemann.Vx2", this->Vx[this->RIGHT]);
77 RP::get("Riemann.Vy1", this->Vy[this->LEFT]);
78 RP::get("Riemann.Vy2", this->Vy[this->RIGHT]);
79 RP::get("Riemann.Vz1", this->Vz[this->LEFT]);
80 RP::get("Riemann.Vz2", this->Vz[this->RIGHT]);
81 RP::get("Riemann.Bx1", this->Bx[this->LEFT]);
82 RP::get("Riemann.Bx2", this->Bx[this->RIGHT]);
83 RP::get("Riemann.By1", this->By[this->LEFT]);
84 RP::get("Riemann.By2", this->By[this->RIGHT]);
85 RP::get("Riemann.Bz1", this->Bz[this->LEFT]);
86 RP::get("Riemann.Bz2", this->Bz[this->RIGHT]);
87 }
88
90 const uint popID,
91 const uint nRequested
92 ) const {
93 //const speciesParameters& sP = this->speciesParams[popID];
94 // Fetch spatial cell center coordinates
95 const Real x = cell->parameters[CellParams::XCRD] + 0.5*cell->parameters[CellParams::DX];
96 // const Real y = cell->parameters[CellParams::YCRD] + 0.5*cell->parameters[CellParams::DY];
97 // const Real z = cell->parameters[CellParams::ZCRD] + 0.5*cell->parameters[CellParams::DZ];
98 cint side = (x < 0.0) ? this->LEFT : this->RIGHT;
99
100 const Real mass = getObjectWrapper().particleSpecies[popID].mass;
101 Real initRho = this->rho[side];
102 Real initT = this->T[side];
103 const Real initV0X = this->Vx[side];
104 const Real initV0Y = this->Vy[side];
105 const Real initV0Z = this->Vz[side];
106
107 #ifdef USE_GPU
110 #else
113 #endif
114 // Loop over blocks
115 Realf rhosum = 0;
117 {WID, WID, WID, nRequested},
118 ARCH_LOOP_LAMBDA (const uint i, const uint j, const uint k, const uint initIndex, Realf *lsum ) {
119 vmesh::GlobalID *GIDlist = vmesh->getGrid()->data();
120 Realf* bufferData = VBC->getData();
121 const vmesh::GlobalID blockGID = GIDlist[initIndex];
122 // Calculate parameters for new block
123 Real blockCoords[6];
124 vmesh->getBlockInfo(blockGID,&blockCoords[0]);
125 creal vxBlock = blockCoords[0];
126 creal vyBlock = blockCoords[1];
127 creal vzBlock = blockCoords[2];
128 creal dvxCell = blockCoords[3];
129 creal dvyCell = blockCoords[4];
130 creal dvzCell = blockCoords[5];
131 ARCH_INNER_BODY(i, j, k, initIndex, lsum) {
132 creal vx = vxBlock + (i+0.5)*dvxCell - initV0X;
133 creal vy = vyBlock + (j+0.5)*dvyCell - initV0Y;
134 creal vz = vzBlock + (k+0.5)*dvzCell - initV0Z;
135 const Realf value = MaxwellianPhaseSpaceDensity(vx,vy,vz,initT,initRho,mass);
136 bufferData[initIndex*WID3 + k*WID2 + j*WID + i] = value;
137 //lsum[0] += value;
138 };
139 }, rhosum);
140 return rhosum;
141 }
142
144
148 setBackgroundFieldToZero(fsgrid, technical, bgb);
149
150 if(!P::isRestart) {
151 // local copies for lambda capture
152 const auto Bx_l = this->Bx;
153 const auto By_l = this->By;
154 const auto Bz_l = this->Bz;
155 const auto LEFT_l = this->LEFT;
156 const auto RIGHT_l = this->RIGHT;
157
158 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
159 phiprof::initializeTimer("setProjectBField-loop"), technical,
160 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
161 const std::array<Real, 3> xyz = coordinates.getPhysicalCoords(stencil.i, stencil.j, stencil.k);
162 auto& cell = perb[stencil.ooo()];
163
164 //Real Bxavg, Byavg, Bzavg;
165 //Bxavg = Byavg = Bzavg = 0.0;
166 cell[fsgrids::bfield::PERBX] = (xyz[0] < 0.0) ? Bx_l[LEFT_l] : Bx_l[RIGHT_l];
167 cell[fsgrids::bfield::PERBY] = (xyz[0] < 0.0) ? By_l[LEFT_l] : By_l[RIGHT_l];
168 cell[fsgrids::bfield::PERBZ] = (xyz[0] < 0.0) ? Bz_l[LEFT_l] : Bz_l[RIGHT_l];
169 });
170 }
171 }
172}
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
static void addParameters(void)
Definition Riemann1.cpp:43
virtual void calcCellParameters(spatial_cell::SpatialCell *cell, creal &t) override
Definition Riemann1.cpp:143
virtual Realf fillPhaseSpace(spatial_cell::SpatialCell *cell, const uint popID, const uint nRequested) const override
Definition Riemann1.cpp:89
virtual void setProjectBField(fsgrids::perbspan perb, fsgrids::bgbspan bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid) override
Definition Riemann1.cpp:145
virtual bool initialize(void) override
Definition Riemann1.cpp:41
virtual ~Riemann1()
Definition Riemann1.cpp:39
virtual void getParameters(void) override
Definition Riemann1.cpp:63
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
const int cint
Definition definitions.h:45
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 bool isRestart
Definition parameters.h:176