Peano
CellFaceData.h
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 #pragma once
4 
5 #include "peano4/utils/Globals.h"
6 #include "tarch/accelerator/accelerator.h"
7 #include "tarch/accelerator/MemoryManager.h"
8 #include "tarch/la/Vector.h"
9 
10 #include <functional>
11 #include <string>
12 
13 namespace exahype2 {
20  template <typename inType = double, typename outType = double> struct CellFaceData {
25  inType* (*QIn)[2 * DIMENSIONS];
26  tarch::la::Vector<DIMENSIONS, double>* cellCentre;
27  tarch::la::Vector<DIMENSIONS, double>* cellSize;
28 
29  double* t;
30  double* dt;
31 
37  int* id;
38 
43  const int numberOfCells;
44 
49  const tarch::MemoryLocation memoryLocation;
50 
55  const int targetDevice;
56 
60  outType* (*QOut)[2 * DIMENSIONS];
61 
73  inType* QIn_[2 * DIMENSIONS],
74  const tarch::la::Vector<DIMENSIONS, double>& cellCentre_,
75  const tarch::la::Vector<DIMENSIONS, double>& cellSize_,
76  double t_,
77  double dt_,
78  outType* QOut_[2 * DIMENSIONS],
79  tarch::MemoryLocation memoryLocation_ = tarch::MemoryLocation::Heap,
80  int targetDevice_ = tarch::accelerator::Device::DefaultDevice
81  );
82 
84  int numberOfCells_,
85  tarch::MemoryLocation memoryLocation_ = tarch::MemoryLocation::Heap,
86  int targetDevice_ = tarch::accelerator::Device::DefaultDevice
87  );
88 
89  CellFaceData(const CellFaceData& copy) = delete;
90  CellFaceData& operator=(const CellFaceData&) = delete;
91 
92  ~CellFaceData();
93 
94  std::string toString() const;
95  };
96 } // namespace exahype2
97 
98 template <typename inType, typename outType>
100  inType* QIn_[2 * DIMENSIONS],
101  const tarch::la::Vector<DIMENSIONS, double>& cellCentre_,
102  const tarch::la::Vector<DIMENSIONS, double>& cellSize_,
103  double t_,
104  double dt_,
105  outType* QOut_[2 * DIMENSIONS],
106  tarch::MemoryLocation memoryLocation_,
107  int targetDevice_
108 ):
109  CellFaceData(1, memoryLocation_, targetDevice_) {
110  QIn[0] = QIn_;
111  cellCentre[0] = cellCentre_;
112  cellSize[0] = cellSize_;
113  t[0] = t_;
114  dt[0] = dt_;
115  QOut[0] = QOut_;
116  id[0] = -1;
117 }
118 
119 template <typename inType, typename outType>
121  CellFaceData(int numberOfCells_, tarch::MemoryLocation memoryLocation_, int targetDevice_):
122  numberOfCells(numberOfCells_),
123  memoryLocation(memoryLocation_),
124  targetDevice(targetDevice_) {
125 
126  QIn = reinterpret_cast<inType* (*)[2 * DIMENSIONS]>(tarch::accelerator::MemoryManager::getInstance().allocate<inType*>(
127  2 * DIMENSIONS * numberOfCells_,
128  memoryLocation_,
129  targetDevice_
130  ));
131  cellCentre = tarch::accelerator::MemoryManager::getInstance().allocate<tarch::la::Vector<DIMENSIONS, double>>(
132  numberOfCells_,
133  memoryLocation_,
134  targetDevice_
135  );
136  cellSize = tarch::accelerator::MemoryManager::getInstance().allocate<tarch::la::Vector<DIMENSIONS, double>>(
137  numberOfCells_,
138  memoryLocation_,
139  targetDevice_
140  );
141  t = tarch::accelerator::MemoryManager::getInstance().allocate<double>(numberOfCells_, memoryLocation_, targetDevice_);
142  dt = tarch::accelerator::MemoryManager::getInstance().allocate<double>(
143  numberOfCells_,
144  memoryLocation_,
145  targetDevice_
146  );
147  id = tarch::accelerator::MemoryManager::getInstance().allocate<int>(numberOfCells_, memoryLocation_, targetDevice_);
148  QOut = reinterpret_cast<inType* (*)[2 * DIMENSIONS]>(tarch::accelerator::MemoryManager::getInstance().allocate<outType*>(
149  2 * DIMENSIONS * numberOfCells_,
150  memoryLocation_,
151  targetDevice_
152  ));
153 }
154 
155 template <typename inType, typename outType> exahype2::CellFaceData<inType, outType>::~CellFaceData() {
156  // tarch::freeMemory(QIn, memoryLocation, targetDevice);
157  // tarch::freeMemory(cellCentre, memoryLocation, targetDevice);
158  // tarch::freeMemory(cellSize, memoryLocation, targetDevice);
159  // tarch::freeMemory(t, memoryLocation, targetDevice);
160  // tarch::freeMemory(dt, memoryLocation, targetDevice);
161  // tarch::freeMemory(QOut, memoryLocation, targetDevice);
162  // tarch::freeMemory(id, memoryLocation, targetDevice);
163 
164  tarch::accelerator::MemoryManager::getInstance().free(QIn, targetDevice);
165  tarch::accelerator::MemoryManager::getInstance().free(cellCentre, targetDevice);
166  tarch::accelerator::MemoryManager::getInstance().free(cellSize, targetDevice);
167  tarch::accelerator::MemoryManager::getInstance().free(t, targetDevice);
168  tarch::accelerator::MemoryManager::getInstance().free(dt, targetDevice);
169  tarch::accelerator::MemoryManager::getInstance().free(QOut, targetDevice);
170  tarch::accelerator::MemoryManager::getInstance().free(id, targetDevice);
171 }
172 
173 template <typename inType, typename outType> std::string exahype2::CellFaceData<inType, outType>::toString() const {
174  std::ostringstream msg;
175  msg << "[";
176  for (int i = 0; i < numberOfCells; i++) {
177  msg << "(x=" << cellCentre[i] << ",h=" << cellSize[i] << ",t=" << t[i] << ",dt=" << dt[i] << ",id=" << id[i] << ")";
178  }
179  msg << "]";
180  return msg.str();
181 }
const tarch::la::Vector< DIMENSIONS, double > cellSize
string msg
parameter setting according to scenarios
Represents the faces of one cell, with a total of 2*Dim faces per cell For ADER QIn will contain the ...
Definition: CellFaceData.h:20
tarch::la::Vector< DIMENSIONS, double > * cellSize
Definition: CellFaceData.h:27
tarch::la::Vector< DIMENSIONS, double > * cellCentre
Definition: CellFaceData.h:26
CellFaceData(inType *QIn_[2 *DIMENSIONS], const tarch::la::Vector< DIMENSIONS, double > &cellCentre_, const tarch::la::Vector< DIMENSIONS, double > &cellSize_, double t_, double dt_, outType *QOut_[2 *DIMENSIONS], tarch::MemoryLocation memoryLocation_=tarch::MemoryLocation::Heap, int targetDevice_=tarch::accelerator::Device::DefaultDevice)
Construct patch data object for one single cell.
Definition: CellFaceData.h:99
const int targetDevice
We might want to allocate data on an accelerator, therefore we save the target device id.
Definition: CellFaceData.h:55
int * id
Id of underlying task.
Definition: CellFaceData.h:37
outType *(* QOut)[2 *DIMENSIONS]
Out values.
Definition: CellFaceData.h:60
const tarch::MemoryLocation memoryLocation
We might want to allocate data on the heap or an accelerator, therefore we save the target device id.
Definition: CellFaceData.h:49
CellFaceData & operator=(const CellFaceData &)=delete
CellFaceData(const CellFaceData &copy)=delete
std::string toString() const
Definition: CellFaceData.h:173
inType *(* QIn)[2 *DIMENSIONS]
QIn may not be const, as some kernels delete it straightaway once the input data has been handled.
Definition: CellFaceData.h:25
const int numberOfCells
As we store data as SoA, we have to know how big the actual arrays are.
Definition: CellFaceData.h:43