DNDSR 0.2.1
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 "Geom/Elements.hpp"
3#include "DNDS/Array.hpp"
7#include "DNDS/ArrayPair.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 // =================================================================
103 // Device-side views for AdjPairTracked (trivially copyable)
104 // =================================================================
105 // Defined here (not in AdjIndexInfo.hpp) because they only depend on
106 // MeshAdjState and ArrayPairDeviceView, both available at this point.
107 // AdjIndexInfo.hpp includes this header, so AdjPairTracked can use them.
108
109 /// \brief Device-side state for an adjacency (trivially copyable).
120
121 /// \brief Mutable device view for AdjPairTracked.
122 ///
123 /// Inherits from ArrayPairDeviceView (providing operator[], operator(),
124 /// Size(), RowSize()) and adds per-adj state.
125 template <DeviceBackend B, class TArray>
141
142 /// \brief Const device view for AdjPairTracked.
143 template <DeviceBackend B, class TArray>
159
160#define DNDS_COPY_MEMBER_VIEW(obj, member) \
161 member = (obj).member.template deviceView<B>();
162#define DNDS_COPY_MEMBER(obj, member) \
163 member = (obj).member;
164
165 template <DeviceBackend B>
167 {
168 int dim = -1;
169 bool isPeriodic{false};
171 // state of: face2cell, face2node, face2bnd
173 // state of: cell2face, bnd2face
175 // state of: node2cell, node2bnd
177 // state of: cell2cellFace
178 // MeshAdjState adjC2CFaceState{Adj_Unknown};
179
181
182 /// reader
190 /// periodic only, after reader
193
207
208 template <class TMain>
224
227
229 {
230 return std::make_tuple(
233 }
234
235 template <class TMain>
236 void create_view_N2CB(TMain &&m_obj)
237 {
240 }
241
242 /// interpolated
249 // std::vector<index> bnd2faceV; // no device
250 // std::unordered_map<index, index> face2bndM; // no device
251 /// periodic only, after interpolated
253
263
264 template <class TMain>
274
276 {
277 return std::make_tuple(
280 }
281
282 template <class TMain>
283 DNDS_HOST void create_view_C2F(TMain &&m_obj)
284 {
287 }
288
289 template <class TMain>
291 {
292 DNDS_assert(placeholder == UnInitIndex);
293
295 DNDS_COPY_MEMBER(mesh, isPeriodic); //! this is needed after
300 // DNDS_COPY_MEMBER(mesh, adjC2CFaceState);
301
302 if (adjPrimaryState && mesh.cell2node.isBuilt())
304 if (adjFacialState && mesh.face2cell.isBuilt())
306 if (adjC2FState && mesh.cell2face.isBuilt())
308 }
309
311
312 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumNode() const { return coords.father.Size(); }
313 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumCell() const { return cell2node.father.Size(); }
314 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumFace() const { return face2node.father.Size(); }
315 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumBnd() const { return bnd2node.father.Size(); }
316
317 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumNodeGhost() const { return coords.son.Size(); }
318 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumCellGhost() const { return cell2node.son.Size(); }
319 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumFaceGhost() const { return face2node.son.Size(); }
320 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumBndGhost() const { return bnd2node.son.Size(); }
321
322 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumNodeProc() const { return coords.Size(); }
323 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumCellProc() const { return cell2node.Size(); }
324 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumFaceProc() const { return face2node.Size(); }
325 DNDS_DEVICE_CALLABLE [[nodiscard]] index NumBndProc() const { return bnd2node.Size(); }
326
330
334
335 /**
336 * @brief fA executes when if2c points to the donor side; fB the main side
337 *
338 * @tparam FA
339 * @tparam FB
340 * @tparam F0
341 * @param iFace
342 * @param if2c
343 * @param fA
344 * @param fB
345 * @param f0
346 * @return auto
347 */
348 template <class FA, class FB, class F0>
350 index iFace, rowsize if2c, FA &&fA, FB &&fB, F0 &&f0 = []() {})
351 {
352 if (!this->isPeriodic)
353 return f0();
354 auto faceID = this->GetFaceZone(iFace);
355 if (!Geom::FaceIDIsPeriodic(faceID))
356 return f0();
357 if ((if2c == 1 && Geom::FaceIDIsPeriodicMain(faceID)) ||
358 (if2c == 0 && Geom::FaceIDIsPeriodicDonor(faceID))) // I am donor
359 return fA();
360 if ((if2c == 1 && Geom::FaceIDIsPeriodicDonor(faceID)) ||
361 (if2c == 0 && Geom::FaceIDIsPeriodicMain(faceID))) // I am main
362 return fB();
363 }
364
365 /**
366 * @brief directly load coords; gets faulty if isPeriodic!
367 */
368 template <class tC2n>
370 {
371 cs.resize(Eigen::NoChange, c2n.size());
372 for (rowsize i = 0; i < c2n.size(); i++)
373 {
374 index iNode = c2n[i];
376 cs(EigenAll, i) = coords[iNode];
377 }
378 }
379
380 /**
381 * @brief directly load coords; gets faulty if isPeriodic!
382 */
383 template <class tC2n, class tCoordExt>
384 DNDS_DEVICE_CALLABLE void _detail_GetCoords(const tC2n &c2n, tSmallCoords &cs, tCoordExt &coo)
385 {
386 cs.resize(Eigen::NoChange, c2n.size());
387 for (rowsize i = 0; i < c2n.size(); i++)
388 {
389 index iNode = c2n[i];
391 cs(EigenAll, i) = coo[iNode];
392 }
393 }
394
395 /**
396 * @brief specially for periodicity
397 */
398 template <class tC2n, class tC2nPbi>
399 DNDS_DEVICE_CALLABLE void _detail_GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs)
400 {
401 cs.resize(Eigen::NoChange, c2n.size());
402 for (rowsize i = 0; i < c2n.size(); i++)
403 {
404 index iNode = c2n[i];
406 cs(EigenAll, i) = periodicInfo.GetCoordByBits(coords[iNode], c2nPbi[i]);
407 }
408 }
409
410 /**
411 * @brief specially for periodicity
412 */
413 template <class tC2n, class tC2nPbi, class tCoordExt>
414 DNDS_DEVICE_CALLABLE void _detail_GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs, tCoordExt &coo)
415 {
416 cs.resize(Eigen::NoChange, c2n.size());
417 for (rowsize i = 0; i < c2n.size(); i++)
418 {
419 index iNode = c2n[i];
421 cs(EigenAll, i) = periodicInfo.GetCoordByBits(coo[iNode], c2nPbi[i]);
422 }
423 }
424
426 {
427 if (!isPeriodic)
428 _detail_GetCoords(cell2node[iCell], cs);
429 else
431 }
432
434 {
435 if (!isPeriodic)
436 _detail_GetCoords(cell2node[iCell], cs, coo);
437 else
438 _detail_GetCoordsOnElem(cell2node[iCell], cell2nodePbi[iCell], cs, coo);
439 }
440
442 {
443 if (!isPeriodic)
444 _detail_GetCoords(face2node[iFace], cs);
445 else
447 }
448
450 {
451 if (!isPeriodic)
452 return coords[cell2node(iCell, ic2n)];
453 return periodicInfo.GetCoordByBits(coords[cell2node(iCell, ic2n)], cell2nodePbi(iCell, ic2n));
454 }
455
457 {
458 if (!isPeriodic)
459 return coords[face2node(iFace, if2n)];
460 return periodicInfo.GetCoordByBits(coords[face2node(iFace, if2n)], face2nodePbi(iFace, if2n));
461 }
462
463 // tPoint GetCoordWallDistOnCell(index iCell, rowsize ic2n)
464 // {
465 // if (!isPeriodic)
466 // return nodeWallDist[cell2node(iCell, ic2n)];
467 // return periodicInfo.GetVectorByBits<3, 1>(nodeWallDist[cell2node(iCell, ic2n)], cell2nodePbi(iCell, ic2n));
468 // }
469
470 // tPoint GetCoordWallDistOnFace(index iFace, rowsize if2n)
471 // {
472 // if (!isPeriodic)
473 // return nodeWallDist[face2node(iFace, if2n)];
474 // return periodicInfo.GetVectorByBits<3, 1>(nodeWallDist[face2node(iFace, if2n)], face2nodePbi(iFace, if2n));
475 // }
476
477 DNDS_DEVICE_CALLABLE [[nodiscard]] bool CellIsFaceBack(index iCell, index iFace) const
478 {
479 DNDS_assert(face2cell(iFace, 0) == iCell || face2cell(iFace, 1) == iCell);
480 return face2cell(iFace, 0) == iCell;
481 }
482
483 DNDS_DEVICE_CALLABLE [[nodiscard]] index CellFaceOther(index iCell, index iFace) const
484 {
485 return CellIsFaceBack(iCell, iFace)
486 ? face2cell(iFace, 1)
487 : face2cell(iFace, 0);
488 }
489 };
490}
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:87
#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:95
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:112
#define DNDS_HD_assert(cond)
Host-only expansion of DNDS_HD_assert (equivalent to DNDS_assert).
Definition Errors.hpp:193
#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:181
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
Definition Defines.hpp:114
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:112
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
Definition Defines.hpp:143
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:110
Const device view of a father-son array pair.
typename TArray::template t_deviceViewConst< B > t_arrayDeviceView
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
typename TArray::template t_deviceView< B > t_arrayDeviceView
Convenience bundle of a father, son, and attached ArrayTransformer.
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
Device-side state for an adjacency (trivially copyable).
DNDS_DEVICE_CALLABLE bool isGlobal() const
DNDS_DEVICE_CALLABLE bool isLocal() const
DNDS_DEVICE_CALLABLE bool isBuilt() const
Const device view for AdjPairTracked.
typename t_base::t_arrayDeviceView t_arrayDeviceView
Mutable device view for AdjPairTracked.
typename t_base::t_arrayDeviceView t_arrayDeviceView
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
DNDS_DEVICE_CALLABLE index NumCellGhost() const
DNDS_DEVICE_CALLABLE index NumCellProc() const
DNDS_DEVICE_CALLABLE index NumBndGhost() const
AdjPairTrackedDeviceView< B, tAdj1Pair::t_arr > face2bnd
DNDS_DEVICE_CALLABLE index NumBndProc() const
DNDS_DEVICE_CALLABLE void GetCoordsOnCell(index iCell, tSmallCoords &cs, tCoordPair &coo)
DNDS_DEVICE_CALLABLE void _detail_GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs)
specially for periodicity
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
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > face2node
DNDS_DEVICE_CALLABLE void _detail_GetCoordsOnElem(const tC2n &c2n, const tC2nPbi &c2nPbi, tSmallCoords &cs, tCoordExt &coo)
specially for periodicity
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > node2bnd
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > bnd2node
DNDS_HOST void create_view_facial(TMain &&m_obj)
AdjPairTrackedDeviceView< B, tAdj2Pair::t_arr > face2cell
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > cell2face
interpolated
tCoordPair::t_deviceView< B > coords
reader
DNDS_DEVICE_CALLABLE bool CellIsFaceBack(index iCell, index iFace) const
DNDS_DEVICE_CALLABLE t_index GetBndZone(index iB)
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > node2cell
DNDS_HOST void create_view_C2F(TMain &&m_obj)
DNDS_DEVICE_CALLABLE Elem::Element GetBndElement(index iB)
DNDS_DEVICE_CALLABLE index NumNode() const
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > cell2cell
tElemInfoArrayPair::t_deviceView< B > cellElemInfo
tPbiPair::t_deviceView< B > cell2nodePbi
periodic only, after reader
DNDS_DEVICE_CALLABLE t_index GetFaceZone(index iF)
AdjPairTrackedDeviceView< B, tAdj2Pair::t_arr > bnd2cell
DNDS_DEVICE_CALLABLE index NumFace() const
DNDS_DEVICE_CALLABLE UnstructuredMeshDeviceView(TMain &mesh, index placeholder)
DNDS_DEVICE_CALLABLE void _detail_GetCoords(const tC2n &c2n, tSmallCoords &cs, tCoordExt &coo)
directly load coords; gets faulty if isPeriodic!
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 void _detail_GetCoords(const tC2n &c2n, tSmallCoords &cs)
directly load coords; gets faulty if isPeriodic!
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
AdjPairTrackedDeviceView< B, tAdjPair::t_arr > cell2node
DNDS_DEVICE_CALLABLE tPoint GetCoordNodeOnFace(index iFace, rowsize if2n)
AdjPairTrackedDeviceView< B, tAdj1Pair::t_arr > bnd2face
DistributedHex3D mesh
DNDS::index idx