Peano
Loading...
Searching...
No Matches
DataRepository.cpp
Go to the documentation of this file.
1// This file is part of the ExaHyPE2 project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#include "DataRepository.h"
4
5#include "FVSolver.h"
6#include "exahype2/fv/BoundaryConditions.h"
7#include "peano4/utils/Linearised.h"
8#include "peano4/utils/Loop.h"
9
10#include <algorithm>
11#include <cmath>
12#include <iterator>
13
16 const tarch::la::Vector<DIMENSIONS, int>& cellIndex,
17 const tarch::la::Vector<DIMENSIONS, double>& cellSize
18 ) {
19 const double ratio = DomainSize[0] / cellSize[0];
20 const int depth = static_cast<int>(std::round(std::log(ratio) / std::log(3.0)));
21
22 int index = 0;
23 int stride = 1;
24 for (int i = 0; i < DIMENSIONS; ++i) {
25 index += cellIndex[i] * stride;
26
27 int dimSize = (i == 0) ? (std::pow(3, depth) + 1) : std::pow(3, depth);
28 stride *= dimSize;
29 }
30 return index;
31 }
32
33 tarch::la::Vector<DIMENSIONS, int> DataRepository::Indexing::getFaceIndices(
34 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
35 const tarch::la::Vector<DIMENSIONS, double>& cellSize
36 ) {
37 tarch::la::Vector<DIMENSIONS, int> faceIndices;
38 tarch::la::Vector<DIMENSIONS, double> cellCentreOffset = cellCentre - DomainOffset; // remove Offset
39 tarch::la::Vector<DIMENSIONS, int> cellIndex = tarch::la::convertScalar<int>(
40 tarch::la::floor(tarch::la::divideComponents(cellCentreOffset, cellSize))
41 );
42 // vector: x_1, x_2, x_3
43 faceIndices[0] = linearise(cellIndex, cellSize);
44 // vector: x_2, x_1, x_3
45 std::swap(cellIndex[0], cellIndex[1]);
46 faceIndices[1] = linearise(cellIndex, cellSize);
47#if DIMENSIONS == 3
48 // vector: x_3, x_1, x_2
49 std::swap(cellIndex[0], cellIndex[2]);
50 faceIndices[2] = linearise(cellIndex, cellSize);
51#endif
52 return faceIndices;
53 }
54
56 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
57 const tarch::la::Vector<DIMENSIONS, double>& cellSize,
58 int axis
59 ) {
60 tarch::la::Vector<DIMENSIONS, double> cellCentreOffset = cellCentre - DomainOffset; // remove Offset
61 tarch::la::Vector<DIMENSIONS, int> cellIndex = tarch::la::convertScalar<int>(
62 tarch::la::floor(tarch::la::divideComponents(cellCentreOffset, cellSize))
63 );
64 // permute as described in getFaceIndices()
65 for (int i = 1; i <= axis % DIMENSIONS; ++i) {
66 std::swap(cellIndex[0], cellIndex[i]);
67 }
68 int faceIndex = linearise(cellIndex, cellSize);
69 return axis >= DIMENSIONS ? faceIndex + 1 : faceIndex;
70 }
71
73 int cellCount = std::pow(GridLength, DIMENSIONS);
74 int faceCount = std::pow(GridLength, DIMENSIONS - 1) * (GridLength + 1);
75 _depthLevel.Q.resize(cellCount);
76 for (int axis = 0; axis < DIMENSIONS; ++axis) {
77 _depthLevel.faces[axis].resize(faceCount);
78 _depthLevel.facesDevice[axis] = tarch::allocateMemory<double>(
79 faceCount * getFaceCardinality(),
80 tarch::MemoryLocation::Pinned
81 );
82 }
83 }
84
86 for (int axis = 0; axis < DIMENSIONS; ++axis) {
87 tarch::freeMemory(_depthLevel.facesDevice[axis], tarch::MemoryLocation::Pinned);
88 }
89 }
90
92 static DataRepository instance;
93 return instance;
94 }
95
96 int DataRepository::getFaceCardinality() { return facedata::FVSolverQNew::Cardinality; }
97
98 int DataRepository::getCellQCardinality() { return celldata::FVSolverQ::Cardinality; }
99
100 int DataRepository::getCellQReconstructedCardinality() { return celldata::FVSolverQReconstructed::Cardinality; }
101
102 double* DataRepository::getCellQ(int index) { return _depthLevel.Q[index].data(); }
103
105 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
106 const tarch::la::Vector<DIMENSIONS, double>& cellSize
107 ) {
108 tarch::la::Vector<DIMENSIONS, double> cellCentreOffset = cellCentre - DomainOffset; // remove Offset
109 tarch::la::Vector<DIMENSIONS, int> cellIndex = tarch::la::convertScalar<int>(
110 tarch::la::floor(tarch::la::divideComponents(cellCentreOffset, cellSize))
111 );
112 int index = peano4::utils::dLinearised(cellIndex, GridLength);
113 return getCellQ(index);
114 }
115
116 double* DataRepository::getFaceQNew(int index, int axis) {
117 auto& faceData = _depthLevel.faces[axis % DIMENSIONS];
118 if (axis >= DIMENSIONS) {
119 // high face
120 return faceData[index + 1].data();
121 } else {
122 // low face
123 return faceData[index].data();
124 }
125 }
126
128 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
129 const tarch::la::Vector<DIMENSIONS, double>& cellSize,
130 int axis
131 ) {
132 int index = Indexing::getFaceIndex(cellCentre, cellSize, axis);
133 return _depthLevel.faces[axis % DIMENSIONS][index].data();
134 }
135
137 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
138 const tarch::la::Vector<DIMENSIONS, double>& cellSize,
139 int axis
140 ) {
141 int index = Indexing::getFaceIndex(cellCentre, cellSize, axis);
142 return _depthLevel.facesDevice[axis % DIMENSIONS] + index * getFaceCardinality();
143 }
144
146 int faceCount = std::pow(GridLength, DIMENSIONS - 1) * (GridLength + 1);
147 for (int axis = 0; axis < DIMENSIONS; ++axis) {
148 tarch::copyTo<double, double>(
149 _depthLevel.facesDevice[axis],
150 _depthLevel.faces[axis][0].data(),
151 faceCount * getFaceCardinality(),
152 tarch::MemoryLocation::Pinned
153 );
154 }
155 }
156
158 int faceCount = std::pow(GridLength, DIMENSIONS - 1) * (GridLength + 1);
159 for (int axis = 0; axis < DIMENSIONS; ++axis) {
160 tarch::copyFrom<double, double>(
161 _depthLevel.facesDevice[axis],
162 _depthLevel.faces[axis][0].data(),
163 faceCount * getFaceCardinality(),
164 tarch::MemoryLocation::Pinned
165 );
166 }
167 }
168} // namespace benchmarks::exahype2::kernelbenchmarks
const tarch::la::Vector< DIMENSIONS, double > cellSize
double * getFaceQNewDevice(const tarch::la::Vector< DIMENSIONS, double > &cellCentre, const tarch::la::Vector< DIMENSIONS, double > &cellSize, int axis)
static tarch::la::Vector< DIMENSIONS, int > getFaceIndices(const tarch::la::Vector< DIMENSIONS, double > &cellCentre, const tarch::la::Vector< DIMENSIONS, double > &cellSize)
Calculates the indices of the lower faces of a cell along along all axis for x axis: x_1 + x_2 * (3^D...
static int linearise(const tarch::la::Vector< DIMENSIONS, int > &cellCentre, const tarch::la::Vector< DIMENSIONS, double > &cellSize)
Calculates the linearised index of the lower face of a cell along one axis (along one axis means the ...
static int getFaceIndex(const tarch::la::Vector< DIMENSIONS, double > &cellCentre, const tarch::la::Vector< DIMENSIONS, double > &cellSize, int axis)