From c7bcdc59eab224167fbb1e97955afe414d02d578 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 29 Oct 2026 10:46:20 +0100 Subject: [PATCH 1/3] Avoid spamming options on getYBoundary() This is called by Div_par_K_Grad_par_mod without caching. --- include/bout/coordinates.hxx | 1 + src/mesh/coordinates.cxx | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/bout/coordinates.hxx b/include/bout/coordinates.hxx index 6b7face8b6..c8c99de66c 100644 --- a/include/bout/coordinates.hxx +++ b/include/bout/coordinates.hxx @@ -552,6 +552,7 @@ private: /// - both, index 2 /// - neither, index 3 -- but note, this is not a sensible value! mutable std::array, 4> ybndrys; + mutable int default_yboundary{-1}; FieldMetric recalculateBxy() const; diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 3c3bcedfb3..69689a113f 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -1233,6 +1233,10 @@ void Coordinates::_compute_cell_volume() const { } const bout::boundary::YBoundary& Coordinates::getYBoundary(Options* options) const { + bool is_default = options == nullptr; + if (is_default and default_yboundary >= 0) { + return ybndrys[default_yboundary]; + } Options* opts = (options == nullptr) ? localoptions : options; if (opts == nullptr) { @@ -1251,6 +1255,12 @@ const bout::boundary::YBoundary& Coordinates::getYBoundary(Options* options) con ? (*opts)["inner_x"].doc("Boundary on inner x?").withDefault(false) : (*opts)["upper_y"].doc("Boundary on upper y?").withDefault(true); + 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); + } + return getYBoundary(lower_y, upper_y); } From acc816630677ababa147d939e5a6f7221cb79dee Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 29 Oct 2026 11:05:13 +0100 Subject: [PATCH 2/3] Fix compile issues --- src/mesh/coordinates.cxx | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 69689a113f..88d718ab9b 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -1232,10 +1232,25 @@ 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 { bool is_default = options == nullptr; if (is_default and default_yboundary >= 0) { - return ybndrys[default_yboundary]; + return *ybndrys.at(default_yboundary); } Options* opts = (options == nullptr) ? localoptions : options; @@ -1264,21 +1279,6 @@ const bout::boundary::YBoundary& Coordinates::getYBoundary(Options* options) con 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; - } - return 3; -} -} // namespace - const bout::boundary::YBoundary& Coordinates::getYBoundary(bool lower_y, bool upper_y) const { const auto index = boundary_bools_to_index(lower_y, upper_y); From abcae69631fbc0586ff4a71a27cba5cf1855ccc7 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 29 Oct 2026 11:06:54 +0100 Subject: [PATCH 3/3] Apply clang-tidy suggestion --- src/mesh/coordinates.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/coordinates.cxx b/src/mesh/coordinates.cxx index 88d718ab9b..0b558a15ec 100644 --- a/src/mesh/coordinates.cxx +++ b/src/mesh/coordinates.cxx @@ -1248,7 +1248,7 @@ std::size_t boundary_bools_to_index(bool lower, bool upper) { } // namespace const bout::boundary::YBoundary& Coordinates::getYBoundary(Options* options) const { - bool is_default = options == nullptr; + const bool is_default = options == nullptr; if (is_default and default_yboundary >= 0) { return *ybndrys.at(default_yboundary); }