@@ -501,9 +501,11 @@ void Coordinates::interpolateFromCoordinates(Options* mesh_options,
501501 checkCovariant ();
502502
503503 setJ (interpolateAndExtrapolate (coords_in->J (), location, true , true , false ,
504- transform.get ()));
504+ transform.get ()),
505+ false );
505506 setBxy (interpolateAndExtrapolate (coords_in->Bxy (), location, true , true , false ,
506- transform.get ()));
507+ transform.get ()),
508+ false );
507509
508510 bout::checkFinite (J (), " The Jacobian" , " RGN_NOCORNERS" );
509511 bout::checkPositive (J (), " The Jacobian" , " RGN_NOCORNERS" );
@@ -567,9 +569,9 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
567569 dy_ = interpolateAndExtrapolate (dy_, location, extrapolate_x, extrapolate_y, false ,
568570 transform.get ());
569571
570- setDx (dx_);
571- setDy (dy_);
572- setDz (dz_);
572+ setDx (dx_, false );
573+ setDy (dy_, false );
574+ setDz (dz_, false );
573575
574576 // grid data source has staggered fields, so read instead of interpolating
575577 // Diagonal components of metric tensor g^{ij} (default to 1)
@@ -618,7 +620,8 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
618620 output_warn.write (" \t WARNING! Covariant components of metric tensor set manually. "
619621 " Contravariant components NOT recalculated\n " );
620622 } else {
621- covariantMetricTensor.setMetricTensor (contravariantMetricTensor.inverse ());
623+ covariantMetricTensor.setMetricTensor (
624+ contravariantMetricTensor.inverse (" RGN_ALL" , false ));
622625 output_warn.write (" Not all covariant components of metric tensor found. "
623626 " Calculating all from the contravariant tensor\n " );
624627 }
@@ -639,15 +642,16 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
639642 const auto J_from_file = getAtLoc (localmesh, " J" , suffix, location);
640643 // Compare calculated and loaded values
641644 output_warn.write (" \t Maximum difference in J is {:e}\n " , max (abs (J () - J_from_file)));
642- setJ (J_from_file);
645+ setJ (J_from_file, false );
643646
644647 communicate (J ());
645648 }
646649
647650 // More robust to extrapolate derived quantities directly, rather than
648651 // deriving from extrapolated covariant metric components
649652 setJ (interpolateAndExtrapolate (J (), location, extrapolate_x, extrapolate_y, false ,
650- transform.get ()));
653+ transform.get ()),
654+ false );
651655
652656 // Check jacobian
653657 bout::checkFinite (J (), " J" + suffix, " RGN_NOCORNERS" );
@@ -662,15 +666,16 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
662666 " Calculating from metric tensor\n " ,
663667 suffix);
664668 // Re-evaluate Bxy using new J
665- setBxy (recalculateBxy ());
669+ setBxy (recalculateBxy (), false );
666670 } else {
667671 const auto Bcalc = getAtLoc (localmesh, " Bxy" , suffix, location);
668- setBxy (Bcalc);
672+ setBxy (Bcalc, false );
669673 output_warn.write (" \t Maximum difference in Bxy is {:e}\n " , max (abs (Bxy () - Bcalc)));
670674 }
671675
672676 setBxy (interpolateAndExtrapolate (Bxy (), location, extrapolate_x, extrapolate_y, false ,
673- transform.get ()));
677+ transform.get ()),
678+ false );
674679
675680 // Check Bxy
676681 bout::checkFinite (Bxy (), " Bxy" + suffix, " RGN_NOCORNERS" );
@@ -762,31 +767,34 @@ const Field2D& Coordinates::zlength() const {
762767 return *zlength_cache;
763768}
764769
765- void Coordinates::setDx (FieldMetric dx) {
770+ void Coordinates::setDx (FieldMetric dx, const bool communicate ) {
766771 if (min (abs (dx)) < 1e-8 ) {
767772 throw BoutException (" dx magnitude less than 1e-8" );
768773 }
769-
770774 dx_ = std::move (dx);
771- localmesh->communicate (dx_);
775+ if (communicate) {
776+ localmesh->communicate (dx_);
777+ }
772778}
773779
774- void Coordinates::setDy (FieldMetric dy) {
780+ void Coordinates::setDy (FieldMetric dy, const bool communicate ) {
775781 if (min (abs (dy)) < 1e-8 ) {
776782 throw BoutException (" dy magnitude less than 1e-8" );
777783 }
778-
779784 dy_ = std::move (dy);
780- localmesh->communicate (dy_);
785+ if (communicate) {
786+ localmesh->communicate (dy_);
787+ }
781788}
782789
783- void Coordinates::setDz (FieldMetric dz) {
790+ void Coordinates::setDz (FieldMetric dz, const bool communicate ) {
784791 if (min (abs (dz)) < 1e-8 ) {
785792 throw BoutException (" dz magnitude less than 1e-8" );
786793 }
787-
788794 dz_ = std::move (dz);
789- localmesh->communicate (dz_);
795+ if (communicate) {
796+ localmesh->communicate (dz_);
797+ }
790798}
791799
792800void Coordinates::recalculateAndReset (bool recalculate_staggered,
@@ -1491,19 +1499,23 @@ FieldMetric& Coordinates::J() const {
14911499 return *jacobian_cache;
14921500}
14931501
1494- void Coordinates::setJ (const FieldMetric& J) {
1502+ void Coordinates::setJ (const FieldMetric& J, const bool communicate ) {
14951503 bout::checkFinite (J, " J" , " RGN_NOCORNERS" );
14961504 bout::checkPositive (J, " J" , " RGN_NOCORNERS" );
14971505
14981506 // TODO: Calculate J and check value is close
14991507 jacobian_cache = std::make_unique<FieldMetric>(J);
1500- localmesh->communicate (*jacobian_cache);
1508+ if (communicate) {
1509+ localmesh->communicate (*jacobian_cache);
1510+ }
15011511}
15021512
1503- void Coordinates::setBxy (FieldMetric Bxy) {
1513+ void Coordinates::setBxy (FieldMetric Bxy, const bool communicate ) {
15041514 // TODO: Calculate Bxy and check value is close
15051515 Bxy_ = std::move (Bxy);
1506- localmesh->communicate (Bxy_);
1516+ if (communicate) {
1517+ localmesh->communicate (Bxy_);
1518+ }
15071519}
15081520
15091521void Coordinates::setContravariantMetricTensor (
@@ -1529,3 +1541,10 @@ void Coordinates::setMetricTensor(
15291541 contravariantMetricTensor.setMetricTensor (contravariant_metric_tensor);
15301542 covariantMetricTensor.setMetricTensor (covariant_metric_tensor);
15311543}
1544+
1545+ void Coordinates::communicateMetricTensor () {
1546+ contravariantMetricTensor.communicate ();
1547+ covariantMetricTensor.communicate ();
1548+ }
1549+
1550+ void Coordinates::communicateDz () { localmesh->communicate (dz_); }
0 commit comments