Vlasiator ebf0dd394 on dev (v5.4.0 + 1054 commits)
Loading...
Searching...
No Matches
gridGlue.hpp
Go to the documentation of this file.
1#pragma once
2#include "../definitions.h"
3#include <fsgrid.hpp>
4#include <vector>
5#include <array>
6#include <map>
7#include <set>
8
9// Datastructure for coupling
10extern std::map<int, std::set<CellID> > onDccrgMapRemoteProcessGlobal;
11extern std::map<int, std::set<CellID> > onFsgridMapRemoteProcessGlobal;
12extern std::map<CellID, std::vector<int64_t> > onFsgridMapCellsGlobal;
13
50
51
52std::vector<CellID> mapDccrgIdToFsGridGlobalID(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
53 CellID dccrgID);
54
65void feedMomentsIntoFsGrid(dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
66 const std::vector<CellID>& cells,
67 fsgrid::FsData<std::array<Real, fsgrids::moments::N_MOMENTS>>& moments,
68 fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, bool dt2 = false);
69
87 dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
88 const std::vector<CellID>& cells);
89
99void getBgFieldsAndDerivativesFromFsGrid(fsgrid::FsData<std::array<Real, fsgrids::bgbfield::N_BGB>>& bgb,
101 dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid,
102 const std::vector<CellID>& cells);
103
104int getNumberOfCellsOnMaxRefLvl(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
105 const std::vector<CellID>& cells);
106
107void feedBoundaryIntoFsGrid(dccrg::Dccrg<SpatialCell,dccrg::Cartesian_Geometry>& mpiGrid,
108 const std::vector<CellID>& cells,
110
111/*Compute coupling DCCRG <=> FSGRID
112
113 onDccrgMapRemoteProcess maps fsgrid processes (key) => set of dccrg cellIDs owned by current rank that map to the fsgrid cells owned by fsgrid process (val)
114
115 onFsgridMapRemoteProcess maps dccrg processes (key) => set of dccrg cellIDs owned by dccrg-process that map to current rank fsgrid cells
116 onFsgridMapCells maps remote dccrg CellIDs to local fsgrid cells
117*/
118
119// this function is declared here as it is a template function
120
121template <int STENCIL>
122void computeCoupling(dccrg::Dccrg<SpatialCell, dccrg::Cartesian_Geometry>& mpiGrid, const std::vector<CellID>& cells,
124
125 phiprof::Timer couplingTimerActual {"CouplingTimerActual"};
126
127 //sorted list of dccrg cells. cells is typicall already sorted, but just to make sure....
128 std::vector<CellID> dccrgCells = cells;
129 std::sort(dccrgCells.begin(), dccrgCells.end());
130
131 //make sure the datastructures are clean
135
136 const auto maxRefLevel = mpiGrid.mapping.get_maximum_refinement_level();
137
138 //Compute what we will receive, and where it should be stored
139 //Probably shouldn't be parallelised unless doing the inserts atomically
140 fsgrid.serial_for([](int timerId) -> phiprof::Timer { return phiprof::Timer{timerId}; },
141 phiprof::initializeTimer("Coupling loop"), technical,
142 [=, &mpiGrid](const fsgrid::Coordinates &coordinates, const fsgrid::FsStencil& stencil, cuint sysBoundaryFlag, cuint sysBoundaryLayer) {
143 const std::array<fsgrid::FsSize_t, 3> globalIndices = coordinates.localToGlobal(stencil.i, stencil.j, stencil.k);
144 const dccrg::Types<3>::indices_t indices = {
145 {(uint64_t)globalIndices[0], (uint64_t)globalIndices[1], (uint64_t)globalIndices[2]}}; //cast to avoid warnings
146 const CellID dccrgCell =
147 mpiGrid.get_existing_cell(indices, 0, maxRefLevel);
148
149 const int process = mpiGrid.get_process(dccrgCell);
150 const fsgrid::LocalID fsgridLid = coordinates.localIDFromLocalCoordinates(stencil.i, stencil.j, stencil.k);
151 onFsgridMapRemoteProcessGlobal[process].insert(dccrgCell); // cells are ordered (sorted) in set
152 onFsgridMapCellsGlobal[dccrgCell].push_back(fsgridLid);
153 });
154
155 // Compute where to send data and what to send
156 for(uint64_t i=0; i< dccrgCells.size(); i++) {
157 //compute to which processes this cell maps
158 const std::vector<CellID> fsCells = mapDccrgIdToFsGridGlobalID(mpiGrid, dccrgCells[i]);
159
160 //loop over fsgrid cells which this dccrg cell maps to
161 for (auto const &fsCellID : fsCells) {
162 const int process = fsgrid.getTaskForGlobalID(fsCellID); // process on fsgrid
163 onDccrgMapRemoteProcessGlobal[process].insert(dccrgCells[i]); //add to map
164 }
165 }
166}
for i
Definition Dispersion.m:24
const uint32_t cuint
Definition definitions.h:50
uint64_t CellID
Definition definitions.h:54
fsgrid::FsGrid< FS_STENCIL_WIDTH > FieldSolverGrid
Definition definitions.h:78
std::map< int, std::set< CellID > > onDccrgMapRemoteProcessGlobal
Definition gridGlue.cpp:11
std::map< int, std::set< CellID > > onFsgridMapRemoteProcessGlobal
Definition gridGlue.cpp:12
std::map< CellID, std::vector< int64_t > > onFsgridMapCellsGlobal
Definition gridGlue.cpp:13
FieldsToCommunicate
Definition gridGlue.hpp:14
@ dVzdx
Definition gridGlue.hpp:45
@ EXGRADPE
Definition gridGlue.hpp:30
@ PERBZVOL
Definition gridGlue.hpp:17
@ dPERBYVOLdx
Definition gridGlue.hpp:21
@ dPERBYVOLdy
Definition gridGlue.hpp:22
@ dVxdx
Definition gridGlue.hpp:39
@ BGBZVOL
Definition gridGlue.hpp:29
@ dPERBZVOLdx
Definition gridGlue.hpp:24
@ dVydx
Definition gridGlue.hpp:42
@ N_FIELDSTOCOMMUNICATE
Definition gridGlue.hpp:48
@ EYGRADPE
Definition gridGlue.hpp:31
@ dVzdz
Definition gridGlue.hpp:47
@ EXVOL
Definition gridGlue.hpp:33
@ dVydy
Definition gridGlue.hpp:43
@ EZVOL
Definition gridGlue.hpp:35
@ PERBYVOL
Definition gridGlue.hpp:16
@ CURVATUREX
Definition gridGlue.hpp:36
@ EZGRADPE
Definition gridGlue.hpp:32
@ CURVATUREZ
Definition gridGlue.hpp:38
@ BGBXVOL
Definition gridGlue.hpp:27
@ PERBXVOL
Definition gridGlue.hpp:15
@ dPERBZVOLdz
Definition gridGlue.hpp:26
@ dPERBYVOLdz
Definition gridGlue.hpp:23
@ dVydz
Definition gridGlue.hpp:44
@ dVxdy
Definition gridGlue.hpp:40
@ BGBYVOL
Definition gridGlue.hpp:28
@ CURVATUREY
Definition gridGlue.hpp:37
@ dPERBZVOLdy
Definition gridGlue.hpp:25
@ EYVOL
Definition gridGlue.hpp:34
@ dVxdz
Definition gridGlue.hpp:41
@ dVzdy
Definition gridGlue.hpp:46
@ dPERBXVOLdz
Definition gridGlue.hpp:20
@ dPERBXVOLdx
Definition gridGlue.hpp:18
@ dPERBXVOLdy
Definition gridGlue.hpp:19
void computeCoupling(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, fsgrid::FsGrid< STENCIL > &fsgrid, fsgrids::technicalspan technical)
Definition gridGlue.hpp:122
std::vector< CellID > mapDccrgIdToFsGridGlobalID(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, CellID dccrgID)
void feedBoundaryIntoFsGrid(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid)
int getNumberOfCellsOnMaxRefLvl(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells)
void getFieldsFromFsGrid(fsgrids::constvolspan volumefields, fsgrids::constbgbspan bgb, fsgrids::constegradpespan egradpe, fsgrids::constdmomentsspan dmoments, fsgrids::consttechnicalspan technical, FieldSolverGrid &fsgrid, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells)
void getBgFieldsAndDerivativesFromFsGrid(fsgrid::FsData< std::array< Real, fsgrids::bgbfield::N_BGB > > &bgb, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells)
void feedMomentsIntoFsGrid(dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &cells, fsgrid::FsData< std::array< Real, fsgrids::moments::N_MOMENTS > > &moments, fsgrids::technicalspan technical, FieldSolverGrid &fsgrid, bool dt2=false)
std::span< const std::array< Real, fsgrids::dmoments::N_DMOMENTS > > constdmomentsspan
Definition common.h:449
std::span< const std::array< Real, bgbfield::N_BGB > > constbgbspan
Definition common.h:445
std::span< technical > technicalspan
Definition common.h:452
std::span< const technical > consttechnicalspan
Definition common.h:453
std::span< const std::array< Real, fsgrids::volfields::N_VOL > > constvolspan
Definition common.h:451
std::span< const std::array< Real, fsgrids::egradpe::N_EGRADPE > > constegradpespan
Definition common.h:441