Skip to content

New Y-Boundaries for unified sheath code#3308

Open
dschwoerer wants to merge 65 commits intonextfrom
new-par-bc-unified
Open

New Y-Boundaries for unified sheath code#3308
dschwoerer wants to merge 65 commits intonextfrom
new-par-bc-unified

Conversation

@dschwoerer
Copy link
Contributor

This allows to implement unified BCs for yup/ydown as well as FCI / FA.
Taking into acount things like whether the boundary is next to the domain, or between the parallel slices.

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

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

protected:
int z{0};
int x;
int y;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member variable 'y' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  int y;
      ^

int z{0};
int x;
int y;
const int bx;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member 'bx' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]

  const int bx;
            ^

int z{0};
int x;
int y;
const int bx;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member variable 'bx' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  const int bx;
            ^

int x;
int y;
const int bx;
const int by;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member 'by' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]

  const int by;
            ^

int x;
int y;
const int bx;
const int by;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member variable 'by' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  const int by;
            ^

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

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

}
};

class BoundaryRegionIterY : public BoundaryRegionIter {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: destructor of 'BoundaryRegionIterY' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class BoundaryRegionIterY : public BoundaryRegionIter {
      ^
Additional context

include/bout/boundary_iterator.hxx:164: make it public and virtual

class BoundaryRegionIterY : public BoundaryRegionIter {
      ^

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

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


bool contains(const int ix, const int iy, const int iz) const {
const auto i2 = xyz2ind(ix, iy, iz, localmesh);
for (auto i1 : bndry_points) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: replace loop by 'std::any_of()' [readability-use-anyofallof]

    for (auto i1 : bndry_points) {
    ^

return BoundaryRegionParIter(bndry_points, bndry_points.end(), dir, localmesh);
}

const int dir;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member 'dir' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]

