PhysTraceExtractOp interpolates a volume field, given at the quadrature points of every
element, onto the quadrature points of the element’s traces:
| (28.1) |
where hp are the cardinal functions of the volume quadrature grid, hp(ξq) = δpq. On a trace at
ξa = ±1 the tensor product factorises into an interpolation in the normal direction with
hpa(±1), which collapses the volume array onto the plane of the trace, followed by a tangential
interpolation of that plane onto the trace quadrature points. The operator is a pure
interpolation: no quadrature weights and no Jacobian enter it. It is the adjoint, in the cardinal
basis, of IProductWRTPhysTraceOp.
The operator follows the standard element-operator layout: the interface
PhysTraceExtractOp.hpp, the whole-field implementation PhysTraceExtractOpImpl.hpp,
the per-block interface PhysTraceExtractBlockOp.hpp, and the per-block
implementations PhysTraceExtractSerialAVXSumFac.hpp (Serial and AVX) and
PhysTraceExtractDeviceSumFac.hpp (Device), with their kernels. Its input is a volume field
laid out by MultiRegions::GetBlockAttributes(); its output is a packed trace field laid out
by MultiRegions::GetLocTraceBlockAttributes(), in which every element carries
every point of every one of its traces. Apply() fills the whole packed record, and
ExtractTrace(traceid, in, out, outOffset) extracts one local trace of every element into
a given offset of it. An overload taking two blocks and the index blk of a block of the
operator’s expansion list, ExtractTrace(traceid, inblock, outblock, outOffset,
blk), does the same for that block alone, for a caller holding blocks rather than
fields.
SetIsCollocated() overwrites the collocation flags of every block. The implementations set
one flag per pair of normal and tangential directions where the trace points coincide with the
volume points, and take a straight copy there instead of the tangential interpolation. Clearing
the flags forces the general interpolation, which the unit tests use to reach that code
path.
By default the operator extracts onto each element’s own trace quadrature. On a collapsed direction of a triangle, tetrahedron, prism or pyramid the volume quadrature is of Gauss–Radau type, with no point at the collapsed end, and on the faces of tetrahedra, prisms and pyramids so are the trace points the element reports for it. (A triangle already reports a Gauss–Lobatto distribution, with the extra point, for its edges.) The trace and boundary expansions of a continuous field instead carry the Gauss–Lobatto variant, with one point more in that direction. Extracting a volume field directly onto the points of a continuous boundary therefore needs that variant, which
1op->SetUseGLLTracePoints(true);
selects. The choice is held by PhysTraceExtractBlockOp and applied by each implementation
through the hook v_SetUseGLLTracePoints(), which rebuilds the interpolation tables, the
point counts, the collocation flags and, on Serial and AVX, the workspaces against
GetTraceBasisKey(traceid, dir, true). It is a choice of table, not an additional stage: the
values land directly on the Gauss–Lobatto points. A discontinuous field’s trace keeps the
element’s own points, and asking for the variant there would interpolate onto points the
destination does not have. On an element without a collapsed direction, such as a hexahedron,
both choices give the same points.
The number of trace points changes with the choice, so the output storage must be sized with the same one: the last argument of
1MultiRegions::GetLocTraceBlockAttributes<TData, FieldState::Phys>( 2 expList, interleaveWidth, useGLLTracePoints);
must agree with the argument given to the operator. The collocation flags are worked out
again for the new points and replace any set by SetIsCollocated(). The Gauss–Lobatto
choice is therefore made first, and SetIsCollocated(), if needed, afterwards.
TestPhysTraceExtract extracts onto the Gauss–Lobatto trace points of tetrahedra, prisms
and pyramids, of uniform and of variable order, and checks that a hexahedron is
unaffected.
The class template PhysTraceExtractBndCond<ExecSpace, TData>, in the namespace
MultiRegions::detail, extracts a volume field onto the physical points of a named boundary
region of a continuous field, for the boundary conditions that need volume data on their
points. It applies no condition itself, so it is not a factory-registered boundary-condition
operator: it is a header-only helper in BndCondOps/Common, beside the continuous Galerkin
coefficient-map builder, defined in PhysTraceExtractBndCond.hpp. ExtractTrace() extracts
one local trace of every element of a block, whereas a boundary region touches a subset of the
elements, through different local traces and orientations. The helper bridges the two:
1PhysTraceExtractBndCond( 2 const MultiRegions::ExpListSharedPtr &volumeExpList, 3 const std::vector<std::string> &components, 4 const MultiRegions::ExpListSharedPtr &bcExpList, 5 const std::string &execStr = "", 6 const SpatialDomains::MeshGraphSharedPtr &graph = nullptr); 7 8void Apply(LibUtilities::Field<TData, FieldState::Phys> &in, 9 LibUtilities::Field<TData, FieldState::Phys> &out);
The input in is laid out as GetBlockAttributes(volumeExpList) and the output out as
GetBlockAttributes(bcExpList). Homogeneous fields are not supported.
All the bookkeeping is done in the constructor:
Geometry-id matching. Every trace of every volume element is recorded under its trace geometry id, with the block, element and local trace of its owner. Every element of the boundary expansion list is then looked up by its own geometry id: both lists come from one mesh graph, so the boundary element is the trace of the volume element owning it. A boundary element with no owner among the volume elements is skipped.
Bucketing. The matched elements are sorted into buckets keyed by the shape of the owner, its local trace, its number of modes in each direction, the boundary block and the volume block. Within a bucket every element extracts the same trace with the same tables and scatters into the same boundary block.
Restricted expansion lists. For every bucket a volume expansion list is
built from the expansion information of its elements only, taken from the mesh
graph of volumeExpList or from the graph argument, which is needed when
volumeExpList was built from an ExpansionInfoMap and has no graph. The
restricted list must form a single block, and it orders its elements by geometry id.
Every bucket has its own PhysTraceExtractOp on this list, and its own volume and
trace storage, each a single BlockAccessor belonging to no field, which Apply()
sets to the interleave width of the volume block; the trace block is padded to the
largest vector width, as the input block of ExtractTrace() is.
Trace points. The boundary element carries Gauss–Lobatto points in every
direction. Where the owner’s own trace points differ in number from the boundary
element’s, on a collapsed direction, the bucket’s operator is switched to the
Gauss–Lobatto variant with SetUseGLLTracePoints(true) (section 28.4.1). The
shape, order and trace of the bucket key fix this choice for the whole bucket.
Reorientation map. The extracted points are then the boundary element’s
points, and only their order differs. For a face the map from extracted to boundary
points is the backward map of ReOrientTracePhysMap() (Forwards = false) for
the trace orientation of the owner, which transposes, flips or rotates the face. The
forward map is its inverse and differs from it for a face rotated by 90 degrees
and for a transposed face with a different number of points in each direction. An
edge is reversed when its orientation is eBackwards. Combined with the position
of each element in the boundary block, this gives the boundary point of every
extracted point, kept on the host. The gather and scatter indices depend on the
interleave width of the volume block, which the bucket’s storage takes and which
is known only when Apply() is called, so Apply() builds them on the host for each
width the first time it sees it, and keeps them, so that no index a kernel may still
read is overwritten. Both run over the element groups of the bucket’s storage in
its own order, the element lane varying fastest, so that consecutive threads touch
consecutive points of the storage and, where the bucket’s elements are neighbours
in the volume block, of the volume block too. The gather index holds, for every
point of the volume storage, its position in the volume block; a padding lane of the
last group reads the first element of its group. The scatter indices hold, for every
extracted point but those of padding lanes, its position in the trace storage and
in the boundary block. No kernel divides an index. The volume field itself is not
reshaped: it is usually far larger than the elements gathered from it.
For every bucket Apply()
gathers its elements from their block of the volume field into the bucket’s volume
storage through the gather index, with CGBndCondGatherKernel;
extracts their trace with the block-level ExtractTrace(traceId, volume,
trace, 0, 0), on the restricted list’s only block, which reshapes only where its
own interleave width differs from that of the volume block;
scatters the trace values onto the boundary field through the scatter indices, with
CGBndCondGatherScatterKernel. Every extracted value has its own destination,
so no atomic operation is needed.
All the work runs on a single stream: the stream of the first block of the PhysTraceExtractOp
of every bucket. Apply() does not synchronise the host. It records an event on the stream of
every volume and boundary block it reads or writes, block b running on stream b + 1, and
makes its own stream wait on those events; once its work is queued, it records an event on
its own stream and makes each of those block streams wait on it. Work queued
on a block stream before Apply() therefore runs before the extraction, and work
queued after it runs after, without the host waiting on either. Serial and AVX have no
streams.
The helper is header-only and lives in MultiRegions::detail: it is not a factory-registered
operator, and it is instantiated for a given execution space by the operator code that uses it.
Its gather and scatter kernels are parallel_for loops over NEKTAR_LAMBDA, so a Device
instantiation compiles only in a translation unit built for the device, such as a device operator
implementation.
TestPhysTraceExtractBndCond therefore runs on Serial and AVX. It seeds the volume field
with u = x + 2y + 3z, which is exact at every order, extracts it onto a boundary region and
compares the result with the same polynomial evaluated at the region’s own coordinates. The
cases cover
a single face of hexahedra, and all six faces of a cube of hexahedra of anisotropic order in one region, which exercises several buckets and face orientations at once;
the boundary of a mesh of hexahedra with a different number of points in each direction, whose faces take seven of the eight orientations, including both rotations by 90 degrees;
faces on a collapsed direction, extracted onto the Gauss–Lobatto trace points, on tetrahedra of variable order and on prisms of uniform and variable order;
edges of a two-dimensional mesh of triangles and quadrilaterals;
a region whose faces come from both tetrahedra and prisms, also with the volume field at the largest vector width and then again at width 1, so that the gather index is built for both;
two-dimensional meshes embedded in three-dimensional space, of triangles and of quadrilaterals on a warped surface.