From 5fd7d452548dd7f5c5bd6b6f5017144fbf5652e9 Mon Sep 17 00:00:00 2001
From: tomc271 <tomc271@gmail.com>
Date: Wed, 15 Jan 2025 12:56:37 +0000
Subject: [PATCH] Fix "Make TokamakCoordinates a struct rather than a class"

(Need to pass TokamakCoordinates to set_tokamak_coordinates_on_mesh(), now that it is a free function).
---
 examples/6field-simple/elm_6f.cxx                        | 2 +-
 examples/conducting-wall-mode/cwm.cxx                    | 2 +-
 examples/constraints/alfven-wave/alfven.cxx              | 2 +-
 examples/dalf3/dalf3.cxx                                 | 2 +-
 examples/gyro-gem/gem.cxx                                | 2 +-
 examples/laplacexy/alfven-wave/alfven.cxx                | 2 +-
 examples/laplacexy/laplace_perp/test.cxx                 | 2 +-
 include/bout/tokamak_coordinates.hxx                     | 5 +++--
 tests/integrated/test-drift-instability/2fluid.cxx       | 2 +-
 tests/integrated/test-interchange-instability/2fluid.cxx | 2 +-
 10 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/examples/6field-simple/elm_6f.cxx b/examples/6field-simple/elm_6f.cxx
index 2b0722ce38..1b39a9d873 100644
--- a/examples/6field-simple/elm_6f.cxx
+++ b/examples/6field-simple/elm_6f.cxx
@@ -1034,7 +1034,7 @@ class Elm_6f : public PhysicsModel {
     }
 
     /**************** CALCULATE METRICS ******************/
-    set_tokamak_coordinates_on_mesh(noshear, Lbar, Bbar);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, noshear, Lbar, Bbar);
 
     //////////////////////////////////////////////////////////////
     // SHIFTED RADIAL COORDINATES
diff --git a/examples/conducting-wall-mode/cwm.cxx b/examples/conducting-wall-mode/cwm.cxx
index 77b4595818..856efc4363 100644
--- a/examples/conducting-wall-mode/cwm.cxx
+++ b/examples/conducting-wall-mode/cwm.cxx
@@ -132,7 +132,7 @@ class CWM : public PhysicsModel {
     Te0 /= Te_x;
 
     // Normalise geometry
-    set_tokamak_coordinates_on_mesh(noshear, rho_s, bmag / 1e4, ShearFactor);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, noshear, rho_s, bmag / 1e4, ShearFactor);
 
     // Set nu
     nu = nu_hat * Ni0 / pow(Te0, 1.5);
diff --git a/examples/constraints/alfven-wave/alfven.cxx b/examples/constraints/alfven-wave/alfven.cxx
index b25803f1f4..8807b5d406 100644
--- a/examples/constraints/alfven-wave/alfven.cxx
+++ b/examples/constraints/alfven-wave/alfven.cxx
@@ -174,7 +174,7 @@ class Alfven : public PhysicsModel {
     }
 
     auto tokamak_coordinates = TokamakCoordinates(*mesh);
-    set_tokamak_coordinates_on_mesh(noshear, Lnorm, Bnorm);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, noshear, Lnorm, Bnorm);
   }
 };
 
diff --git a/examples/dalf3/dalf3.cxx b/examples/dalf3/dalf3.cxx
index 542be38676..239d45a94f 100644
--- a/examples/dalf3/dalf3.cxx
+++ b/examples/dalf3/dalf3.cxx
@@ -224,7 +224,7 @@ class DALF3 : public PhysicsModel {
     b0xcv.z *= rho_s * rho_s;
 
     // Metrics
-    set_tokamak_coordinates_on_mesh(noshear, rho_s, Bnorm);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, noshear, rho_s, Bnorm);
 
     SOLVE_FOR3(Vort, Pe, Vpar);
     comms.add(Vort, Pe, Vpar);
diff --git a/examples/gyro-gem/gem.cxx b/examples/gyro-gem/gem.cxx
index bdf3f60a97..4edbb3007f 100644
--- a/examples/gyro-gem/gem.cxx
+++ b/examples/gyro-gem/gem.cxx
@@ -252,7 +252,7 @@ class GEM : public PhysicsModel {
     Bbar = options["Bbar"].withDefault(Bbar); // Override in options file
     SAVE_ONCE(Bbar);
 
-    set_tokamak_coordinates_on_mesh(true, Lbar, Bbar);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, true, Lbar, Bbar);
 
     beta_e = 4.e-7 * PI * max(p_e, true) / (Bbar * Bbar);
     SAVE_ONCE(beta_e);
