Skip to content
Closed
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
4 changes: 2 additions & 2 deletions examples/fci-wave-logn/fci-wave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FCIwave : public PhysicsModel {
Field3D Div_par_integrate(const Field3D &f) {
Field3D f_B = f / Bxyz;

f_B.splitYupYdown();
f_B.createYupYdown();
mesh->getParallelTransform().integrateYUpDown(f_B);

// integrateYUpDown replaces all yup/down points, so the boundary conditions
Expand Down Expand Up @@ -106,7 +106,7 @@ class FCIwave : public PhysicsModel {
// Calculate the flux divergence using Div_par_integrate

Field3D nv = n * v;
nv.splitYupYdown();
nv.createYupYdown();
for (const auto &reg : mesh->getBoundariesPar()) {
Field3D &nv_next = nv.ynext(reg->dir);
nv_next.allocate();
Expand Down
8 changes: 4 additions & 4 deletions examples/fci-wave/fci-wave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class FCIwave : public PhysicsModel {
Field3D Div_par_integrate(const Field3D &f) {
Field3D f_B = f / Bxyz;

f_B.splitYupYdown();
f_B.createYupYdown();
mesh->getParallelTransform().integrateYUpDown(f_B);

// integrateYUpDown replaces all yup/down points, so the boundary conditions
Expand Down Expand Up @@ -93,7 +93,7 @@ class FCIwave : public PhysicsModel {
logn.applyParallelBoundary();

n = exp(logn);
n.splitYupYdown();
n.createYupYdown();
n.yup() = exp(logn.yup());
n.ydown() = exp(logn.ydown());
} else {
Expand All @@ -107,15 +107,15 @@ class FCIwave : public PhysicsModel {
Field3D momflux = nv * v;

// Apply boundary conditions to v
v.splitYupYdown();
v.createYupYdown();
v.yup().allocate();
v.ydown().allocate();
v.applyParallelBoundary();

// Ensure that boundary conditions are consistent
// between v, nv and momentum flux

momflux.splitYupYdown();
momflux.createYupYdown();
for (const auto &reg : mesh->getBoundariesPar()) {
// Using the values of density and velocity on the boundary
const Field3D &n_next = n.ynext(reg->dir);
Expand Down
2 changes: 1 addition & 1 deletion include/bout/paralleltransform.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public:
* Merges the yup and ydown() fields of f, so that
* f.yup() = f.ydown() = f
*/
void calcYUpDown(Field3D &f) override {f.mergeYupYdown();}
void calcYUpDown(Field3D &f) override;

/*!
* The field is already aligned in Y, so this
Expand Down
7 changes: 4 additions & 3 deletions include/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Mesh; // #include "bout/mesh.hxx"

To have separate fields for yup and ydown, first call

f.splitYupYdown(); // f.yup() and f.ydown() separate
f.createYupYdown(); // f.yup() and f.ydown() separate

f.yup(); // ok
f.yup()(0,1,0) // error; f.yup not allocated
Expand Down Expand Up @@ -229,12 +229,13 @@ class Field3D : public Field, public FieldData {
* Ensure that this field has separate fields
* for yup and ydown.
*/
void splitYupYdown();
DEPRECATED(void splitYupYdown());
void createYupYdown();

/*!
* Ensure that yup and ydown refer to this field
*/
void mergeYupYdown();
DEPRECATED(void mergeYupYdown());

/// Check if this field has yup and ydown fields
bool hasYupYdown() const {
Expand Down
11 changes: 11 additions & 0 deletions src/field/field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,17 @@ void Field3D::splitYupYdown() {
ydown_field = new Field3D(fieldmesh);
}

void Field3D::createYupYdown() {
TRACE("Field3D::createYupYdown");

if((yup_field != this) && (yup_field != nullptr))
return;

// yup_field and ydown_field null
yup_field = new Field3D(fieldmesh);
ydown_field = new Field3D(fieldmesh);
}

void Field3D::mergeYupYdown() {
TRACE("Field3D::mergeYupYdown");

Expand Down
2 changes: 1 addition & 1 deletion src/mesh/coordinates.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ const Field3D Coordinates::Div_par(const Field3D &f, CELL_LOC outloc,
f_B.mergeYupYdown();
} else {
// Distinct fields
f_B.splitYupYdown();
f_B.createYupYdown();
f_B.yup() = f.yup() / Bxy_floc;
f_B.ydown() = f.ydown() / Bxy_floc;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mesh/parallel/fci.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void FCITransform::calcYUpDown(Field3D &f) {
TRACE("FCITransform::calcYUpDown");

// Ensure that yup and ydown are different fields
f.splitYupYdown();
f.createYupYdown();

// Interpolate f onto yup and ydown fields
f.ynext(forward_map.dir) = forward_map.interpolate(f);
Expand All @@ -308,7 +308,7 @@ void FCITransform::integrateYUpDown(Field3D &f) {
TRACE("FCITransform::integrateYUpDown");

// Ensure that yup and ydown are different fields
f.splitYupYdown();
f.createYupYdown();

// Integrate f onto yup and ydown fields
f.ynext(forward_map.dir) = forward_map.integrate(f);
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/parallel/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BOUT_TOP = ../../..

DIRS =
SOURCEC = shiftedmetric.cxx fci.cxx
SOURCEC = shiftedmetric.cxx fci.cxx paralleltransformidentity.cxx
TARGET = lib

include $(BOUT_TOP)/make.config
28 changes: 28 additions & 0 deletions src/mesh/parallel/paralleltransformidentity.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/***************************************************************************
* Copyright 2018 B.D. Dudson, J.T. Omotani
*
* Contact: Ben Dudson, bd512@york.ac.uk
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BOUT++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with BOUT++. If not, see <http://www.gnu.org/licenses/>.
*
**************************************************************************/

#include<bout/paralleltransform.hxx>
#include<field3d.hxx>

void ParallelTransformIdentity::calcYUpDown(Field3D &f) {
f.mergeYupYdown();
}
2 changes: 1 addition & 1 deletion src/mesh/parallel/shiftedmetric.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ShiftedMetric::ShiftedMetric(Mesh &m) : mesh(m), zShift(&m) {
* Calculate the Y up and down fields
*/
void ShiftedMetric::calcYUpDown(Field3D &f) {
f.splitYupYdown();
f.createYupYdown();

Field3D& yup = f.yup();
yup.allocate();
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/field/test_field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ TEST_F(Field3DTest, SplitYupYDown) {

EXPECT_FALSE(field.hasYupYdown());

field.splitYupYdown();
field.createYupYdown();

EXPECT_TRUE(field.hasYupYdown());

Expand All @@ -223,8 +223,8 @@ TEST_F(Field3DTest, SplitYupYDown) {
auto& ydown = field.ydown();
EXPECT_NE(&field, &ydown);

// Should be able to split again without any problems
field.splitYupYdown();
// Should be able to create again without any problems
field.createYupYdown();

// Would be nice to check yup2 != yup, but not sure this is possible
// to do in general
Expand Down Expand Up @@ -259,11 +259,11 @@ TEST_F(Field3DTest, MergeYupYDown) {
EXPECT_EQ(&field, &ydown2);
}

TEST_F(Field3DTest, SplitThenMergeYupYDown) {
TEST_F(Field3DTest, CreateThenMergeYupYDown) {
Field3D field;

field = 0.;
field.splitYupYdown();
field.createYupYdown();

auto& yup = field.yup();
EXPECT_NE(&field, &yup);
Expand All @@ -282,7 +282,7 @@ TEST_F(Field3DTest, Ynext) {
Field3D field;

field = 0.;
field.splitYupYdown();
field.createYupYdown();

auto& yup = field.ynext(1);
EXPECT_NE(&field, &yup);
Expand All @@ -296,7 +296,7 @@ TEST_F(Field3DTest, Ynext) {
TEST_F(Field3DTest, ConstYnext) {
Field3D field(0.);

field.splitYupYdown();
field.createYupYdown();

const Field3D& field2 = field;

Expand Down