Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
ldz_volume.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
25#include "fs_common.h"
26#include "ldz_volume.hpp"
27
28#ifdef DEBUG_VLASIATOR
29 #define DEBUG_FSOLVER
30#endif
31
36 const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
37 const auto center = stencil.ooo();
38 std::array<Real, fsgrids::volfields::N_VOL>& vol = vols[center];
39 const auto sbflag = sysBoundaryFlag;
40
41#ifdef DEBUG_FSOLVER
42 const bool ok = stencil.cellExists(0, 1, 0) && stencil.cellExists(0, 0, 1) && stencil.cellExists(0, 1, 1) &&
43 stencil.cellExists(1, 0, 0) && stencil.cellExists(1, 1, 0) && stencil.cellExists(1, 0, 1);
44
45 if (ok == false) {
46 std::cerr << "Out-of-bounds access in " << __FILE__ << ":" << __LINE__ << endl;
47 exit(1);
48 }
49#endif
50
51 // Calculate reconstruction coefficients for this cell:
52 // This handles domain edges so no need to skip DO_NOT_COMPUTE or OUTER_BOUNDARY_PADDING cells.
53 const auto perturbedCoefficients = reconstructionCoefficients(perb, dperb, stencil, 2);
54
55 // Calculate volume average of B:
56 vol[fsgrids::volfields::PERBXVOL] = perturbedCoefficients[Rec::a_0];
57 vol[fsgrids::volfields::PERBYVOL] = perturbedCoefficients[Rec::b_0];
58 vol[fsgrids::volfields::PERBZVOL] = perturbedCoefficients[Rec::c_0];
59
60 // This avoids out of domain accesses below.
62 return;
63 }
64
65 if (sbflag == sysboundarytype::NOT_SYSBOUNDARY || sysBoundaryLayer == 1) {
66 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i1j1k1 = e[center];
67 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i1j2k1 = e[stencil.opo()];
68 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i1j1k2 = e[stencil.oop()];
69 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i1j2k2 = e[stencil.opp()];
70 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i2j1k1 = e[stencil.poo()];
71 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i2j1k2 = e[stencil.pop()];
72 const std::array<Real, fsgrids::efield::N_EFIELD>& E_i2j2k1 = e[stencil.ppo()];
73
86
90 } else {
94 }
95
99}
100
103 fsgrids::dperbspan dperb,
106 phiprof::Timer timer{"Calculate volume averaged fields"};
107 const size_t numCells = fsgrid.getNumCells();
108 fsgrid.parallel_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
109 phiprof::initializeTimer("volume averaged fields compute cells"), technical,
110 [=](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
111 calculateVolumeAveragedFields(perb, e, dperb, vol, stencil, sysBoundaryFlag,
112 sysBoundaryLayer);
113 });
114 timer.stop(numCells, "Spatial Cells");
115}
#define CHECK_FLOAT(x)
Definition common.h:42
const uint32_t cuint
Definition definitions.h:50
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
std::array< Real, Rec::N_REC_COEFFICIENTS > reconstructionCoefficients(fsgrids::perbspan perb, fsgrids::constdperbspan dperb, const fsgrid::FsStencil &stencil, Real reconstructionOrder)
Low-level helper function.
Definition fs_common.cpp:53
const Real FOURTH
Definition fs_common.h:53
void calculateVolumeAveragedFieldsSimple(fsgrids::perbspan perb, fsgrids::efieldspan e, fsgrids::dperbspan dperb, fsgrids::volspan vol, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)
Top-level field averaging function.
void calculateVolumeAveragedFields(fsgrids::perbspan perb, fsgrids::constefieldspan e, fsgrids::constdperbspan dperb, fsgrids::volspan vols, const fsgrid::FsStencil &stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer)
@ a_0
Definition fs_common.h:88
@ b_0
Definition fs_common.h:89
@ c_0
Definition fs_common.h:90
std::span< std::array< Real, fsgrids::bfield::N_BFIELD > > perbspan
Definition common.h:434
std::span< const std::array< Real, fsgrids::efield::N_EFIELD > > constefieldspan
Definition common.h:437
std::span< technical > technicalspan
Definition common.h:452
std::span< std::array< Real, fsgrids::dperb::N_DPERB > > dperbspan
Definition common.h:442
@ PERBYVOL
Definition common.h:405
@ EZVOL
Definition common.h:418
@ EXVOL
Definition common.h:416
@ PERBXVOL
Definition common.h:404
@ EYVOL
Definition common.h:417
@ PERBZVOL
Definition common.h:406
std::span< std::array< Real, fsgrids::efield::N_EFIELD > > efieldspan
Definition common.h:436
std::span< std::array< Real, fsgrids::volfields::N_VOL > > volspan
Definition common.h:450
std::span< const std::array< Real, fsgrids::dperb::N_DPERB > > constdperbspan
Definition common.h:443
@ OUTER_BOUNDARY_PADDING
Definition common.h:493