chombo-discharge
Loading...
Searching...
No Matches
CD_PolyhedralEBUtils.H File Reference

Declaration of the cell topology and polygon geometry the polyhedral cut cells are built from. More...

#include <BaseFab.H>
#include <BaseIF.H>
#include <Box.H>
#include <IntVect.H>
#include <RealVect.H>
#include <CD_CutCellSurface.H>
#include <CD_NamespaceHeader.H>
#include <CD_NamespaceFooter.H>
#include <CD_PolyhedralEBUtilsImplem.H>
Include dependency graph for CD_PolyhedralEBUtils.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  PolyhedralEB::detail
 Cell topology and polygon geometry the cut cell classes are assembled from.

Functions

bool PolyhedralEB::isFluid (const Real a_value) noexcept
 Which side of the interface a value lies on.
int PolyhedralEB::detail::edgeDirection (const int a_edge) noexcept
 Direction a cell edge runs along.
void PolyhedralEB::detail::edgeOrigin (const int a_edge, int a_offset[SpaceDim]) noexcept
 Corner offsets of a cell edge's low end.
void PolyhedralEB::detail::edgeCorners (const int a_edge, int &a_lo, int &a_hi) noexcept
 The corners a cell edge joins, low end first.
RealVect PolyhedralEB::detail::cornerPosition (const int a_corner) noexcept
 Position of a cell corner in the cell's own frame.
void PolyhedralEB::detail::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.
int PolyhedralEB::detail::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.
RealVect PolyhedralEB::detail::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.
void PolyhedralEB::detail::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.
void PolyhedralEB::detail::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.
int PolyhedralEB::detail::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.
int PolyhedralEB::detail::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.
bool PolyhedralEB::detail::sameVertex (const RealVect &a_a, const RealVect &a_b) noexcept
 Whether two positions are the same vertex.
bool PolyhedralEB::detail::sameToRoundOff (const RealVect &a_a, const RealVect &a_b) noexcept
 Whether two vertices differ only by round-off.
bool PolyhedralEB::detail::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.
RealVect PolyhedralEB::detail::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 way round the segment is given.
bool PolyhedralEB::isDust (const PolyhedralEB::CutCellBody &a_body) noexcept
 Whether a cut body holds nothing at all and is therefore a regular cell.
void PolyhedralEB::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.
void PolyhedralEB::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.
Real PolyhedralEB::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.
void PolyhedralEB::fillCorners (PolyhedralEB::CutCellSurface &a_surface, const BaseFab< Real > &a_nodeValues, const IntVect &a_cell)
 Read one cell's corner values off the node values.
void PolyhedralEB::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.
void PolyhedralEB::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 solid ones meet across it.
Real PolyhedralEB::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.
Real PolyhedralEB::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 read as exactly zero, and a zero that is a tangency read from beside the point instead.
Real PolyhedralEB::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.

Variables

constexpr int PolyhedralEB::detail::s_transverse [3][2] = {{1, 2}, {0, 2}, {0, 1}}
 The two directions transverse to each coordinate direction, in increasing order.
constexpr Real PolyhedralEB::detail::s_weldTolerance = 1.0E-10
 Distance within which two vertices are taken to be the same one.
constexpr Real PolyhedralEB::detail::s_roundOffTolerance = 1.0E-13
 Distance below which two vertices of a body cut from another are one, since they then differ only by the round-off of the arithmetic that placed them. Far below the weld tolerance, so fluid thinner than the weld keeps its vertices, and far below the tolerance to which a cut reproduces its parent's moments.
constexpr Real PolyhedralEB::s_snapTolerance = 1.0E-12
 Fraction of a cell width within which an implicit-function value is read as exactly zero.
constexpr Real PolyhedralEB::s_rootSnap = 1.0E-4
 Distance along an edge, from an endpoint that is exactly zero, within which a root is put on it.
constexpr Real PolyhedralEB::s_probeSpacing = 1.0E-6
 Fraction of a cell width the implicit function is read at either side of a point, to tell a surface through the point from a zero no surface passes through.

Detailed Description

Declaration of the cell topology and polygon geometry the polyhedral cut cells are built from.

Author
Robert Marskar

Function Documentation

◆ buildSurface()

void PolyhedralEB::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.

