Skip to content

Commit

Permalink
Add MetricTensor::map() method and use to call interpolateAndExtrapol…
Browse files Browse the repository at this point in the history
…ate() on each component.
  • Loading branch information
tomchapman committed Nov 22, 2023
1 parent 23cd85c commit 2231154
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
3 changes: 3 additions & 0 deletions include/bout/metricTensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public:
MetricTensor oppositeRepresentation(const CELL_LOC location, Mesh* mesh,
const std::string& region = "RGN_ALL");

// Transforms the MetricTensor by applying the given function to every component
void map(const std::function<const Field2D(const FieldMetric)> function);

MetricTensor applyToComponents(
const std::function<const FieldMetric(const FieldMetric)> function) const;

Expand Down
32 changes: 9 additions & 23 deletions src/mesh/coordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -634,30 +634,16 @@ Coordinates::Coordinates(Mesh* mesh, Options* options, const CELL_LOC loc,
}
}

FieldMetric g_11, g_22, g_33, g_12, g_13, g_23;

// More robust to extrapolate derived quantities directly, rather than
// deriving from extrapolated covariant metric components
g_11 =
interpolateAndExtrapolate(covariantMetricTensor.Getg11(), location, extrapolate_x,
extrapolate_y, false, transform.get());
g_22 =
interpolateAndExtrapolate(covariantMetricTensor.Getg22(), location, extrapolate_x,
extrapolate_y, false, transform.get());
g_33 =
interpolateAndExtrapolate(covariantMetricTensor.Getg33(), location, extrapolate_x,
extrapolate_y, false, transform.get());
g_12 =
interpolateAndExtrapolate(covariantMetricTensor.Getg12(), location, extrapolate_x,
extrapolate_y, false, transform.get());
g_13 =
interpolateAndExtrapolate(covariantMetricTensor.Getg13(), location, extrapolate_x,
extrapolate_y, false, transform.get());
g_23 =
interpolateAndExtrapolate(covariantMetricTensor.Getg23(), location, extrapolate_x,
extrapolate_y, false, transform.get());
covariantMetricTensor.setMetricTensor(
MetricTensor(g_11, g_22, g_33, g_12, g_13, g_23));

std::function<const FieldMetric(const FieldMetric)>
interpolateAndExtrapolate_function =
[this, extrapolate_y, extrapolate_x](const FieldMetric component) {
return interpolateAndExtrapolate(component, location, extrapolate_x,
extrapolate_y, false, transform.get());
};
covariantMetricTensor.map(interpolateAndExtrapolate_function);

// Check covariant metrics
checkCovariant();
Expand All @@ -684,7 +670,7 @@ Coordinates::Coordinates(Mesh* mesh, Options* options, const CELL_LOC loc,
communicate(this_J);

// Re-evaluate Bxy using new J
this_Bxy = sqrt(g_22) / this_J;
this_Bxy = sqrt(g_22()) / this_J;
}

// Check jacobian
Expand Down
9 changes: 9 additions & 0 deletions src/mesh/metricTensor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ std::vector<MetricTensor::FieldMetric> MetricTensor::getComponents() const {
return std::vector<FieldMetric>{g11, g22, g33, g12, g13, g23};
}

void MetricTensor::map(
const std::function<const FieldMetric(const FieldMetric)> function) {

const auto components_out = applyToComponents(function);

auto [g_11, g_22, g_33, g_12, g_13, g_23] = components_out;
setMetricTensor(MetricTensor(g_11, g_22, g_33, g_12, g_13, g_23));
}

MetricTensor MetricTensor::applyToComponents(
const std::function<const FieldMetric(const FieldMetric)> function) const {

Expand Down

0 comments on commit 2231154

Please sign in to comment.