Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do things automatically for FCI #3004

Open
wants to merge 96 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
3583476
Switch hermite_spline_xz to index
dschwoerer Dec 16, 2021
4ec74ef
Switch toward regions
dschwoerer Sep 22, 2021
d096020
Switch to regions for FCI regions
dschwoerer Sep 24, 2021
d2a81bf
Use region_id in interpolation
dschwoerer Nov 19, 2021
ea5640f
Switch hermite_spline_xz to index
dschwoerer Dec 16, 2021
089ddfa
Improve hermitesplinesXZ
dschwoerer Nov 16, 2022
de7d1de
Cleanup
dschwoerer Nov 17, 2022
8a1c230
Enable splitting in X using PETSc
dschwoerer Feb 2, 2023
8234ccf
Test parallised interpolation if PETSc is found
dschwoerer Feb 2, 2023
9525e2c
Fall back to region if not shifted
dschwoerer Feb 2, 2023
b62082c
Split in X only if we have PETSc
dschwoerer Feb 2, 2023
e147bc5
Add test-interpolate for splitting in X
dschwoerer Feb 2, 2023
62d5bbe
Cleanup
dschwoerer Feb 2, 2023
5c32415
Only run in parallel if we split in X
dschwoerer Feb 2, 2023
a4a28c6
Delete object
dschwoerer Feb 3, 2023
0e28dc1
Create PetscVecs only once
dschwoerer Feb 3, 2023
66bde04
Be more general about cleaning up before BoutFinialise
dschwoerer Feb 3, 2023
adba877
Run different interpolations in the fci test
dschwoerer Feb 3, 2023
cbaf894
Fix parallel boundary region with x splitting
dschwoerer Feb 7, 2023
5673f0c
Add integrated test for FCI X splitting
dschwoerer Feb 7, 2023
9149bf4
Apply black changes
dschwoerer Feb 8, 2023
a088700
Apply clang-format changes
dschwoerer Feb 8, 2023
32ea2fd
Apply clang-format changes
dschwoerer Feb 8, 2023
faac69c
Apply clang-format changes
dschwoerer Feb 8, 2023
0ee0d07
Merge remote-tracking branch 'origin/next' into fci-splitting
dschwoerer Feb 4, 2024
49cd985
Merge remote-tracking branch 'origin/next' into fci-splitting
dschwoerer Feb 4, 2024
4566405
Apply black changes
dschwoerer Feb 4, 2024
4935742
CI: install wget
dschwoerer Feb 4, 2024
01a436c
Merge remote-tracking branch 'origin/next' into fci-splitting
dschwoerer Feb 4, 2024
147a872
Apply clang-format changes
dschwoerer Feb 4, 2024
cee68f2
Add asserts to serial methods to avoid using in parallel
dschwoerer Feb 7, 2024
15aaa05
Apply clang-format changes
dschwoerer Feb 7, 2024
eba722b
Merge branch 'par-bc-cleanup' into fci-splitting
dschwoerer Feb 7, 2024
30ea7e3
Remove accidentially added files
dschwoerer Feb 13, 2024
66ff716
Merge remote-tracking branch 'origin/next' into fci-splitting
dschwoerer Feb 13, 2024
10d320f
Use parallel_neumann as BC
dschwoerer Feb 15, 2024
4b05708
fix usage of f-string
dschwoerer Feb 15, 2024
60224e4
Use localmesh
dschwoerer Feb 19, 2024
608bb5d
add PETSc requirement for MPI test
dschwoerer Feb 19, 2024
88741c5
Update header location
dschwoerer Feb 19, 2024
09f609b
More const correctness
dschwoerer Feb 19, 2024
d46efba
Merge branch 'origin/next' into fci-splitting
dschwoerer Mar 19, 2024
1fb921e
Add some asserts for non parallelised XZ interpolation
dschwoerer Feb 2, 2023
4a79fb4
enable openmp for sundials if it is enabled for BOUT++
dschwoerer Feb 23, 2023
b5bd5f0
Add required interfaces
dschwoerer Nov 3, 2023
6819718
Add maskFromRegion
dschwoerer Mar 19, 2024
fa357c1
Add isFci to check if a field is a FCI field.
dschwoerer Mar 19, 2024
ca59edb
Improve isFci
dschwoerer Nov 3, 2023
8b1fbba
Apply clang-format changes
dschwoerer Mar 19, 2024
23d309f
Make isFci a member function and add missing func
dschwoerer Mar 20, 2024
4bbd9ba
Add option to automatically compute parallel fields
dschwoerer Nov 3, 2023
4fac018
Explicitly set parallel boundary order
dschwoerer Nov 6, 2023
29a195f
Make Field2d and Field3D more similar
dschwoerer Nov 6, 2023
4ee8630
Do more things automagically
dschwoerer Nov 6, 2023
2e216be
Allow DDY without parallel slices
dschwoerer Nov 6, 2023
faa1046
Add more fci-auto-magic
dschwoerer Mar 18, 2024
414247b
Add copy function
dschwoerer Mar 18, 2024
6ba17ed
Inherit applyParallelBoundary functions
dschwoerer Mar 18, 2024
b319807
Merge remote-tracking branch 'origin/add-is-fci' into fci-auto
dschwoerer Mar 20, 2024
b814c9b
update calls to isFci
dschwoerer Mar 20, 2024
1260730
Merge remote-tracking branch 'origin/par-bc-improve' into fci-auto
dschwoerer Mar 20, 2024
4a6fdba
Fix remaining usage of free isFci function
dschwoerer Mar 20, 2024
0aca4a5
Merge remote-tracking branch 'origin/par-bc-regions' into fci-auto
dschwoerer Mar 20, 2024
413e54f
Fixup porting to shared_ptr
dschwoerer Mar 20, 2024
d5d7c6a
Update include to moved location
dschwoerer Mar 26, 2024
652be61
Move iteration mostly to iterator
dschwoerer Mar 26, 2024
7d48dbd
Move stencils to separte header
dschwoerer Mar 27, 2024
59cd39d
Add more dummy functions to field2d
dschwoerer Mar 27, 2024
127fc9a
Add basic boundary region iterator
dschwoerer Mar 27, 2024
9b68bf2
Provide a new boundary iterator based on RangeIterator
dschwoerer Apr 9, 2024
052e735
Fix: remove broken code
dschwoerer Aug 9, 2024
d6ddf3b
Add missing header
dschwoerer Sep 30, 2024
9fd8aa8
Fall back to non fv div_par for fci
dschwoerer Jul 2, 2024
44084cc
Add isFci also to mesh
dschwoerer Jul 2, 2024
81dcc62
fixup again
dschwoerer Aug 9, 2024
fa27812
fixup fv_ops
dschwoerer Aug 9, 2024
175f8d7
Always set region for hermite_spline_xz
dschwoerer Aug 9, 2024
f189d4f
Avoid using FV in y direction with FCI
dschwoerer Aug 9, 2024
697c89e
Add option to disallow calculating parallel fields
dschwoerer Aug 9, 2024
2b47ecd
Add const version for getCoordinates
dschwoerer Aug 9, 2024
78611d0
Add simple interface to store parallel fields
dschwoerer Aug 9, 2024
0149bd0
ensure we dont mix non-fci BCs with fci
dschwoerer Jul 5, 2024
a307426
Only check hasBndry*Y if they would be included
dschwoerer Jul 2, 2024
cd288e9
Add const version for getCoordinates
dschwoerer Aug 9, 2024
003c466
Merge branch 'next' of github.com:boutproject/BOUT-dev into fci-auto
dschwoerer Oct 22, 2024
089baa8
Remove duplicate functions
dschwoerer Aug 9, 2024
992681d
Merge branch 'is-fci-mesh' into fci-auto
dschwoerer Oct 22, 2024
1d6ecb0
Apply clang-format changes
dschwoerer Oct 22, 2024
a63ecfc
Fix floor() for non-Field3D
dschwoerer Oct 22, 2024
2d9d524
Avoid warning from unused-argument
dschwoerer Oct 22, 2024
7aa8d01
Set field to be aligned
dschwoerer Oct 22, 2024
25fe475
Use new iterator
dschwoerer Oct 22, 2024
255eccb
Apply clang-format changes
dschwoerer Oct 22, 2024
c69bff5
Fix default region name
dschwoerer Oct 1, 2024
1505840
Update boundary name
dschwoerer Oct 22, 2024
ae578be
Ensure we have a valid region
dschwoerer Oct 22, 2024
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: 1 addition & 1 deletion .ci_fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ then
# Ignore weak depencies
echo "install_weak_deps=False" >> /etc/dnf/dnf.conf
time dnf -y install dnf5
time dnf5 -y install dnf5-plugins cmake python3-zoidberg python3-natsort
time dnf5 -y install dnf5-plugins cmake python3-zoidberg python3-natsort wget
# Allow to override packages - see #2073
time dnf5 copr enable -y davidsch/fixes4bout || :
time dnf5 -y upgrade
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,9 @@ else()
endif()
set(BOUT_USE_METRIC_3D ${BOUT_ENABLE_METRIC_3D})

