diff --git a/include/bout/paralleltransform.hxx b/include/bout/paralleltransform.hxx index a25540354a..6a3c6d4648 100644 --- a/include/bout/paralleltransform.hxx +++ b/include/bout/paralleltransform.hxx @@ -93,7 +93,7 @@ public: class ShiftedMetric : public ParallelTransform { public: ShiftedMetric() = delete; - ShiftedMetric(Mesh &mesh); + ShiftedMetric(Mesh &mesh, Field2D zShift); /*! * Calculates the yup() and ydown() fields of f diff --git a/src/mesh/mesh.cxx b/src/mesh/mesh.cxx index 740ae1a8a1..620a3d1f9d 100644 --- a/src/mesh/mesh.cxx +++ b/src/mesh/mesh.cxx @@ -292,24 +292,44 @@ void Mesh::setParallelTransform() { // Convert to lower case for comparison ptstr = lowercase(ptstr); - - if(ptstr == "identity") { + + if (ptstr == "identity") { // Identity method i.e. no transform needed transform = std::unique_ptr(new ParallelTransformIdentity()); - - }else if(ptstr == "shifted") { + + } else if (ptstr == "shifted") { // Shifted metric method - transform = std::unique_ptr(new ShiftedMetric(*this)); - - }else if(ptstr == "fci") { - Options *fci_options = Options::getRoot()->getSection("fci"); + Field2D zShift{this}; + + // Read the zShift angle from the mesh + if (get(zShift, "zShift")) { + // No zShift variable. Try qinty in BOUT grid files + get(zShift, "qinty"); + } + + // TwistShift needs to be set for derivatives to be correct at the jump where + // poloidal angle theta goes 2pi->0 + bool twistshift = Options::root()["TwistShift"].withDefault(false); + bool shift_without_twist = Options::root()["ShiftWithoutTwist"].withDefault(false); + if (!twistshift and !shift_without_twist) { + throw BoutException( + "ShiftedMetric usually requires the option TwistShift=true\n" + " Set ShiftWithoutTwist=true to use ShiftedMetric without TwistShift"); + } + + transform = std::unique_ptr(new ShiftedMetric(*this, zShift)); + + } else if (ptstr == "fci") { + + Options* fci_options = Options::getRoot()->getSection("fci"); // Flux Coordinate Independent method bool fci_zperiodic; fci_options->get("z_periodic", fci_zperiodic, true); - transform = std::unique_ptr(new FCITransform(*this, fci_zperiodic)); - - }else { + transform = + std::unique_ptr(new FCITransform(*this, fci_zperiodic)); + + } else { throw BoutException(_("Unrecognised paralleltransform option.\n" "Valid choices are 'identity', 'shifted', 'fci'")); } diff --git a/src/mesh/parallel/shiftedmetric.cxx b/src/mesh/parallel/shiftedmetric.cxx index 80fdc37274..3c23e10c89 100644 --- a/src/mesh/parallel/shiftedmetric.cxx +++ b/src/mesh/parallel/shiftedmetric.cxx @@ -15,23 +15,7 @@ #include -ShiftedMetric::ShiftedMetric(Mesh &m) : mesh(m), zShift(&m) { - // Read the zShift angle from the mesh - - if(mesh.get(zShift, "zShift")) { - // No zShift variable. Try qinty in BOUT grid files - mesh.get(zShift, "qinty"); - } - - // TwistShift needs to be set for derivatives to be correct at the jump where - // poloidal angle theta goes 2pi->0 - bool twistshift = Options::root()["TwistShift"].withDefault(false); - bool shift_without_twist = Options::root()["ShiftWithoutTwist"].withDefault(false); - if (!twistshift and !shift_without_twist) { - throw BoutException("ShiftedMetric usually requires the option TwistShift=true\n" - " Set ShiftWithoutTwist=true to use ShiftedMetric without TwistShift"); - } - +ShiftedMetric::ShiftedMetric(Mesh &m, Field2D zShift_) : mesh(m), zShift(std::move(zShift_)) { //If we wanted to be efficient we could move the following cached phase setup //into the relevant shifting routines (with static bool first protection) //so that we only calculate the phase if we actually call a relevant shift diff --git a/tests/integrated/test-yupdown/test_yupdown.cxx b/tests/integrated/test-yupdown/test_yupdown.cxx index e414c0ba88..c8a31f65fc 100644 --- a/tests/integrated/test-yupdown/test_yupdown.cxx +++ b/tests/integrated/test-yupdown/test_yupdown.cxx @@ -37,7 +37,10 @@ int main(int argc, char** argv) { BoutInitialise(argc, argv); - ShiftedMetric s(*mesh); + Field2D zShift{mesh}; + mesh->get(zShift, "zShift"); + + ShiftedMetric s(*mesh, zShift); // Read variable from mesh Field3D var;