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

Fix Field3D::setBoundaryTo parallel boundary conditions #2962

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ public:
/// This uses 2nd order central differences to set the value
/// on the boundary to the value on the boundary in field \p f3d.
/// Note: does not just copy values in boundary region.
///
/// - If f3d has parallel slices then this field must also have them.
/// - If f3d has no parallel slices then this field's parallel slices
/// (if any) will be cleared, and to/fromFieldAligned will be used
/// to set parallel boundary conditions.
void setBoundaryTo(const Field3D& f3d);

void applyParallelBoundary() override;
Expand Down
86 changes: 76 additions & 10 deletions src/field/field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -451,22 +451,88 @@ void Field3D::setBoundaryTo(const Field3D& f3d) {

allocate(); // Make sure data allocated

/// Loop over boundary regions
for (const auto& reg : fieldmesh->getBoundaries()) {
/// Loop within each region
for (reg->first(); !reg->isDone(); reg->next()) {
for (int z = 0; z < nz; z++) {
// Get value half-way between cells
if (!fieldmesh->periodicX) {
// X boundaries
if (fieldmesh->firstX()) {
for (int jy = fieldmesh->ystart; jy <= fieldmesh->yend; ++jy) {
for (int jz = 0; jz < fieldmesh->LocalNz; jz++) {
BoutReal const val =
0.5 * (f3d(fieldmesh->xstart, jy, jz) + f3d(fieldmesh->xstart - 1, jy, jz));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: expression result unused [clang-diagnostic-unused-value]

              0.5 * (f3d(fieldmesh->xstart, jy, jz) + f3d(fieldmesh->xstart - 1, jy, jz));
                  ^

0.5 * (f3d(fieldmesh->xstart, jy, jz) + f3d(fieldmesh->xstart - 1, jy, jz));
(*this)(fieldmesh->xstart - 1, jy, jz) =
2. * val - (*this)(fieldmesh->xstart, jy, jz);
}
}
}
if (fieldmesh->lastX()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jy' [clang-diagnostic-error]

          BoutReal const val = 0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
                                                           ^

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jz' [clang-diagnostic-error]

          BoutReal const val = 0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
                                                               ^

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jy' [clang-diagnostic-error]

          BoutReal const val = 0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
                                                                                              ^

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jz' [clang-diagnostic-error]

          BoutReal const val = 0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
                                                                                                  ^

BoutReal const val =
0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
for (int jz = 0; jz < fieldmesh->LocalNz; jz++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jy' [clang-diagnostic-error]

              0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
                                          ^

Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jy' [clang-diagnostic-error]

              0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
                                                                             ^

BoutReal val =
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jy' [clang-diagnostic-error]

          (*this)(fieldmesh->xend + 1, jy, jz) =
                                       ^

0.5 * (f3d(reg->x, reg->y, z) + f3d(reg->x - reg->bx, reg->y - reg->by, z));
// Set to this value
(*this)(reg->x, reg->y, z) =
2. * val - (*this)(reg->x - reg->bx, reg->y - reg->by, z);
0.5 * (f3d(fieldmesh->xend, jy, jz) + f3d(fieldmesh->xend + 1, jy, jz));
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'jy' [clang-diagnostic-error]

              2. * val - (*this)(fieldmesh->xend, jy, jz);
                                                  ^

(*this)(fieldmesh->xend + 1, jy, jz) =
2. * val - (*this)(fieldmesh->xend, jy, jz);
}
}
}
}

// Y boundaries
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: expected unqualified-id [clang-diagnostic-error]

  if (f3d.hasParallelSlices()) {
  ^


if (f3d.hasParallelSlices()) {
// Argument has parallel slices, so this field must as well.
ASSERT1(hasParallelSlices());

for (auto& bndry : fieldmesh->getBoundariesPar()) {
const Field3D& f3d_next = f3d.ynext(bndry->dir);
Field3D& this_next = ynext(bndry->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: no member named 'z' in 'BoundaryRegionPar' [clang-diagnostic-error]

        const int z = bndry->z;
                             ^

for (bndry->first(); !bndry->isDone(); bndry->next()) {
const int x = bndry->x;
const int y = bndry->y;
const int z = bndry->z;
BoutReal val = 0.5 * (f3d(x, y, z) + f3d_next(x, y + bndr->dir, z));
this_next(x, y + bndry->dir, z) = 2. * val - (*this)(x, y, z);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: expected unqualified-id [clang-diagnostic-error]

  } else {
    ^


} else {
// Argument does not have parallel slices
// Make sure that this field also doesn't have them because in that case
// the parallel derivative operators would erroneously use parallel slices
clearParallelSlices();

// Shift into field-aligned coordinates to apply Y boundary conditions.

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 'r' is too short, expected at least 2 characters [readability-identifier-length]

    for (RangeIterator r = fieldmesh->iterateBndryLowerY(); !r.isDone(); r++) {
                       ^

const Field3D f3d_fa = toFieldAligned(f3d);
BoutReal const val =
0.5
* (f3d_fa(r.ind, fieldmesh->ystart, jz) + f3d_fa(r.ind, fieldmesh->ystart - 1, jz));

for (RangeIterator r = fieldmesh->iterateBndryLowerY(); !r.isDone(); r++) {
for (int jz = 0; jz < fieldmesh->LocalNz; jz++) {
BoutReal val = 0.5
* (f3d_fa(r.ind, fieldmesh->ystart, jz)
+ f3d_fa(r.ind, fieldmesh->ystart - 1, jz));
(*this)(r.ind, fieldmesh->ystart - 1, jz) =
2. * val - (*this)(r.ind, fieldmesh->ystart, jz);
}
}

for (RangeIterator r = fieldmesh->iterateBndryUpperY(); !r.isDone(); r++) {
for (int jz = 0; jz < fieldmesh->LocalNz; jz++) {
BoutReal val =
0.5
* (f3d_fa(r.ind, fieldmesh->yend, jz) + f3d_fa(r.ind, fieldmesh->yend + 1, jz));
(*this)(r.ind, fieldmesh->yend + 1, jz) =
2. * val - (*this)(r.ind, fieldmesh->yend, jz);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: extraneous closing brace ('}') [clang-diagnostic-error]

}
^


(*this) = fromFieldAligned(*this);
}
}

void Field3D::applyParallelBoundary() {

TRACE("Field3D::applyParallelBoundary()");
Expand Down