Skip to content

Field3DParallel#3320

Merged
bendudson merged 97 commits into
nextfrom
f3dparallel
Jun 4, 2026
Merged

Field3DParallel#3320
bendudson merged 97 commits into
nextfrom
f3dparallel

Conversation

@dschwoerer
Copy link
Copy Markdown
Contributor

@dschwoerer dschwoerer commented Mar 12, 2026

A field that can be used to compute parallel derivatives. For FCI that means, it has parallel slices, and will preserve them.

Any Field3D can be turned into a Field3DParallel, if it has parallel slices. If not, it will raise a runtime error, as that is not known at compile time.

This can be used to preserve parallel slices, by turning a Field3D into a Field3DParallel:

Field3D f = (f1.asField3DParallel() * f2) + f3;

f will have parallel slices. If f2 or f3 do not have parallel slices, this will throw an error.

Includes #3334

Copy link
Copy Markdown
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

There were too many comments to post at once. Showing the first 25 out of 33. Check the log or trigger a new build to see more.

Comment thread include/bout/deriv_store.hxx
Comment thread include/bout/deriv_store.hxx
Comment thread include/bout/deriv_store.hxx
Comment thread include/bout/field2d.hxx
Comment thread include/bout/field2d.hxx
Comment thread src/field/field3d.cxx
Comment thread src/field/field3d.cxx
Comment thread src/field/field3d.cxx
Comment thread src/field/field3d.cxx
Comment thread src/field/generated_fieldops.cxx
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.
the functions where implemented, but not defined in the header
Otherwise `Field3DParallel(0.0)` fails, as it constructs a `Field3D`
without parallel slices, and then fails as that cannot be converted to a
`Field3DParallel`
Copy link
Copy Markdown
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

Comment thread include/bout/field3d.hxx Outdated
}
return Field3DParallel(*this, true);
}
const Field3DParallel Field3D::asField3DParallel() const {
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: 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:546:

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

Comment thread src/mesh/coordinates.cxx
return bout::derivatives::index::DDY(f_parallel, outloc, method, region);
}
#endif
Field3D Coordinates::DDY(const Field3DParallel& f, CELL_LOC outloc,
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: no header providing "Field3DParallel" is directly included [misc-include-cleaner]

src/mesh/coordinates.cxx:6:

- #include "bout/field_data.hxx"
+ #include "bout/field3d.hxx"
+ #include "bout/field_data.hxx"

Comment thread src/mesh/parallel/fci.cxx
return direction + "_" + field + slice_suffix;
};

#if BOUT_USE_METRIC_3D
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: no header providing "BOUT_USE_METRIC_3D" is directly included [misc-include-cleaner]

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

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

Comment thread include/bout/field2d.hxx

int size() const override { return nx * ny; }

Field2D& asField3DParallel() { return *this; }
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.

This looks potentially very confusing: surely asField3DParallel should return Field3DParallel, not Field2D?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed, it looks confusing. However, this is needed to write FA / FCI independent code.
Maybe we should rename asField3DParallel() to something along the lines of .allowYDerivatives()?

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.

Ah I see. Perhaps just a comment might be sufficient.

bendudson
bendudson previously approved these changes Jun 4, 2026
Copy link
Copy Markdown
Contributor

@bendudson bendudson left a comment

Choose a reason for hiding this comment

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

Thanks @dschwoerer !

@bendudson bendudson merged commit e6c652c into next Jun 4, 2026
23 checks passed
@bendudson bendudson deleted the f3dparallel branch June 4, 2026 19:20
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