Skip to content
Open
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
1 change: 1 addition & 0 deletions include/bout/coordinates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ private:
/// - both, index 2
/// - neither, index 3 -- but note, this is not a sensible value!
mutable std::array<std::shared_ptr<bout::boundary::YBoundary>, 4> ybndrys;
mutable int default_yboundary{-1};

FieldMetric recalculateBxy() const;

Expand Down
40 changes: 25 additions & 15 deletions src/mesh/coordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,26 @@ void Coordinates::_compute_cell_volume() const {
}
}

namespace {
std::size_t boundary_bools_to_index(bool lower, bool upper) {
if (lower and upper) {
return 2;
}
if (upper) {
return 1;
}
if (lower) {
return 0;
}
return 3;
}
} // namespace

const bout::boundary::YBoundary& Coordinates::getYBoundary(Options* options) const {
const bool is_default = options == nullptr;
if (is_default and default_yboundary >= 0) {
return *ybndrys.at(default_yboundary);
}
Options* opts = (options == nullptr) ? localoptions : options;

if (opts == nullptr) {
Expand All @@ -1251,23 +1270,14 @@ const bout::boundary::YBoundary& Coordinates::getYBoundary(Options* options) con
? (*opts)["inner_x"].doc("Boundary on inner x?").withDefault<bool>(false)
: (*opts)["upper_y"].doc("Boundary on upper y?").withDefault<bool>(true);

return getYBoundary(lower_y, upper_y);
}

namespace {
std::size_t boundary_bools_to_index(bool lower, bool upper) {
if (lower and upper) {
return 2;
}
if (upper) {
return 1;
}
if (lower) {
return 0;
if (is_default) {
// populate cache first to avoid race condition
getYBoundary(lower_y, upper_y);
default_yboundary = boundary_bools_to_index(lower_y, upper_y);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'std::size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions]

    default_yboundary = boundary_bools_to_index(lower_y, upper_y);
                        ^

}
return 3;

return getYBoundary(lower_y, upper_y);
}
} // namespace

const bout::boundary::YBoundary& Coordinates::getYBoundary(bool lower_y,
bool upper_y) const {
Expand Down
Loading