The corners come from the shared node values and every edge whose ends disagree gets its crossing through the shared cache, so every caller that reconstructs a cell – the graph, the surface pass and the grid builder's curvature test – builds the same cell.

Parameters
[in,out]a_interceptEdge-centred crossing cache
[out]a_surfaceThe values the cell's body is reconstructed from
[in]a_functionImplicit function
[in]a_nodeValuesNode-centred implicit function values
[in]a_cellThe cell
[in]a_probLoLower-left corner of computational domain
[in]a_dxGrid resolution

◆ decideFaces()

void PolyhedralEB::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 solid ones meet across it.

Four alternating corners admit both readings, and the bilinear interpolant of the corners picks the one its saddle falls on, which for a feature thinner than the face is the wrong one: the large values at two corners outweigh the small ones of a thin plate at the other two, and the chords pierce the plate. The implicit function at the centre of the face is read instead, with the value snap of a grid twice as fine, so that it is the very node a finer level holds there. Every cell sharing the face reads the same point. A centre that reads exactly zero falls back to the bilinear saddle. In two dimensions the face is the cell itself.

Parameters
[in,out]a_surfaceSurface whose corners are filled; its face decisions are set.
[in]a_functionImplicit function.
[in]a_cellThe cell.
[in]a_probLoLower-left corner of the domain.
[in]a_dxGrid spacing.

◆ defineIntercepts()

void PolyhedralEB::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.

One fab per direction, over the edges of the region's cells, addressed by the node at the low end of the edge as edgeCrossing addresses them.

Parameters
[out]a_interceptEdge-centred cache, one fab per direction
[in]a_regionCell-centred region whose edges are wanted

◆ edgeCrossing()

Real PolyhedralEB::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.

Bisection between the two endpoints, looked up in a cache first. Every cut edge is reached from both of its adjoining faces and from each neighbouring cell, always with the same endpoints, so the root is found once and reused. That is what makes two cells agree on a shared aperture bit for bit.

Parameters
[in]a_functionImplicit function
[in,out]a_interceptEdge-centred cache, one component per direction
[in]a_cellCell the edge is being read from
[in]a_edgeEdge index within the cell
[in]a_loImplicit function at the edge's low corner
[in]a_hiImplicit function at the edge's high corner
[in]a_probLoLower-left corner of computational domain
[in]a_dxGrid resolution
Returns
Position along the edge, parameterised from its low corner.

◆ edgeRoot()

Real PolyhedralEB::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.