  const int dir;
            ^

return BoundaryRegionParIter(bndry_points, bndry_points.end(), dir, localmesh);
}

const int dir;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: member variable 'dir' has public visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  const int dir;
            ^

Makes it easier to reuse for other code
Mimicks the parallel case, to write FCI independent code
The boundary region does not match what is done for the parallel case,
thus porting it to a iterator does not work.
hasBndryUpperY / hasBndryLowerY does not work for FCI and thus the
request does not make sense / can be configured to throw.
Thus it should not be checked if it is not needed.
BoundaryRegionIter has been delted
This allows to extend the boundary code to place the boundary further
away from the boundary.
This is more general and takes the offset() into account, and thus works
for cases where the boundary is between the first and second guard cell
Previously only the first boundary point was set
Taken from hermes-3, adopted for higher order
This allows to write code for FCI and non-FCI using templates.
Directly iterate over the points
@dschwoerer
Copy link
Contributor Author

I rebased this, and applied clang-format to all commits, with respect to origin/next.

I fail to see why clang-format in CI is not happy. I am using git-clang-format-21.1.8-4.fc43.x86_64.

And this is the reason why I think having CI fail for missing clang-format is an issue.

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

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

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

#include "bout/sys/range.hxx"
#include <functional>
#include <utility>

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 utility is not used directly [misc-include-cleaner]

Suggested change

#include <functional>
#include <utility>

class BoundaryRegionIter {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'BoundaryRegionIter' defines a 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 BoundaryRegionIter {
      ^

}

void limit_at_least(Field3D& f, BoutReal value) const {
ynext(f) = std::max(ynext(f), 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::max" is directly included [misc-include-cleaner]

include/bout/boundary_iterator.hxx:12:

- #include <functional>
+ #include <algorithm>
+ #include <functional>

}
};

class BoundaryRegionIterY : public BoundaryRegionIter {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: class 'BoundaryRegionIterY' defines a 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 BoundaryRegionIterY : public BoundaryRegionIter {
      ^


class BoundaryRegionIterY : public BoundaryRegionIter {
public:
virtual ~BoundaryRegionIterY() = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]

Suggested change
virtual ~BoundaryRegionIterY() = default;
~BoundaryRegionIterY() override = default;


BoutReal extrapolate_sheath_free(const Field3D& f, SheathLimitMode mode) const {
const auto fac = valid() > 0 ? limitFreeScale(yprev(f), ythis(f), mode)
: (mode == SheathLimitMode::linear_free ? 0 : 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                 : (mode == SheathLimitMode::linear_free ? 0 : 1);
                                    ^
Additional context

include/bout/parallel_boundary_region.hxx:293: parent conditional operator here

    const auto fac = valid() > 0 ? limitFreeScale(yprev(f), ythis(f), mode)
                     ^


void set_free(Field3D& f, SheathLimitMode mode) const {
const auto fac = valid() > 0 ? limitFreeScale(yprev(f), ythis(f), mode)
: (mode == SheathLimitMode::linear_free ? 0 : 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: conditional operator is used as sub-expression of parent conditional operator, refrain from using nested conditional operators [readability-avoid-nested-conditional-operator]

                                 : (mode == SheathLimitMode::linear_free ? 0 : 1);
                                    ^
Additional context

include/bout/parallel_boundary_region.hxx:301: parent conditional operator here

    const auto fac = valid() > 0 ? limitFreeScale(yprev(f), ythis(f), mode)
                     ^

boundary->add_point(x, y, z, x + dx, y + offset - (sgn(offset) * 0.5),
z + dz, // Intersection point in local index space
std::abs(offset) - 0.5, // Distance to intersection
defValid, 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: narrowing conversion from 'int' to signed type 'char' is implementation-defined [bugprone-narrowing-conversions]

                          defValid, offset);
                          ^

boundary->add_point(x, y, z, x + dx, y + offset - (sgn(offset) * 0.5),
z + dz, // Intersection point in local index space
std::abs(offset) - 0.5, // Distance to intersection
defValid, 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: narrowing conversion from 'int' to signed type 'signed char' is implementation-defined [bugprone-narrowing-conversions]

                          defValid, offset);
                                    ^

bndry->setValid(0);
for (auto pnt : *bndry) {
for (auto pnt2 : *bndry2) {
#warning this could likely be done faster
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: this could likely be done faster [clang-diagnostic-#warnings]

#warning this could likely be done faster
 ^

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

});
}

bool contains_ylow(Ind3D ind) const { return _contains[0][ind] }
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 "Ind3D" is directly included [misc-include-cleaner]

include/bout/yboundary_regions.hxx:8:

- #include <memory>
+ #include "bout/region.hxx"
+ #include <memory>

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

const bool inner_x =
options["inner_x"].doc("Boundary on inner x?").withDefault<bool>(false);

if (mesh->isFci()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]

    if (mesh->isFci()) {
        ^
Additional context

tests/integrated/test-fci-boundary/get_par_bndry.cxx:23: Assuming the condition is false

  for (int i = 0; i < fields.size(); i++) {
                  ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:23: Loop condition is false. Execution continues on line 40

  for (int i = 0; i < fields.size(); i++) {
  ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:39: Assuming '__begin1' is equal to '__end1'

  for (const auto& name : {"forward_xt_prime", "backward_xt_prime"}) {
                        ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:46: Value assigned to 'mesh'

    Options dummy;
            ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:48: Calling 'YBoundary::init'

    ybndry.init(dummy, mesh);
    ^

include/bout/yboundary_regions.hxx:47: Field 'is_init' is false

    if (is_init) {
        ^

include/bout/yboundary_regions.hxx:47: Taking false branch

    if (is_init) {
    ^

include/bout/yboundary_regions.hxx:53: Assuming pointer value is null

    if (mesh == nullptr) {
        ^

include/bout/yboundary_regions.hxx:53: Taking true branch

    if (mesh == nullptr) {
    ^

include/bout/yboundary_regions.hxx:54: Null pointer value stored to 'mesh'

      mesh = bout::globals::mesh;
      ^

include/bout/yboundary_regions.hxx:66: Called C++ object pointer is null

    if (mesh->isFci()) {
        ^

});
}

bool contains_ylow(Ind3D ind) const { return _contains[0][ind]; }
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 "Ind3D" is directly included [misc-include-cleaner]

include/bout/yboundary_regions.hxx:9:

- #include <memory>
+ #include "bout/region.hxx"
+ #include <memory>

YBoundary ybndry;
ybndry.init(dummy, mesh);

std::vector<Field3D> fields(mesh->ystart * 2 + 1, Field3D{0.0});
Copy link
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
std::vector<Field3D> fields(mesh->ystart * 2 + 1, Field3D{0.0});
std::vector<Field3D> fields((mesh->ystart * 2) + 1, Field3D{0.0});

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

const bool inner_x =
options["inner_x"].doc("Boundary on inner x?").withDefault<bool>(false);

if (mesh->isFci()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]

    if (mesh->isFci()) {
        ^
Additional context

tests/integrated/test-fci-boundary/get_par_bndry.cxx:23: Assuming the condition is false

  for (int i = 0; i < fields.size(); i++) {
                  ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:23: Loop condition is false. Execution continues on line 40

  for (int i = 0; i < fields.size(); i++) {
  ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:39: Assuming '__begin1' is equal to '__end1'

  for (const auto& name : {"forward_xt_prime", "backward_xt_prime"}) {
                        ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:46: Value assigned to 'mesh'

    Options dummy;
            ^

tests/integrated/test-fci-boundary/get_par_bndry.cxx:48: Calling 'YBoundary::init'

    ybndry.init(dummy, mesh);
    ^

include/bout/yboundary_regions.hxx:48: Field 'is_init' is false

    if (is_init) {
        ^

include/bout/yboundary_regions.hxx:48: Taking false branch

    if (is_init) {
    ^

include/bout/yboundary_regions.hxx:54: Assuming pointer value is null

    if (mesh == nullptr) {
        ^

include/bout/yboundary_regions.hxx:54: Taking true branch

    if (mesh == nullptr) {
    ^

include/bout/yboundary_regions.hxx:55: Null pointer value stored to 'mesh'

      mesh = bout::globals::mesh;
      ^

include/bout/yboundary_regions.hxx:67: Called C++ object pointer is null

    if (mesh->isFci()) {
        ^

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


bool contains(const int ix, const int iy, const int iz) const {
const auto i2 = xyz2ind(ix, iy, iz, localmesh);
for (auto i1 : bndry_points) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: replace loop by 'std::ranges::any_of()' [readability-use-anyofallof]

    for (auto i1 : bndry_points) {
    ^

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.

1 participant