Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/bout/paralleltransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 31 additions & 11 deletions src/mesh/mesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParallelTransform>(new ParallelTransformIdentity());
}else if(ptstr == "shifted") {

} else if (ptstr == "shifted") {
// Shifted metric method
transform = std::unique_ptr<ParallelTransform>(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<ParallelTransform>(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<ParallelTransform>(new FCITransform(*this, fci_zperiodic));

}else {
transform =
std::unique_ptr<ParallelTransform>(new FCITransform(*this, fci_zperiodic));

} else {
throw BoutException(_("Unrecognised paralleltransform option.\n"
"Valid choices are 'identity', 'shifted', 'fci'"));
}
Expand Down
18 changes: 1 addition & 17 deletions src/mesh/parallel/shiftedmetric.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,7 @@

#include <output.hxx>

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
Expand Down
5 changes: 4 additions & 1 deletion tests/integrated/test-yupdown/test_yupdown.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down