DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Mesh_DeviceView.hpp
Go to the documentation of this file.
1#pragma once
2#include "Elements.hpp"
3#include "DNDS/Array.hpp"
7#include "DNDS/ArrayPair.hpp"
8#include "PeriodicInfo.hpp"
10#include "DNDS/ObjectUtils.hpp"
12
13namespace DNDS::Geom
14{
15 static const t_index INTERNAL_ZONE = -1;
16 struct ElemInfo
17 {
19 /// @brief positive for BVnum, 0 for internal Elems, Negative for ?
20 t_index zone = INTERNAL_ZONE;
21
23
24 DNDS_DEVICE_CALLABLE [[nodiscard]] Elem::ElemType getElemType() const
25 {
26 return static_cast<Elem::ElemType>(type);
27 }
28
30 {
31 type = static_cast<t_index>(t);
32 }
33
34 // bool ZoneIsInternal()
35 // {
36 // return zone == INTERNAL_ZONE;
37 // }
38 // bool ZoneIsIndexed()
39 // {
40 // return zone >= 0;
41 // }
42
43 static MPI_Datatype CommType()
44 {
45 static_assert(sizeof(ElemInfo) <= (4ULL * 2));
46 return MPI_INT32_T;
47 }
48 static int CommMult() { return 2; }
49 static std::string pybind11_name() { return "ElemInfo"; }
50 };
51
52}
53namespace DNDS
54{
55// DNDS_DEVICE_STORAGE_BASE_DELETER_INST(Geom::ElemInfo, extern)
56// DNDS_DEVICE_STORAGE_INST(Geom::ElemInfo, DeviceBackend::Host, extern)
57// #ifdef DNDS_USE_CUDA
58// DNDS_DEVICE_STORAGE_INST(Geom::ElemInfo, DeviceBackend::CUDA, extern)
59// #endif
60}
61namespace DNDS::Geom
62{
63
65 using tAdj = decltype(tAdjPair::father);
67 using tPbi = decltype(tPbiPair::father);
69 using tAdj1 = decltype(tAdj1Pair::father);
71 using tAdj2 = decltype(tAdj2Pair::father);
73 using tAdj3 = decltype(tAdj3Pair::father);
75 using tAdj4 = decltype(tAdj4Pair::father);
77 using tAdj8 = decltype(tAdj8Pair::father);
79 using tCoord = decltype(tCoordPair::father);
83 using tInd = decltype(tIndPair::father);
84
85 using tFGetName = std::function<std::string(int)>;
86 using tFGetData = std::function<DNDS::real(int, DNDS::index)>;
87 using tFGetVecData = std::function<DNDS::real(int, DNDS::index, DNDS::rowsize)>;
88
95
101
102#define DNDS_COPY_MEMBER_VIEW(obj, member) \
103 member = (obj).member.template deviceView<B>();
104#define DNDS_COPY_MEMBER(obj, member) \
105 member = (obj).member;
106
107 template <DeviceBackend B>
109 {
110 int dim = -1;
111 bool isPeriodic{false};
113 // state of: face2cell, face2node, face2bnd
115 // state of: cell2face, bnd2face
117 // state of: node2cell, node2bnd
119 // state of: cell2cellFace
120 // MeshAdjState adjC2CFaceState{Adj_Unknown};
121
123
124 /// reader
132 // tAdj1Pair::t_deviceView<B> cell2cellOrig; // no device
133 // tAdj1Pair::t_deviceView<B> node2nodeOrig; // no device
134 // tAdj1Pair::t_deviceView<B> bnd2bndOrig; // no device
135 /// periodic only, after reader
138
152
153 template <class TMain>
169
172
174 {
175 return std::make_tuple(
178 }
179
180 template <class TMain>
181 void create_view_N2CB(TMain &&m_obj)
182 {
185 }
186
187 /// interpolated
194 // std::vector<index> bnd2faceV; // no device
195 // std::unordered_map<index, index> face2bndM; // no device
196 /// periodic only, after interpolated
198
208
209 template <class TMain>
219
221 {
222 return std::make_tuple(
225 }
226
227 template <class TMain>
228 DNDS_HOST void create_view_C2F(TMain &&m_obj)
229 {
232 }
233
234 template <class TMain>
236 {
237 DNDS_assert(placeholder == UnInitIndex);
238
239 DNDS_COPY_MEMBER(mesh, dim);
240 DNDS_COPY_MEMBER(mesh, isPeriodic); //! this is needed after
245 // DNDS_COPY_MEMBER(mesh, adjC2CFaceState);
246
247
248
249 if (adjPrimaryState)
251 if (adjFacialState)
252 create_view_facial(mesh);
253 if (adjC2FState)
254 create_view_C2F(mesh);
255 }
256
258
259 DNDS_DEVICE_CALLABLE index NumNode() const { return coords.father.Size(); }
263
268
273
277
281
282 /**
283 * @brief fA executes when if2c points to the donor side; fB the main side
284 *
285 * @tparam FA
286 * @tparam FB
287 * @tparam F0
288 * @param iFace
289 * @param if2c
290 * @param fA
291 * @param fB
292 * @param f0
293 * @return auto
294 */
295 template <class FA, class FB, class F0>
297 index iFace, rowsize if2c, FA &&fA, FB &&fB, F0 &&f0 = []() {})
298 {
299 if (!this->isPeriodic)
300 return f0();
301 auto faceID = this->GetFaceZone(iFace);
302 if (!Geom::FaceIDIsPeriodic(faceID))
303 return f0();
304 if ((if2c == 1 && Geom::FaceIDIsPeriodicMain(faceID)) ||
305 (if2c == 0 && Geom::FaceIDIsPeriodicDonor(faceID))) // I am donor
306 return fA();
307 if ((if2c == 1 && Geom::FaceIDIsPeriodicDonor(faceID)) ||
308 (if2c == 0 && Geom::FaceIDIsPeriodicMain(faceID))) // I am main
309 return fB();
310 }
311
312 /**
313 * @brief directly load coords; gets faulty if isPeriodic!
314 */
315 template <class tC2n>
317 {
318 cs.resize(Eigen::NoChange, c2n.size());
319 for (rowsize i = 0; i < c2n.size(); i++)
320 {
321 index iNode = c2n[i];
323 cs(EigenAll, i) = coords[iNode];
324 }
325 }
326
327 /**
328 * @brief directly load coords; gets faulty if isPeriodic!
329 */
330 template <class tC2n, class tCoordExt>
331 DNDS_DEVICE_CALLABLE void __GetCoords(const tC2n &c2n, tSmallCoords &cs, tCoordExt &coo)
332 {
333 cs.resize(Eigen::NoChange, c2n.size());
334 for (rowsize i = 0; i < c2n.size(); i++)
335 {
336 index iNode = c2n[i];
338 cs(EigenAll, i) = coo[iNode];
339 }
340 }
341
342 /**
343 * @brief specially for periodicity
344 */
345 template <class tC2n, class tC2nPbi>
346 DNDS_DEVICE_CALLABLE void __GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs)
347 {
348 cs.resize(Eigen::NoChange, c2n.size());
349 for (rowsize i = 0; i < c2n.size(); i++)
350 {
351 index iNode = c2n[i];
353 cs(EigenAll, i) = periodicInfo.GetCoordByBits(coords[iNode], c2nPbi[i]);
354 }
355 }
356
357 /**
358 * @brief specially for periodicity
359 */
360 template <class tC2n, class tC2nPbi, class tCoordExt>
361 DNDS_DEVICE_CALLABLE void __GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs, tCoordExt &coo)
362 {
363 cs.resize(Eigen::NoChange, c2n.size());
364 for (rowsize i = 0; i < c2n.size(); i++)
365 {
366 index iNode = c2n[i];
368 cs(EigenAll, i) = periodicInfo.GetCoordByBits(coo[iNode], c2nPbi[i]);
369 }
370 }
371
373 {
374 if (!isPeriodic)
375 __GetCoords(cell2node[iCell], cs);
376 else
377 __GetCoordsOnElem(cell2node[iCell], cell2nodePbi[iCell], cs);
378 }
379
381 {
382 if (!isPeriodic)
383 __GetCoords(cell2node[iCell], cs, coo);
384 else
385 __GetCoordsOnElem(cell2node[iCell], cell2nodePbi[iCell], cs, coo);
386 }
387
389 {
390 if (!isPeriodic)
391 __GetCoords(face2node[iFace], cs);
392 else
393 __GetCoordsOnElem(face2node[iFace], face2nodePbi[iFace], cs);
394 }
395
397 {
398 if (!isPeriodic)
399 return coords[cell2node(iCell, ic2n)];
400 return periodicInfo.GetCoordByBits(coords[cell2node(iCell, ic2n)], cell2nodePbi(iCell, ic2n));
401 }
402
404 {
405 if (!isPeriodic)
406 return coords[face2node(iFace, if2n)];
407 return periodicInfo.GetCoordByBits(coords[face2node(iFace, if2n)], face2nodePbi(iFace, if2n));
408 }
409
410 // tPoint GetCoordWallDistOnCell(index iCell, rowsize ic2n)
411 // {
412 // if (!isPeriodic)
413 // return nodeWallDist[cell2node(iCell, ic2n)];
414 // return periodicInfo.GetVectorByBits<3, 1>(nodeWallDist[cell2node(iCell, ic2n)], cell2nodePbi(iCell, ic2n));
415 // }
416
417 // tPoint GetCoordWallDistOnFace(index iFace, rowsize if2n)
418 // {
419 // if (!isPeriodic)
420 // return nodeWallDist[face2node(iFace, if2n)];
421 // return periodicInfo.GetVectorByBits<3, 1>(nodeWallDist[face2node(iFace, if2n)], face2nodePbi(iFace, if2n));
422 // }
423
425 {
426 DNDS_assert(face2cell(iFace, 0) == iCell || face2cell(iFace, 1) == iCell);
427 return face2cell(iFace, 0) == iCell;
428 }
429
431 {
432 return CellIsFaceBack(iCell, iFace)
433 ? face2cell(iFace, 1)
434 : face2cell(iFace, 0);
435 }
436 };
437}
Adjacency array (CSR-like index storage) built on ParArray.
Eigen-vector array: each row is an Eigen::Map over contiguous real storage.
Father-son array pairs with device views and ghost communication.
Core 2D variable-length array container with five data layouts.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
Definition Defines.hpp:83
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_HOST
Definition Defines.hpp:78
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE_NO_EMPTY_CTOR(T, T_Self)
Definition Defines.hpp:91
Device memory abstraction layer with backend-specific storage and factory creation.
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
#define DNDS_HD_assert(cond)
Host-only expansion of DNDS_HD_assert (equivalent to DNDS_assert).
Definition Errors.hpp:189
#define DNDS_COPY_MEMBER(obj, member)
#define DNDS_COPY_MEMBER_VIEW(obj, member)
Tiny reflection-style helpers (MemberRef, MemberPtr) and for_each_member_* visitors used by config / ...
#define DNDS_MAKE_1_MEMBER_REF(x)
Construct a MemberRef capturing x and its stringified name.
decltype(tAdj1Pair::father) tAdj1
std::function< std::string(int)> tFGetName
decltype(tAdj8Pair::father) tAdj8
int32_t t_index
Definition Geometric.hpp:6
decltype(tAdj4Pair::father) tAdj4
decltype(tIndPair::father) tInd
decltype(tAdj2Pair::father) tAdj2
decltype(tAdjPair::father) tAdj
std::function< DNDS::real(int, DNDS::index)> tFGetData
std::function< DNDS::real(int, DNDS::index, DNDS::rowsize)> tFGetVecData
Eigen::Vector3d tPoint
Definition Geometric.hpp:9
decltype(tAdj3Pair::father) tAdj3
DNDS::ssp< DNDS::ParArray< ElemInfo > > tElemInfoArray
Eigen::Matrix< real, 3, Eigen::Dynamic > tSmallCoords
Definition Geometric.hpp:50
DNDS_DEVICE_CALLABLE bool FaceIDIsPeriodic(t_index id)
DNDS_DEVICE_CALLABLE bool FaceIDIsPeriodicDonor(t_index id)
DNDS_DEVICE_CALLABLE bool FaceIDIsPeriodicMain(t_index id)
decltype(tPbiPair::father) tPbi
decltype(tCoordPair::father) tCoord
the host side operators are provided as implemented
DNDS_CONSTANT const index UnInitIndex
Sentinel "not initialised" index value (= INT64_MIN).
Definition Defines.hpp:176
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
Definition Defines.hpp:109
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
Definition Defines.hpp:138
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:105
DNDS_DEVICE_CALLABLE index Size() const
Combined father + son row count.
Definition ArrayPair.hpp:33
Mutable device view onto an ArrayPair (for CUDA kernels).
t_arrayDeviceView father
t_arrayDeviceView son
Convenience bundle of a father, son, and attached ArrayTransformer.
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
DNDS_DEVICE_CALLABLE Elem::ElemType getElemType() const
t_index zone
positive for BVnum, 0 for internal Elems, Negative for ?
static std::string pybind11_name()
DNDS_DEVICE_CALLABLE void setElemType(Elem::ElemType t)
static MPI_Datatype CommType()
DNDS_DEVICE_CALLABLE tPoint GetCoordByBits(const tPoint &c, const NodePeriodicBits &bits) const
tAdj2Pair::t_deviceView< B > face2cell
DNDS_DEVICE_CALLABLE index NumCellGhost() const
DNDS_DEVICE_CALLABLE index NumCellProc() const
DNDS_DEVICE_CALLABLE index NumBndGhost() const
DNDS_DEVICE_CALLABLE index NumBndProc() const
tAdjPair::t_deviceView< B > cell2node
DNDS_DEVICE_CALLABLE void GetCoordsOnCell(index iCell, tSmallCoords &cs, tCoordPair &coo)
DNDS_DEVICE_CALLABLE void GetCoordsOnFace(index iFace, tSmallCoords &cs)
DNDS_DEVICE_CALLABLE t_index GetCellZone(index iC)
DNDS_DEVICE_CALLABLE index CellFaceOther(index iCell, index iFace) const
tAdj2Pair::t_deviceView< B > bnd2cell
DNDS_DEVICE_CALLABLE void __GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs)
specially for periodicity
DNDS_HOST void create_view_facial(TMain &&m_obj)
tAdjPair::t_deviceView< B > cell2face
interpolated
tCoordPair::t_deviceView< B > coords
reader
DNDS_DEVICE_CALLABLE bool CellIsFaceBack(index iCell, index iFace) const
tAdjPair::t_deviceView< B > face2node
DNDS_DEVICE_CALLABLE t_index GetBndZone(index iB)
DNDS_DEVICE_CALLABLE void __GetCoords(const tC2n &c2n, tSmallCoords &cs, tCoordExt &coo)
directly load coords; gets faulty if isPeriodic!
tAdjPair::t_deviceView< B > node2cell
DNDS_DEVICE_CALLABLE void __GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs, tCoordExt &coo)
specially for periodicity
DNDS_HOST void create_view_C2F(TMain &&m_obj)
DNDS_DEVICE_CALLABLE Elem::Element GetBndElement(index iB)
DNDS_DEVICE_CALLABLE index NumNode() const
tElemInfoArrayPair::t_deviceView< B > cellElemInfo
tPbiPair::t_deviceView< B > cell2nodePbi
periodic only, after reader
DNDS_DEVICE_CALLABLE t_index GetFaceZone(index iF)
DNDS_DEVICE_CALLABLE index NumFace() const
tAdj1Pair::t_deviceView< B > face2bnd
tAdj1Pair::t_deviceView< B > bnd2face
DNDS_DEVICE_CALLABLE UnstructuredMeshDeviceView(TMain &mesh, index placeholder)
DNDS_DEVICE_CALLABLE void GetCoordsOnCell(index iCell, tSmallCoords &cs)
tPbiPair::t_deviceView< B > face2nodePbi
periodic only, after interpolated
DNDS_DEVICE_CALLABLE Elem::Element GetFaceElement(index iF)
tPbiPair::t_deviceView< B > bnd2nodePbi
DNDS_DEVICE_CALLABLE index NumNodeProc() const
DNDS_DEVICE_CALLABLE auto CellOtherCellPeriodicHandle(index iFace, rowsize if2c, FA &&fA, FB &&fB, F0 &&f0=[]() {})
fA executes when if2c points to the donor side; fB the main side
DNDS_DEVICE_CALLABLE index NumCell() const
DNDS_DEVICE_CALLABLE Elem::Element GetCellElement(index iC)
DNDS_DEVICE_CALLABLE index NumFaceProc() const
DNDS_DEVICE_CALLABLE index NumBnd() const
tElemInfoArrayPair::t_deviceView< B > bndElemInfo
DNDS_DEVICE_CALLABLE index NumNodeGhost() const
tElemInfoArrayPair::t_deviceView< B > faceElemInfo
DNDS_DEVICE_CALLABLE tPoint GetCoordNodeOnCell(index iCell, rowsize ic2n)
DNDS_DEVICE_CALLABLE index NumFaceGhost() const
DNDS_DEVICE_CALLABLE void __GetCoords(const tC2n &c2n, tSmallCoords &cs)
directly load coords; gets faulty if isPeriodic!
DNDS_DEVICE_CALLABLE tPoint GetCoordNodeOnFace(index iFace, rowsize if2n)
tAdjPair::t_deviceView< B > cell2cell