Skip to content

Commit

Permalink
Make MetricTensor abstract (by making calcCovariant() and calcContrav…
Browse files Browse the repository at this point in the history
…ariant() implementations of CalculateOppositeRepresentation()).
  • Loading branch information
tomchapman committed Nov 6, 2023
1 parent 6f67ca2 commit 62a287b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
6 changes: 4 additions & 2 deletions include/bout/contravariantMetricTensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions include/bout/covariantMetricTensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion include/bout/metricTensor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
};
Expand Down
7 changes: 3 additions & 4 deletions src/mesh/contravariantMetricTensor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions src/mesh/coordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
6 changes: 3 additions & 3 deletions src/mesh/covariantMetricTensor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/pylib/_boutpp_build/boutcpp.pxd.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit 62a287b

Please sign in to comment.