1 #ifndef ERF_GRID_UTILS_H_
2 #define ERF_GRID_UTILS_H_
10 #include <AMReX_GpuQualifiers.H>
11 #include <AMReX_Math.H>
12 #include <AMReX_REAL.H>
13 #include <AMReX_Vector.H>
27 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
34 if (lhs_abs > scale) scale = lhs_abs;
35 if (rhs_abs > scale) scale = rhs_abs;
46 return (real_ulp > float_ulp) ? real_ulp : float_ulp;
58 const std::string& axis_name,
59 const std::string& field_description,
63 if (expected_size < 2) {
64 return field_description +
" requires at least two " + axis_name +
65 " coordinates for bilinear interpolation";
67 if (coordinates.size() !=
static_cast<amrex::Long
>(expected_size)) {
68 return field_description +
" has " + axis_name +
" coordinate length " +
69 std::to_string(coordinates.size()) +
", expected " +
70 std::to_string(expected_size);
73 origin = coordinates.front();
84 spacing = (coordinates[expected_size-1] - coordinates.front()) /
86 if (!std::isfinite(origin) || !std::isfinite(spacing) || spacing <=
amrex::Real(0.0)) {
87 return field_description +
" must have finite, strictly increasing " +
88 axis_name +
" coordinates with nonzero spacing";
91 for (
int index = 1; index < expected_size; ++index) {
93 if (!std::isfinite(coordinate) || coordinate <= coordinates[index-1]) {
94 return field_description +
" must have finite, strictly increasing " +
95 axis_name +
" coordinates";
114 const amrex::Real local_spacing = coordinate - coordinates[index-1];
118 if (std::abs(local_spacing - spacing) > spacing_tolerance) {
119 return field_description +
" has nonuniform " + axis_name +
120 " coordinates, which are not supported";
130 const std::string& reference_description,
131 const std::string& candidate_description)
133 if (candidate.
nx != reference.
nx || candidate.
ny != reference.
ny) {
134 return candidate_description +
" dimensions (" + std::to_string(candidate.
nx) +
135 " x " + std::to_string(candidate.
ny) +
") do not match " +
136 reference_description +
" dimensions (" + std::to_string(reference.
nx) +
137 " x " + std::to_string(reference.
ny) +
")";
140 struct MetadataValue {
145 const MetadataValue values[] = {
146 {
"x spacing", reference.
dx, candidate.
dx},
147 {
"y spacing", reference.
dy, candidate.
dy},
148 {
"x origin", reference.
xmin, candidate.
xmin},
149 {
"y origin", reference.
ymin, candidate.
ymin}
151 for (
const auto& value : values) {
152 if (!
nearly_equal(value.reference_value, value.candidate_value)) {
153 std::ostringstream message;
154 message << candidate_description <<
" " << value.name <<
" ("
155 << value.candidate_value <<
") does not match "
156 << reference_description <<
" (" << value.reference_value <<
")";
157 return message.str();
171 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
176 int point_count) noexcept
179 if (point_count < 2 || spacing <=
amrex::Real(0.0)) {
187 if (coordinate < origin - lower_tolerance || coordinate > upper + upper_tolerance) {
192 (coordinate <= origin + lower_tolerance) ? origin :
193 ((coordinate >= upper - upper_tolerance) ? upper : coordinate);
194 const amrex::Real fractional_index = (bounded_coordinate - origin) / spacing;
195 int lower =
static_cast<int>(amrex::Math::floor(fractional_index));
196 lower = (lower < point_count - 1) ? lower : point_count - 2;
202 stencil.
lower = lower;
std::string name
Definition: ERF_Plotfile2DCatalog.cpp:101
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_GridUtils.H:15
std::string validate_uniform_axis(const amrex::Vector< amrex::Real > &coordinates, int expected_size, const std::string &axis_name, const std::string &field_description, amrex::Real &origin, amrex::Real &spacing)
Definition: ERF_GridUtils.H:56
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE InterpolationStencil uniform_interpolation_stencil(amrex::Real coordinate, amrex::Real origin, amrex::Real spacing, int point_count) noexcept
Definition: ERF_GridUtils.H:173
bool nearly_equal(amrex::Real lhs, amrex::Real rhs)
Definition: ERF_GridUtils.H:50
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real comparison_tolerance(amrex::Real lhs, amrex::Real rhs) noexcept
Definition: ERF_GridUtils.H:29
std::string validate_matching_grid(const UniformGridMetadata &reference, const UniformGridMetadata &candidate, const std::string &reference_description, const std::string &candidate_description)
Definition: ERF_GridUtils.H:128
real(c_double), parameter epsilon
Definition: ERF_module_model_constants.F90:12
Definition: ERF_GridUtils.H:165
int lower
Definition: ERF_GridUtils.H:166
bool inside
Definition: ERF_GridUtils.H:168
amrex::Real weight
Definition: ERF_GridUtils.H:167