chombo-discharge
Loading...
Searching...
No Matches
CD_PolyhedralEBUtils.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
12
13#ifndef CD_POLYHEDRALEBUTILS_H
14#define CD_POLYHEDRALEBUTILS_H
15
16// Chombo includes
17#include <BaseFab.H>
18#include <BaseIF.H>
19#include <Box.H>
20#include <IntVect.H>
21#include <RealVect.H>
22
23// Our includes
24#include <CD_CutCellSurface.H>
25#include <CD_NamespaceHeader.H>
26
27namespace PolyhedralEB {
28
41inline bool
42isFluid(const Real a_value) noexcept;
43
55namespace detail {
56
57#if CH_SPACEDIM == 3
63constexpr int s_transverse[3][2] = {{1, 2}, {0, 2}, {0, 1}};
64#endif
65
71inline int
72edgeDirection(const int a_edge) noexcept;
73
79inline void
80edgeOrigin(const int a_edge, int a_offset[SpaceDim]) noexcept;
81
88inline void
89edgeCorners(const int a_edge, int& a_lo, int& a_hi) noexcept;
90
96inline RealVect
97cornerPosition(const int a_corner) noexcept;
98
108inline void
109faceCorners(const int a_dir, const int a_side, int a_corner[1 << (SpaceDim - 1)]) noexcept;
110
119inline int
120edgeIndex(const int a_dir, const int a_offset[SpaceDim]) noexcept;
121
135inline RealVect
136crossingPosition(const CutCellSurface& a_surface, const int a_edge, const Real a_tolerance) noexcept;
137
138#if CH_SPACEDIM == 3
145inline void
146faceEdges(const int a_dir, const int a_side, int a_edge[4]) noexcept;
147
163inline void
164polygonMoments(const RealVect* a_vertex,
165 const int a_num,
166 Real& a_area,
167 RealVect& a_vector,
168 RealVect& a_centroid) noexcept;
169
185inline int
186facePairs(const int a_dir, const int a_side, const CutCellSurface& a_surface, int a_pair[2][2]) noexcept;
187
201inline int
202crossingLoops(const CutCellSurface& a_surface,
203 int a_loop[CutCellSurface::s_numEdges],
204 int a_start[CutCellSurface::s_numEdges + 1]) noexcept;
205#endif
214constexpr Real s_weldTolerance = 1.0E-10;
215
222inline bool
223sameVertex(const RealVect& a_a, const RealVect& a_b) noexcept;
224
230constexpr Real s_roundOffTolerance = 1.0E-13;
231
238inline bool
239sameToRoundOff(const RealVect& a_a, const RealVect& a_b) noexcept;
240
250inline bool
251withinInEveryDirection(const RealVect& a_a, const RealVect& a_b, const Real a_margin) noexcept;
252
264inline RealVect
265crossing(const RealVect& a_a, const RealVect& a_b, const int a_dir) noexcept;
266
267} // namespace detail
268
269class CutCellBody;
270
283bool
284isDust(const PolyhedralEB::CutCellBody& a_body) noexcept;
285
296void
297fillNodeValues(BaseFab<Real>& a_nodeValues,
298 const BaseIF& a_function,
299 const Box& a_region,
300 const RealVect& a_probLo,
301 const Real& a_dx);
302
310void
311defineIntercepts(BaseFab<Real> a_intercept[SpaceDim], const Box& a_region);
312
328Real
329edgeCrossing(const BaseIF& a_function,
330 BaseFab<Real> a_intercept[SpaceDim],
331 const IntVect& a_cell,
332 const int a_edge,
333 const Real a_lo,
334 const Real a_hi,
335 const RealVect& a_probLo,
336 const Real& a_dx);
337
345void
346fillCorners(PolyhedralEB::CutCellSurface& a_surface, const BaseFab<Real>& a_nodeValues, const IntVect& a_cell);
347
361void
362buildSurface(BaseFab<Real> a_intercept[SpaceDim],
364 const BaseIF& a_function,
365 const BaseFab<Real>& a_nodeValues,
366 const IntVect& a_cell,
367 const RealVect& a_probLo,
368 const Real& a_dx);
369
385void
387 const BaseIF& a_function,
388 const IntVect& a_cell,
389 const RealVect& a_probLo,
390 const Real a_dx) noexcept;
391
407Real
408edgeRoot(const BaseIF& a_function,
409 const IntVect& a_edgeIV,
410 const int a_dir,
411 const Real a_loValue,
412 const Real a_hiValue,
413 const RealVect& a_probLo,
414 const Real a_dx) noexcept;
415
419constexpr Real s_snapTolerance = 1.0E-12;
420
429constexpr Real s_rootSnap = 1.0E-4;
430
437constexpr Real s_probeSpacing = 1.0E-6;
438
453Real
454snappedValue(const BaseIF& a_function, const RealVect& a_point, const Real a_dx) noexcept;
455
475Real
476resolveTangency(const BaseIF& a_function, const RealVect& a_point, const Real a_dx) noexcept;
477} // namespace PolyhedralEB
478
479#include <CD_NamespaceFooter.H>
480
482
483#endif
Declaration of the data a cut cell's embedded boundary is reconstructed from.
Implementation of CD_PolyhedralEBUtils.H.
constexpr Real s_probeSpacing
Fraction of a cell width the implicit function is read at either side of a point, to tell a surface t...
Definition CD_PolyhedralEBUtils.H:437
constexpr Real s_snapTolerance
Fraction of a cell width within which an implicit-function value is read as exactly zero.
Definition CD_PolyhedralEBUtils.H:419
bool isFluid(const Real a_value) noexcept
Which side of the interface a value lies on.
Definition CD_PolyhedralEBUtilsImplem.H:29
constexpr Real s_rootSnap
Distance along an edge, from an endpoint that is exactly zero, within which a root is put on it.
Definition CD_PolyhedralEBUtils.H:429
void defineIntercepts(BaseFab< Real > a_intercept[SpaceDim], const Box &a_region)
Size the edge-crossing cache for a region and mark every edge as not yet bisected.
Definition CD_PolyhedralEBUtils.cpp:59
bool isDust(const PolyhedralEB::CutCellBody &a_body) noexcept
Whether a cut body holds nothing at all and is therefore a regular cell.
Definition CD_PolyhedralEBUtils.cpp:117
Real snappedValue(const BaseIF &a_function, const RealVect &a_point, const Real a_dx) noexcept
Read the implicit function at a point, with a value within s_snapTolerance of a cell width of zero re...
Definition CD_PolyhedralEBUtils.cpp:125
void fillCorners(PolyhedralEB::CutCellSurface &a_surface, const BaseFab< Real > &a_nodeValues, const IntVect &a_cell)
Read one cell's corner values off the node values.
Definition CD_PolyhedralEBUtils.cpp:256
void fillNodeValues(BaseFab< Real > &a_nodeValues, const BaseIF &a_function, const Box &a_region, const RealVect &a_probLo, const Real &a_dx)
Evaluate the implicit function at every node of a region.
Definition CD_PolyhedralEBUtils.cpp:30
void buildSurface(BaseFab< Real > a_intercept[SpaceDim], PolyhedralEB::CutCellSurface &a_surface, const BaseIF &a_function, const BaseFab< Real > &a_nodeValues, const IntVect &a_cell, const RealVect &a_probLo, const Real &a_dx)
Gather the corner values and edge crossings one cell's surface is built from.
Definition CD_PolyhedralEBUtils.cpp:272
void decideFaces(PolyhedralEB::CutCellSurface &a_surface, const BaseIF &a_function, const IntVect &a_cell, const RealVect &a_probLo, const Real a_dx) noexcept
Decide, for every face of a cell whose corners alternate in sign, whether its fluid corners or its so...
Definition CD_PolyhedralEBUtils.cpp:311
Real edgeCrossing(const BaseIF &a_function, BaseFab< Real > a_intercept[SpaceDim], const IntVect &a_cell, const int a_edge, const Real a_lo, const Real a_hi, const RealVect &a_probLo, const Real &a_dx)
Find where the implicit function changes sign along a cell edge.
Definition CD_PolyhedralEBUtils.cpp:74
Real resolveTangency(const BaseIF &a_function, const RealVect &a_point, const Real a_dx) noexcept
Read the implicit function beside a point where it is zero, when no surface passes through the point.
Definition CD_PolyhedralEBUtils.cpp:139
Real edgeRoot(const BaseIF &a_function, const IntVect &a_edgeIV, const int a_dir, const Real a_loValue, const Real a_hiValue, const RealVect &a_probLo, const Real a_dx) noexcept
Bisect one cell edge for the crossing on it.
Definition CD_PolyhedralEBUtils.cpp:179
The closed polyhedron bounding the fluid in one cut cell, and its moments.
Definition CD_CutCellBody.H:52
The values a cut cell's embedded boundary is reconstructed from.
Definition CD_CutCellSurface.H:41
static constexpr int s_numEdges
Number of cell edges a crossing can sit on.
Definition CD_CutCellSurface.H:46
Cell topology and polygon geometry the cut cell classes are assembled from.
Definition CD_PolyhedralEBUtils.H:55
void edgeOrigin(const int a_edge, int a_offset[SpaceDim]) noexcept
Corner offsets of a cell edge's low end.
Definition CD_PolyhedralEBUtilsImplem.H:45
void polygonMoments(const RealVect *a_vertex, const int a_num, Real &a_area, RealVect &a_vector, RealVect &a_centroid) noexcept
Area vector, area and centroid of a planar polygon given in circuit order.
Definition CD_PolyhedralEBUtilsImplem.H:206
constexpr int s_transverse[3][2]
The two directions transverse to each coordinate direction, in increasing order.
Definition CD_PolyhedralEBUtils.H:63
bool withinInEveryDirection(const RealVect &a_a, const RealVect &a_b, const Real a_margin) noexcept
Whether two positions differ by no more than a margin in any coordinate.
Definition CD_PolyhedralEBUtilsImplem.H:407
void faceEdges(const int a_dir, const int a_side, int a_edge[4]) noexcept
The edges of a cell face, edge i joining face corners i and i+1.
Definition CD_PolyhedralEBUtilsImplem.H:175
int facePairs(const int a_dir, const int a_side, const CutCellSurface &a_surface, int a_pair[2][2]) noexcept
The chords on a cell face, each an unordered pair of edge indices.
Definition CD_PolyhedralEBUtilsImplem.H:253
bool sameVertex(const RealVect &a_a, const RealVect &a_b) noexcept
Whether two positions are the same vertex.
Definition CD_PolyhedralEBUtilsImplem.H:421
RealVect cornerPosition(const int a_corner) noexcept
Position of a cell corner in the cell's own frame.
Definition CD_PolyhedralEBUtilsImplem.H:86
constexpr Real s_weldTolerance
Distance within which two vertices are taken to be the same one.
Definition CD_PolyhedralEBUtils.H:214
int edgeDirection(const int a_edge) noexcept
Direction a cell edge runs along.
Definition CD_PolyhedralEBUtilsImplem.H:37
void edgeCorners(const int a_edge, int &a_lo, int &a_hi) noexcept
The corners a cell edge joins, low end first.
Definition CD_PolyhedralEBUtilsImplem.H:67
RealVect crossing(const RealVect &a_a, const RealVect &a_b, const int a_dir) noexcept
Where the segment between two vertices crosses the plane x[a_dir] = 0, the same to the bit whichever ...
Definition CD_PolyhedralEBUtilsImplem.H:434
bool sameToRoundOff(const RealVect &a_a, const RealVect &a_b) noexcept
Whether two vertices differ only by round-off.
Definition CD_PolyhedralEBUtilsImplem.H:427
void faceCorners(const int a_dir, const int a_side, int a_corner[1<<(SpaceDim - 1)]) noexcept
The corners of a cell face, in circuit order around the face.
Definition CD_PolyhedralEBUtilsImplem.H:100
constexpr Real s_roundOffTolerance
Distance below which two vertices of a body cut from another are one, since they then differ only by ...
Definition CD_PolyhedralEBUtils.H:230
int edgeIndex(const int a_dir, const int a_offset[SpaceDim]) noexcept
Index of the edge running along a_dir whose low corner has the given offsets.
Definition CD_PolyhedralEBUtilsImplem.H:124
RealVect crossingPosition(const CutCellSurface &a_surface, const int a_edge, const Real a_tolerance) noexcept
Position of an edge crossing in the cell's own frame.
Definition CD_PolyhedralEBUtilsImplem.H:140
int crossingLoops(const CutCellSurface &a_surface, int a_loop[CutCellSurface::s_numEdges], int a_start[CutCellSurface::s_numEdges+1]) noexcept
Order the crossings into closed loops, or fail if they do not form clean cycles.
Definition CD_PolyhedralEBUtilsImplem.H:309