diff --git a/include/bout/coordinates.hxx b/include/bout/coordinates.hxx index 49feffa0a7..5ea2d276fc 100644 --- a/include/bout/coordinates.hxx +++ b/include/bout/coordinates.hxx @@ -133,9 +133,10 @@ public: transform = std::move(pt); } + bool hasParallelTransform() const { return transform != nullptr; } /// Return the parallel transform - ParallelTransform& getParallelTransform() { - ASSERT1(transform != nullptr); + ParallelTransform& getParallelTransform() const { + ASSERT1(hasParallelTransform()); return *transform; } diff --git a/include/bout/field.hxx b/include/bout/field.hxx index c0693ec0fb..d0828e8f6c 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -86,6 +86,8 @@ public: std::string name; + bool isFci() const; + #if CHECK > 0 // Routines to test guard/boundary cells set diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index c80716fc12..ed9f6f8d60 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -636,9 +636,22 @@ public: return inserted.first->second; } + std::shared_ptr + getCoordinatesConst(const CELL_LOC location = CELL_CENTRE) const { + ASSERT1(location != CELL_DEFAULT); + ASSERT1(location != CELL_VSHIFT); + + auto found = coords_map.find(location); + if (found != coords_map.end()) { + // True branch most common, returns immediately + return found->second; + } + throw BoutException("Coordinates not yet set. Use non-const version!"); + } + /// Returns the non-CELL_CENTRE location /// allowed as a staggered location - CELL_LOC getAllowedStaggerLoc(DIRECTION direction) const { + static CELL_LOC getAllowedStaggerLoc(DIRECTION direction) { AUTO_TRACE(); switch (direction) { case (DIRECTION::X): @@ -828,6 +841,16 @@ public: ASSERT1(RegionID.has_value()); return region3D[RegionID.value()]; } + bool isFci() const { + const auto coords = this->getCoordinatesConst(); + if (coords == nullptr) { + return false; + } + if (not coords->hasParallelTransform()) { + return false; + } + return not coords->getParallelTransform().canToFromFieldAligned(); + } private: /// Allocates default Coordinates objects @@ -837,8 +860,7 @@ private: /// (useful if CELL_CENTRE Coordinates have been changed, so reading from file /// would not be correct). std::shared_ptr - createDefaultCoordinates(const CELL_LOC location, - bool force_interpolate_from_centre = false); + createDefaultCoordinates(CELL_LOC location, bool force_interpolate_from_centre = false); //Internal region related information std::map regionMap3D; diff --git a/src/field/field.cxx b/src/field/field.cxx index e48a8f3ef7..797df6c405 100644 --- a/src/field/field.cxx +++ b/src/field/field.cxx @@ -39,3 +39,14 @@ int Field::getNx() const { return getMesh()->LocalNx; } int Field::getNy() const { return getMesh()->LocalNy; } int Field::getNz() const { return getMesh()->LocalNz; } + +bool Field::isFci() const { + const auto* coords = this->getCoordinates(); + if (coords == nullptr) { + return false; + } + if (not coords->hasParallelTransform()) { + return false; + } + return not coords->getParallelTransform().canToFromFieldAligned(); +}