From 62a287bfd88e32a3a237f7d405411f3419a3cce1 Mon Sep 17 00:00:00 2001 From: tomc271 Date: Mon, 6 Nov 2023 15:41:32 +0000 Subject: [PATCH] Make MetricTensor abstract (by making calcCovariant() and calcContravariant() implementations of CalculateOppositeRepresentation()). --- include/bout/contravariantMetricTensor.hxx | 6 ++++-- include/bout/covariantMetricTensor.hxx | 6 ++++-- include/bout/metricTensor.hxx | 5 ++++- src/mesh/contravariantMetricTensor.cxx | 7 +++---- src/mesh/coordinates.cxx | 16 ++++++++++------ src/mesh/covariantMetricTensor.cxx | 6 +++--- tools/pylib/_boutpp_build/boutcpp.pxd.jinja | 4 ++-- 7 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/bout/contravariantMetricTensor.hxx b/include/bout/contravariantMetricTensor.hxx index 4c9225a6b5..de04927ce1 100644 --- a/include/bout/contravariantMetricTensor.hxx +++ b/include/bout/contravariantMetricTensor.hxx @@ -14,9 +14,11 @@ public: ContravariantMetricTensor(const BoutReal g11, const BoutReal g22, const BoutReal g33, const BoutReal g12, const BoutReal g13, const BoutReal g23, Mesh* mesh); + /// Invert covariant metric to get contravariant components - void calcContravariant(CovariantMetricTensor covariantMetricTensor, CELL_LOC location, - const std::string& region = "RGN_ALL"); + void CalculateOppositeRepresentation(MetricTensor& covariantMetricTensor, + CELL_LOC location, + const std::string& region = "RGN_ALL") override; }; #endif //BOUT_CONTRAVARIANTMETRICTENSOR_HXX diff --git a/include/bout/covariantMetricTensor.hxx b/include/bout/covariantMetricTensor.hxx index 25d80cc01f..30c0f178cd 100644 --- a/include/bout/covariantMetricTensor.hxx +++ b/include/bout/covariantMetricTensor.hxx @@ -14,9 +14,11 @@ public: CovariantMetricTensor(const BoutReal g_11, const BoutReal g_22, const BoutReal g_33, const BoutReal g_12, const BoutReal g_13, const BoutReal g_23, Mesh* mesh); + /// Invert contravariant metric to get covariant components - void calcCovariant(ContravariantMetricTensor contravariantMetricTensor, - CELL_LOC location, const std::string& region = "RGN_ALL"); + void CalculateOppositeRepresentation(MetricTensor& contravariantMetricTensor, + const CELL_LOC location, + const std::string& region = "RGN_ALL") override; }; #endif //BOUT_COVARIANTMETRICTENSOR_HXX diff --git a/include/bout/metricTensor.hxx b/include/bout/metricTensor.hxx index 96e3bda7e0..17db1af321 100644 --- a/include/bout/metricTensor.hxx +++ b/include/bout/metricTensor.hxx @@ -17,7 +17,6 @@ public: using FieldMetric = Field2D; #endif - MetricTensor(); MetricTensor(const FieldMetric& g11, const FieldMetric& g22, const FieldMetric& g33, const FieldMetric& g12, const FieldMetric& g13, const FieldMetric& g23); @@ -40,6 +39,10 @@ public: void setLocation(const CELL_LOC location); + virtual void CalculateOppositeRepresentation(MetricTensor& covariantMetricTensor, + CELL_LOC location, + const std::string& region) = 0; + protected: FieldMetric g11, g22, g33, g12, g13, g23; }; diff --git a/src/mesh/contravariantMetricTensor.cxx b/src/mesh/contravariantMetricTensor.cxx index 1481151e66..5a1bb6035a 100644 --- a/src/mesh/contravariantMetricTensor.cxx +++ b/src/mesh/contravariantMetricTensor.cxx @@ -13,11 +13,10 @@ ContravariantMetricTensor::ContravariantMetricTensor( const BoutReal g13, const BoutReal g23, Mesh* mesh) : MetricTensor::MetricTensor(g11, g22, g33, g12, g13, g23, mesh) {} -void ContravariantMetricTensor::calcContravariant( - CovariantMetricTensor covariantMetricTensor, CELL_LOC location, - const std::string& region) { +void ContravariantMetricTensor::CalculateOppositeRepresentation( + MetricTensor& covariantMetricTensor, CELL_LOC location, const std::string& region) { - TRACE("ContravariantMetricTensor::calcContravariant"); + TRACE("ContravariantMetricTensor::CalculateOppositeRepresentation"); // Perform inversion of g{ij} to get g^{ij} // NOTE: Currently this bit assumes that metric terms are Field2D objects diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 9811467dbf..d700481001 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -1386,14 +1386,16 @@ void Coordinates::CalculateChristoffelSymbols() { } CovariantMetricTensor Coordinates::calcCovariant(const std::string& region) { - TRACE("Coordinates::calcCovariant"); - covariantMetricTensor.calcCovariant(contravariantMetricTensor, location, region); + TRACE("Coordinates::CalculateOppositeRepresentation"); + covariantMetricTensor.CalculateOppositeRepresentation(contravariantMetricTensor, + location, region); return covariantMetricTensor; } ContravariantMetricTensor Coordinates::calcContravariant(const std::string& region) { - TRACE("Coordinates::calcContravariant"); - contravariantMetricTensor.calcContravariant(covariantMetricTensor, location, region); + TRACE("Coordinates::CalculateOppositeRepresentation"); + contravariantMetricTensor.CalculateOppositeRepresentation(covariantMetricTensor, + location, region); return contravariantMetricTensor; } @@ -2013,7 +2015,8 @@ void Coordinates::checkContravariant() { void Coordinates::setMetricTensor(ContravariantMetricTensor metric_tensor, const std::string& region) { contravariantMetricTensor.setMetricTensor(metric_tensor); - covariantMetricTensor.calcCovariant(contravariantMetricTensor, location, region); + covariantMetricTensor.CalculateOppositeRepresentation(contravariantMetricTensor, + location, region); } const CovariantMetricTensor::FieldMetric& Coordinates::g_11() const { @@ -2056,5 +2059,6 @@ const ContravariantMetricTensor::FieldMetric& Coordinates::g23() const { void Coordinates::setMetricTensor(CovariantMetricTensor metric_tensor) { covariantMetricTensor.setMetricTensor(metric_tensor); - contravariantMetricTensor.calcContravariant(covariantMetricTensor, location); + contravariantMetricTensor.CalculateOppositeRepresentation(covariantMetricTensor, + location); } \ No newline at end of file diff --git a/src/mesh/covariantMetricTensor.cxx b/src/mesh/covariantMetricTensor.cxx index 4064af07df..f7aa40cb25 100644 --- a/src/mesh/covariantMetricTensor.cxx +++ b/src/mesh/covariantMetricTensor.cxx @@ -15,10 +15,10 @@ CovariantMetricTensor::CovariantMetricTensor(const BoutReal g_11, const BoutReal Mesh* mesh) : MetricTensor::MetricTensor(g_11, g_22, g_33, g_12, g_13, g_23, mesh) {} -void CovariantMetricTensor::calcCovariant( - ContravariantMetricTensor contravariantMetricTensor, const CELL_LOC location, +void CovariantMetricTensor::CalculateOppositeRepresentation( + MetricTensor& contravariantMetricTensor, const CELL_LOC location, const std::string& region) { - TRACE("CovariantMetricTensor::calcCovariant"); + TRACE("CovariantMetricTensor::CalculateOppositeRepresentation"); // Perform inversion of g^{ij} to get g{ij} // NOTE: Currently this bit assumes that metric terms are Field2D objects diff --git a/tools/pylib/_boutpp_build/boutcpp.pxd.jinja b/tools/pylib/_boutpp_build/boutcpp.pxd.jinja index c94fd14a17..622c6ae8e2 100644 --- a/tools/pylib/_boutpp_build/boutcpp.pxd.jinja +++ b/tools/pylib/_boutpp_build/boutcpp.pxd.jinja @@ -79,8 +79,8 @@ cdef extern from "bout/coordinates.hxx": {{ metric_field }} ShiftTorsion {{ metric_field }} IntShiftTorsion int geometry() - int calcCovariant() - int calcContravariant() + int CalculateOppositeRepresentation() + int CalculateOppositeRepresentation() int jacobian() cdef extern from "bout/fieldgroup.hxx":