From 96b27ee9c648a92022eae0aa934c1f2a5491aa04 Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 8 Jul 2026 14:12:40 +0200 Subject: [PATCH 1/2] Add API to normalise metric for FCI --- include/bout/coordinates.hxx | 7 +++++-- src/mesh/coordinates.cxx | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/bout/coordinates.hxx b/include/bout/coordinates.hxx index 2c33701762..da9338ce33 100644 --- a/include/bout/coordinates.hxx +++ b/include/bout/coordinates.hxx @@ -103,11 +103,14 @@ public: /// Covariant metric tensor FieldMetric g_11, g_22, g_33, g_12, g_13, g_23; + /// Normalise metric for FCI + /// This normalises B by Bnorm and all lengths by rho_0 + void normaliseFCI(BoutReal Bnorm, BoutReal rho_0); + /// get g_22 at the cell faces; const FieldMetric& g_22_ylow() const; const FieldMetric& g_22_yhigh() const; - FieldMetric& g_22_ylow(); - FieldMetric& g_22_yhigh(); + // Cell Areas const FieldMetric& cell_area_xlow() const { if (_cell_area_xlow.has_value()) { diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 3543995702..7ba0944781 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -1874,3 +1874,30 @@ void Coordinates::_compute_cell_volume() const { std::shared_ptr Coordinates::makeYBoundary(YBndryType type) const { return std::make_shared(type, localoptions, *localmesh); } + +void Coordinates::normaliseFCI(const BoutReal Bnorm, const BoutReal rho_0) { + g11 *= SQ(rho_s0); + g22 *= SQ(rho_s0); + g33 *= SQ(rho_s0); + g12 *= SQ(rho_s0); + g13 *= SQ(rho_s0); + g23 *= SQ(rho_s0); + + J /= rho_s0 * rho_s0 * rho_s0; + + g_11 /= SQ(rho_s0); + g_22 /= SQ(rho_s0); + g_33 /= SQ(rho_s0); + g_12 /= SQ(rho_s0); + g_13 /= SQ(rho_s0); + g_23 /= SQ(rho_s0); + + Bxy /= Bnorm; + + geometry(); // Calculate other metrics + + g_22_ylow(); + g_22_yhigh(); + (*_g_22_ylow) /= SQ(rho_s0); + (*_g_22_yhigh) /= SQ(rho_s0); +} From 6a9fb42d9404ede2816e81876bf2a15da4ed3df3 Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 8 Jul 2026 14:15:58 +0200 Subject: [PATCH 2/2] Allow using for non-FCI code --- src/mesh/coordinates.cxx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 7ba0944781..0111a986fa 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -1896,8 +1896,10 @@ void Coordinates::normaliseFCI(const BoutReal Bnorm, const BoutReal rho_0) { geometry(); // Calculate other metrics - g_22_ylow(); - g_22_yhigh(); - (*_g_22_ylow) /= SQ(rho_s0); - (*_g_22_yhigh) /= SQ(rho_s0); + if (Bxy.isFci()) { + g_22_ylow(); + g_22_yhigh(); + (*_g_22_ylow) /= SQ(rho_s0); + (*_g_22_yhigh) /= SQ(rho_s0); + } }