From 36bf7b07606b61568602c74198ec20b4a3c8b0e0 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 28 Mar 2021 23:14:29 +0200 Subject: [PATCH] Make sure all ranks compute h and u, not just rank 0 --- src/plugins/output_swift.cc | 45 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/plugins/output_swift.cc b/src/plugins/output_swift.cc index cac166c..64d9505 100644 --- a/src/plugins/output_swift.cc +++ b/src/plugins/output_swift.cc @@ -92,6 +92,28 @@ public: MPI_Comm_size(MPI_COMM_WORLD, &num_ranks_); #endif + if (bdobaryons_) { + + const double gamma = cf_.get_value_safe("cosmology", "gamma", 5.0 / 3.0); + const double YHe = pcc_->cosmo_param_["YHe"]; + const double omegab = pcc_->cosmo_param_["Omega_b"]; + const double Tcmb0 = pcc_->cosmo_param_["Tcmb"]; + + // compute gas internal energy + const double npol = (fabs(1.0 - gamma) > 1e-7) ? 1.0 / (gamma - 1.) : 1.0; + const double unitv = 1e5; + const double adec = 1.0 / (160. * std::pow(omegab * hubble_param_ * hubble_param_ / 0.022, 2.0 / 5.0)); + const double Tini = astart_ < adec ? Tcmb0 / astart_ : Tcmb0 / astart_ / astart_ * adec; + const double mu = (Tini > 1.e4) ? 4.0 / (8. - 5. * YHe) : 4.0 / (1. + 3. * (1. - YHe)); + ceint_ = 1.3806e-16 / 1.6726e-24 * Tini * npol / mu / unitv / unitv; + + music::ilog.Print("Swift : Calculated initial gas temperature: %.2f K/mu", Tini / mu); + music::ilog.Print("Swift : set initial internal energy to %.2e km^2/s^2", ceint_); + + h_ = boxsize_ / hubble_param_ / cf_.get_value("setup","GridRes"); + music::ilog.Print("Swift : set initial smoothing length to mean inter-part separation: %.2f Mpc", h_); + } + // Only ranks 0 writes the header if (this_rank_ != 0) return; @@ -148,29 +170,6 @@ public: std::string desc = cf_.get_value("random", "descriptor"); HDFWriteGroupAttribute(fname_, "ICs_parameters", "Descriptor", desc); } - - - if (bdobaryons_) { - - const double gamma = cf_.get_value_safe("cosmology", "gamma", 5.0 / 3.0); - const double YHe = pcc_->cosmo_param_["YHe"]; - const double omegab = pcc_->cosmo_param_["Omega_b"]; - const double Tcmb0 = pcc_->cosmo_param_["Tcmb"]; - - // compute gas internal energy - const double npol = (fabs(1.0 - gamma) > 1e-7) ? 1.0 / (gamma - 1.) : 1.0; - const double unitv = 1e5; - const double adec = 1.0 / (160. * std::pow(omegab * hubble_param_ * hubble_param_ / 0.022, 2.0 / 5.0)); - const double Tini = astart_ < adec ? Tcmb0 / astart_ : Tcmb0 / astart_ / astart_ * adec; - const double mu = (Tini > 1.e4) ? 4.0 / (8. - 5. * YHe) : 4.0 / (1. + 3. * (1. - YHe)); - ceint_ = 1.3806e-16 / 1.6726e-24 * Tini * npol / mu / unitv / unitv; - - music::ilog.Print("Swift : Calculated initial gas temperature: %.2f K/mu", Tini / mu); - music::ilog.Print("Swift : set initial internal energy to %.2e km^2/s^2", ceint_); - - h_ = boxsize_ / hubble_param_ / cf_.get_value("setup","GridRes"); - music::ilog.Print("Swift : set initial smoothing length to mean inter-part separation: %.2f Mpc", h_); - } } // use destructor to write header post factum