Skip to content

Commit 0663ea8

Browse files
committed
Ensure grid spacings, Bxy, J, are always communicated
1 parent 8a1d040 commit 0663ea8

5 files changed

Lines changed: 41 additions & 27 deletions

File tree

include/bout/coordinates.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public:
108108
const BoutReal& J(int x, int y) const { return J()(x, y); }
109109
#endif
110110

111-
void setDx(FieldMetric dx) { dx_ = std::move(dx); }
112-
void setDy(FieldMetric dy) { dy_ = std::move(dy); }
113-
void setDz(FieldMetric dz) { dz_ = std::move(dz); }
111+
void setDx(FieldMetric dx);
112+
void setDy(FieldMetric dy);
113+
void setDz(FieldMetric dz);
114114

115115
void setD1_dx(FieldMetric d1_dx) { d1_dx_ = std::move(d1_dx); }
116116
void setD1_dy(FieldMetric d1_dy) { d1_dy_ = std::move(d1_dy); }

src/mesh/coordinates.cxx

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
567567
dy_ = interpolateAndExtrapolate(dy_, location, extrapolate_x, extrapolate_y, false,
568568
transform.get());
569569

570+
setDx(dx_);
571+
setDy(dy_);
572+
setDz(dz_);
573+
570574
// grid data source has staggered fields, so read instead of interpolating
571575
// Diagonal components of metric tensor g^{ij} (default to 1)
572576
const auto g11 = getAtLocOrUnaligned(localmesh, "g11", 1.0, suffix, location);
@@ -758,27 +762,39 @@ const Field2D& Coordinates::zlength() const {
758762
return *zlength_cache;
759763
}
760764

761-
int Coordinates::communicateAndCheckMeshSpacing() {
762-
TRACE("Coordinates::communicateAndCheckMeshSpacing");
763-
764-
localmesh->communicate(dx_, dy_, dz_, Bxy_, J());
765-
covariantMetricTensor.communicate(localmesh);
766-
contravariantMetricTensor.communicate(localmesh);
767-
768-
output_progress.write("Calculating differential geometry terms\n");
769-
770-
if (min(abs(dx())) < 1e-8) {
765+
void Coordinates::setDx(FieldMetric dx) {
766+
if (min(abs(dx)) < 1e-8) {
771767
throw BoutException("dx magnitude less than 1e-8");
772768
}
773769

774-
if (min(abs(dy())) < 1e-8) {
770+
dx_ = std::move(dx);
771+
localmesh->communicate(dx_);
772+
}
773+
774+
void Coordinates::setDy(FieldMetric dy) {
775+
if (min(abs(dy)) < 1e-8) {
775776
throw BoutException("dy magnitude less than 1e-8");
776777
}
777778

778-
if (min(abs(dz())) < 1e-8) {
779+
dy_ = std::move(dy);
780+
localmesh->communicate(dy_);
781+
}
782+
783+
void Coordinates::setDz(FieldMetric dz) {
784+
if (min(abs(dz)) < 1e-8) {
779785
throw BoutException("dz magnitude less than 1e-8");
780786
}
781787

788+
dz_ = std::move(dz);
789+
localmesh->communicate(dz_);
790+
}
791+
792+
int Coordinates::communicateAndCheckMeshSpacing() {
793+
TRACE("Coordinates::communicateAndCheckMeshSpacing");
794+
795+
covariantMetricTensor.communicate(localmesh);
796+
contravariantMetricTensor.communicate(localmesh);
797+
782798
return 0;
783799
}
784800

@@ -1503,21 +1519,24 @@ void Coordinates::checkContravariant() {
15031519
FieldMetric& Coordinates::J() const {
15041520
if (jacobian_cache == nullptr) {
15051521
const auto j = recalculateJacobian();
1506-
auto ptr = std::make_unique<FieldMetric>(j);
1507-
jacobian_cache = std::move(ptr);
1522+
jacobian_cache = std::make_unique<FieldMetric>(j);
15081523
}
15091524
return *jacobian_cache;
15101525
}
15111526

15121527
void Coordinates::setJ(const FieldMetric& J) {
1528+
bout::checkFinite(J, "J", "RGN_NOCORNERS");
1529+
bout::checkPositive(J, "J", "RGN_NOCORNERS");
1530+
15131531
//TODO: Calculate J and check value is close
1514-
auto ptr = std::make_unique<FieldMetric>(J);
1515-
jacobian_cache = std::move(ptr);
1532+
jacobian_cache = std::make_unique<FieldMetric>(J);
1533+
localmesh->communicate(*jacobian_cache);
15161534
}
15171535

15181536
void Coordinates::setBxy(FieldMetric Bxy) {
15191537
//TODO: Calculate Bxy and check value is close
15201538
Bxy_ = std::move(Bxy);
1539+
localmesh->communicate(Bxy_);
15211540
}
15221541

15231542
void Coordinates::setContravariantMetricTensor(

tests/unit/mesh/test_coordinates.cxx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,9 @@ TEST_F(CoordinatesTest, SmallMeshSpacing) {
231231
static_cast<FakeMesh*>(bout::globals::mesh)
232232
->setGridDataSource(new FakeGridDataSource({{"dx", 1e-9}}));
233233

234-
output_info.disable();
235-
output_warn.disable();
236-
Coordinates coords(mesh);
237-
EXPECT_THROW(coords.communicateAndCheckMeshSpacing(), BoutException);
238-
output_warn.enable();
239-
output_info.enable();
234+
WithQuietOutput quiet_info{output_info};
235+
WithQuietOutput quiet_warn{output_warn};
236+
EXPECT_THROW(Coordinates{mesh}, BoutException);
240237
}
241238

242239
TEST_F(CoordinatesTest, ConstructWithDiagonalContravariantMetric) {

tools/pylib/_boutpp_build/boutcpp.pxd.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ cdef extern from "bout/coordinates.hxx":
7878
{{ metric_field }} G1, G2, G3
7979
{{ metric_field }} ShiftTorsion
8080
{{ metric_field }} IntShiftTorsion
81-
int communicateAndCheckMeshSpacing()
8281

8382
cdef extern from "bout/fieldgroup.hxx":
8483
cppclass FieldGroup:

tools/pylib/_boutpp_build/helper.cxx.jinja

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,4 @@ void c_mesh_normalise(Mesh * msh, double norm){
173173
coord->setDx(coord->dx() / norm);
174174
coord->setDy(coord->dy() / norm);
175175
coord->setDz(coord->dz() / norm);
176-
coord->communicateAndCheckMeshSpacing();
177176
}

0 commit comments

Comments
 (0)