@@ -501,9 +501,9 @@ 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 ()), false );
505505 setBxy (interpolateAndExtrapolate (coords_in->Bxy (), location, true , true , false ,
506- transform.get ()));
506+ transform.get ()), false );
507507
508508 bout::checkFinite (J (), " The Jacobian" , " RGN_NOCORNERS" );
509509 bout::checkPositive (J (), " The Jacobian" , " RGN_NOCORNERS" );
@@ -567,9 +567,9 @@ 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_);
570+ setDx (dx_, false );
571+ setDy (dy_, false );
572+ setDz (dz_, false );
573573
574574 // grid data source has staggered fields, so read instead of interpolating
575575 // Diagonal components of metric tensor g^{ij} (default to 1)
@@ -618,7 +618,7 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
618618 output_warn.write (" \t WARNING! Covariant components of metric tensor set manually. "
619619 " Contravariant components NOT recalculated\n " );
620620 } else {
621- covariantMetricTensor.setMetricTensor (contravariantMetricTensor.inverse ());
621+ covariantMetricTensor.setMetricTensor (contravariantMetricTensor.inverse (" RGN_ALL " , false ));
622622 output_warn.write (" Not all covariant components of metric tensor found. "
623623 " Calculating all from the contravariant tensor\n " );
624624 }
@@ -639,15 +639,15 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
639639 const auto J_from_file = getAtLoc (localmesh, " J" , suffix, location);
640640 // Compare calculated and loaded values
641641 output_warn.write (" \t Maximum difference in J is {:e}\n " , max (abs (J () - J_from_file)));
642- setJ (J_from_file);
642+ setJ (J_from_file, false );
643643
644644 communicate (J ());
645645 }
646646
647647 // More robust to extrapolate derived quantities directly, rather than
648648 // deriving from extrapolated covariant metric components
649649 setJ (interpolateAndExtrapolate (J (), location, extrapolate_x, extrapolate_y, false ,
650- transform.get ()));
650+ transform.get ()), false );
651651
652652 // Check jacobian
653653 bout::checkFinite (J (), " J" + suffix, " RGN_NOCORNERS" );
@@ -662,15 +662,15 @@ void Coordinates::readFromMesh(Options* mesh_options, const std::string& suffix)
662662 " Calculating from metric tensor\n " ,
663663 suffix);
664664 // Re-evaluate Bxy using new J
665- setBxy (recalculateBxy ());
665+ setBxy (recalculateBxy (), false );
666666 } else {
667667 const auto Bcalc = getAtLoc (localmesh, " Bxy" , suffix, location);
668- setBxy (Bcalc);
668+ setBxy (Bcalc, false );
669669 output_warn.write (" \t Maximum difference in Bxy is {:e}\n " , max (abs (Bxy () - Bcalc)));
670670 }
671671
672672 setBxy (interpolateAndExtrapolate (Bxy (), location, extrapolate_x, extrapolate_y, false ,
673- transform.get ()));
673+ transform.get ()), false );
674674
675675 // Check Bxy
676676 bout::checkFinite (Bxy (), " Bxy" + suffix, " RGN_NOCORNERS" );
@@ -762,31 +762,34 @@ const Field2D& Coordinates::zlength() const {
762762 return *zlength_cache;
763763}
764764
765- void Coordinates::setDx (FieldMetric dx) {
765+ void Coordinates::setDx (FieldMetric dx, const bool communicate ) {
766766 if (min (abs (dx)) < 1e-8 ) {
767767 throw BoutException (" dx magnitude less than 1e-8" );
768768 }
769-
770769 dx_ = std::move (dx);
771- localmesh->communicate (dx_);
770+ if (communicate) {
771+ localmesh->communicate (dx_);
772+ }
772773}
773774
774- void Coordinates::setDy (FieldMetric dy) {
775+ void Coordinates::setDy (FieldMetric dy, const bool communicate ) {
775776 if (min (abs (dy)) < 1e-8 ) {
776777 throw BoutException (" dy magnitude less than 1e-8" );
777778 }
778-
779779 dy_ = std::move (dy);
780- localmesh->communicate (dy_);
780+ if (communicate) {
781+ localmesh->communicate (dy_);
782+ }
781783}
782784
783- void Coordinates::setDz (FieldMetric dz) {
785+ void Coordinates::setDz (FieldMetric dz, const bool communicate ) {
784786 if (min (abs (dz)) < 1e-8 ) {
785787 throw BoutException (" dz magnitude less than 1e-8" );
786788 }
787-
788789 dz_ = std::move (dz);
789- localmesh->communicate (dz_);
790+ if (communicate) {
791+ localmesh->communicate (dz_);
792+ }
790793}
791794
792795void Coordinates::recalculateAndReset (bool recalculate_staggered,
@@ -1491,19 +1494,23 @@ FieldMetric& Coordinates::J() const {
14911494 return *jacobian_cache;
14921495}
14931496
1494- void Coordinates::setJ (const FieldMetric& J) {
1497+ void Coordinates::setJ (const FieldMetric& J, const bool communicate ) {
14951498 bout::checkFinite (J, " J" , " RGN_NOCORNERS" );
14961499 bout::checkPositive (J, " J" , " RGN_NOCORNERS" );
14971500
14981501 // TODO: Calculate J and check value is close
14991502 jacobian_cache = std::make_unique<FieldMetric>(J);
1500- localmesh->communicate (*jacobian_cache);
1503+ if (communicate) {
1504+ localmesh->communicate (*jacobian_cache);
1505+ }
15011506}
15021507
1503- void Coordinates::setBxy (FieldMetric Bxy) {
1508+ void Coordinates::setBxy (FieldMetric Bxy, const bool communicate ) {
15041509 // TODO: Calculate Bxy and check value is close
15051510 Bxy_ = std::move (Bxy);
1506- localmesh->communicate (Bxy_);
1511+ if (communicate) {
1512+ localmesh->communicate (Bxy_);
1513+ }
15071514}
15081515
15091516void Coordinates::setContravariantMetricTensor (
@@ -1529,3 +1536,8 @@ void Coordinates::setMetricTensor(
15291536 contravariantMetricTensor.setMetricTensor (contravariant_metric_tensor);
15301537 covariantMetricTensor.setMetricTensor (covariant_metric_tensor);
15311538}
1539+
1540+ void Coordinates::communicateMetricTensor () {
1541+ contravariantMetricTensor.communicate ();
1542+ covariantMetricTensor.communicate ();
1543+ }
0 commit comments