Skip to content

Port some Hermes-3 finite volume operators (rebased)#3335

Open
dschwoerer wants to merge 107 commits intonextfrom
move-ops
Open

Port some Hermes-3 finite volume operators (rebased)#3335
dschwoerer wants to merge 107 commits intonextfrom
move-ops

Conversation

@dschwoerer
Copy link
Contributor

Rebase of #3200 on top of #3320 and #3334

ZedThree and others added 30 commits March 11, 2026 12:48
Includes bug fix:

```diff
-    BoutReal gL = n.c - n.L;
-    BoutReal gR = n.R - n.c;
+    BoutReal gL = n.c - n.m;
+    BoutReal gR = n.p - n.c;
```
Co-authored-by: Peter Hill <peter.hill@york.ac.uk>
Field3DParallel enforces that parallel derivatives can be taken.
This means for FCI, parallel fields are present.
It also ensures that if an operation is taken on such a field, the
parallel fields are retained.
This replaces part of fci-automagic, that always retained parallel
fields on operations.
dicts have been preserving order for several releases now.
Otherwise, the Field3DParallel is casted to Field3D and the wrong
overloads are used
The communication was a no-op, as that did never calculate the parallel
fields.
They should return Field3D, not Field3DParallel
This is needed for 2D metrics, and in this case we probably want to
clear the parallel fields.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions


template <typename T>
auto& getStore() {
if constexpr (std::is_same<T, Field3DParallel>::value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "Field3DParallel" is directly included [misc-include-cleaner]

include/bout/deriv_store.hxx:37:

- #include <bout/scorepwrapper.hxx>
+ #include "bout/field3d.hxx"
+ #include <bout/scorepwrapper.hxx>


template <typename T>
auto& getStore() {
if constexpr (std::is_same<T, Field3DParallel>::value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "std::is_same" is directly included [misc-include-cleaner]

include/bout/deriv_store.hxx:35:

- #include <unordered_map>
+ #include <type_traits>
+ #include <unordered_map>

template <typename T>
auto& getStore() {
if constexpr (std::is_same<T, Field3DParallel>::value) {
return DerivativeStore<Field3D>::getInstance();
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "Field3D" is directly included [misc-include-cleaner]

    return DerivativeStore<Field3D>::getInstance();
                           ^

}
return Field3DParallel(*this, true);
}
const Field3DParallel Field3D::asField3DParallel() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: return type 'const Field3DParallel' is 'const'-qualified at the top level, which may reduce code readability without improving const correctness [readability-const-return-type]

include/bout/field3d.hxx:544:

-   inline const Field3DParallel asField3DParallel() const;
+   inline Field3DParallel asField3DParallel() const;
Suggested change
const Field3DParallel Field3D::asField3DParallel() const {
Field3DParallel Field3D::asField3DParallel() const {

for (size_t i = 0; i < result.numberParallelSlices(); ++i) {
result.yup(i).allocate();
BOUT_FOR(d, result.yup(i).getValidRegionWithDefault("RGN_INVALID")) {
result.yup(i)[d] = func(i + 1, d);
Copy link
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 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [bugprone-narrowing-conversions]

        result.yup(i)[d] = func(i + 1, d);
                                ^

#include "bout/unused.hxx"
#include "bout/utils.hxx"
#include "bout/vecops.hxx"

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: included header vecops.hxx is not used directly [misc-include-cleaner]

Suggested change


namespace {
// Get a unique name for a field based on the sign/magnitude of the offset
std::string parallel_slice_field_name(std::string field, int offset) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: the parameter 'field' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
std::string parallel_slice_field_name(std::string field, int offset) {
std::string parallel_slice_field_name(const std::string& field, int offset) {

return direction + "_" + field + slice_suffix;
};

#if BOUT_USE_METRIC_3D
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "BOUT_USE_METRIC_3D" is directly included [misc-include-cleaner]

src/mesh/parallel/fci.cxx:43:

- #include "bout/field2d.hxx"
+ #include "bout/build_defines.hxx"
+ #include "bout/field2d.hxx"

output_options["Z"].force(Z, "FCI");
}

void FCITransform::loadParallelMetrics(Coordinates* coords) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unused parameter 'coords' [clang-diagnostic-unused-parameter]

void FCITransform::loadParallelMetrics(Coordinates* coords) {
                                                    ^

////////////// Y DERIVATIVE /////////////////

Field3D DDY(const Field3D& f, CELL_LOC outloc, const std::string& method,
Field3D DDY(const Field3DParallel& f, CELL_LOC outloc, const std::string& method,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: no header providing "Field3DParallel" is directly included [misc-include-cleaner]

Field3D DDY(const Field3DParallel& f, CELL_LOC outloc, const std::string& method,
                  ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants