Skip to content

Commit

Permalink
Make TokamakCoordinatesFactory.normalise() private and call in make_t…
Browse files Browse the repository at this point in the history
…okamak_coordinates() method
  • Loading branch information
tomchapman committed Dec 4, 2024
1 parent ae7f55f commit f04cea5
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 50 deletions.
13 changes: 8 additions & 5 deletions examples/6field-simple/elm_6f.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,6 @@ class Elm_6f : public PhysicsModel {
J0 = SI::mu0 * Lbar * J0 / tokamak_coordinates_factory.get_Bxy();
P0 = P0 / (SI::kb * (Tibar + Tebar) * eV_K / 2. * Nbar * density);

tokamak_coordinates_factory.normalise(Lbar, Bbar);

b0xcv.x /= Bbar;
b0xcv.y *= Lbar * Lbar;
b0xcv.z *= Lbar * Lbar;
Expand Down Expand Up @@ -906,7 +904,10 @@ class Elm_6f : public PhysicsModel {
q95 = q95_input; // use a constant for test
} else {
if (local_q) {
q95 = abs(tokamak_coordinates_factory.get_hthe() * tokamak_coordinates_factory.get_Btxy() / tokamak_coordinates_factory.get_Bpxy()) * q_alpha;
q95 = abs(tokamak_coordinates_factory.get_hthe()
* tokamak_coordinates_factory.get_Btxy()
/ tokamak_coordinates_factory.get_Bpxy())
* q_alpha;
} else {
output.write("\tUsing q profile from grid.\n");
if (mesh->get(q95, "q")) {
Expand Down Expand Up @@ -1028,8 +1029,9 @@ class Elm_6f : public PhysicsModel {
}

/**************** CALCULATE METRICS ******************/
const auto& coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);

const auto& coord =
tokamak_coordinates_factory.make_tokamak_coordinates(noshear, Lbar, Bbar);

//////////////////////////////////////////////////////////////
// SHIFTED RADIAL COORDINATES

Expand Down Expand Up @@ -1191,6 +1193,7 @@ class Elm_6f : public PhysicsModel {

return 0;
}

int rhs(BoutReal UNUSED(t)) override {

Coordinates* coord = mesh->getCoordinates();
Expand Down
4 changes: 2 additions & 2 deletions examples/conducting-wall-mode/cwm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class CWM : public PhysicsModel {
Te0 /= Te_x;

// Normalise geometry
tokamak_coordinates_factory.normalise(rho_s, bmag / 1e4, ShearFactor);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, rho_s,
bmag / 1e4, ShearFactor);

// Set nu
nu = nu_hat * Ni0 / pow(Te0, 1.5);
Expand Down
4 changes: 2 additions & 2 deletions examples/constraints/alfven-wave/alfven.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ class Alfven : public PhysicsModel {
}

auto tokamak_coordinates_factory = TokamakCoordinatesFactory(*mesh);
tokamak_coordinates_factory.normalise(Lnorm, Bnorm);
const auto& coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
const auto& coord =
tokamak_coordinates_factory.make_tokamak_coordinates(noshear, Lnorm, Bnorm);
}
};

Expand Down
4 changes: 2 additions & 2 deletions examples/dalf3/dalf3.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ class DALF3 : public PhysicsModel {
b0xcv.z *= rho_s * rho_s;

// Metrics
tokamak_coordinates_factory.normalise(rho_s, Bnorm);
const auto& coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
const auto& coord =
tokamak_coordinates_factory.make_tokamak_coordinates(noshear, rho_s, Bnorm);

SOLVE_FOR3(Vort, Pe, Vpar);
comms.add(Vort, Pe, Vpar);
Expand Down
3 changes: 1 addition & 2 deletions examples/elm-pb-outerloop/elm_pb_outerloop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@ class ELMpb : public PhysicsModel {
if (mesh->get(Lbar, "rmag") != 0) { // Typical length scale
Lbar = 1.0;
}
tokamak_coordinates_factory.normalise(Lbar, Bbar);
const auto& metric = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
const auto& metric = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, Lbar, Bbar);

V0 = -tokamak_coordinates_factory.get_Rxy() * tokamak_coordinates_factory.get_Bpxy() * Dphi0 / tokamak_coordinates_factory.get_Bxy();

Expand Down
3 changes: 1 addition & 2 deletions examples/elm-pb/elm_pb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,7 @@ class ELMpb : public PhysicsModel {
b0xcv.y *= Lbar * Lbar;
b0xcv.z *= Lbar * Lbar;

tokamak_coordinates_factory.normalise(Lbar, Bbar);
const auto& metric = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
const auto& metric = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, Lbar, Bbar);


//////////////////////////////////////////////////////////////
Expand Down
3 changes: 1 addition & 2 deletions examples/gyro-gem/gem.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ class GEM : public PhysicsModel {
Bbar = options["Bbar"].withDefault(Bbar); // Override in options file
SAVE_ONCE(Bbar);

tokamak_coordinates_factory.normalise(Lbar, Bbar);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(true);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(true, Lbar, Bbar);

beta_e = 4.e-7 * PI * max(p_e, true) / (Bbar * Bbar);
SAVE_ONCE(beta_e);
Expand Down
4 changes: 2 additions & 2 deletions examples/laplacexy/alfven-wave/alfven.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ class Alfven : public PhysicsModel {


auto tokamak_coordinates_factory = TokamakCoordinatesFactory(*mesh);
tokamak_coordinates_factory.normalise(Lnorm, Bnorm);
const auto& coord = tokamak_coordinates_factory.make_tokamak_coordinates(true);
const auto& coord =
tokamak_coordinates_factory.make_tokamak_coordinates(true, Lnorm, Bnorm);
}
};

Expand Down
37 changes: 18 additions & 19 deletions include/bout/tokamak_coordinates_factory.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
#define BOUT_TOKAMAK_COORDINATES_FACTORY_HXX

#include "bout.hxx"
#include "bout/utils.hxx"
#include "bout/bout_types.hxx"
#include "bout/christoffel_symbols.hxx"
#include "bout/vector2d.hxx"
#include "bout/field2d.hxx"
#include "bout/coordinates.hxx"
#include "bout/field2d.hxx"
#include "bout/utils.hxx"
#include "bout/vector2d.hxx"

class TokamakCoordinatesFactory {

private:

Mesh& mesh_m;
Field2D Rxy_m;
Field2D Bpxy_m;
Expand All @@ -23,11 +22,19 @@ private:
FieldMetric ShearFactor_m;
FieldMetric dx_m;

void normalise(BoutReal Lbar, BoutReal Bbar, BoutReal ShearFactor) {

public:
Rxy_m /= Lbar;
Bpxy_m /= Bbar;
Btxy_m /= Bbar;
Bxy_m /= Bbar;
hthe_m /= Lbar;
ShearFactor_m *= Lbar * Lbar * Bbar * ShearFactor;
dx_m /= Lbar * Lbar * Bbar;
}

TokamakCoordinatesFactory(Mesh& mesh)
: mesh_m(mesh) {
public:
TokamakCoordinatesFactory(Mesh& mesh) : mesh_m(mesh) {

mesh.get(Rxy_m, "Rxy");
// mesh->get(Zxy, "Zxy");
Expand All @@ -46,7 +53,10 @@ public:
return 1.0;
}

Coordinates* make_tokamak_coordinates(const bool noshear) {
Coordinates* make_tokamak_coordinates(const bool noshear, BoutReal Lbar, BoutReal Bbar,
BoutReal ShearFactor = 1.0) {

normalise(Lbar, Bbar, ShearFactor);

const BoutReal sign_of_bp = get_sign_of_bp();

Expand Down Expand Up @@ -80,17 +90,6 @@ public:
return coord;
}

void normalise(BoutReal Lbar, BoutReal Bbar, BoutReal ShearFactor=1.0) {

Rxy_m /= Lbar;
Bpxy_m /= Bbar;
Btxy_m /= Bbar;
Bxy_m /= Bbar;
hthe_m /= Lbar;
ShearFactor_m *= Lbar * Lbar * Bbar * ShearFactor;
dx_m /= Lbar * Lbar * Bbar;
}

const Field2D& get_Rxy() const { return Rxy_m; }
const Field2D& get_Bpxy() const { return Bpxy_m; }
const Field2D& get_Btxy() const { return Btxy_m; }
Expand Down
3 changes: 1 addition & 2 deletions tests/MMS/GBS/gbs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ int GBS::init(bool restarting) {
void GBS::LoadMetric(BoutReal Lnorm, BoutReal Bnorm) {

auto tokamak_coordinates_factory = TokamakCoordinatesFactory(*mesh);
tokamak_coordinates_factory.normalise(Lnorm, Bnorm);
coords = tokamak_coordinates_factory.make_tokamak_coordinates(true);
coords = tokamak_coordinates_factory.make_tokamak_coordinates(true, Lnorm, Bnorm);

// just define a macro for V_E dot Grad
#define vE_Grad(f, p) (bracket(p, f, bm_exb))
Expand Down
3 changes: 1 addition & 2 deletions tests/MMS/elm-pb/elm_pb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,7 @@ class ELMpb : public PhysicsModel {
noshear = true;
}

tokamak_coordinates_factory.normalise(Lbar, Bbar);
coords = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
coords = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, Lbar, Bbar);

//////////////////////////////////////////////////////////////
// SHIFTED RADIAL COORDINATES
Expand Down
4 changes: 2 additions & 2 deletions tests/MMS/tokamak/tokamak.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class TokamakMMS : public PhysicsModel {
void LoadMetric(BoutReal Lnorm, BoutReal Bnorm) {

auto tokamak_coordinates_factory = TokamakCoordinatesFactory(*mesh);
tokamak_coordinates_factory.normalise(Lnorm, Bnorm);
auto coords = tokamak_coordinates_factory.make_tokamak_coordinates(true);
auto coords =
tokamak_coordinates_factory.make_tokamak_coordinates(true, Lnorm, Bnorm);
}

private:
Expand Down
4 changes: 2 additions & 2 deletions tests/integrated/test-drift-instability/2fluid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ class TwoFluid : public PhysicsModel {
pei0 = (Ti0 + Te0) * Ni0;
pe0 = Te0 * Ni0;

tokamak_coordinates_factory.normalise(rho_s, bmag / 1e4, ShearFactor);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, rho_s,
bmag / 1e4, ShearFactor);

/**************** SET EVOLVING VARIABLES *************/

Expand Down
4 changes: 2 additions & 2 deletions tests/integrated/test-interchange-instability/2fluid.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ class Interchange : public PhysicsModel {
hthe0 / rho_s);
}

tokamak_coordinates_factory.normalise(rho_s, bmag / 1e4, ShearFactor);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
coord = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, rho_s,
bmag / 1e4, ShearFactor);

if (ShiftXderivs) {
b0xcv.z += tokamak_coordinates_factory.get_ShearFactor() * b0xcv.x;
Expand Down
3 changes: 1 addition & 2 deletions tests/integrated/test-laplacexy/loadmetric.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ void LoadMetric(BoutReal Lnorm, BoutReal Bnorm) {
}

auto tokamak_coordinates_factory = TokamakCoordinatesFactory(*mesh);
tokamak_coordinates_factory.normalise(Lnorm, Bnorm);
auto coords = tokamak_coordinates_factory.make_tokamak_coordinates(noshear);
auto coords = tokamak_coordinates_factory.make_tokamak_coordinates(noshear, Lnorm, Bnorm);
}

0 comments on commit f04cea5

Please sign in to comment.