diff --git a/examples/laplacexy/alfven-wave/alfven.cxx b/examples/laplacexy/alfven-wave/alfven.cxx
index 05d1a9a771..92f1905061 100644
--- a/examples/laplacexy/alfven-wave/alfven.cxx
+++ b/examples/laplacexy/alfven-wave/alfven.cxx
@@ -172,7 +172,7 @@ class Alfven : public PhysicsModel {
   void LoadMetric(BoutReal Lnorm, BoutReal Bnorm) {
 
     auto tokamak_coordinates = TokamakCoordinates(*mesh);
-    set_tokamak_coordinates_on_mesh(true, Lnorm, Bnorm);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, true, Lnorm, Bnorm);
     Coordinates* coord = mesh->getCoordinates(); // Metric tensor
   }
 };
diff --git a/examples/laplacexy/laplace_perp/test.cxx b/examples/laplacexy/laplace_perp/test.cxx
index cdd0f5a177..da692fc119 100644
--- a/examples/laplacexy/laplace_perp/test.cxx
+++ b/examples/laplacexy/laplace_perp/test.cxx
@@ -15,7 +15,7 @@ int main(int argc, char** argv) {
   calc_metric = Options::root()["calc_metric"].withDefault(false);
   if (calc_metric) {
     auto tokamak_coordinates = TokamakCoordinates(*mesh);
-    set_tokamak_coordinates_on_mesh(true, 1.0, 1.0);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, true, 1.0, 1.0);
   }
 
     Coordinates* coord = mesh->getCoordinates();
diff --git a/include/bout/tokamak_coordinates.hxx b/include/bout/tokamak_coordinates.hxx
index 167a158c02..b3f6a863c1 100644
--- a/include/bout/tokamak_coordinates.hxx
+++ b/include/bout/tokamak_coordinates.hxx
@@ -48,8 +48,9 @@ BoutReal get_sign_of_bp(Field2D Bpxy) {
     return 1.0;
 }
 
-void set_tokamak_coordinates_on_mesh(Mesh& mesh, const bool noshear, BoutReal Lbar,
-                              BoutReal Bbar, BoutReal ShearFactor = 1.0) {
+void
+set_tokamak_coordinates_on_mesh(tokamak_coordinates, TokamakCoordinates &tokamakCoordinates, Mesh &mesh, const bool noshear, BoutReal Lbar,
+                                BoutReal Bbar, BoutReal ShearFactor = 1.0) {
 
     tokamakCoordinates.normalise(Lbar, Bbar, ShearFactor);
 
diff --git a/tests/integrated/test-drift-instability/2fluid.cxx b/tests/integrated/test-drift-instability/2fluid.cxx
index a469623f9f..145effe81c 100644
--- a/tests/integrated/test-drift-instability/2fluid.cxx
+++ b/tests/integrated/test-drift-instability/2fluid.cxx
@@ -194,7 +194,7 @@ class TwoFluid : public PhysicsModel {
     pei0 = (Ti0 + Te0) * Ni0;
     pe0 = Te0 * Ni0;
 
-    set_tokamak_coordinates_on_mesh(noshear, rho_s, bmag / 1e4, ShearFactor);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, noshear, rho_s, bmag / 1e4, ShearFactor);
 
     /**************** SET EVOLVING VARIABLES *************/
 
diff --git a/tests/integrated/test-interchange-instability/2fluid.cxx b/tests/integrated/test-interchange-instability/2fluid.cxx
index 79f8328fa2..85f1d41525 100644
--- a/tests/integrated/test-interchange-instability/2fluid.cxx
+++ b/tests/integrated/test-interchange-instability/2fluid.cxx
@@ -101,7 +101,7 @@ class Interchange : public PhysicsModel {
           hthe0 / rho_s);
     }
 
-    set_tokamak_coordinates_on_mesh(noshear, rho_s, bmag / 1e4, ShearFactor);
+    set_tokamak_coordinates_on_mesh(tokamak_coordinates, noshear, rho_s, bmag / 1e4, ShearFactor);
 
     if (ShiftXderivs) {
       b0xcv.z += tokamak_coordinates.ShearFactor * b0xcv.x;