30 #ifndef MESH_WITH_DATA_PACKAGES_H 31 #define MESH_WITH_DATA_PACKAGES_H 34 #include "my_memory_pool.h" 47 template <
class ReturnType,
class DataPackageType>
50 template <
class DataPackageType>
54 for (
size_t i = 0; i != data_pkgs.size(); ++i)
55 pkg_functor(data_pkgs[i], dt);
58 template <
class DataPackageType>
63 blocked_range<size_t>(0, data_pkgs.size()),
64 [&](
const blocked_range<size_t> &r)
66 for (
size_t i = r.begin(); i != r.end(); ++i)
68 pkg_functor(data_pkgs[i], dt);
74 template <
class ReturnType,
typename ReduceOperation,
class DataPackageType>
77 ReduceOperation &reduce_operation, Real dt = 0.0)
79 for (
size_t i = 0; i < data_pkgs.size(); ++i)
81 temp = reduce_operation(temp, reduce_pkg_functor(data_pkgs[i], dt));
86 template <
class ReturnType,
typename ReduceOperation,
class DataPackageType>
89 ReduceOperation &reduce_operation, Real dt = 0.0)
91 return parallel_reduce(
92 blocked_range<size_t>(0, data_pkgs.size()),
93 temp, [&](
const blocked_range<size_t> &r, ReturnType temp0) -> ReturnType
95 for (
size_t i = r.begin(); i != r.end(); ++i)
97 temp0 = reduce_operation(temp, reduce_pkg_functor(data_pkgs[i], dt));
100 [&](ReturnType x, ReturnType y) -> ReturnType
102 return reduce_operation(x, y);
132 template <
int PKG_SIZE,
int ADDRS_SIZE>
136 template <
typename DataType>
137 using PackageData = PackageDataMatrix<DataType, PKG_SIZE>;
138 template <
typename DataType>
139 using PackageDataAddress = PackageDataMatrix<DataType *, ADDRS_SIZE>;
144 template <
typename DataType>
150 constexpr
int PackageSize() {
return PKG_SIZE; };
151 constexpr
int AddressSize() {
return ADDRS_SIZE; };
152 constexpr
int AddressBufferWidth() {
return (ADDRS_SIZE - PKG_SIZE) / 2; };
153 constexpr
int OperationUpperBound() {
return PKG_SIZE + AddressBufferWidth(); };
155 Vecd
DataLowerBound() {
return mesh_lower_bound_ + Vecd(grid_spacing_) * (Real)AddressBufferWidth(); };
159 mesh_lower_bound_ = pkg_lower_bound - Vecd(data_spacing) * ((Real)AddressBufferWidth() - 0.5);
160 grid_spacing_ = data_spacing;
163 template <
typename DataType>
164 DataType probeDataPackage(PackageDataAddress<DataType> &pkg_data_addrs,
const Vecd &position);
166 template <
typename InDataType,
typename OutDataType>
167 void computeGradient(PackageDataAddress<InDataType> &in_pkg_data_addrs,
168 PackageDataAddress<OutDataType> out_pkg_data_addrs, Real dt = 0.0);
170 template <
typename InDataType,
typename OutDataType>
171 void computeNormalizedGradient(PackageDataAddress<InDataType> &in_pkg_data_addrs,
172 PackageDataAddress<OutDataType> out_pkg_data_addrs, Real dt = 0.0);
176 template <
typename DataType>
178 PackageDataAddress<DataType> &pkg_data_addrs)
181 std::get<type_index>(all_pkg_data_).push_back(&pkg_data);
182 std::get<type_index>(all_pkg_data_addrs_).push_back(&pkg_data_addrs);
185 template <
typename DataType>
193 template <
typename DataType>
197 const Vecu &addrs_index,
199 const Vecu &data_index);
204 template <
typename DataType>
205 DataType CornerAverage(PackageDataAddress<DataType> &pkg_data_addrs,
Veci addrs_index,
Veci corner_direction);
208 void initializeSingularDataAddress()
210 initialize_pkg_data_addrs_(all_pkg_data_, all_pkg_data_addrs_);
215 assign_pkg_data_addrs_(all_pkg_data_addrs_, addrs_index, src_pkg->all_pkg_data_, data_index);
235 template <
class MeshFieldType,
class Gr
idDataPackageType>
243 template <
typename... Args>
246 Mesh(tentative_bounds, GridDataPackageType().PackageSize() * data_spacing, buffer_size),
247 data_spacing_(data_spacing),
248 global_mesh_(this->mesh_lower_bound_ + Vecd(data_spacing) * 0.5, data_spacing, this->number_of_cells_ * pkg_size_)
250 allocateMeshDataMatrix();
254 void allocateMeshDataMatrix();
255 void deleteMeshDataMatrix();
258 template <
class DataType,
typename PackageDataAddressType, PackageDataAddressType Gr
idDataPackageType::*MemPtr>
259 DataType probeMesh(
const Vecd &position);
260 virtual Real DataSpacing()
override {
return data_spacing_; };
264 const int pkg_size_ = GridDataPackageType().PackageSize();
265 const int pkg_addrs_buffer_ = GridDataPackageType().AddressBufferWidth();
266 const int pkg_operations_ = pkg_size_ + pkg_addrs_buffer_;
267 const int pkg_addrs_size_ = pkg_size_ + 2 * pkg_addrs_buffer_;
274 template <
typename... ConstructorArgs>
275 void initializeASingularDataPackage(ConstructorArgs &&...args)
277 GridDataPackageType *new_data_pkg = data_pkg_pool_.malloc();
278 new_data_pkg->registerAllVariables();
279 new_data_pkg->initializeSingularData(std::forward<ConstructorArgs>(args)...);
280 new_data_pkg->initializeSingularDataAddress();
281 singular_data_pkgs_addrs_.push_back(new_data_pkg);
284 void assignDataPackageAddress(
const Vecu &cell_index, GridDataPackageType *data_pkg);
285 GridDataPackageType *DataPackageFromCellIndex(
const Vecu &cell_index);
287 template <
typename DataType,
typename PackageDataType, PackageDataType Gr
idDataPackageType::*MemPtr>
288 DataType DataValueFromGlobalIndex(
const Vecu &global_grid_index);
289 void initializePackageAddressesInACell(
const Vecu &cell_index);
293 std::pair<int, int> shift_and_index;
294 int signed_date_index = data_addrs_index_component - pkg_addrs_buffer_;
295 shift_and_index.first = (signed_date_index + pkg_size_) / pkg_size_ - 1;
296 shift_and_index.second = signed_date_index - shift_and_index.first * pkg_size_;
297 return shift_and_index;
301 #endif // MESH_WITH_DATA_PACKAGES_H void initializePackageGeometry(const Vecd &pkg_lower_bound, Real data_spacing)
Definition: mesh_with_data_packages.h:157
This is the base classes of mesh, which is used to describe ordered and indexed data sets...
std::function< ReturnType(DataPackageType *, Real)> PackageFunctor
Definition: mesh_with_data_packages.h:48
Definition: base_data_type.h:43
std::pair< int, int > CellShiftAndDataIndex(int data_addrs_index_component)
Definition: mesh_with_data_packages.h:291
void PackageIterator_parallel(ConcurrentVector< DataPackageType *> &data_pkgs, PackageFunctor< void, DataPackageType > &pkg_functor, Real dt=0.0)
Definition: mesh_with_data_packages.h:59
Definition: base_data_package.h:46
Abstract base class for cell-based mesh by introducing number of cells, buffer width and mesh-based d...
Definition: base_mesh.h:106
Vecd DataLowerBound()
Definition: mesh_with_data_packages.h:155
Base class for all structured meshes which may be grid or cell based. The basic properties of the mes...
Definition: base_mesh.h:63
Abstract base class for a data package, by which the data in a derived class can be on- or off-grid...
Definition: mesh_with_data_packages.h:114
StdVec< GridDataPackageType * > singular_data_pkgs_addrs_
Definition: mesh_with_data_packages.h:272
PackageDataMatrix< DataType, ADDRS_SIZE > PackageTemporaryData
Definition: mesh_with_data_packages.h:145
ReturnType ReducePackageIterator_parallel(ConcurrentVector< DataPackageType *> &data_pkgs, ReturnType temp, PackageFunctor< ReturnType, DataPackageType > &reduce_pkg_functor, ReduceOperation &reduce_operation, Real dt=0.0)
Definition: mesh_with_data_packages.h:87
ConcurrentVector< GridDataPackageType * > inner_data_pkgs_
Definition: mesh_with_data_packages.h:241
LargeVec< DataType > ConcurrentVector
Definition: sph_data_containers.h:50
void PackageIterator(ConcurrentVector< DataPackageType *> &data_pkgs, PackageFunctor< void, DataPackageType > &pkg_functor, Real dt=0.0)
Definition: mesh_with_data_packages.h:51
BaseMesh global_mesh_
Definition: mesh_with_data_packages.h:269
Abstract class for mesh with data packages.
Definition: mesh_with_data_packages.h:236
Definition: mesh_with_data_packages.h:186
MeshDataMatrix< GridDataPackageType * > data_pkg_addrs_
Definition: mesh_with_data_packages.h:240
void registerPackageData(PackageData< DataType > &pkg_data, PackageDataAddress< DataType > &pkg_data_addrs)
Definition: mesh_with_data_packages.h:177
std::mutex mutex_my_pool
Definition: mesh_with_data_packages.h:268
Definition: mesh_with_data_packages.h:194
Vecu pkg_index_
Definition: mesh_with_data_packages.h:117
ReturnType ReducePackageIterator(ConcurrentVector< DataPackageType *> &data_pkgs, ReturnType temp, PackageFunctor< ReturnType, DataPackageType > &reduce_pkg_functor, ReduceOperation &reduce_operation, Real dt=0.0)
Definition: mesh_with_data_packages.h:75
MyMemoryPool< GridDataPackageType > data_pkg_pool_
Definition: mesh_with_data_packages.h:239
Definition: base_data_type.h:320
Abstract base class for a data package whose data are defined on the grids of a small mesh patch...
Definition: mesh_with_data_packages.h:133
bool is_inner_pkg_
Definition: mesh_with_data_packages.h:118
Definition: solid_body_supplementary.cpp:9