1#ifndef APPARENT_HORIZON_FINDER_AHF_DATA_H_
2#define APPARENT_HORIZON_FINDER_AHF_DATA_H_
111 "gammaTilde_xx",
"gammaTilde_xy",
"gammaTilde_xz",
112 "gammaTilde_yy",
"gammaTilde_yz",
"gammaTilde_zz",
113 "ATilde_xx",
"ATilde_xy",
"ATilde_xz",
114 "ATilde_yy",
"ATilde_yz",
"ATilde_zz",
132inline constexpr std::array<CompactField, NumberOfSymmetricTensorComponents>
139inline constexpr std::array<CompactField, NumberOfSymmetricTensorComponents>
175 return std::all_of(components.begin(), components.end(), [](
Index index) {
176 return index != NotStored;
182 for (std::size_t field = 0; field < components.size(); ++field) {
184 throw std::invalid_argument(
185 "SourceVariableMapping: required field "
190 for (std::size_t first = 0; first < components.size(); ++first) {
191 for (std::size_t second = first + 1; second < components.size(); ++second) {
192 if (components[first] == components[second]) {
193 throw std::invalid_argument(
194 "SourceVariableMapping: required fields "
197 + std::to_string(components[first]));
206 for (std::size_t field = 0; field < components.size(); ++field) {
207 if (components[field] >= numberOfSourceComponents) {
208 throw std::invalid_argument(
209 "SourceVariableMapping: required field "
211 + std::to_string(components[field]) +
", but the source tuple has only "
212 + std::to_string(numberOfSourceComponents) +
" components");
217 bool isValid(std::size_t numberOfSourceComponents)
const {
219 for (std::size_t field = 0; field < components.size(); ++field) {
220 if (components[field] >= numberOfSourceComponents) {
223 for (std::size_t previous = 0; previous < field; ++previous) {
224 if (components[field] == components[previous]) {
240 .conformalMetric = {0, 1, 2, 3, 4, 5},
241 .conformalExtrinsicCurvature = {6, 7, 8, 9, 10, 11},
243 .conformalFactor = 24
254 .conformalMetric = {0, 1, 2, 3, 4, 5},
255 .conformalExtrinsicCurvature = {6, 7, 8, 9, 10, 11},
257 .conformalFactor = 54
268 "G[0]",
"G[1]",
"G[2]",
"G[3]",
"G[4]",
"G[5]",
269 "K[0]",
"K[1]",
"K[2]",
"K[3]",
"K[4]",
"K[5]",
278 std::span<const std::string> componentNames
280 std::array<SourceVariableMapping::Index, NumberOfCompactFields> components;
282 for (std::size_t component = 0; component < componentNames.size(); ++component) {
288 components[field] = component;
293 != components.end()) {
315 std::span<const std::string> componentNames
323 const auto expected = named->componentsInCompactOrder();
324 for (std::size_t field = 0; field < given.size(); ++field) {
325 if (given[field] != expected[field]) {
326 const std::string givenComponent = given[field] < componentNames.size()
327 ?
"which the data names " + componentNames[given[field]]
328 : std::string(
"which the data does not have");
329 throw std::invalid_argument(
330 "SourceVariableMapping: required field "
332 + std::to_string(given[field]) +
", " + givenComponent +
", but "
334 + std::to_string(expected[field])
335 +
"; the mapping does not match this data's layout");
346 std::span<const double> sourceTuple,
353 std::array<double, NumberOfCompactFields> compact{};
354 for (std::size_t column = 0; column < compact.size(); ++column) {
355 compact[column] = sourceTuple[sourceComponents[column]];
366 std::span<const double, NumberOfCompactFields> values
369 std::span<const double, NumberOfCompactFields>
row()
const {
385 "conformal extrinsic curvature"
403 return _values[
static_cast<std::size_t
>(field)];
407 std::size_t component,
408 const std::array<CompactField, NumberOfSymmetricTensorComponents>& fields,
409 const char* tensorName
411 if (component >= fields.size()) {
412 throw std::out_of_range(
413 "CompactCellView: " + std::string(tensorName)
414 +
" component index " + std::to_string(component)
415 +
" is outside xx, xy, xz, yy, yz, zz");
420 std::span<const double, NumberOfCompactFields>
_values;
450 throw std::logic_error(
451 "GridData::cell: malformed compact data; expected "
453 + std::to_string(
coordinates.size()) +
" cells, but found "
454 + std::to_string(
values.size()));
457 throw std::out_of_range(
458 "GridData::cell: cell index " + std::to_string(cellIndex)
459 +
" is outside " + std::to_string(
coordinates.size()) +
" cells");
463 std::span<const double, NumberOfCompactFields>(
479 return value(coordinate,
static_cast<std::size_t
>(field));
483 return value(coordinate,
static_cast<std::size_t
>(field));
489 throw std::out_of_range(
"GridData variable index is out of range");
492 const auto point = std::find_if(
496 return coordinatesEqual(candidate.x, coordinate.x)
497 && coordinatesEqual(candidate.y, coordinate.y)
498 && coordinatesEqual(candidate.z, coordinate.z);
502 throw std::out_of_range(
"GridData coordinate was not found");
505 const auto pointIndex =
static_cast<std::size_t
>(
point -
coordinates.begin());
510 constexpr double AbsoluteTolerance = 1.0e-12;
511 constexpr double RelativeTolerance = 1.0e-10;
512 return std::abs(first - second)
514 + RelativeTolerance * std::max(std::abs(first), std::abs(second));
519using Tensor3 = std::array<std::array<double, 3>, 3>;
527 std::span<const double, NumberOfSymmetricTensorComponents> components
530 {{components[0], components[1], components[2]}},
531 {{components[1], components[3], components[4]}},
532 {{components[2], components[4], components[5]}}
540 if (!std::isfinite(phi)) {
541 throw std::invalid_argument(
542 "Geometry conversion: direct phi must be finite");
545 throw std::invalid_argument(
546 "Geometry conversion: direct phi must be strictly positive");
549 throw std::invalid_argument(
550 "Geometry conversion: direct phi is below the safe division threshold 1e-2");
557 const double inversePhiSquared = 1.0 / (phi * phi);
560 for (std::size_t i = 0; i < 3; ++i) {
561 for (std::size_t j = i; j < 3; ++j) {
562 gamma[i][j] = gammaTilde[i][j] * inversePhiSquared;
563 gamma[j][i] = gamma[i][j];
579 const double inversePhiSquared = 1.0 / (phi * phi);
582 for (std::size_t i = 0; i < 3; ++i) {
583 for (std::size_t j = i; j < 3; ++j) {
584 extrinsicCurvature[i][j] =
585 (ATilde[i][j] + traceK * gammaTilde[i][j] / 3.0) * inversePhiSquared;
586 extrinsicCurvature[j][i] = extrinsicCurvature[i][j];
589 return extrinsicCurvature;
604 const double inversePhiSquared = 1.0 / (phi * phi);
605 const double inversePhiCubed = inversePhiSquared / phi;
608 for (std::size_t k = 0; k < 3; ++k) {
609 for (std::size_t i = 0; i < 3; ++i) {
610 for (std::size_t j = i; j < 3; ++j) {
611 gammaDerivative[k][i][j] =
612 gammaTildeDerivative[k][i][j] * inversePhiSquared
613 - 2.0 * gammaTilde[i][j] * phiDerivative[k] * inversePhiCubed;
614 gammaDerivative[k][j][i] = gammaDerivative[k][i][j];
618 return gammaDerivative;
659 std::vector<InterpolatedShellPoint>
points;
680 if (!std::isfinite(
point.r) || !std::isfinite(
point.rho)
691 const auto point = std::find_if(
695 return coordinatesEqual(candidate.r, coordinate.r)
696 && coordinatesEqual(candidate.rho, coordinate.rho)
697 && coordinatesEqual(candidate.sigma, coordinate.sigma);
701 throw std::out_of_range(
"InterpolatedShell coordinate was not found");
707 const auto point = std::find_if(
711 return coordinatesEqual(candidate.r, coordinate.r)
712 && coordinatesEqual(candidate.rho, coordinate.rho)
713 && coordinatesEqual(candidate.sigma, coordinate.sigma);
717 throw std::out_of_range(
"InterpolatedShell coordinate was not found");
723 constexpr double AbsoluteTolerance = 1.0e-12;
724 constexpr double RelativeTolerance = 1.0e-10;
725 return std::abs(first - second)
727 + RelativeTolerance * std::max(std::abs(first), std::abs(second));
751 std::vector<InterpolatedSurfacePoint>
points;
771 if (!std::isfinite(
point.r) || !std::isfinite(
point.rho)
772 || !std::isfinite(
point.sigma) ||
point.r < 0.0) {
784 for (std::size_t i = 0; i <
points.size(); ++i) {
796 const auto point = std::find_if(
800 return coordinatesEqual(candidate.r, coordinate.r)
801 && coordinatesEqual(candidate.rho, coordinate.rho)
802 && coordinatesEqual(candidate.sigma, coordinate.sigma);
806 throw std::out_of_range(
"InterpolatedSurface coordinate was not found");
812 const auto point = std::find_if(
816 return coordinatesEqual(candidate.r, coordinate.r)
817 && coordinatesEqual(candidate.rho, coordinate.rho)
818 && coordinatesEqual(candidate.sigma, coordinate.sigma);
822 throw std::out_of_range(
"InterpolatedSurface coordinate was not found");
828 constexpr double AbsoluteTolerance = 1.0e-12;
829 constexpr double RelativeTolerance = 1.0e-10;
830 return std::abs(first - second)
832 + RelativeTolerance * std::max(std::abs(first), std::abs(second));
Read-only, zero-copy view of one fixed-layout compact cell row.
std::span< const double, NumberOfCompactFields > _values
double conformalMetricComponent(SymmetricTensorComponent component) const
double conformalExtrinsicCurvatureComponent(std::size_t component) const
double compactValue(CompactField field) const
CompactCellView(std::span< const double, NumberOfCompactFields > values)
double conformalMetricComponent(std::size_t component) const
double tensorComponent(std::size_t component, const std::array< CompactField, NumberOfSymmetricTensorComponents > &fields, const char *tensorName) const
std::span< const double, NumberOfCompactFields > row() const
double conformalExtrinsicCurvatureComponent(SymmetricTensorComponent component) const
std::array< Tensor3, 3 > Tensor3Derivative
constexpr std::size_t NumberOfCompactFields
@ RadiusWeightedPolynomial
All cells inside supportRadius, using compact Wendland-C2 weights.
@ UnweightedDegree1
Backward-compatible names retained for callers of the original degree-1 API.
constexpr std::array< CompactField, NumberOfSymmetricTensorComponents > ConformalMetricCompactFields
std::optional< SourceVariableMapping > SourceVariableMappingFromComponentNames(std::span< const std::string > componentNames)
Build the mapping from the component names of a source tuple.
SourceVariableMapping ExaGRyPESourceMapping()
Mapping for output of the exagrype.api solvers, in the order of FOCCZ4Solver.Unknowns (src/exagrype/a...
std::array< double, 3 > Vector3
Tensor3 ComputePhysicalSpatialMetric(const Tensor3 &gammaTilde, double phi)
Compute gamma_ij = gammaTilde_ij / phi^2 for direct (not logarithmic) phi.
constexpr std::size_t NumberOfSymmetricTensorComponents
Tensor3 ComputePhysicalExtrinsicCurvature(const Tensor3 &ATilde, double traceK, const Tensor3 &gammaTilde, double phi)
Compute K_ij = (ATilde_ij + K gammaTilde_ij / 3) / phi^2 using direct phi.
constexpr double MinimumPhysicalPhi
Active kernels use 1e-2 as the safe lower bound for direct phi.
SymmetricTensorComponent
Symmetric-tensor component order used by both compact tensors.
constexpr std::array< CompactField, NumberOfSymmetricTensorComponents > ConformalExtrinsicCurvatureCompactFields
std::array< double, NumberOfCompactFields > CompactSourceTuple(std::span< const double > sourceTuple, const SourceVariableMapping &sourceMapping)
Apply the sole source-index to compact-index transformation.
SourceVariableMapping LegacyCCZ4SourceMapping()
Mapping for output of the legacy applications/exahype2/ccz4/ccz4.py, which stores traceK at 53 and ph...
CompactField
Fixed column layout of every compact row stored in GridData.
void ValidatePhysicalPhi(double phi)
std::array< std::array< double, 3 >, 3 > Tensor3
void ValidateSourceMappingAgainstComponentNames(const SourceVariableMapping &sourceMapping, std::span< const std::string > componentNames)
Reject a mapping that contradicts the component names of the source tuple.
constexpr std::array< const char *, NumberOfCompactFields > CompactFieldNames
Tensor3Derivative ComputePhysicalSpatialMetricDerivative(const Tensor3 &gammaTilde, const Tensor3Derivative &gammaTildeDerivative, double phi, const Vector3 &phiDerivative)
Compute Cartesian physical-metric derivatives in [k][i][j] order: partial_k gamma_ij = partial_k gamm...
Tensor3 UnpackSymmetricTensor(std::span< const double, NumberOfSymmetricTensorComponents > components)
Expand symmetric components ordered xx, xy, xz, yy, yz, zz into a 3x3 tensor.
constexpr std::array< const char *, NumberOfCompactFields > CCZ4SourceComponentNames
Names the CCZ4 solvers give the AHF fields, in CompactField order.
One point on an apparent-horizon guess, expressed in spherical coordinates.
One apparent-horizon hypersurface guess.
std::vector< AHGuessPoint > points
User-provided angular coordinate at which the shell should be sampled.
Cartesian coordinate for one sampled grid point.
Pointwise Cartesian grid data.
const double & value(const GridCoordinate &coordinate, std::size_t variableIndex) const
std::vector< double > values
double & value(const GridCoordinate &coordinate, CompactField field)
void resize(std::size_t numberOfPoints)
static constexpr std::size_t numberOfVariables
const double & value(const GridCoordinate &coordinate, CompactField field) const
std::vector< GridCoordinate > coordinates
bool isConsistent() const
std::size_t valueIndex(const GridCoordinate &coordinate, std::size_t variableIndex) const
static bool coordinatesEqual(double first, double second)
double & value(const GridCoordinate &coordinate, std::size_t variableIndex)
CompactCellView cell(std::size_t cellIndex) const
std::size_t numberOfPoints() const
Physical and geometrical quantities shared by shell and surface samples.
std::array< Tensor3, 2 > coordinateHessian
std::array< Vector3, 2 > coordinateGradient
bool spatialMetricDerivativeAvailable
Tensor3 extrinsicCurvature
Tensor3Derivative spatialMetricDerivative
Interpolated quantities at one spherical shell sample (r, rho, sigma).
InterpolatedGeometryData geometry
Interpolated data on the shell-like subdomain around an AH guess.
std::vector< InterpolatedShellPoint >::iterator findPoint(const AHGuessPoint &coordinate)
bool isConsistent() const
InterpolatedShellPoint & value(const AHGuessPoint &coordinate)
std::size_t numberOfPoints() const
std::vector< InterpolatedShellPoint > points
static bool coordinatesEqual(double first, double second)
const InterpolatedShellPoint & value(const AHGuessPoint &coordinate) const
std::vector< InterpolatedShellPoint >::const_iterator findPoint(const AHGuessPoint &coordinate) const
Interpolated quantities at one point on the current AH surface.
InterpolatedGeometryData geometry
Tensor3 surfaceNormalDerivative
InterpolationDiagnostics interpolationDiagnostics
Interpolated data on the current AH surface r = h(rho, sigma).
std::vector< InterpolatedSurfacePoint >::const_iterator findPoint(const AHGuessPoint &coordinate) const
std::vector< InterpolatedSurfacePoint >::iterator findPoint(const AHGuessPoint &coordinate)
bool matches(const AHGuess &ahGuess) const
static bool coordinatesEqual(double first, double second)
std::vector< InterpolatedSurfacePoint > points
bool isConsistent() const
const InterpolatedSurfacePoint & value(const AHGuessPoint &coordinate) const
std::size_t numberOfPoints() const
InterpolatedSurfacePoint & value(const AHGuessPoint &coordinate)
CartesianToSurfaceMethod requestedMethod
std::size_t neighbourCount
std::size_t requestedDegree
Cartesian reference coordinate for one apparent-horizon centre point.
Reader-side mapping from compact fields to components of a source tuple.
std::array< Index, 6 > conformalExtrinsicCurvature
bool isValid(std::size_t numberOfSourceComponents) const
void validateAgainstSourceTuple(std::size_t numberOfSourceComponents) const
std::array< Index, 6 > conformalMetric
std::array< Index, NumberOfCompactFields > componentsInCompactOrder() const
static constexpr Index NotStored
void validateRequiredFields() const