An endpoint at exactly zero is not taken to be the crossing: the function may be zero along a stretch of the edge (a face of the geometry lying in the edge's plane), and the crossing is where it leaves that stretch. The bisection walks through zeros, which the fluid predicate reads as solid, and a root that lands within s_snapTolerance of an endpoint that is exactly zero is put exactly on it.

Parameters
[in]a_functionImplicit function.
[in]a_edgeIVNode at the low end of the edge.
[in]a_dirDirection the edge runs in.
[in]a_loValueImplicit function at the low end.
[in]a_hiValueImplicit function at the high end.
[in]a_probLoLower-left corner of the domain.
[in]a_dxGrid spacing.
Returns
Position along the edge, in [0,1].

◆ fillCorners()

void PolyhedralEB::fillCorners ( PolyhedralEB::CutCellSurface & a_surface,
const BaseFab< Real > & a_nodeValues,
const IntVect & a_cell )

Read one cell's corner values off the node values.

Corner c of the cell is the node offset by ((c >> d) & 1) in each direction d.

Parameters
[out]a_surfaceSurface whose corners are filled. Its crossings are left alone.
[in]a_nodeValuesNode-centred implicit function values
[in]a_cellThe cell

◆ fillNodeValues()

void PolyhedralEB::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.

One evaluation per node rather than per cell corner, since the cells meeting at a node share it and must agree on its value. Values are read through snappedValue.

Parameters
[out]a_nodeValuesNode-centred values over a_region
[in]a_functionImplicit function
[in]a_regionCell-centred region whose nodes are wanted
[in]a_probLoLower-left corner of computational domain
[in]a_dxGrid resolution

◆ isDust()

bool PolyhedralEB::isDust ( const PolyhedralEB::CutCellBody & a_body)
noexcept

Whether a cut body holds nothing at all and is therefore a regular cell.

A node that lands exactly on the interface is solid by rule, so the cells around it classify as cut from their corners while their bodies hold no solid and no interface whatsoever – the reconstruction finds an empty polyhedron. Those cells are regular, and dropping them discards nothing, since there is no surface in them for a neighbour to meet. Emptiness is exact rather than thresholded: a body with any solid in it, however little, keeps its cell, because its interface is what closes the surface against its neighbours, and a rule that discarded it by size would leave a hole the size of what it discarded. A cell whose interface lies in one of its faces has no solid volume either, but it does have boundary area, and it is not dust.

Parameters
[in]a_bodyBody of the cell.
Returns
True if the cell should be treated as regular.

◆ isFluid()

bool PolyhedralEB::isFluid ( const Real a_value)
inlinenoexcept

Which side of the interface a value lies on.

One predicate for corners and crossings alike: negative is fluid, and anything else, an exact zero of either sign included, is solid. GeometryShop reads an exact zero by its sign bit, which a negated distance function turns over, and then rescues the regular cell that leaves beside a covered one by looking at its neighbour. A cell here is classified from its own corners alone, so the zero has to fall on one side by rule: on the solid side, so that a fluid cell whose face lies in the interface is cut with that face as its interface, and the cell on the other side is covered.

Parameters
[in]a_valueImplicit function value.
Returns
True on the fluid side.

◆ resolveTangency()

Real PolyhedralEB::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.

A composite function can be zero over a whole region that is not its surface: a difference of two bodies sharing a face evaluates to the maximum of zero and something negative over the whole of that face. Taken at face value such a zero is material by the fluid rule, and it invents an interface where the geometry has none and displaces the interfaces of whatever else the cell holds. It is told apart from a surface by the function's sign a probe spacing off the point, along each axis in turn. A surface through the point changes the sign across it along any axis the surface is not parallel to, and since a surface has a normal there is always such an axis, so one sign change is enough to leave the zero alone. The zero is read through only on the evidence of an axis whose two readings are both away from zero and of the same sign, which is what a function that touches zero without a surface being there looks like; the largest such reading stands in for the zero. One reading of zero is not evidence of anything – it is the point's own zero again, which is what an axis along a face of the geometry returns, and what both axes along the faces meeting at a convex edge return.

Parameters
[in]a_functionImplicit function.
[in]a_pointPoint the function is zero at.
[in]a_dxGrid spacing that sets the probe spacing.
Returns
The reading beside the point, or exactly zero if a surface passes through it.

◆ snappedValue()

Real PolyhedralEB::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 read as exactly zero, and a zero that is a tangency read from beside the point instead.

A face of the geometry lying in a node plane evaluates to zero there only up to round-off: the same face comes back as plus zero, minus zero and a few parts in 1e19 at neighbouring nodes, and cells on either side of it would then be classified by which of those they were handed. Reading everything within a fixed fraction of the cell width of zero as zero puts every such node on one side by rule, in the corner values and in the bisection alike. A zero that no surface passes through is then read through resolveTangency, so that nothing downstream sees it.

Parameters
[in]a_functionImplicit function.
[in]a_pointPoint to evaluate at.
[in]a_dxGrid spacing that sets the scale.
Returns
The value, or exactly zero.

Variable Documentation

◆ s_probeSpacing

Real PolyhedralEB::s_probeSpacing = 1.0E-6
constexpr

Fraction of a cell width the implicit function is read at either side of a point, to tell a surface through the point from a zero no surface passes through.

Large enough that a function of unit gradient reads well clear of s_snapTolerance beside the point, and small enough that the reading belongs to the point rather than to its neighbourhood.

◆ s_rootSnap

Real PolyhedralEB::s_rootSnap = 1.0E-4
constexpr

Distance along an edge, from an endpoint that is exactly zero, within which a root is put on it.

A surface tangent to a node reads as zero for a stretch either side of it under the value snap, of length about sqrt(2 R tol / dx) for a radius of curvature R – a few parts in 1e6 of an edge for any R that is not itself below the cell width. A root that close to a corner the surface passes through is that stretch's end, not a second crossing; a genuine second crossing within 1e-4 of a cell width of the first would be a feature no cell resolves.