22#ifndef CPU_TRANS_PENCILS_H
23#define CPU_TRANS_PENCILS_H
27#include <unordered_set>
29#include <dccrg_cartesian_geometry.hpp>
39 std::vector< CellID >
ids;
43 std::vector< Real >
x,
y;
45 std::vector< std::vector<uint> >
path;
55 size_t gpu_lengthOfPencils = 0;
56 size_t gpu_idsStart = 0;
57 size_t gpu_sourceDZ = 0;
58 size_t gpu_targetRatios = 0;
60 size_t host_binStart = 0;
61 size_t host_binSize = 0;
90 void addPencil(std::vector<CellID> idsIn,
Real xIn,
Real yIn,
bool periodicIn, std::vector<uint> pathIn) {
93 if (idsIn.front() != 0) {
94 idsIn.insert(idsIn.begin(),VLASOV_STENCIL_WIDTH,0);
96 if (idsIn.back() != 0) {
97 for (
int i = 0;
i < VLASOV_STENCIL_WIDTH;
i++)
105 ids.insert(
ids.end(),idsIn.begin(),idsIn.end());
111 path.push_back(pathIn);
119 std::unordered_set<CellID> allTargetCells = {};
120 #pragma omp parallel for
124 if (targ && (ratio > 0.0)) {
126 allTargetCells.insert(targ);
132 for (uint
i = 0;
i <
N; ++
i) {
139 if (*
id && allTargetCells.contains(*
id)) {
147 std::set<uint> binsToDelete;
149 binsToDelete.clear();
151 if (binsToDelete.contains(binIndex1)) {
156 if (binIndex1 == binIndex2 || binsToDelete.contains(binIndex2)) {
161 for (
auto cell : cellsInBin2) {
162 if (cellsInBin1.contains(cell)) {
163 binsToDelete.insert(binIndex2);
166 cellsInBin1.insert(cellsInBin2.begin(), cellsInBin2.end());
176 for (
auto bin : binsToDelete) {
179 }
while (!binsToDelete.empty());
182 for (uint
i = 0;
i <
N; ++
i) {
210 uint *host_binStartPointer =
gpuMemoryManager.getPointer<uint>(host_binStart);
211 uint *host_binSizePointer =
gpuMemoryManager.getPointer<uint>(host_binSize);
216 for(
size_t bin = 0; bin <
activeBins.size(); bin++){
218 host_binStartPointer[bin] = offset;
221 host_binSizePointer[bin] = binSize;
235 x.erase(
x.begin() + pencilId);
236 y.erase(
y.begin() + pencilId);
238 path.erase(
path.begin() + pencilId);
251 std::vector<CellID>
getIds(
const uint pencilId)
const {
253 std::vector<CellID> idsEmpty;
257 std::vector<CellID>::const_iterator ibeg =
ids.begin() +
idsStart[pencilId] + VLASOV_STENCIL_WIDTH;
258 std::vector<CellID>::const_iterator iend = ibeg +
lengthOfPencils[pencilId] - 2*VLASOV_STENCIL_WIDTH;
259 std::vector<CellID> idsOut(ibeg, iend);
266 auto myIds = this->
getIds(myPencilId);
270 std::vector<int> existingSteps;
272 #pragma omp parallel for
273 for (uint theirPencilId = 0; theirPencilId < this->N; ++theirPencilId) {
274 if(theirPencilId == myPencilId) {
277 auto theirIds = this->
getIds(theirPencilId);
278 for (
auto theirId : theirIds) {
279 for (
auto myId : myIds) {
280 if (myId == theirId) {
281 std::vector<uint> theirPath = this->path.at(theirPencilId);
282 std::vector<uint> myPath = this->path.at(myPencilId);
283 if(theirPath.size() > myPath.size()) {
284 bool samePath =
true;
285 for (uint
i = 0;
i < myPath.size(); ++
i) {
286 if(myPath.at(
i) != theirPath.at(
i)) {
292 uint theirStep = theirPath.at(myPath.size());
295 existingSteps.push_back(theirStep);
304 bool firstPencil =
true;
305 const auto copy_of_path =
path.at(myPencilId);
306 const auto copy_of_x =
x.at(myPencilId);
307 const auto copy_of_y =
y.at(myPencilId);
310 for (
int step = 0; step < 4; ++step) {
311 if (std::any_of(existingSteps.begin(), existingSteps.end(), [step](
int i){return step == i;})) {
326 auto myX = copy_of_x + signX * 0.25 *
dx;
327 auto myY = copy_of_y + signY * 0.25 * dy;
331 path.at(myPencilId).push_back(step);
332 x.at(myPencilId) = myX;
333 y.at(myPencilId) = myY;
336 auto myPath = copy_of_path;
337 myPath.push_back(step);
351 const uint dimension);
358 const std::vector<CellID>& localPropagatedCells);
#define gpuMemcpyHostToDevice
std::unordered_set< CellID > ghostTranslate_sources_x
std::unordered_set< CellID > ghostTranslate_sources_z
std::unordered_set< CellID > ghostTranslate_active_z
std::array< setOfPencils, 3 > DimensionPencils
std::unordered_set< CellID > ghostTranslate_active_x
std::unordered_set< CellID > ghostTranslate_sources_y
std::unordered_set< CellID > ghostTranslate_active_y
void prepareSeedIdsAndPencils(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid)
void prepareGhostTranslationCellLists(const dccrg::Dccrg< SpatialCell, dccrg::Cartesian_Geometry > &mpiGrid, const std::vector< CellID > &localPropagatedCells)
bool do_translate_cell(const spatial_cell::SpatialCell *const SC)
GPUMemoryManager gpuMemoryManager
__global__ void const Realf const uint *__restrict__ const uint *__restrict__ const vmesh::GlobalID *__restrict__ const uint const uint const uint const Realf const vmesh::VelocityMesh *__restrict__ const vmesh::VelocityBlockContainer Realf Realf const Realf *__restrict__ const Realf *__restrict__ uint uint uint * dev_binStart
__global__ void const Realf const uint *__restrict__ const uint *__restrict__ const vmesh::GlobalID *__restrict__ const uint const uint const uint sumOfLengths
__global__ void const Realf const uint *__restrict__ const uint *__restrict__ const vmesh::GlobalID *__restrict__ const uint const uint const uint const Realf const vmesh::VelocityMesh *__restrict__ const vmesh::VelocityBlockContainer Realf Realf const Realf *__restrict__ const Realf *__restrict__ uint uint uint uint * dev_binSize
__global__ void const Realf const uint *__restrict__ const uint *__restrict__ const vmesh::GlobalID *__restrict__ const uint const uint const uint const Realf const vmesh::VelocityMesh *__restrict__ const vmesh::VelocityBlockContainer Realf Realf const Realf *__restrict__ const Realf *__restrict__ uint uint * dev_pencilsInBin
std::map< uint, std::vector< uint > > pencilsInBin
Vector of pencils in each bin.
std::vector< bool > periodic
void split(const uint myPencilId, const Real dx, const Real dy)
std::vector< uint > activeBins
set of keys in the above two maps
void removePencil(const uint pencilId)
std::vector< CellID > getIds(uint pencilId)
std::vector< uint > binOfPencil
Bin of each pencil.
std::vector< Realf > targetRatios
std::map< uint, std::set< CellID > > targetCellsInBin
Set of source and target cells in each bin which are a target cell of any pencil.
std::vector< Realf > sourceDZ
std::vector< CellID > ids
std::vector< uint > idsStart
std::vector< CellID > getIds(const uint pencilId) const
void addPencil(vector< CellID > idsIn, Real xIn, Real yIn)
void addPencil(std::vector< CellID > idsIn, Real xIn, Real yIn, bool periodicIn, std::vector< uint > pathIn)
std::vector< uint > lengthOfPencils
std::vector< std::vector< uint > > path
An interface to a type with floating point values.