option(BOUT_ENABLE_FCI_AUTOMAGIC "Enable (slow?) automatic features for FCI" ON)
set(BOUT_USE_FCI_AUTOMAGIC ${BOUT_ENABLE_FCI_AUTOMAGIC})

include(CheckCXXSourceCompiles)
check_cxx_source_compiles("int main() { const char* name = __PRETTY_FUNCTION__; }"
HAS_PRETTY_FUNCTION)
Expand Down
16 changes: 15 additions & 1 deletion cmake/BOUT++functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ endfunction()
#
function(bout_add_integrated_or_mms_test BUILD_CHECK_TARGET TESTNAME)
set(options USE_RUNTEST USE_DATA_BOUT_INP)
set(oneValueArgs EXECUTABLE_NAME PROCESSORS)
set(oneValueArgs EXECUTABLE_NAME PROCESSORS DOWNLOAD DOWNLOAD_NAME)
set(multiValueArgs SOURCES EXTRA_FILES REQUIRES CONFLICTS TESTARGS EXTRA_DEPENDS)
cmake_parse_arguments(BOUT_TEST_OPTIONS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

Expand Down Expand Up @@ -202,6 +202,20 @@ function(bout_add_integrated_or_mms_test BUILD_CHECK_TARGET TESTNAME)
add_custom_target(${TESTNAME})
endif()

if (BOUT_TEST_OPTIONS_DOWNLOAD)
if (NOT BOUT_TEST_OPTIONS_DOWNLOAD_NAME)
message(FATAL_ERROR "We need DOWNLOAD_NAME if we should DOWNLOAD!")
endif()
set(output )
add_custom_command(OUTPUT ${BOUT_TEST_OPTIONS_DOWNLOAD_NAME}
COMMAND wget ${BOUT_TEST_OPTIONS_DOWNLOAD} -O ${BOUT_TEST_OPTIONS_DOWNLOAD_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Downloading ${BOUT_TEST_OPTIONS_DOWNLOAD_NAME}"
)
add_custom_target(download_test_data DEPENDS ${BOUT_TEST_OPTIONS_DOWNLOAD_NAME})
add_dependencies(${TESTNAME} download_test_data)
endif()

if (BOUT_TEST_OPTIONS_EXTRA_DEPENDS)
add_dependencies(${TESTNAME} ${BOUT_TEST_OPTIONS_EXTRA_DEPENDS})
endif()
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupBOUTThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ if (BOUT_USE_SUNDIALS)
set(EXAMPLES_ENABLE_C OFF CACHE BOOL "" FORCE)
set(EXAMPLES_INSTALL OFF CACHE BOOL "" FORCE)
set(ENABLE_MPI ${BOUT_USE_MPI} CACHE BOOL "" FORCE)
set(ENABLE_OPENMP OFF CACHE BOOL "" FORCE)
set(ENABLE_OPENMP ${BOUT_USE_OPENMP} CACHE BOOL "" FORCE)
if (BUILD_SHARED_LIBS)
set(BUILD_STATIC_LIBS OFF CACHE BOOL "" FORCE)
else()
Expand Down
1 change: 1 addition & 0 deletions cmake_build_defines.hxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#cmakedefine BOUT_METRIC_TYPE @BOUT_METRIC_TYPE@
#cmakedefine01 BOUT_USE_METRIC_3D
#cmakedefine01 BOUT_USE_MSGSTACK
#cmakedefine01 BOUT_USE_FCI_AUTOMAGIC

// CMake build does not support legacy interface
#define BOUT_HAS_LEGACY_NETCDF 0
Expand Down
4 changes: 2 additions & 2 deletions examples/fci-wave-logn/boundary/BOUT.inp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ bndry_par_ydown = parallel_neumann_o2

[v]

bndry_par_yup = parallel_dirichlet(+1.0)
bndry_par_ydown = parallel_dirichlet(-1.0)
bndry_par_yup = parallel_dirichlet_o2(+1.0)
bndry_par_ydown = parallel_dirichlet_o2(-1.0)
2 changes: 1 addition & 1 deletion examples/fci-wave-logn/div-integrate/BOUT.inp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ bndry_par_ydown = parallel_neumann_o2

[v]

bndry_par_all = parallel_dirichlet
bndry_par_all = parallel_dirichlet_o2
2 changes: 1 addition & 1 deletion examples/fci-wave-logn/expanded/BOUT.inp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ bndry_par_ydown = parallel_neumann_o2

[v]

bndry_par_all = parallel_dirichlet
bndry_par_all = parallel_dirichlet_o2
2 changes: 1 addition & 1 deletion examples/fci-wave/div-integrate/BOUT.inp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ bndry_par_ydown = parallel_neumann_o2

[v]

bndry_par_all = parallel_dirichlet
bndry_par_all = parallel_dirichlet_o2
2 changes: 1 addition & 1 deletion examples/fci-wave/div/BOUT.inp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ bndry_par_ydown = parallel_neumann_o2

[v]

bndry_par_all = parallel_dirichlet
bndry_par_all = parallel_dirichlet_o2
2 changes: 1 addition & 1 deletion examples/fci-wave/logn/BOUT.inp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ bndry_par_ydown = parallel_neumann_o2

[nv]

bndry_par_all = parallel_dirichlet
bndry_par_all = parallel_dirichlet_o2
117 changes: 117 additions & 0 deletions include/bout/boundary_iterator.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#pragma once

#include "bout/mesh.hxx"
#include "bout/sys/parallel_stencils.hxx"
#include "bout/sys/range.hxx"

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: destructor of 'BoundaryRegionIter' is public and non-virtual [cppcoreguidelines-virtual-class-destructor]

class BoundaryRegionIter {
      ^
Additional context

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

class BoundaryRegionIter {
      ^

public:
BoundaryRegionIter(int x, int y, int bx, int by, Mesh* mesh)
dschwoerer marked this conversation as resolved.
Show resolved Hide resolved
dschwoerer marked this conversation as resolved.
Show resolved Hide resolved
: dir(bx + by), x(x), y(y), bx(bx), by(by), localmesh(mesh) {
ASSERT3(bx * by == 0);
}
bool operator!=(const BoundaryRegionIter& rhs) { return ind() != rhs.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: method 'operator!=' can be made const [readability-make-member-function-const]

Suggested change
bool operator!=(const BoundaryRegionIter& rhs) { return ind() != rhs.ind(); }
bool operator!=(const BoundaryRegionIter& rhs) const { return ind() != rhs.ind(); }


Ind3D ind() const { return xyz2ind(x, y, z); }
BoundaryRegionIter& operator++() {
ASSERT3(z < nz());
z++;
if (z == nz()) {
z = 0;
_next();
}
return *this;
}
virtual void _next() = 0;
BoundaryRegionIter& operator*() { return *this; }

void dirichlet_o2(Field3D& f, BoutReal value) const {
ynext(f) = parallel_stencil::dirichlet_o2(1, f[ind()], 0.5, value);
}

BoutReal extrapolate_grad_o2(const Field3D& f) const { return f[ind()] - yprev(f); }

BoutReal extrapolate_sheath_o2(const Field3D& f) const {
return (f[ind()] * 3 - yprev(f)) * 0.5;
}

BoutReal extrapolate_next_o2(const Field3D& f) const { return 2 * f[ind()] - yprev(f); }

BoutReal
extrapolate_next_o2(const std::function<BoutReal(int yoffset, Ind3D ind)>& f) const {
return 2 * f(0, ind()) - f(0, ind().yp(-by).xp(-bx));
}

BoutReal interpolate_sheath(const Field3D& f) const {
return (f[ind()] + ynext(f)) * 0.5;
}

BoutReal& ynext(Field3D& f) const { return f[ind().yp(by).xp(bx)]; }
const BoutReal& ynext(const Field3D& f) const { return f[ind().yp(by).xp(bx)]; }
BoutReal& yprev(Field3D& f) const { return f[ind().yp(-by).xp(-bx)]; }
const BoutReal& yprev(const Field3D& f) const { return f[ind().yp(-by).xp(-bx)]; }

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;
            ^

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;
            ^


protected:
int z{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: member variable 'z' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  int z{0};
      ^

int x;
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 'x' has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

  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;
      ^

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;
            ^

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;
            ^

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;
            ^

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;
            ^


private:
Mesh* localmesh;
int nx() const { return localmesh->LocalNx; }
int ny() const { return localmesh->LocalNy; }
int nz() const { return localmesh->LocalNz; }

Ind3D xyz2ind(int x, int y, int z) const {
return Ind3D{(x * ny() + y) * nz() + z, ny(), nz()};
}
};

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:73: make it public and virtual

class BoundaryRegionIterY : public BoundaryRegionIter {
      ^

public:
BoundaryRegionIterY(RangeIterator r, int y, int dir, bool is_end, Mesh* mesh)
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 'r' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
BoundaryRegionIterY(RangeIterator r, int y, int dir, bool is_end, Mesh* mesh)
BoundaryRegionIterY(const RangeIterator& r, int y, int dir, bool is_end, Mesh* mesh)

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: parameter name 'r' is too short, expected at least 3 characters [readability-identifier-length]

  BoundaryRegionIterY(RangeIterator r, int y, int dir, bool is_end, Mesh* mesh)
                                    ^

: BoundaryRegionIter(r.ind, y, 0, dir, mesh), r(r), is_end(is_end) {}

bool operator!=(const BoundaryRegionIterY& rhs) {
ASSERT2(y == rhs.y);
if (is_end) {
if (rhs.is_end) {
return false;
}
return !rhs.r.isDone();
}
if (rhs.is_end) {
return !r.isDone();
}
return x != rhs.x;
}

virtual void _next() override {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'virtual' is redundant since the function is already declared 'override' [cppcoreguidelines-explicit-virtual-functions]

Suggested change
virtual void _next() override {
void _next() override {

++r;
x = r.ind;
}

private:
RangeIterator r;
bool is_end;
};

class NewBoundaryRegionY {
public:
NewBoundaryRegionY(Mesh* mesh, bool lower, RangeIterator r)
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 'r' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]

Suggested change
NewBoundaryRegionY(Mesh* mesh, bool lower, RangeIterator r)
NewBoundaryRegionY(Mesh* mesh, bool lower, const RangeIterator& r)

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: parameter name 'r' is too short, expected at least 3 characters [readability-identifier-length]

  NewBoundaryRegionY(Mesh* mesh, bool lower, RangeIterator r)
                                                           ^

: mesh(mesh), lower(lower), r(std::move(r)) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg]

Suggested change
: mesh(mesh), lower(lower), r(std::move(r)) {}
: mesh(mesh), lower(lower), r(r) {}

BoundaryRegionIterY begin(bool begin = true) {
return BoundaryRegionIterY(r, lower ? mesh->ystart : mesh->yend, lower ? -1 : +1,
!begin, mesh);
}
BoundaryRegionIterY end() { return begin(false); }

private:
Mesh* mesh;
bool lower;
RangeIterator r;
};
3 changes: 3 additions & 0 deletions include/bout/boundary_region.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class BoundaryRegion;
#ifndef BOUT_BNDRY_REGION_H
#define BOUT_BNDRY_REGION_H

#include "bout/mesh.hxx"
#include "bout/region.hxx"
#include "bout/sys/parallel_stencils.hxx"
#include <string>
#include <utility>

Expand Down
5 changes: 3 additions & 2 deletions include/bout/coordinates.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ public:
transform = std::move(pt);
}

bool hasParallelTransform() const { return transform != nullptr; }
/// Return the parallel transform
ParallelTransform& getParallelTransform() {
ASSERT1(transform != nullptr);
ParallelTransform& getParallelTransform() const {
ASSERT1(hasParallelTransform());
return *transform;
}

Expand Down
24 changes: 23 additions & 1 deletion include/bout/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public:

std::string name;

bool isFci() const;

#if CHECK > 0
// Routines to test guard/boundary cells set

Expand Down Expand Up @@ -677,7 +679,27 @@ inline T floor(const T& var, BoutReal f, const std::string& rgn = "RGN_ALL") {
result[d] = f;
}
}

if constexpr (bout::utils::is_Field3D<T>()) {
#if BOUT_USE_FCI_AUTOMAGIC
if (var.isFci()) {
for (size_t i = 0; i < result.numberParallelSlices(); ++i) {
BOUT_FOR(d, result.yup(i).getRegion(rgn)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: loop variable name 'd' is too short, expected at least 2 characters [readability-identifier-length]

{
                   ^

if (result.yup(i)[d] < f) {
result.yup(i)[d] = f;
}
}
BOUT_FOR(d, result.ydown(i).getRegion(rgn)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: loop variable name 'd' is too short, expected at least 2 characters [readability-identifier-length]

}
                   ^

if (result.ydown(i)[d] < f) {
result.ydown(i)[d] = f;
}
}
}
} else
#endif
{
result.clearParallelSlices();
}
}
return result;
}

Expand Down
7 changes: 5 additions & 2 deletions include/bout/field2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ public:
return *this;
}

/// Check if this field has yup and ydown fields
/// Dummy functions to increase portability
bool hasParallelSlices() const { return true; }
void calcParallelSlices() const {}
void clearParallelSlices() {}
int numberParallelSlices() { return 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: method 'numberParallelSlices' can be made static [readability-convert-member-functions-to-static]

Suggested change
int numberParallelSlices() { return 0; }
static int numberParallelSlices() { return 0; }


Field2D& yup(std::vector<Field2D>::size_type UNUSED(index) = 0) { return *this; }
const Field2D& yup(std::vector<Field2D>::size_type UNUSED(index) = 0) const {
Expand Down Expand Up @@ -280,7 +283,7 @@ public:

friend void swap(Field2D& first, Field2D& second) noexcept;

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

private:
/// Internal data array. Handles allocation/freeing of memory
Expand Down
29 changes: 29 additions & 0 deletions include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,38 @@ public:
#endif
}

/// get number of parallel slices
size_t numberParallelSlices() const {
// Do checks
hasParallelSlices();
return yup_fields.size();
}

/// Check if this field has yup and ydown fields
/// Return reference to yup field
Field3D& yup(std::vector<Field3D>::size_type index = 0) {
ASSERT2(index < yup_fields.size());
ASSERT2(allow_parallel_slices);
return yup_fields[index];
}
/// Return const reference to yup field
const Field3D& yup(std::vector<Field3D>::size_type index = 0) const {
ASSERT2(index < yup_fields.size());
ASSERT2(allow_parallel_slices);
return yup_fields[index];
}

/// Return reference to ydown field
Field3D& ydown(std::vector<Field3D>::size_type index = 0) {
ASSERT2(index < ydown_fields.size());
ASSERT2(allow_parallel_slices);
return ydown_fields[index];
}

/// Return const reference to ydown field
const Field3D& ydown(std::vector<Field3D>::size_type index = 0) const {
ASSERT2(index < ydown_fields.size());
ASSERT2(allow_parallel_slices);
return ydown_fields[index];
}

Expand Down Expand Up @@ -473,6 +484,11 @@ public:
friend class Vector2D;

Field3D& calcParallelSlices();
void allowParallelSlices([[maybe_unused]] bool allow) {
#if CHECK > 0
allow_parallel_slices = allow;
#endif
}

void applyBoundary(bool init = false) override;
void applyBoundary(BoutReal t);
Expand All @@ -487,6 +503,7 @@ public:
/// Note: does not just copy values in boundary region.
void setBoundaryTo(const Field3D& f3d);

using FieldData::applyParallelBoundary;
void applyParallelBoundary() override;
void applyParallelBoundary(BoutReal t) override;
void applyParallelBoundary(const std::string& condition) override;
Expand Down Expand Up @@ -514,6 +531,8 @@ private:

/// RegionID over which the field is valid
std::optional<size_t> regionID;

bool allow_parallel_slices{true};
};

// Non-member overloaded operators
Expand Down Expand Up @@ -656,4 +675,14 @@ bool operator==(const Field3D& a, const Field3D& b);
/// Output a string describing a Field3D to a stream
std::ostream& operator<<(std::ostream& out, const Field3D& value);

inline Field3D copy(const Field3D& f) {
Field3D result{f};
result.allocate();
for (size_t i = 0; i < result.numberParallelSlices(); ++i) {
result.yup(i).allocate();
result.ydown(i).allocate();
}
return result;
}

#endif /* BOUT_FIELD3D_H */
3 changes: 2 additions & 1 deletion include/bout/field_data.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class BoundaryOpPar;
class Coordinates;
class Mesh;

#include "bout/boundary_region.hxx"
class BoundaryRegion;
//#include "bout/boundary_region.hxx"
class BoundaryRegionPar;
enum class BndryLoc;

Expand Down
Loading