peclet.voro 1.0.4
Device-native moving-particle Voronoi dynamics
Loading...
Searching...
No Matches
polymesh.hpp
Go to the documentation of this file.
1
18#ifndef PECLET_VORO_FV_POLYMESH_HPP
19#define PECLET_VORO_FV_POLYMESH_HPP
20
21#include <cmath>
22#include <cstdio>
23#include <functional>
24#include <Kokkos_Core.hpp>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29#include "peclet/core/common/view.hpp"
31#include "peclet/voro/sdf.hpp"
33
34namespace peclet::voro::fv {
35
36template <class Real>
37struct PolyMesh {
38 int nCells = 0, nFaces = 0, nInterior = 0;
39 std::vector<Real> points; // 3 * nPoints (world)
40 std::vector<int> faceOffset; // nFaces + 1
41 std::vector<int> faceVerts; // point ids, CCW about the owner's outward normal
42 std::vector<int> owner; // nFaces
43 std::vector<int> neighbour; // nFaces, -1 on boundary
44 std::vector<int> patch; // nFaces: 0 interior, 1 wall, 2 box
45 std::vector<int> cellFaceOffset; // nCells + 1
46 std::vector<int> cellFace; // faces of each cell (interior faces in both)
47 std::vector<Real> cellVolume; // nCells, from the assembled polygons
48 int nPoints() const { return (int)points.size() / 3; }
49};
50
51namespace detail {
52struct VertexKey {
53 long long a, b, c;
54 bool operator==(const VertexKey& o) const { return a == o.a && b == o.b && c == o.c; }
55};
57 std::size_t operator()(const VertexKey& k) const {
58 std::size_t h = (std::size_t)k.a * 73856093u;
59 h ^= (std::size_t)k.b * 19349663u;
60 h ^= (std::size_t)k.c * 83492791u;
61 return h;
62 }
63};
64} // namespace detail
65
66namespace detail {
68inline int unionFindRoot(std::vector<int>& parent, int a) {
69 while (parent[a] != a)
70 a = parent[a] = parent[parent[a]];
71 return a;
72}
73
75template <class Real>
76std::vector<int> wallVertexIds(const PolyMesh<Real>& m) {
77 const int nP = m.nPoints();
78 std::vector<char> onWall(nP, 0);
79 for (int f = 0; f < m.nFaces; ++f)
80 if (m.patch[f] == 1)
81 for (int q = m.faceOffset[f]; q < m.faceOffset[f + 1]; ++q)
82 onWall[m.faceVerts[q]] = 1;
83 std::vector<int> ids;
84 for (int p = 0; p < nP; ++p)
85 if (onWall[p])
86 ids.push_back(p);
87 return ids;
88}
89
91template <class Real>
92void unionWithinTolerance(const PolyMesh<Real>& m, const Real L[3], Real tol2, int p,
93 const std::vector<int>& candidates, std::vector<int>& parent) {
94 for (int q : candidates) {
95 if (q <= p)
96 continue;
97 Real d2 = 0;
98 for (int k = 0; k < 3; ++k) {
99 Real d = m.points[3 * q + k] - m.points[3 * p + k];
100 d -= L[k] * std::round(d / L[k]);
101 d2 += d * d;
102 }
103 if (d2 <= tol2) {
104 const int ra = unionFindRoot(parent, p), rb = unionFindRoot(parent, q);
105 if (ra != rb)
106 parent[rb] = ra;
107 }
108 }
109}
110
113template <class Real>
114void unionNearWallVertices(const PolyMesh<Real>& m, const Real L[3], Real tol,
115 const std::vector<int>& ids, std::vector<int>& parent) {
116 // hash grid of cell size tol over the periodic box
117 std::unordered_map<detail::VertexKey, std::vector<int>, detail::VertexKeyHash> grid;
118 long long Mq[3];
119 for (int k = 0; k < 3; ++k)
120 Mq[k] = std::max<long long>(1, (long long)std::floor(L[k] / tol));
121 auto cellOf = [&](Real x, int k) {
122 long long c = (long long)std::floor(x / L[k] * (Real)Mq[k]);
123 c %= Mq[k];
124 return c < 0 ? c + Mq[k] : c;
125 };
126 for (int p : ids)
127 grid[detail::VertexKey{cellOf(m.points[3 * p], 0), cellOf(m.points[3 * p + 1], 1),
128 cellOf(m.points[3 * p + 2], 2)}]
129 .push_back(p);
130 const Real tol2 = tol * tol;
131 for (int p : ids) {
132 const long long c0[3] = {cellOf(m.points[3 * p], 0), cellOf(m.points[3 * p + 1], 1),
133 cellOf(m.points[3 * p + 2], 2)};
134 for (int dz = -1; dz <= 1; ++dz)
135 for (int dy = -1; dy <= 1; ++dy)
136 for (int dx = -1; dx <= 1; ++dx) {
137 auto w = [&](long long c, long long M) { return ((c % M) + M) % M; };
138 auto it = grid.find(
139 detail::VertexKey{w(c0[0] + dx, Mq[0]), w(c0[1] + dy, Mq[1]), w(c0[2] + dz, Mq[2])});
140 if (it == grid.end())
141 continue;
142 unionWithinTolerance(m, L, tol2, p, it->second, parent);
143 }
144 }
145}
146
149template <class Real>
150int moveRootsToGroupMean(PolyMesh<Real>& m, const Real L[3], const std::vector<int>& ids,
151 std::vector<int>& parent) {
152 const int nP = m.nPoints();
153 std::vector<Real> acc(3 * (size_t)nP, Real(0));
154 std::vector<int> cnt(nP, 0);
155 int merged = 0;
156 for (int p : ids) {
157 const int r = unionFindRoot(parent, p);
158 for (int k = 0; k < 3; ++k) {
159 Real d = m.points[3 * p + k] - m.points[3 * r + k];
160 d -= L[k] * std::round(d / L[k]);
161 acc[3 * r + k] += d;
162 }
163 ++cnt[r];
164 if (r != p)
165 ++merged;
166 }
167 for (int p : ids)
168 if (unionFindRoot(parent, p) == p && cnt[p] > 1)
169 for (int k = 0; k < 3; ++k)
170 m.points[3 * p + k] += acc[3 * p + k] / (Real)cnt[p];
171 return merged;
172}
173
176template <class Real>
177void rewriteMergedFaces(PolyMesh<Real>& m, std::vector<int>& parent) {
178 std::vector<int> newVerts, newOff(1, 0), newOwner, newNbr, newPatch;
179 std::vector<int> faceMap(m.nFaces, -1);
180 for (int f = 0; f < m.nFaces; ++f) {
181 std::vector<int> poly;
182 for (int q = m.faceOffset[f]; q < m.faceOffset[f + 1]; ++q) {
183 const int v = unionFindRoot(parent, m.faceVerts[q]);
184 if (poly.empty() || poly.back() != v)
185 poly.push_back(v);
186 }
187 while (poly.size() > 1 && poly.front() == poly.back())
188 poly.pop_back();
189 if (poly.size() < 3)
190 continue; // a degenerate face (collapsed by the merge)
191 faceMap[f] = (int)newOff.size() - 1;
192 newVerts.insert(newVerts.end(), poly.begin(), poly.end());
193 newOff.push_back((int)newVerts.size());
194 newOwner.push_back(m.owner[f]);
195 newNbr.push_back(m.neighbour[f]);
196 newPatch.push_back(m.patch[f]);
197 }
198 std::vector<int> cf, cfo(1, 0);
199 for (int i = 0; i < m.nCells; ++i) {
200 for (int q = m.cellFaceOffset[i]; q < m.cellFaceOffset[i + 1]; ++q)
201 if (faceMap[m.cellFace[q]] >= 0)
202 cf.push_back(faceMap[m.cellFace[q]]);
203 cfo.push_back((int)cf.size());
204 }
205 int nInt = 0;
206 for (int f = 0; f < (int)newPatch.size(); ++f)
207 nInt += newPatch[f] == 0;
208 m.faceVerts = newVerts;
209 m.faceOffset = newOff;
210 m.owner = newOwner;
211 m.neighbour = newNbr;
212 m.patch = newPatch;
213 m.cellFace = cf;
214 m.cellFaceOffset = cfo;
215 m.nFaces = (int)newPatch.size();
216 m.nInterior = nInt;
217}
218} // namespace detail
219
230template <class Real>
231int mergeWallVertices(PolyMesh<Real>& m, const Real L[3], Real tol) {
232 const int nP = m.nPoints();
233 const std::vector<int> ids = detail::wallVertexIds(m);
234 std::vector<int> parent(nP);
235 for (int p = 0; p < nP; ++p)
236 parent[p] = p;
237 detail::unionNearWallVertices(m, L, tol, ids, parent);
238 const int merged = detail::moveRootsToGroupMean(m, L, ids, parent);
240 return merged;
241}
242
243namespace detail {
246template <class Real>
248 std::unordered_map<VertexKey, int, VertexKeyHash> vmap;
249 long long M[3];
251 const Real* L;
252
253 PeriodicVertexIds(const Real L_[3], Real quantum_, int N) : quantum(quantum_), L(L_) {
254 vmap.reserve((size_t)N * 8);
255 for (int k = 0; k < 3; ++k)
256 M[k] = (long long)std::llround(Real(1) / quantum);
257 }
258 static long long wrapq(long long v, long long m) {
259 v %= m;
260 return v < 0 ? v + m : v;
261 }
263 int operator()(PolyMesh<Real>& m, Real x, Real y, Real z) {
264 VertexKey k{wrapq((long long)std::llround(x / (quantum * L[0])), M[0]),
265 wrapq((long long)std::llround(y / (quantum * L[1])), M[1]),
266 wrapq((long long)std::llround(z / (quantum * L[2])), M[2])};
267 auto it = vmap.find(k);
268 if (it != vmap.end())
269 return it->second;
270 const int id = m.nPoints();
271 m.points.push_back(x);
272 m.points.push_back(y);
273 m.points.push_back(z);
274 vmap.emplace(k, id);
275 return id;
276 }
277};
278
281 std::vector<std::vector<int>> cellFaces; // faces of each cell (interior faces in both)
282 std::vector<int> owner, nbr, patch, off{0}, verts;
283 explicit PolyFaceList(int N) : cellFaces(N) {}
284};
285
288template <class Real, class Cell, class PosM, class RefM, class RecM, class CntM>
289void restoreWallPlanesHost(Cell& c, int i, const PosM& ph, const RefM& xrM, const RecM& wrecM,
290 const CntM& wcntM, const Real L[3]) {
291 const Real Lh[3] = {L[0] / 2, L[1] / 2, L[2] / 2};
292 const Real sx = ph(3 * i), sy = ph(3 * i + 1), sz = ph(3 * i + 2);
293 Real dx = sx - xrM(3 * i), dy = sy - xrM(3 * i + 1), dz = sz - xrM(3 * i + 2);
294 dx = dx > Lh[0] ? dx - L[0] : (dx < -Lh[0] ? dx + L[0] : dx);
295 dy = dy > Lh[1] ? dy - L[1] : (dy < -Lh[1] ? dy + L[1] : dy);
296 dz = dz > Lh[2] ? dz - L[2] : (dz < -Lh[2] ? dz + L[2] : dz);
297 // restore the wall planes from the host mirrors (same arithmetic as WallStore::load)
298 int r = 0;
299 const int nrec = wcntM(i);
300 for (int k = 6; k < c.np; ++k) {
301 if (c.pnbr[k] >= 0 || r >= nrec)
302 continue;
303 const size_t o = ((size_t)i * WallStore<Real>::kMax + r) * 4;
304 const Real ux = wrecM(o), uy = wrecM(o + 1), uz = wrecM(o + 2);
305 const Real h = wrecM(o + 3) - (ux * dx + uy * dy + uz * dz);
306 c.n[k][0] = h * ux;
307 c.n[k][1] = h * uy;
308 c.n[k][2] = h * uz;
309 c.nn[k] = h * h;
310 ++r;
311 }
312}
313
316template <class Real, class Cell>
317Real emitCellFaces(const Cell& c, int i, Real sx, Real sy, Real sz,
319 Real V = 0;
320 for (int k = 0; k < c.np; ++k) {
321 Real fx[Cell::MAXFV], fy[Cell::MAXFV], fz[Cell::MAXFV];
322 const int nv = c.faceOrdered(k, fx, fy, fz);
323 if (nv < 3)
324 continue;
325 const int j = c.pnbr[k];
326 // pyramid volume from the seed (exact for the convex cell)
327 for (int q = 1; q + 1 < nv; ++q) {
328 const Real ax = fx[0], ay = fy[0], az = fz[0], bx = fx[q], by = fy[q], bz = fz[q],
329 cx = fx[q + 1], cy = fy[q + 1], cz = fz[q + 1];
330 V += std::fabs(ax * (by * cz - bz * cy) - ay * (bx * cz - bz * cx) +
331 az * (bx * cy - by * cx)) /
332 Real(6);
333 }
334 if (j >= 0 && j < i)
335 continue; // emitted from the lower cell
336 const int fid = (int)faces.owner.size();
337 faces.owner.push_back(i);
338 faces.nbr.push_back(j >= 0 ? j : -1);
339 faces.patch.push_back(j >= 0 ? 0 : (j == kBoundaryFacet ? 1 : 2));
340 for (int q = 0; q < nv; ++q)
341 faces.verts.push_back(vertexId(m, sx + fx[q], sy + fy[q], sz + fz[q]));
342 faces.off.push_back((int)faces.verts.size());
343 faces.cellFaces[i].push_back(fid);
344 if (j >= 0)
345 faces.cellFaces[j].push_back(fid);
346 }
347 return V;
348}
349
351template <class Real>
352void storeInteriorFirst(PolyMesh<Real>& m, const PolyFaceList& faces, int N) {
353 const int nF = (int)faces.owner.size();
354 std::vector<int> perm(nF), inv(nF);
355 int q = 0;
356 for (int f = 0; f < nF; ++f)
357 if (faces.patch[f] == 0)
358 perm[q++] = f;
359 m.nInterior = q;
360 for (int f = 0; f < nF; ++f)
361 if (faces.patch[f] != 0)
362 perm[q++] = f;
363 for (int f = 0; f < nF; ++f)
364 inv[perm[f]] = f;
365 m.nFaces = nF;
366 m.faceOffset.assign(1, 0);
367 for (int f = 0; f < nF; ++f) {
368 const int o = perm[f];
369 m.owner.push_back(faces.owner[o]);
370 m.neighbour.push_back(faces.nbr[o]);
371 m.patch.push_back(faces.patch[o]);
372 for (int v = faces.off[o]; v < faces.off[o + 1]; ++v)
373 m.faceVerts.push_back(faces.verts[v]);
374 m.faceOffset.push_back((int)m.faceVerts.size());
375 }
376 m.cellFaceOffset.assign(1, 0);
377 for (int i = 0; i < N; ++i) {
378 for (int f : faces.cellFaces[i])
379 m.cellFace.push_back(inv[f]);
380 m.cellFaceOffset.push_back((int)m.cellFace.size());
381 }
382}
383} // namespace detail
384
386template <class Real, int MAXP, int MAXT>
388 const Kokkos::View<Real*, peclet::core::MemSpace>& pos, int N,
389 const Real L[3], WallStore<Real> wall = {},
390 Kokkos::View<Real*, peclet::core::MemSpace> xRef = {},
391 Real quantum = Real(1e-9)) {
392 using Cell = ConvexCell<Real, MAXP, MAXT, false>;
393 auto np = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, store.np);
394 auto nt = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, store.nt);
395 auto pnbr = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, store.pnbr);
396 auto tri = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, store.tri);
397 auto ph = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, pos);
398 // host decode of the store (the same steps as TopologyStore::load, on the mirrors)
399 auto loadHost = [&](int i, Cell& c) {
400 c.initBoxPlanes(L[0], L[1], L[2]);
401 const int npi = np(i), nti = nt(i);
402 c.np = npi;
403 c.nt = nti;
404 c.overflow = false;
405 for (int k = 6; k < npi; ++k)
406 c.pnbr[k] = pnbr((size_t)i * MAXP + k);
407 for (int t = 0; t < nti; ++t) {
408 const unsigned w = tri((size_t)i * MAXT + t);
409 c.t0[t] = (unsigned char)(w & 0xffu);
410 c.t1[t] = (unsigned char)((w >> 8) & 0xffu);
411 c.t2[t] = (unsigned char)((w >> 16) & 0xffu);
412 c.alive[t] = ((w >> 24) & 1u) != 0u;
413 }
414 };
415 const bool hasWall = wall.cnt.extent(0) > 0;
416 typename Kokkos::View<Real*, peclet::core::MemSpace>::host_mirror_type wrecM, xrM;
417 typename Kokkos::View<int*, peclet::core::MemSpace>::host_mirror_type wcntM;
418 if (hasWall) {
419 wrecM = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, wall.rec);
420 wcntM = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, wall.cnt);
421 xrM = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, xRef);
422 }
423 PolyMesh<Real> m;
424 m.nCells = N;
425 m.cellVolume.assign(N, Real(0));
426 detail::PeriodicVertexIds<Real> vertexId(L, quantum, N);
427 // interior faces are keyed by (min cell, max cell) to be emitted once
428 detail::PolyFaceList faces(N);
429 for (int i = 0; i < N; ++i) {
430 Cell c;
431 loadHost(i, c);
432 const Real sx = ph(3 * i), sy = ph(3 * i + 1), sz = ph(3 * i + 2);
433 if (hasWall)
434 detail::restoreWallPlanesHost(c, i, ph, xrM, wrecM, wcntM, L);
435 c.reevalGeometry(sx, sy, sz, ph.data(), L[0]);
436 m.cellVolume[i] = detail::emitCellFaces(c, i, sx, sy, sz, vertexId, m, faces);
437 }
438 // order: interior faces first
439 detail::storeInteriorFirst(m, faces, N);
440 return m;
441}
442
445template <class Real>
446bool writeVtu(const std::string& path, const PolyMesh<Real>& m,
447 const std::vector<Real>* cellScalar = nullptr, const char* scalarName = "scalar") {
448 std::FILE* fp = std::fopen(path.c_str(), "w");
449 if (!fp)
450 return false;
451 const int nP = m.nPoints(), nC = m.nCells;
452 std::fprintf(fp,
453 "<?xml version=\"1.0\"?>\n<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" "
454 "byte_order=\"LittleEndian\">\n<UnstructuredGrid>\n<Piece NumberOfPoints=\"%d\" "
455 "NumberOfCells=\"%d\">\n",
456 nP, nC);
457 std::fprintf(
458 fp, "<Points>\n<DataArray type=\"Float64\" NumberOfComponents=\"3\" format=\"ascii\">\n");
459 for (int p = 0; p < nP; ++p)
460 std::fprintf(fp, "%.17g %.17g %.17g\n", (double)m.points[3 * p], (double)m.points[3 * p + 1],
461 (double)m.points[3 * p + 2]);
462 std::fprintf(fp, "</DataArray>\n</Points>\n<Cells>\n");
463 // connectivity: the union of a cell's face vertices (unique), offsets, types = 42
464 std::vector<int> conn, connOff, faces, faceOff;
465 std::vector<char> seen(nP, 0);
466 for (int i = 0; i < nC; ++i) {
467 std::vector<int> touched;
468 for (int q = m.cellFaceOffset[i]; q < m.cellFaceOffset[i + 1]; ++q) {
469 const int f = m.cellFace[q];
470 for (int v = m.faceOffset[f]; v < m.faceOffset[f + 1]; ++v) {
471 const int p = m.faceVerts[v];
472 if (!seen[p]) {
473 seen[p] = 1;
474 touched.push_back(p);
475 conn.push_back(p);
476 }
477 }
478 }
479 for (int p : touched)
480 seen[p] = 0;
481 connOff.push_back((int)conn.size());
482 const int nf = m.cellFaceOffset[i + 1] - m.cellFaceOffset[i];
483 faces.push_back(nf);
484 for (int q = m.cellFaceOffset[i]; q < m.cellFaceOffset[i + 1]; ++q) {
485 const int f = m.cellFace[q];
486 const int nv = m.faceOffset[f + 1] - m.faceOffset[f];
487 faces.push_back(nv);
488 // orientation: outward for the owner; reversed for the neighbour
489 if (m.owner[f] == i)
490 for (int v = m.faceOffset[f]; v < m.faceOffset[f + 1]; ++v)
491 faces.push_back(m.faceVerts[v]);
492 else
493 for (int v = m.faceOffset[f + 1] - 1; v >= m.faceOffset[f]; --v)
494 faces.push_back(m.faceVerts[v]);
495 }
496 faceOff.push_back((int)faces.size());
497 }
498 std::fprintf(fp, "<DataArray type=\"Int64\" Name=\"connectivity\" format=\"ascii\">\n");
499 for (int v : conn)
500 std::fprintf(fp, "%d\n", v);
501 std::fprintf(fp, "</DataArray>\n<DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n");
502 for (int o : connOff)
503 std::fprintf(fp, "%d\n", o);
504 std::fprintf(fp, "</DataArray>\n<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n");
505 for (int i = 0; i < nC; ++i)
506 std::fprintf(fp, "42\n");
507 std::fprintf(fp, "</DataArray>\n<DataArray type=\"Int64\" Name=\"faces\" format=\"ascii\">\n");
508 for (int v : faces)
509 std::fprintf(fp, "%d\n", v);
510 std::fprintf(fp,
511 "</DataArray>\n<DataArray type=\"Int64\" Name=\"faceoffsets\" format=\"ascii\">\n");
512 for (int o : faceOff)
513 std::fprintf(fp, "%d\n", o);
514 std::fprintf(fp, "</DataArray>\n</Cells>\n<CellData>\n");
515 std::fprintf(fp, "<DataArray type=\"Float64\" Name=\"volume\" format=\"ascii\">\n");
516 for (int i = 0; i < nC; ++i)
517 std::fprintf(fp, "%.17g\n", (double)m.cellVolume[i]);
518 std::fprintf(fp, "</DataArray>\n");
519 if (cellScalar) {
520 std::fprintf(fp, "<DataArray type=\"Float64\" Name=\"%s\" format=\"ascii\">\n", scalarName);
521 for (int i = 0; i < nC; ++i)
522 std::fprintf(fp, "%.17g\n", (double)(*cellScalar)[i]);
523 std::fprintf(fp, "</DataArray>\n");
524 }
525 std::fprintf(fp, "</CellData>\n</Piece>\n</UnstructuredGrid>\n</VTKFile>\n");
526 std::fclose(fp);
527 return true;
528}
529
530} // namespace peclet::voro::fv
531
532#endif // PECLET_VORO_FV_POLYMESH_HPP
KOKKOS_INLINE_FUNCTION Dual< Real, K > dnum(Real c)
Definition convex_cell.hpp:53
void storeInteriorFirst(PolyMesh< Real > &m, const PolyFaceList &faces, int N)
Copy the emitted faces into m, interior faces first, and the cell face lists renumbered.
Definition polymesh.hpp:352
Real emitCellFaces(const Cell &c, int i, Real sx, Real sy, Real sz, PeriodicVertexIds< Real > &vertexId, PolyMesh< Real > &m, PolyFaceList &faces)
Definition polymesh.hpp:317
void unionWithinTolerance(const PolyMesh< Real > &m, const Real L[3], Real tol2, int p, const std::vector< int > &candidates, std::vector< int > &parent)
Join vertex p with every candidate q > p within the min-image distance sqrt(tol2).
Definition polymesh.hpp:92
int moveRootsToGroupMean(PolyMesh< Real > &m, const Real L[3], const std::vector< int > &ids, std::vector< int > &parent)
Definition polymesh.hpp:150
void unionNearWallVertices(const PolyMesh< Real > &m, const Real L[3], Real tol, const std::vector< int > &ids, std::vector< int > &parent)
Definition polymesh.hpp:114
int unionFindRoot(std::vector< int > &parent, int a)
Root of a in a union–find forest, halving the path on the way (mergeWallVertices).
Definition polymesh.hpp:68
void rewriteMergedFaces(PolyMesh< Real > &m, std::vector< int > &parent)
Definition polymesh.hpp:177
void restoreWallPlanesHost(Cell &c, int i, const PosM &ph, const RefM &xrM, const RecM &wrecM, const CntM &wcntM, const Real L[3])
Definition polymesh.hpp:289
std::vector< int > wallVertexIds(const PolyMesh< Real > &m)
The vertices of the wall faces (patch 1), ascending.
Definition polymesh.hpp:76
Definition collocated.hpp:38
PolyMesh< Real > buildPolyMesh(const TopologyStore< MAXP, MAXT > &store, const Kokkos::View< Real *, peclet::core::MemSpace > &pos, int N, const Real L[3], WallStore< Real > wall={}, Kokkos::View< Real *, peclet::core::MemSpace > xRef={}, Real quantum=Real(1e-9))
Assemble the polyhedral mesh of a store at positions posHost (3N, world, in [0,L)).
Definition polymesh.hpp:387
bool writeVtu(const std::string &path, const PolyMesh< Real > &m, const std::vector< Real > *cellScalar=nullptr, const char *scalarName="scalar")
Definition polymesh.hpp:446
int mergeWallVertices(PolyMesh< Real > &m, const Real L[3], Real tol)
Definition polymesh.hpp:231
constexpr int kBoundaryFacet
Definition sdf.hpp:36
Definition topology_store.hpp:39
Kokkos::View< int *, MemSpace > np
Definition topology_store.hpp:42
Kokkos::View< unsigned *, MemSpace > tri
Definition topology_store.hpp:45
Kokkos::View< int *, MemSpace > nt
Definition topology_store.hpp:43
Kokkos::View< int *, MemSpace > pnbr
Definition topology_store.hpp:44
Definition sdf.hpp:352
Definition polymesh.hpp:37
std::vector< int > faceOffset
Definition polymesh.hpp:40
std::vector< Real > points
Definition polymesh.hpp:39
std::vector< int > patch
Definition polymesh.hpp:44
std::vector< int > neighbour
Definition polymesh.hpp:43
std::vector< int > cellFaceOffset
Definition polymesh.hpp:45
std::vector< int > faceVerts
Definition polymesh.hpp:41
int nInterior
Definition polymesh.hpp:38
int nCells
Definition polymesh.hpp:38
int nPoints() const
Definition polymesh.hpp:48
std::vector< Real > cellVolume
Definition polymesh.hpp:47
std::vector< int > cellFace
Definition polymesh.hpp:46
std::vector< int > owner
Definition polymesh.hpp:42
int nFaces
Definition polymesh.hpp:38
long long M[3]
Definition polymesh.hpp:249
static long long wrapq(long long v, long long m)
Definition polymesh.hpp:258
PeriodicVertexIds(const Real L_[3], Real quantum_, int N)
Definition polymesh.hpp:253
std::unordered_map< VertexKey, int, VertexKeyHash > vmap
Definition polymesh.hpp:248
const Real * L
Definition polymesh.hpp:251
Real quantum
Definition polymesh.hpp:250
int operator()(PolyMesh< Real > &m, Real x, Real y, Real z)
The id of the vertex at (x, y, z), appended to m.points if it is new.
Definition polymesh.hpp:263
The faces of a PolyMesh as they are emitted cell by cell, before the interior-first order.
Definition polymesh.hpp:280
std::vector< std::vector< int > > cellFaces
Definition polymesh.hpp:281
std::vector< int > verts
Definition polymesh.hpp:282
std::vector< int > nbr
Definition polymesh.hpp:282
std::vector< int > patch
Definition polymesh.hpp:282
PolyFaceList(int N)
Definition polymesh.hpp:283
std::vector< int > off
Definition polymesh.hpp:282
std::vector< int > owner
Definition polymesh.hpp:282
Definition polymesh.hpp:56
std::size_t operator()(const VertexKey &k) const
Definition polymesh.hpp:57
Definition polymesh.hpp:52
bool operator==(const VertexKey &o) const
Definition polymesh.hpp:54
long long b
Definition polymesh.hpp:53
long long a
Definition polymesh.hpp:53
long long c
Definition polymesh.hpp:53