From fa357c118dd2db162ce8288046c871f835b9b37f Mon Sep 17 00:00:00 2001 From: David Bold Date: Tue, 19 Mar 2024 15:43:50 +0100 Subject: [PATCH 1/9] Add isFci to check if a field is a FCI field. --- include/bout/field.hxx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/bout/field.hxx b/include/bout/field.hxx index c0693ec0fb..c0ce04dbed 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -178,6 +178,11 @@ inline bool areFieldsCompatible(const Field& field1, const Field& field2) { #define ASSERT1_FIELDS_COMPATIBLE(field1, field2) ; #endif +template +inline bool isFci(const F& f) { + return not f.getCoordinates()->getParallelTransform().canToFromFieldAligned(); +} + /// Return an empty shell field of some type derived from Field, with metadata /// copied and a data array that is allocated but not initialised. template From ca59edb366be164e3583dc6041ea26d28c569ed8 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 3 Nov 2023 14:04:13 +0100 Subject: [PATCH 2/9] Improve isFci Ensure this does not crash if coordinates or transform is not set. In this case no FCI transformation is set, and this returns false. --- include/bout/field.hxx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/bout/field.hxx b/include/bout/field.hxx index c0ce04dbed..4433af6d19 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -180,7 +180,14 @@ inline bool areFieldsCompatible(const Field& field1, const Field& field2) { template inline bool isFci(const F& f) { - return not f.getCoordinates()->getParallelTransform().canToFromFieldAligned(); + const auto coords = f.getCoordinates(); + if (coords == nullptr){ + return false; + } + if (not coords->hasParallelTransform()) { + return false; + } + return not coords->getParallelTransform().canToFromFieldAligned(); } /// Return an empty shell field of some type derived from Field, with metadata From 8b1fbba650fbaa17c572c7036c4a3d949892cece Mon Sep 17 00:00:00 2001 From: dschwoerer Date: Tue, 19 Mar 2024 15:27:28 +0000 Subject: [PATCH 3/9] Apply clang-format changes --- include/bout/field.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bout/field.hxx b/include/bout/field.hxx index 4433af6d19..61e4af4d4b 100644 --- a/include/bout/field.hxx +++ b/include/bout/field.hxx @@ -181,7 +181,7 @@ inline bool areFieldsCompatible(const Field& field1, const Field& field2) { template inline bool isFci(const F& f) { const auto coords = f.getCoordinates(); - if (coords == nullptr){ + if (coords == nullptr) { return false; } if (not coords->hasParallelTransform()) { From 23d309f2532376be77e653535e9e67f96915d20b Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 20 Mar 2024 10:28:57 +0100 Subject: [PATCH 4/9] Make isFci a member function and add missing func --- include/bout/coordinates.hxx | 5 +++-- include/bout/field.hxx | 14 ++------------ src/field/field.cxx | 11 +++++++++++ 3 files changed, 16 insertions(+), 14 deletions(-) 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 61e4af4d4b..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 @@ -178,18 +180,6 @@ inline bool areFieldsCompatible(const Field& field1, const Field& field2) { #define ASSERT1_FIELDS_COMPATIBLE(field1, field2) ; #endif -template -inline bool isFci(const F& f) { - const auto coords = f.getCoordinates(); - if (coords == nullptr) { - return false; - } - if (not coords->hasParallelTransform()) { - return false; - } - return not coords->getParallelTransform().canToFromFieldAligned(); -} - /// Return an empty shell field of some type derived from Field, with metadata /// copied and a data array that is allocated but not initialised. template diff --git a/src/field/field.cxx b/src/field/field.cxx index e48a8f3ef7..c9373454bf 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(); +} From 18fca62f3367981fc173ba58297715e9e3f2c351 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 12 Apr 2024 15:00:21 +0200 Subject: [PATCH 5/9] Make it explicit that this is a pointer --- src/field/field.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/field/field.cxx b/src/field/field.cxx index c9373454bf..797df6c405 100644 --- a/src/field/field.cxx +++ b/src/field/field.cxx @@ -41,7 +41,7 @@ int Field::getNy() const { return getMesh()->LocalNy; } int Field::getNz() const { return getMesh()->LocalNz; } bool Field::isFci() const { - const auto coords = this->getCoordinates(); + const auto* coords = this->getCoordinates(); if (coords == nullptr) { return false; } From 44084cca1fa150f760102aa10d97b4be714ed10e Mon Sep 17 00:00:00 2001 From: David Bold Date: Tue, 2 Jul 2024 14:38:47 +0200 Subject: [PATCH 6/9] Add isFci also to mesh --- include/bout/mesh.hxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index c80716fc12..a3a36ad933 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -828,6 +828,17 @@ 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 From cd288e98d1964d517380ce883fcb83da1106e3f0 Mon Sep 17 00:00:00 2001 From: David Bold Date: Fri, 9 Aug 2024 10:47:16 +0200 Subject: [PATCH 7/9] Add const version for getCoordinates --- include/bout/mesh.hxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index a3a36ad933..ccc979987b 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -636,6 +636,19 @@ 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 { From 061b82ffbd14373f744ad205f6577c3c03120b3a Mon Sep 17 00:00:00 2001 From: dschwoerer Date: Tue, 22 Oct 2024 10:04:02 +0000 Subject: [PATCH 8/9] Apply clang-format changes --- include/bout/mesh.hxx | 1 - 1 file changed, 1 deletion(-) diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index ccc979987b..c1a6a1336d 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -852,7 +852,6 @@ public: return not coords->getParallelTransform().canToFromFieldAligned(); } - private: /// Allocates default Coordinates objects /// By default attempts to read staggered Coordinates from grid data source, From ececfb831dff6ae17aff36924fe01e97c9eeb7d7 Mon Sep 17 00:00:00 2001 From: David Bold Date: Wed, 6 Nov 2024 16:46:26 +0100 Subject: [PATCH 9/9] Apply suggestions from clang-tidy --- include/bout/mesh.hxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/bout/mesh.hxx b/include/bout/mesh.hxx index c1a6a1336d..ed9f6f8d60 100644 --- a/include/bout/mesh.hxx +++ b/include/bout/mesh.hxx @@ -651,7 +651,7 @@ public: /// 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): @@ -860,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;