Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
ldz_gradpe.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 "fs_common.h"
24#include "ldz_gradpe.hpp"
25#include <limits>
26
27#ifdef DEBUG_VLASIATOR
28 #define DEBUG_FSOLVER
29#endif
30
31using namespace std;
32
96
97
110 fsgrids::consttechnicalspan technical, const fsgrid::FsStencil& stencil,
111 const auto& gridSpacing, SysBoundary& sysBoundaries) {
112#ifdef DEBUG_FSOLVER
113 if (stencil.ooo() >= moments.size()) {
114 cerr << "Out-of-bounds access in " << __FILE__ << ":" << __LINE__ << endl;
115 exit(1);
116 }
117#endif
118 auto& egradpe = egradpes[stencil.ooo()];
119 const auto& moment = moments[stencil.ooo()];
120 const auto& dmoment = dmoments[stencil.ooo()];
121 const auto& tech = technical[stencil.ooo()];
122
123 cuint cellSysBoundaryFlag = tech.sysBoundaryFlag;
124 cuint cellSysBoundaryLayer = tech.sysBoundaryLayer;
125
126 if (cellSysBoundaryFlag == sysboundarytype::DO_NOT_COMPUTE ||
127 cellSysBoundaryFlag == sysboundarytype::OUTER_BOUNDARY_PADDING) {
128 return;
129 }
130
131 if ((cellSysBoundaryFlag != sysboundarytype::NOT_SYSBOUNDARY) && (cellSysBoundaryLayer != 1)) {
132 sysBoundaries.getSysBoundary(cellSysBoundaryFlag)->fieldSolverBoundaryCondGradPeElectricField(egradpes, stencil, 0);
133 sysBoundaries.getSysBoundary(cellSysBoundaryFlag)->fieldSolverBoundaryCondGradPeElectricField(egradpes, stencil, 1);
134 sysBoundaries.getSysBoundary(cellSysBoundaryFlag)->fieldSolverBoundaryCondGradPeElectricField(egradpes, stencil, 2);
135 } else {
136 if (Parameters::ohmGradPeTerm == 0) {
137 cerr << __FILE__ << __LINE__
138 << "You shouldn't be in a electron pressure gradient term function if Parameters::ohmGradPeTerm == 0."
139 << endl;
140 } else if (Parameters::ohmGradPeTerm == 1) {
141 auto calculateEdgeGradPeTermComponent = [&egradpe, &moment, &dmoment](size_t i, size_t j, Real spacing) {
142 const Real rhoq = moment[fsgrids::moments::RHOQ];
144 const Real max = std::numeric_limits<Real>::max();
145 const Real hallRhoq = std::clamp(rhoq, min, max);
146 egradpe[i] = -dmoment[j] / (hallRhoq * spacing);
147 };
148 calculateEdgeGradPeTermComponent(fsgrids::egradpe::EXGRADPE, fsgrids::dmoments::dPedx, gridSpacing[0]);
149 calculateEdgeGradPeTermComponent(fsgrids::egradpe::EYGRADPE, fsgrids::dmoments::dPedy, gridSpacing[1]);
150 calculateEdgeGradPeTermComponent(fsgrids::egradpe::EZGRADPE, fsgrids::dmoments::dPedz, gridSpacing[2]);
151 } else {
152 cerr << __FILE__ << ":" << __LINE__ << "You are welcome to code higher-order Hall term correction terms." << endl;
153 }
154 }
155}
156
158 fsgrids::egradpespan egradpedt2,
159 fsgrids::momentsspan moments,
160 fsgrids::momentsspan momentsdt2,
161 fsgrids::dmomentsspan dmoments,
162 fsgrids::dmomentsspan dmomentsdt2,
164 SysBoundary& sysBoundaries, cint& RKCase) {
165 phiprof::Timer gradPeTimer{"Calculate GradPe term"};
166
167 const size_t numCells = fsgrid.getNumCells();
168
169 if (not(RKCase == RK_ORDER1 || RKCase == RK_ORDER2_STEP2)) {
170 egradpe = egradpedt2;
171 moments = momentsdt2;
172 dmoments = dmomentsdt2;
173 }
174
175 phiprof::Timer mpiTimer{"EgradPe field update ghosts MPI", {"MPI"}};
176 fsgrid.updateGhostCells(dmoments);
177 mpiTimer.stop();
178
179 // Calculate GradPe term
180 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
181 phiprof::initializeTimer("EgradPe compute cells"), technical,
182 [=, &sysBoundaries](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
183 calculateGradPeTerm(egradpe, moments, dmoments, technical, stencil, coordinates.physicalGridSpacing, sysBoundaries);
184 });
185
186 gradPeTimer.stop(numCells, "Spatial Cells");
187}
for i
Definition Dispersion.m:24
virtual void fieldSolverBoundaryCondGradPeElectricField(fsgrids::egradpespan EGradPe, const fsgrid::FsStencil &stencil, cuint component)=0
SysBoundary contains the SysBoundaryConditions used in the simulation.
Definition sysboundary.h:54
SBC::SysBoundaryCondition * getSysBoundary(cuint sysBoundaryType) const
@ RK_ORDER1
Definition common.h:508
@ RK_ORDER2_STEP2
Definition common.h:510
const uint32_t cuint
Definition definitions.h:50
float Real
Definition definitions.h:41
const int cint
Definition definitions.h:45
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
const int j
void calculateGradPeTerm(fsgrids::egradpespan egradpes, fsgrids::constmomentsspan moments, fsgrids::constdmomentsspan dmoments, fsgrids::consttechnicalspan technical, const fsgrid::FsStencil &stencil, const auto &gridSpacing, SysBoundary &sysBoundaries)
void calculateGradPeTermSimple(fsgrids::egradpespan egradpe, fsgrids::egradpespan egradpedt2, fsgrids::momentsspan moments, fsgrids::momentsspan momentsdt2, fsgrids::dmomentsspan dmoments, fsgrids::dmomentsspan dmomentsdt2, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, SysBoundary &sysBoundaries, cint &RKCase)
std::span< const std::array< Real, fsgrids::dmoments::N_DMOMENTS > > constdmomentsspan
Definition common.h:449
@ EZGRADPE
Definition common.h:307
@ EYGRADPE
Definition common.h:306
@ EXGRADPE
Definition common.h:305
std::span< const std::array< Real, fsgrids::moments::N_MOMENTS > > constmomentsspan
Definition common.h:447
std::span< std::array< Real, fsgrids::moments::N_MOMENTS > > momentsspan
Definition common.h:446
std::span< std::array< Real, fsgrids::egradpe::N_EGRADPE > > egradpespan
Definition common.h:440
std::span< std::array< Real, fsgrids::dmoments::N_DMOMENTS > > dmomentsspan
Definition common.h:448
@ RHOQ
Definition common.h:313
std::span< technical > technicalspan
Definition common.h:452
std::span< const technical > consttechnicalspan
Definition common.h:453
@ dPedz
Definition common.h:369
@ dPedx
Definition common.h:367
@ dPedy
Definition common.h:368
@ OUTER_BOUNDARY_PADDING
Definition common.h:493
static uint ohmGradPeTerm
Definition parameters.h:144
static Real hallMinimumRhoq
Definition parameters.h:161
static ARCH_HOSTDEV VecSimple< T > min(VecSimple< T > const &l, VecSimple< T > const &r)
static ARCH_HOSTDEV VecSimple< T > max(VecSimple< T > const &l, VecSimple< T > const &r)