Skip to content

Conversation

@ZedThree
Copy link
Member

@ZedThree ZedThree commented Nov 4, 2025

  • Add MMS tests for all the main FCI derivative operators
  • A bunch of drive-by fixes for clang-tidy warnings

ZedThree and others added 25 commits October 6, 2025 14:22
- Include all relevant headers, remove unused ones, add some forward
  declarations
- Make data `private` instead of `protected`
- Add getter instead of `const` member
- Change member reference to pointer
- Move ctor to .cxx file
- Use `std::array` instead of C array
- Bunch of other small clang-tidy fixes
The Div_par operators use parallel slices of B -- with 2D metrics,
these are just the field itself, in 3D we need the actual
slices. While `Coordinates::geometry` does communicate the fields, it
puts off calculating the parallel slices because that needs the fully
constructed `Coordinates`.

Upcoming changes should fix this and remove the need to explicitly
communicate `Coordinates` members.
* next: (78 commits)
  Apply clang-format changes
  Add `has_hypre` to python `boutconfig`
  Update examples for LaplaceXY factory
  Fix call to virtual function in ctor
  CI: Don't warn about including PETSc or MPI symbols directly
  Try to appease clang-tidy `misc-include-cleaner`
  Remove private variables from base class
  Fix typo in define
  Apply clang-format changes
  Add factory for LaplaceXY, LaplaceXY2, LaplaceXY2Hypre
  Enable non-const iteration over `Options`
  snes solver: Consider timestep change at output
  Bump DOI
  Add shim for ARKodeGetNumRhsEvals
  Suppress warning from `nodiscard` function
  Remove `boututils` from requirements; bump `boutdata`
  Fix deprecation warning
  Bump bundled fmt
  Fix some easy clang-tidy snes warnings
  Fix reorder warning from snes
  ...
@ZedThree ZedThree requested a review from dschwoerer November 4, 2025 11:50
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

dschwoerer
dschwoerer previously approved these changes Nov 4, 2025
Copy link
Contributor

@dschwoerer dschwoerer left a comment

Choose a reason for hiding this comment

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

Looks good!
Thanks @ZedThree

Comment on lines +191 to +192
// TODO(peter): Can we remove this if we apply (dirichlet?) BCs to
// the X derivatives? Note that we need at least _2_
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think that applying dirichlet BCs will be in general a good idea.
I think in general this is not really an issue - anything that takes the case below should be i_corn == xend and t_x = 0. Other cases should be boundaries, and should not take this path.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that's true about the boundaries. The pain here is for grids where there's only one point in either x or z, so this fudge ends up cancelling out and breaking things. That's probably not super common, so maybe we just need ASSERT4(mesh.Nx() >= 2) or something

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I think that is only an issue for tests, that try to have a minimal grid. I do not think we should to much effort in for them ...

Comment on lines +361 to +362
// TODO(peter): Should we apply dirichlet BCs to derivatives?

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think so. What would be the motivation? So we do not need two x-guard cells?

// Div_par operators require B parallel slices:
// Coordinates::geometry doesn't ensure this (yet)
auto& Bxy = mesh->getCoordinates()->Bxy;
mesh->communicate(Bxy);
Copy link
Contributor

Choose a reason for hiding this comment

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

In general you would need to apply parallel BCs, but I guess the tested grids do not have this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, no BCs set because all the input fields are created from expressions

Copy link
Contributor

Choose a reason for hiding this comment

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

I think B should be loaded also for the parallel slices, in which case we do not need to communicate at all ...

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't seem to be the case -- the communicate was necessary here to get any parallel slices on Bxy

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, these changes are not in next, only in f3dwy (PR #3197 )

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

@ZedThree
Copy link
Member Author

ZedThree commented Nov 6, 2025

A silly typo meant that the new FCI tests were always passing. Fixing that showed that the monotonichermitespline cases were actually failing. It's known that the interpolation is degraded around extrema, but the errors appear with a strange pattern:

Grad_par:

mhs_grad_par

and they accumulate with higher derivatives:

Grad2_par2:

mhs_grad2_par2

How widely used is monotonichermitespline in practice?

@bendudson
Copy link
Contributor

Thanks @ZedThree ! monotonichermitespline is used in practice: It's been my favorite interpolator. It's useful because it should avoid overshoot oscillations in e.g. low-density regions.

@dschwoerer
Copy link
Contributor

Note that this is not https://en.wikipedia.org/wiki/Monotone_cubic_interpolation - but hermitespline - with the value cropped to the bound of the 4 surrounding values.

@dschwoerer
Copy link
Contributor

Ah, the test do not always pass - they still fail if order is negative 😇
I had failing tests when I merged this into f3dwy. I will check whether I also see this issue ...

@ZedThree
Copy link
Member Author

ZedThree commented Nov 7, 2025

Ok, so the errors are just coming from extrema in the input function. The question now is what is the appropriate fix:

  1. don't test monotonichermitespline in this test, or possibly just skip it for the higher derivatives?
  2. change the input function to have fewer/smaller extrema -- we could set yperiodic=False and have the function monotonic in y, although we'd then also introduce some dependence on the BCs, otherwise we need at least one extrema to make it periodic
  3. change the implementation (or introduce a new interpolator) to control overshoots in a different manner, for example by damping the derivative parts to change the tension in the spline

For reference, here's the error scaling for the different operators for monotonichermitespline:

  • grad_par convergence order = 1.437273 (fit), 1.547833 (small spacing)
  • grad2_par2 convergence order = 0.682735 (fit), 0.723754 (small spacing)
  • div_par convergence order = 1.437273 (fit), 1.547833 (small spacing)
  • div_par_K_grad_par convergence order = 0.720145 (fit), 0.898745 (small spacing)
  • laplace_par convergence order = 0.682735 (fit), 0.723754 (small spacing)

Note that they're not even first order

This allows the user to control the clipping, allowing some overshoot

Also restore the FCI MMS test with this interpolator
@ZedThree
Copy link
Member Author

I've used @dschwoerer's suggestion and added rtol and atol parameters for monotonichermitespline, and it now successfully passes the MMS test. The default values give the old behaviour, but they are user configurable

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


class XZInterpolationFactory
: public Factory<XZInterpolation, XZInterpolationFactory, Mesh*> {
: public Factory<XZInterpolation, XZInterpolationFactory, Mesh*, Options*> {
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 "Factory" is directly included [misc-include-cleaner]

include/bout/interpolation_xz.hxx:27:

- #include "bout/mask.hxx"
+ #include "bout/generic_factory.hxx"
+ #include "bout/mask.hxx"


ReturnType create(Options* options = nullptr, Mesh* mesh = nullptr) const {
return Factory::create(getType(options), mesh);
return Factory::create(getType(options), mesh, options);
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 "Factory" is directly included [misc-include-cleaner]

    return Factory::create(getType(options), mesh, options);
           ^

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.

4 participants