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 const auto cellCount = std::pow(GridLength, DIMENSIONS);
74 const auto faceCount = std::pow(GridLength, DIMENSIONS - 1) * (GridLength + 1);
75 const int depth = static_cast<int>(std::round(std::log(GridLength) / std::log(3.0)));
76 _depthLevels.resize(depth + 1); // For 1 AMR level
77 _depthLevels[depth - 1].Q.resize(cellCount);
78 _depthLevels[depth - 1].QReconstructed.resize(cellCount);
79 for (int axis = 0; axis < DIMENSIONS; ++axis) {
80 _depthLevels[depth - 1].faces[axis].resize(faceCount);
81 }
82
83 if (UseAMR) {
84 const auto cellCountAMR = std::pow(GridLength * 3, DIMENSIONS);
85 const auto faceCountAMR = std::pow(GridLength * 3, DIMENSIONS - 1) * (GridLength * 3 + 1);
86 _depthLevels[depth].Q.resize(cellCountAMR);
87 _depthLevels[depth].QReconstructed.resize(cellCountAMR);
88 for (int axis = 0; axis < DIMENSIONS; ++axis) {
89 _depthLevels[depth].faces[axis].resize(faceCountAMR);
90 }
91 }
92 }
93
95 static DataRepository instance;
96 return instance;
97 }
98
99 int DataRepository::getFaceCardinality() const { return facedata::FVSolverQNew::Cardinality; }
100
101 int DataRepository::getCellQCardinality() const { return celldata::FVSolverQ::Cardinality; }
102
103 int DataRepository::getCellQReconstructedCardinality() const { return celldata::FVSolverQReconstructed::Cardinality; }
104
106 const auto cellCount = std::pow(GridLength, DIMENSIONS);
107 const auto faceCount = std::pow(GridLength, DIMENSIONS - 1) * (GridLength + 1);
108 const auto volumeCount = cellCount * std::pow(AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch, DIMENSIONS);
109 const auto volumeReconstructedCount = cellCount
110 * std::
111 pow(AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch + 2, DIMENSIONS);
112 const auto facesVolumesCount = faceCount
113 * std::pow(AbstractFVSolver::NumberOfFiniteVolumesPerAxisPerPatch, DIMENSIONS - 1) * 2;
114 std::size_t totalStorageSize = (volumeCount + volumeReconstructedCount + facesVolumesCount)
115 * (AbstractFVSolver::NumberOfUnknowns + AbstractFVSolver::NumberOfAuxiliaryVariables)
116 * sizeof(double);
117 return totalStorageSize;
118 }
119
121 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
122 const tarch::la::Vector<DIMENSIONS, double>& cellSize
123 ) {
124 const double ratio = DomainSize[0] / cellSize[0];
125 const int depth = static_cast<int>(std::round(std::log(ratio) / std::log(3.0)));
126 tarch::la::Vector<DIMENSIONS, double> cellCentreOffset = cellCentre - DomainOffset; // remove Offset
127 tarch::la::Vector<DIMENSIONS, int> cellIndex = tarch::la::convertScalar<int>(
128 tarch::la::floor(tarch::la::divideComponents(cellCentreOffset, cellSize))
129 );
130 int index = peano4::utils::dLinearised(cellIndex, std::pow(3, depth));
131 return _depthLevels[depth - 1].Q[index].data();
132 }
133
135 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
136 const tarch::la::Vector<DIMENSIONS, double>& cellSize
137 ) {
138 const double ratio = DomainSize[0] / cellSize[0];
139 const int depth = static_cast<int>(std::round(std::log(ratio) / std::log(3.0)));
140 tarch::la::Vector<DIMENSIONS, double> cellCentreOffset = cellCentre - DomainOffset; // remove Offset
141 tarch::la::Vector<DIMENSIONS, int> cellIndex = tarch::la::convertScalar<int>(
142 tarch::la::floor(tarch::la::divideComponents(cellCentreOffset, cellSize))
143 );
144 int index = peano4::utils::dLinearised(cellIndex, std::pow(3, depth));
145 return _depthLevels[depth - 1].QReconstructed[index].data();
146 }
147
148 double* DataRepository::getFaceQNew(int index, int depth, int axis) {
149 auto& faceData = _depthLevels[depth - 1].faces[axis % DIMENSIONS];
150 if (axis >= DIMENSIONS) {
151 // High face
152 return faceData[index + 1].data();
153 } else {
154 // Low face
155 return faceData[index].data();
156 }
157 }
158
160 const tarch::la::Vector<DIMENSIONS, double>& cellCentre,
161 const tarch::la::Vector<DIMENSIONS, double>& cellSize,
162 int axis
163 ) {
164 const double ratio = DomainSize[0] / cellSize[0];
165 const int depth = static_cast<int>(std::round(std::log(ratio) / std::log(3.0)));
166 int index = Indexing::getFaceIndex(cellCentre, cellSize, axis);
167 return _depthLevels[depth - 1].faces[axis % DIMENSIONS][index].data();
168 }
169} // namespace benchmarks::exahype2::kernelbenchmarks
const tarch::la::Vector< DIMENSIONS, double > cellSize
A singleton repository to manage and provide access to grid cell and face data.
double * getFaceQNew(int index, int depth, int axis)
double * getCellQReconstructed(const tarch::la::Vector< DIMENSIONS, double > &cellCentre, const tarch::la::Vector< DIMENSIONS, double > &cellSize)
double * getCellQ(const tarch::la::Vector< DIMENSIONS, double > &cellCentre, const tarch::la::Vector< DIMENSIONS, double > &cellSize)
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)