Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isFci for fields #2887

Open
wants to merge 12 commits into
base: next
Choose a base branch
from
5 changes: 3 additions & 2 deletions include/bout/coordinates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions include/bout/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public:

std::string name;

bool isFci() const;

#if CHECK > 0
// Routines to test guard/boundary cells set

Expand Down
28 changes: 25 additions & 3 deletions include/bout/mesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,22 @@ public:
return inserted.first->second;
}

std::shared_ptr<Coordinates>
getCoordinatesConst(const CELL_LOC location = CELL_CENTRE) const {
ASSERT1(location != CELL_DEFAULT);
ASSERT1(location != CELL_VSHIFT);

auto found = coords_map.find(location);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: method 'getAllowedStaggerLoc' can be made static [readability-convert-member-functions-to-static]

Suggested change
auto found = coords_map.find(location);
static CELL_LOC getAllowedStaggerLoc(DIRECTION direction) {

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):
Expand Down Expand Up @@ -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();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: parameter 'location' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]

Suggested change
}
createDefaultCoordinates(CELL_LOC location,


private:
/// Allocates default Coordinates objects
Expand All @@ -837,8 +860,7 @@ private:
/// (useful if CELL_CENTRE Coordinates have been changed, so reading from file
/// would not be correct).
std::shared_ptr<Coordinates>
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<std::string, size_t> regionMap3D;
Expand Down
11 changes: 11 additions & 0 deletions src/field/field.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Loading