Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
sysboundarycondition.h
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#ifndef SYSBOUNDARYCONDITION_H
24#define SYSBOUNDARYCONDITION_H
25
26#include <dccrg.hpp>
27#include <dccrg_cartesian_geometry.hpp>
28#include <fsgrid.hpp>
29
30#include <vector>
31#include "../common.h"
32#include "../definitions.h"
34#include "../projects/project.h"
35
36using namespace spatial_cell;
37using namespace projects;
38
39namespace SBC {
57 public:
59 virtual ~SysBoundaryCondition();
60
61 static void addParameters();
62 virtual void getParameters() {
63 std::cerr << "ERROR: base class SysBoundaryCondition::getParameters called!" << std::endl;
64 }
65 virtual void generateTemplateCell() {
66 std::cerr << "ERROR: base class SysBoundaryCondition::generateTemplateCells called!" << std::endl;
67 }
68
69 virtual void initSysBoundary(
70 creal& t,
71 Project &project
72 )=0;
73 virtual void assignSysBoundary(dccrg::Dccrg<SpatialCell,
74 dccrg::Cartesian_Geometry>& mpiGrid,
76 virtual void applyInitialState(dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
80 Project& project) = 0;
81 virtual void updateState(dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
84 fsgrids::bgbspan bgb, creal t) = 0;
85 virtual Real
89 const std::array<Real, 3>& gridSpacing,
90 const std::array<fsgrid::FsSize_t, 3>& globalCoordinates,
91 const fsgrid::FsStencil& stencil, cuint component) = 0;
93 const fsgrid::FsStencil& stencil, cuint component) = 0;
94 virtual void
96 const fsgrid::FsStencil& stencil, cuint component) = 0;
97 virtual void
99 const fsgrid::FsStencil& stencil, cuint component) = 0;
100 virtual void
102 fsgrids::dmomentsspan dmoments,
103 const fsgrid::FsStencil& stencil, cuint RKCase, cuint component) = 0;
104 virtual void
106 const fsgrid::FsStencil& stencil, cuint component) = 0;
108 fsgrids::dmomentsspan dmoments,
109 const fsgrid::FsStencil& stencil, cuint component);
111 const fsgrid::FsStencil& stencil, cuint component);
112
114 std::array<Real, CellParams::N_SPATIAL_CELL_PARAMS>& cellParams
115 );
116
124 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
125 const CellID& cellID,
126 const uint popID,
127 const bool calculate_V_moments
128 )=0;
129
131 dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid
132 ) {
133 std::cerr << "ERROR: base class SysBoundaryCondition::setupL2OutflowAtRestart called!" << std::endl;
134 }
135
136
137
142 virtual void getFaces(bool *faces) = 0;
143 virtual std::string getName() const {
144 std::cerr << "ERROR: base class SysBoundaryCondition::getName called!" << std::endl;
145 return "ERROR";
146 }
147 virtual uint getIndex() const = 0; // {
148// std::cerr << "ERROR: base class SysBoundaryCondition::getIndex called!" << std::endl;
149// return sysboundarytype::N_SYSBOUNDARY_CONDITIONS;
150// }
151 uint getPrecedence() const;
152 bool isDynamic() const;
153
155 const dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
156 const std::vector<CellID> & local_cells_on_boundary
157 );
158 bool doApplyUponRestart() const;
159 void setPeriodicity(
160 std::array<bool, 3> isFacePeriodic
161 );
162 protected:
163 void determineFace(
164 bool* isThisCellOnAFace,
165 const creal x,const creal y,const creal z,
166 const creal dx,const creal dy,const creal dz,
167 const bool excludeSlicesAndPeriodicDimensions = false
168 ) const;
169 void determineFace(
170 std::array<bool, 6> &isThisCellOnAFace,
171 const dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
172 CellID id,
173 const bool excludeSlicesAndPeriodicDimensions = false
174 );
175 void copyCellData(
176 const SpatialCell *from,
177 SpatialCell *to,
178 const bool copyMomentsOnly,
179 const uint popID,
180 const bool copy_V_moments
181 );
182 std::array<SpatialCell*,27> & getFlowtoCells(
183 const CellID& cellID
184 );
185
186 std::array<Realf*,27> getFlowtoCellsBlock(
187 const std::array<SpatialCell*,27> flowtoCells,
188 const vmesh::GlobalID blockGID,
189 const uint popID
190 );
191
192
199 inline int nbrID(const int i, const int j, const int k){
200 return (k+1)*9 + (j+1)*3 + i + 1;
201 }
202
204 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
205 const CellID& cellID,
206 const bool& copyMomentsOnly,
207 const uint popID,
208 const bool calculate_V_moments
209 );
211 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
212 const CellID& cellID,
213 const bool& copyMomentsOnly,
214 const uint popID,
215 const bool calculate_V_moments
216 );
218 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
219 const CellID& cellID,
220 const uint popID,
221 const bool calculate_V_moments
222 );
224 dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
225 const CellID& cellID,
226 const uint popID,
227 const bool calculate_V_moments,
228 creal fluffiness
229 );
230 std::array<int, 3> getTheClosestNonsysboundaryCell(
232 cint i,
233 cint j,
234 cint k
235 );
236 std::vector< std::array<int, 3> > getAllClosestNonsysboundaryCells(
238 cint i,
239 cint j,
240 cint k
241 );
243 const CellID& cellID
244 );
245 std::vector<CellID> & getAllClosestNonsysboundaryCells(
246 const CellID& cellID
247 );
248 std::vector<CellID> & getAllCloseNonsysboundaryCells(
249 const CellID& cellID
250 );
251 Real
254 const fsgrid::FsStencil& stencil, cuint component, cuint mask);
255
257 const CellID& cellID
258 );
259 std::vector<CellID> & getAllClosestL1OutflowCells(
260 const CellID& cellID
261 );
262
268 std::array<bool, 3> periodic;
270 std::unordered_map<CellID, std::vector<CellID>> allClosestNonsysboundaryCells;
272 std::unordered_map<CellID, std::vector<CellID>> allCloseNonsysboundaryCells;
274 std::unordered_map<CellID, std::vector<CellID>> allClosestL1OutflowCells;
276 std::unordered_map<CellID, std::vector<CellID>> allCloseL1OutflowCells;
277
280 };
281
283 public:
284 virtual void assignSysBoundary(dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid);
285 protected:
287 std::array<bool, 6> facesToProcess;
288 };
289
290 // Moved outside the class since it's a helper function that doesn't require member access
292 const dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
293 std::vector<CellID> cellList,
294 SpatialCell *to,
295 const uint popID,
296 const creal fluffiness = 0
297 );
298
309 const uint popID,
311 creal& rho,
312 creal& T,
313 creal& VX0,
314 creal& VY0,
315 creal& VZ0);
316
318 bool* isThisCellOnAFace,
319 creal x, creal y, creal z,
320 creal dx, creal dy, creal dz,
321 const std::array<bool, 3> periodicity,
322 const bool excludeSlicesAndPeriodicDimensions=false // (default)
323 );
324
325} // namespace SBC
326
327#endif
for i
Definition Dispersion.m:24
dx
Definition Dispersion.m:38
virtual void assignSysBoundary(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)
std::array< bool, 6 > facesToProcess
virtual void fieldSolverBoundaryCondHallElectricField(fsgrids::ehallspan ehall, const fsgrid::FsStencil &stencil, cuint component)=0
virtual void vlasovBoundaryCondition(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const CellID &cellID, const uint popID, const bool calculate_V_moments)=0
virtual std::string getName() const
std::array< int, 3 > getTheClosestNonsysboundaryCell(fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, cint i, cint j, cint k)
virtual void assignSysBoundary(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)=0
void vlasovBoundaryCopyFromAllClosestNbrs(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const CellID &cellID, const uint popID, const bool calculate_V_moments)
static void setCellBVOLDerivativesToZero(fsgrids::volspan vols, const fsgrid::FsStencil &stencil, cuint component)
virtual void fieldSolverBoundaryCondElectricField(fsgrids::efieldspan e, const fsgrid::FsStencil &stencil, cuint component)=0
void determineFace(bool *isThisCellOnAFace, const creal x, const creal y, const creal z, const creal dx, const creal dy, const creal dz, const bool excludeSlicesAndPeriodicDimensions=false) const
Function used to determine on which face(s) if any the cell at given coordinates is.
void vlasovBoundaryCopyFromTheClosestNbr(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const CellID &cellID, const bool &copyMomentsOnly, const uint popID, const bool calculate_V_moments)
std::vector< std::array< int, 3 > > getAllClosestNonsysboundaryCells(fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, cint i, cint j, cint k)
std::unordered_map< CellID, std::vector< CellID > > allCloseL1OutflowCells
virtual void fieldSolverBoundaryCondBVOLDerivatives(fsgrids::volspan vols, const fsgrid::FsStencil &stencil, cuint component)=0
std::array< SpatialCell *, 27 > & getFlowtoCells(const CellID &cellID)
void vlasovBoundaryCopyFromTheClosestL1OutflowNbr(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const CellID &cellID, const bool &copyMomentsOnly, const uint popID, const bool calculate_V_moments)
void setPeriodicity(std::array< bool, 3 > isFacePeriodic)
virtual void fieldSolverBoundaryCondGradPeElectricField(fsgrids::egradpespan EGradPe, const fsgrid::FsStencil &stencil, cuint component)=0
virtual uint getIndex() const =0
virtual void updateState(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, fsgrids::perbspan perb, fsgrids::bgbspan bgb, creal t)=0
std::unordered_map< CellID, std::vector< CellID > > allClosestNonsysboundaryCells
std::unordered_map< CellID, std::vector< CellID > > allCloseNonsysboundaryCells
void vlasovBoundaryFluffyCopyFromAllCloseNbrs(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const CellID &cellID, const uint popID, const bool calculate_V_moments, creal fluffiness)
virtual void initSysBoundary(creal &t, Project &project)=0
virtual void setupL2OutflowAtRestart(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
std::vector< CellID > & getAllCloseNonsysboundaryCells(const CellID &cellID)
int nbrID(const int i, const int j, const int k)
void copyCellData(const SpatialCell *from, SpatialCell *to, const bool copyMomentsOnly, const uint popID, const bool copy_V_moments)
CellID & getTheClosestL1OutflowCell(const CellID &cellID)
virtual void applyInitialState(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, fsgrids::perbspan perb, fsgrids::bgbspan bgb, Project &project)=0
virtual void fieldSolverBoundaryCondDerivatives(fsgrids::dperbspan dperb, fsgrids::dmomentsspan dmoments, const fsgrid::FsStencil &stencil, cuint RKCase, cuint component)=0
Real fieldBoundaryCopyFromSolvingNbrMagneticField(fsgrids::perbspan b, fsgrids::consttechnicalspan technical, const fsgrid::FsStencil &stencil, cuint component, cuint mask)
std::array< Realf *, 27 > getFlowtoCellsBlock(const std::array< SpatialCell *, 27 > flowtoCells, const vmesh::GlobalID blockGID, const uint popID)
static void setCellDerivativesToZero(fsgrids::dperbspan dperb, fsgrids::dmomentsspan dmoments, const fsgrid::FsStencil &stencil, cuint component)
virtual Real fieldSolverBoundaryCondMagneticField(fsgrids::perbspan b, fsgrids::constbgbspan bgb, fsgrids::consttechnicalspan technical, const std::array< Real, 3 > &gridSpacing, const std::array< fsgrid::FsSize_t, 3 > &globalCoordinates, const fsgrid::FsStencil &stencil, cuint component)=0
virtual void getFaces(bool *faces)=0
std::vector< CellID > & getAllClosestL1OutflowCells(const CellID &cellID)
virtual void mapCellPotentialAndGetEXBDrift(std::array< Real, CellParams::N_SPATIAL_CELL_PARAMS > &cellParams)
std::array< bool, 3 > periodic
std::unordered_map< CellID, std::vector< CellID > > allClosestL1OutflowCells
bool updateSysBoundaryConditionsAfterLoadBalance(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &local_cells_on_boundary)
const uint32_t cuint
Definition definitions.h:50
float Real
Definition definitions.h:41
const int cint
Definition definitions.h:45
uint64_t CellID
Definition definitions.h:54
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
const float creal
Definition definitions.h:42
const int j
const int k
vmesh::LocalID findMaxwellianBlocksToInitialize(const uint popID, spatial_cell::SpatialCell &cell, creal &rho, creal &T, creal &VX0, creal &VY0, creal &VZ0)
SBC::findMaxwellianBlocksToInitialize returns a list of blocks to construct the VDF with.
void determineFaceNoClassMembers(bool *isThisCellOnAFace, creal x, creal y, creal z, creal dx, creal dy, creal dz, const std::array< bool, 3 > periodicity, const bool excludeSlicesAndPeriodicDimensions)
void averageCellData(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const vector< CellID > cellList, SpatialCell *to, const uint popID, const creal fluffiness)
std::span< std::array< Real, fsgrids::bfield::N_BFIELD > > perbspan
Definition common.h:434
std::span< const std::array< Real, bgbfield::N_BGB > > constbgbspan
Definition common.h:445
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
std::span< technical > technicalspan
Definition common.h:452
std::span< std::array< Real, bgbfield::N_BGB > > bgbspan
Definition common.h:444
std::span< std::array< Real, fsgrids::dperb::N_DPERB > > dperbspan
Definition common.h:442
std::span< const technical > consttechnicalspan
Definition common.h:453
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< std::array< Real, fsgrids::ehall::N_EHALL > > ehallspan
Definition common.h:438
uint32_t LocalID
Definition definitions.h:60
uint32_t GlobalID
Definition definitions.h:59