Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
5502ce3
Allow XZHermiteSpline also without y-offset
dschwoerer Sep 27, 2024
c74d330
Add communication routine for FCI operation
dschwoerer Jan 15, 2025
afc68d9
Unify XZMonotonicHermiteSpline and XZMonotonicHermiteSpline
dschwoerer Jan 15, 2025
84237c8
Use x-splitting for monotonichermitespline test
dschwoerer Jan 15, 2025
0662449
Set region for lagrange4pt
dschwoerer Jan 16, 2025
f77849e
Add monotonic check also to other code branches
dschwoerer Jan 21, 2025
820f0a5
use lower_bound instead of find
dschwoerer Jan 21, 2025
1178243
Do not shadow mapping
dschwoerer Jan 21, 2025
3d6f587
Ensure setup has been called
dschwoerer Jan 21, 2025
265c8cd
Use pointer to data
dschwoerer Jan 21, 2025
16a162e
Call setup before communicator is used
dschwoerer Jan 21, 2025
e5878c1
Deduplicate code
dschwoerer Jan 21, 2025
aee2713
Fix tags for comm
dschwoerer Jan 21, 2025
b4f7be5
Use pointer instead of std::vector
dschwoerer Jan 21, 2025
578ee8d
Do not reuse requests if the array is still in use
dschwoerer Jan 21, 2025
bf9c9eb
rename offset to getOffsets
dschwoerer Jan 22, 2025
2155f06
Fix: mixup of sending / receiving size
dschwoerer Jan 22, 2025
0662247
Fix receive data offset
dschwoerer Jan 22, 2025
28d4e28
Add check to ensure the proc layout is as expected
dschwoerer Jan 22, 2025
e4507d9
clang-format
dschwoerer Jan 22, 2025
d7ba297
Use BOUT++ assert
dschwoerer Jan 22, 2025
f55f8e4
Fix check
dschwoerer Jan 22, 2025
0e9f7d6
Take periodicity into account
dschwoerer Jan 28, 2025
944adfb
Sort a reference, not a copy
dschwoerer Jan 28, 2025
6daec20
Only communicate non-empty vectors
dschwoerer Jan 28, 2025
3444dd0
Make check stricter
dschwoerer Jan 31, 2025
91bee68
Fix: include global offset in monotonic spline
dschwoerer Jan 31, 2025
d7aeae4
make fci_comm openmp thread safe
dschwoerer Jan 31, 2025
ac5cc70
Fix communication for fci
dschwoerer Feb 7, 2025
885b465
Add check to reduce risk of bugs
dschwoerer Feb 7, 2025
a1c4033
tests: Increase nx for hermitespline interpolation boundary problem
ZedThree Oct 9, 2025
1c25b0e
region may be not used
dschwoerer Feb 2, 2026
c7f8504
Fix [[maybe_unused]] location
dschwoerer Feb 2, 2026
96aa2bd
Add some wiggle room for monotonichermitespline
dschwoerer Feb 4, 2026
65880e4
[bot] Apply format changes
dschwoerer Mar 3, 2026
a91d3e7
[bot] Add last format changes commit to ignore file
dschwoerer Mar 3, 2026
f473a6b
Apply fixes from clang-format
dschwoerer Mar 4, 2026
f341037
Apply clang-tidy changes
dschwoerer Mar 4, 2026
999d4ca
Apply clang-tidy improvements
dschwoerer Mar 4, 2026
614a727
MPI_Request may not be a pointer
dschwoerer Mar 4, 2026
d1cfb8a
[bot] Apply format changes
dschwoerer Mar 4, 2026
5c0d41d
[bot] Add last format changes commit to ignore file
dschwoerer Mar 4, 2026
eaf35d9
Merge branch 'next' into hermitespline
dschwoerer Mar 9, 2026
a5392af
Merge branch 'next' into hermitespline
dschwoerer Mar 9, 2026
b8bfd3b
Rename to GlobalToLocal1D
dschwoerer Mar 10, 2026
52373e7
Rename to request
dschwoerer Mar 10, 2026
c650881
Add some docs
dschwoerer Mar 10, 2026
3a62dc4
Use templates over pre-processing
dschwoerer Mar 10, 2026
cb84b76
Test serveral implementations
dschwoerer Mar 10, 2026
a81d3eb
Cleanup interface and move more functions to cxx file
dschwoerer Mar 10, 2026
4632df0
Move processor ID calculation to mesh
dschwoerer Mar 10, 2026
4b0ed1c
Use getNZPE()
dschwoerer Mar 10, 2026
325dde3
respect mesh->periodicX
dschwoerer Mar 10, 2026
8dc7b4f
Ensure we are periodic in Y
dschwoerer Mar 10, 2026
db53852
avoid static_cast<void*> for pointer
dschwoerer Mar 10, 2026
29f9727
Merge remote-tracking branch 'origin/next' into hermitespline
dschwoerer Mar 10, 2026
dcafb6c
Add more docs
dschwoerer Mar 10, 2026
424136b
Use better names
dschwoerer Mar 10, 2026
500989b
Fixup getProcIndex
dschwoerer Mar 10, 2026
cabf678
Add headers from clang-tidy
dschwoerer Mar 10, 2026
01e2263
[bot] Apply format changes
dschwoerer Mar 10, 2026
6bd15d2
Apply clang-tidy fixes
dschwoerer Mar 10, 2026
f2d860f
Fixup compile issues
dschwoerer Mar 10, 2026
159ce2f
Add getProcIndex to fake_mesh
dschwoerer Mar 11, 2026
1de6329
Add guards for petsc related code
dschwoerer Mar 11, 2026
47f93b1
Fixup: always use proc for proc computation
dschwoerer Mar 11, 2026
58db33a
Fixup rename
dschwoerer Mar 11, 2026
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ a71cad2dd6ace5741a754e2ca7daacd4bb094e0e
2c2402ed59c91164eaff46dee0f79386b7347e9e
05b7c571544c3bcb153fce67d12b9ac48947fc2d
c8f38049359170a34c915e209276238ea66b9a1e
65880e4af16cb95438437bf057c4b9fdb427b142
d1cfb8abd6aa5c76e6c1a4d7ab20929c65f8afc2
8d5cb39e03c2644715a50684f8cd0318b4e82676
ec69e8838be2dde140a915e50506f8e1ce3cb534
f2bc0488a298f136294c523bc5ab4086d090059b
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ set(BOUT_SOURCES
./src/mesh/interpolation/hermite_spline_z.cxx
./src/mesh/interpolation/interpolation_z.cxx
./src/mesh/interpolation/lagrange_4pt_xz.cxx
./src/mesh/interpolation/monotonic_hermite_spline_xz.cxx
./src/mesh/invert3x3.hxx
./src/mesh/mesh.cxx
./src/mesh/parallel/fci.cxx
./src/mesh/parallel/fci.hxx
./src/mesh/parallel/fci_comm.cxx
./src/mesh/parallel/fci_comm.hxx
./src/mesh/parallel/identity.cxx
./src/mesh/parallel/shiftedmetric.cxx
./src/mesh/parallel/shiftedmetricinterp.cxx
Expand Down
120 changes: 49 additions & 71 deletions include/bout/interpolation_xz.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@
#include <bout/bout_types.hxx>
#include <bout/generic_factory.hxx>
#include <bout/mask.hxx>
#include <array>

#define USE_NEW_WEIGHTS 1
#if BOUT_HAS_PETSC
#define HS_USE_PETSC 1
#endif

#ifdef HS_USE_PETSC
#include "bout/petsclib.hxx"
#endif

namespace {
enum class implementation_type { new_weights, petsc, legacy };
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: enum 'implementation_type' uses a larger base type ('int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]

enum class implementation_type { new_weights, petsc, legacy };
           ^

}

class Options;
class GlobalField3DAccess;

/// Interpolate a field onto a perturbed set of points
const Field3D interpolate(const Field3D& f, const Field3D& delta_x,
Expand Down Expand Up @@ -135,14 +136,26 @@ public:
}
};

class XZHermiteSpline : public XZInterpolation {
/// Monotonic Hermite spline interpolator
///
/// Similar to XZHermiteSpline, so uses most of the same code.
/// Forces the interpolated result to be in the range of the
/// neighbouring cell values. This prevents unphysical overshoots,
/// but also degrades accuracy near maxima and minima.
/// Perhaps should only impose near boundaries, since that is where
/// problems most obviously occur.
template <bool monotonic, implementation_type imp_type>
class XZHermiteSplineBase : public XZInterpolation {
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: class 'XZHermiteSplineBase' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

class XZHermiteSplineBase : public XZInterpolation {
      ^

protected:
/// This is protected rather than private so that it can be
/// extended and used by HermiteSplineMonotonic

Tensor<SpecificInd<IND_TYPE::IND_3D>> i_corner; // index of bottom-left grid point
Tensor<int> k_corner; // z-index of bottom-left grid point

std::unique_ptr<GlobalField3DAccess> gf3daccess;
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: member variable 'gf3daccess' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  std::unique_ptr<GlobalField3DAccess> gf3daccess;
                                       ^

Tensor<std::array<int, 4>> g3dinds;
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: member variable 'g3dinds' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  Tensor<std::array<int, 4>> g3dinds;
                             ^

Comment thread
dschwoerer marked this conversation as resolved.

// Basis functions for cubic Hermite spline interpolation
// see http://en.wikipedia.org/wiki/Cubic_Hermite_spline
// The h00 and h01 basis functions are applied to the function itself
Expand All @@ -160,23 +173,28 @@ protected:

std::vector<Field3D> newWeights;

#if HS_USE_PETSC
#if BOUT_HAS_PETSC
PetscLib* petsclib;
bool isInit{false};
Mat petscWeights;
Vec rhs, result;
Mat petscWeights{};
Comment thread
dschwoerer marked this conversation as resolved.
Vec rhs{}, result{};
Comment thread
dschwoerer marked this conversation as resolved.
Comment thread
dschwoerer marked this conversation as resolved.
#endif

/// Factors to allow for some wiggleroom
BoutReal abs_fac_monotonic{1e-2};
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: member variable 'abs_fac_monotonic' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  BoutReal abs_fac_monotonic{1e-2};
           ^

BoutReal rel_fac_monotonic{1e-1};
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: member variable 'rel_fac_monotonic' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  BoutReal rel_fac_monotonic{1e-1};
           ^


public:
XZHermiteSpline(Mesh* mesh = nullptr, [[maybe_unused]] Options* options = nullptr)
: XZHermiteSpline(0, mesh) {}
XZHermiteSpline(int y_offset = 0, Mesh* mesh = nullptr);
XZHermiteSpline(const BoutMask& mask, int y_offset = 0, Mesh* mesh = nullptr)
: XZHermiteSpline(y_offset, mesh) {
XZHermiteSplineBase(Mesh* mesh = nullptr, [[maybe_unused]] Options* options = nullptr)
: XZHermiteSplineBase(0, mesh, options) {}
XZHermiteSplineBase(int y_offset = 0, Mesh* mesh = nullptr, Options* options = nullptr);
XZHermiteSplineBase(const BoutMask& mask, int y_offset = 0, Mesh* mesh = nullptr,
Options* options = nullptr)
: XZHermiteSplineBase(y_offset, mesh, options) {
setRegion(regionFromMask(mask, localmesh));
}
~XZHermiteSpline() {
#if HS_USE_PETSC
~XZHermiteSplineBase() override {
#if BOUT_HAS_PETSC
if (isInit) {
MatDestroy(&petscWeights);
VecDestroy(&rhs);
Expand Down Expand Up @@ -205,61 +223,21 @@ public:
getWeightsForYApproximation(int i, int j, int k, int yoffset) override;
};

/// Monotonic Hermite spline interpolator
///
/// Similar to XZHermiteSpline, so uses most of the same code.
/// Forces the interpolated result to be in the range of the
/// neighbouring cell values. This prevents unphysical overshoots,
/// but also degrades accuracy near maxima and minima.
/// Perhaps should only impose near boundaries, since that is where
/// problems most obviously occur.
///
/// You can control how tight the clipping to the range of the neighbouring cell
/// values through ``rtol`` and ``atol``:
///
/// diff = (max_of_neighours - min_of_neighours) * rtol + atol
///
/// and the interpolated value is instead clipped to the range
/// ``[min_of_neighours - diff, max_of_neighours + diff]``
class XZMonotonicHermiteSpline : public XZHermiteSpline {
/// Absolute tolerance for clipping
BoutReal atol = 0.0;
/// Relative tolerance for clipping
BoutReal rtol = 1.0;

public:
XZMonotonicHermiteSpline(Mesh* mesh = nullptr, Options* options = nullptr)
: XZHermiteSpline(0, mesh),
atol{(*options)["atol"]
.doc("Absolute tolerance for clipping overshoot")
.withDefault(0.0)},
rtol{(*options)["rtol"]
.doc("Relative tolerance for clipping overshoot")
.withDefault(1.0)} {
if (localmesh->getNXPE() > 1) {
throw BoutException("Do not support MPI splitting in X");
}
}
XZMonotonicHermiteSpline(int y_offset = 0, Mesh* mesh = nullptr)
: XZHermiteSpline(y_offset, mesh) {
if (localmesh->getNXPE() > 1) {
throw BoutException("Do not support MPI splitting in X");
}
}
XZMonotonicHermiteSpline(const BoutMask& mask, int y_offset = 0, Mesh* mesh = nullptr)
: XZHermiteSpline(mask, y_offset, mesh) {
if (localmesh->getNXPE() > 1) {
throw BoutException("Do not support MPI splitting in X");
}
}

using XZHermiteSpline::interpolate;
/// Interpolate using precalculated weights.
/// This function is called by the other interpolate functions
/// in the base class XZHermiteSpline.
Field3D interpolate(const Field3D& f,
const std::string& region = "RGN_NOBNDRY") const override;
};
using XZMonotonicHermiteSplineSerial =
XZHermiteSplineBase<true, implementation_type::new_weights>;
using XZHermiteSplineSerial =
XZHermiteSplineBase<false, implementation_type::new_weights>;
using XZMonotonicHermiteSplineLegacy =
XZHermiteSplineBase<true, implementation_type::legacy>;
using XZHermiteSplineLegacy = XZHermiteSplineBase<false, implementation_type::legacy>;
#if BOUT_HAS_PETSC
using XZMonotonicHermiteSpline = XZHermiteSplineBase<true, implementation_type::petsc>;
using XZHermiteSpline = XZHermiteSplineBase<false, implementation_type::petsc>;
#else
using XZMonotonicHermiteSpline =
XZHermiteSplineBase<true, implementation_type::new_weights>;
using XZHermiteSpline = XZHermiteSplineBase<false, implementation_type::new_weights>;
#endif

/// XZLagrange4pt interpolation class
///
Expand Down
2 changes: 2 additions & 0 deletions include/bout/mesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ public:
virtual int getXProcIndex() const = 0; ///< This processor's index in X direction
virtual int getYProcIndex() const = 0; ///< This processor's index in Y direction
virtual int getZProcIndex() const = 0; ///< This processor's index in Z direction
/// The index of a processor with given X, Y, and Z index
virtual int getProcIndex(int X, int Y, int Z) const = 0;

// X communications
virtual bool firstX()
Expand Down
2 changes: 1 addition & 1 deletion include/bout/msg_stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public:
}

void pop() {}
void pop(int [[maybe_unused]] id) {}
void pop([[maybe_unused]] int id) {}
void clear() {}

void dump() {}
Expand Down
3 changes: 2 additions & 1 deletion include/bout/region.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class BoutMask;
BOUT_FOR_OMP(index, (region), for schedule(BOUT_OPENMP_SCHEDULE) nowait)
// NOLINTEND(cppcoreguidelines-macro-usage,bugprone-macro-parentheses)

enum class IND_TYPE { IND_3D = 0, IND_2D = 1, IND_PERP = 2 };
enum class IND_TYPE { IND_3D = 0, IND_2D = 1, IND_PERP = 2, IND_GLOBAL_3D = 3 };
Comment thread
ZedThree marked this conversation as resolved.

/// Indices base class for Fields -- Regions are dereferenced into these
///
Expand Down Expand Up @@ -386,6 +386,7 @@ inline SpecificInd<N> operator-(SpecificInd<N> lhs, const SpecificInd<N>& rhs) {
using Ind3D = SpecificInd<IND_TYPE::IND_3D>;
using Ind2D = SpecificInd<IND_TYPE::IND_2D>;
using IndPerp = SpecificInd<IND_TYPE::IND_PERP>;
using IndG3D = SpecificInd<IND_TYPE::IND_GLOBAL_3D>;

/// Get string representation of Ind3D
inline std::string toString(const Ind3D& i) {
Expand Down
4 changes: 4 additions & 0 deletions src/mesh/impls/bout/boutmesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,8 @@ int BoutMesh::load() {
PE_XIND = MYPE % NXPE;
PE_ZIND = 0;

ASSERT2(MYPE == getProcIndex(PE_XIND, PE_YIND, PE_ZIND));
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 "ASSERT2" is directly included [misc-include-cleaner]

  ASSERT2(MYPE == getProcIndex(PE_XIND, PE_YIND, PE_ZIND));
  ^


// Set the other grid sizes from nx, ny, nz
setDerivedGridSizes();

Expand Down Expand Up @@ -1015,6 +1017,8 @@ void BoutMesh::createXBoundaries() {
}
}

int BoutMesh::getProcIndex(int X, int Y, int Z) const { return Y * NXPE + X; }
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: '*' has higher precedence than '+'; add parentheses to explicitly specify the order of operations [readability-math-missing-parentheses]

Suggested change
int BoutMesh::getProcIndex(int X, int Y, int Z) const { return Y * NXPE + X; }
int BoutMesh::getProcIndex(int X, int Y, int Z) const { return (Y * NXPE) + X; }

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: parameter 'Z' is unused [misc-unused-parameters]

Suggested change
int BoutMesh::getProcIndex(int X, int Y, int Z) const { return Y * NXPE + X; }
int BoutMesh::getProcIndex(int X, int Y, int /*Z*/) const { return Y * NXPE + X; }

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: unused parameter 'Z' [clang-diagnostic-unused-parameter]

int BoutMesh::getProcIndex(int X, int Y, int Z) const { return Y * NXPE + X; }
                                             ^


void BoutMesh::createYBoundaries() {
if (MYG <= 0) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/mesh/impls/bout/boutmesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public:
int getXProcIndex() const override; ///< This processor's index in X direction
int getYProcIndex() const override; ///< This processor's index in Y direction
int getZProcIndex() const override; ///< This processor's index in Z direction
int getProcIndex(int X, int Y, int Z) const override;

/////////////////////////////////////////////
// X communications
Expand Down
Loading
Loading