diff --git a/CarpetX/src/driver.cxx b/CarpetX/src/driver.cxx index ccd9f8fb8..89aea53d1 100644 --- a/CarpetX/src/driver.cxx +++ b/CarpetX/src/driver.cxx @@ -36,14 +36,13 @@ #include namespace CarpetX { -using namespace std; // Global variables int ghext_handle = -1; amrex::AMReX *restrict pamrex = nullptr; -unique_ptr ghext; +std::unique_ptr ghext; // Registered functions @@ -116,12 +115,12 @@ std::ostream &operator<<(std::ostream &os, const boundary_t boundary) { return os; } -array, 2> get_symmetries(const int patch) { +std::array, 2> get_symmetries(const int patch) { // patch < 0 return symmetries without taking interpatch boundaries into // account DECLARE_CCTK_PARAMETERS; - array, 2> is_interpatch{ + std::array, 2> is_interpatch{ {{{false, false, false}}, {{false, false, false}}}}; if (patch >= 0 && CCTK_IsFunctionAliased("MultiPatch_GetBoundarySpecification2")) { @@ -133,7 +132,7 @@ array, 2> get_symmetries(const int patch) { for (int d = 0; d < dim; ++d) is_interpatch[f][d] = is_interpatch_boundary[2 * d + f]; } - const array, 2> is_periodic{{ + const std::array, 2> is_periodic{{ {{bool(periodic_x), bool(periodic_y), bool(periodic_z)}}, {{bool(periodic_x), bool(periodic_y), bool(periodic_z)}}, }}; @@ -148,7 +147,7 @@ array, 2> get_symmetries(const int patch) { assert(is_interpatch[f][d] + is_periodic[f][d] + is_reflection[f][d] <= 1); - array, 2> symmetries; + std::array, 2> symmetries; for (int f = 0; f < 2; ++f) for (int d = 0; d < dim; ++d) symmetries[f][d] = is_interpatch[f][d] ? symmetry_t::interpatch @@ -159,16 +158,17 @@ array, 2> get_symmetries(const int patch) { return symmetries; } -array, 2> get_default_boundaries() { +std::array, 2> get_default_boundaries() { DECLARE_CCTK_PARAMETERS; - const array, 2> symmetries = get_symmetries(-1); - array, 2> is_symmetry; + const std::array, 2> symmetries = + get_symmetries(-1); + std::array, 2> is_symmetry; for (int f = 0; f < 2; ++f) for (int d = 0; d < dim; ++d) is_symmetry[f][d] = symmetries[f][d] != symmetry_t::none; - const array, 2> is_dirichlet{{ + const std::array, 2> is_dirichlet{{ {{ bool(CCTK_EQUALS(boundary_x, "dirichlet")), bool(CCTK_EQUALS(boundary_y, "dirichlet")), @@ -180,7 +180,7 @@ array, 2> get_default_boundaries() { bool(CCTK_EQUALS(boundary_upper_z, "dirichlet")), }}, }}; - const array, 2> is_linear_extrapolation{{ + const std::array, 2> is_linear_extrapolation{{ {{ bool(CCTK_EQUALS(boundary_x, "linear extrapolation")), bool(CCTK_EQUALS(boundary_y, "linear extrapolation")), @@ -192,7 +192,7 @@ array, 2> get_default_boundaries() { bool(CCTK_EQUALS(boundary_upper_z, "linear extrapolation")), }}, }}; - const array, 2> is_neumann{{ + const std::array, 2> is_neumann{{ {{ bool(CCTK_EQUALS(boundary_x, "neumann")), bool(CCTK_EQUALS(boundary_y, "neumann")), @@ -204,7 +204,7 @@ array, 2> get_default_boundaries() { bool(CCTK_EQUALS(boundary_upper_z, "neumann")), }}, }}; - const array, 2> is_robin{{ + const std::array, 2> is_robin{{ {{ bool(CCTK_EQUALS(boundary_x, "robin")), bool(CCTK_EQUALS(boundary_y, "robin")), @@ -223,7 +223,7 @@ array, 2> get_default_boundaries() { is_robin[f][d] <= 1); - array, 2> boundaries; + std::array, 2> boundaries; for (int f = 0; f < 2; ++f) for (int d = 0; d < dim; ++d) boundaries[f][d] = is_symmetry[f][d] ? boundary_t::symmetry_boundary @@ -237,16 +237,18 @@ array, 2> get_default_boundaries() { return boundaries; } -array, 2> get_group_boundaries(const int gi) { +std::array, 2> get_group_boundaries(const int gi) { DECLARE_CCTK_PARAMETERS; - const array, 2> symmetries = get_symmetries(-1); - array, 2> is_symmetry; + const std::array, 2> symmetries = + get_symmetries(-1); + std::array, 2> is_symmetry; for (int f = 0; f < 2; ++f) for (int d = 0; d < dim; ++d) is_symmetry[f][d] = symmetries[f][d] != symmetry_t::none; - array, 2> boundaries = get_default_boundaries(); + std::array, 2> boundaries = + get_default_boundaries(); const auto override_group_boundary = [&](const char *const var_set_string, const int dir, const int face, @@ -254,8 +256,8 @@ array, 2> get_group_boundaries(const int gi) { // Arguments for the callback function struct arg_t { const int gi; - const array, 2> &is_symmetry; - array, 2> &boundaries; + const std::array, 2> &is_symmetry; + std::array, 2> &boundaries; const int dir, face; const boundary_t boundary; } arg{gi, is_symmetry, boundaries, dir, face, boundary}; @@ -316,7 +318,7 @@ bool get_group_checkpoint_flag(const int gi) { if (iret == UTIL_ERROR_TABLE_NO_SUCH_KEY) { return true; } else if (iret >= 0) { - string str(buf); + std::string str(buf); for (auto &c : str) c = tolower(c); if (str == "yes") @@ -337,7 +339,7 @@ bool get_group_restrict_flag(const int gi) { if (iret == UTIL_ERROR_TABLE_NO_SUCH_KEY) { return true; } else if (iret >= 0) { - string str(buf); + std::string str(buf); for (auto &c : str) c = tolower(c); if (str == "yes") @@ -350,14 +352,14 @@ bool get_group_restrict_flag(const int gi) { } } -array get_group_indextype(const int gi) { +std::array get_group_indextype(const int gi) { DECLARE_CCTK_PARAMETERS; assert(gi >= 0); const int tags = CCTK_GroupTagsTableI(gi); assert(tags >= 0); - array index; + std::array index; // The CST stage doesn't look for the `index` tag, and // `CCTK_ARGUMENTSX_...` would thus ignore it @@ -389,11 +391,11 @@ array get_group_indextype(const int gi) { return indextype; } -array get_group_fluxes(const int gi) { +std::array get_group_fluxes(const int gi) { assert(gi >= 0); const int tags = CCTK_GroupTagsTableI(gi); assert(tags >= 0); - vector fluxes_buf(1000); + std::vector fluxes_buf(1000); const int iret = Util_TableGetString(tags, fluxes_buf.size(), fluxes_buf.data(), "fluxes"); if (iret == UTIL_ERROR_TABLE_NO_SUCH_KEY) { @@ -404,18 +406,18 @@ array get_group_fluxes(const int gi) { assert(0); } - const string str(fluxes_buf.data()); - vector strs; - size_t end = 0; + const std::string str(fluxes_buf.data()); + std::vector strs; + std::size_t end = 0; while (end < str.size()) { - const size_t begin = str.find_first_not_of(' ', end); + const std::size_t begin = str.find_first_not_of(' ', end); if (begin == string::npos) break; end = str.find(' ', begin); strs.push_back(str.substr(begin, end - begin)); } - array fluxes; + std::array fluxes; fluxes.fill(-1); if (strs.empty()) return fluxes; // No fluxes specified @@ -438,12 +440,12 @@ array get_group_fluxes(const int gi) { return fluxes; } -array get_group_nghostzones(const int gi) { +std::array get_group_nghostzones(const int gi) { DECLARE_CCTK_PARAMETERS; assert(gi >= 0); const int tags = CCTK_GroupTagsTableI(gi); assert(tags >= 0); - array nghostzones; + std::array nghostzones; int iret = Util_TableGetIntArray(tags, dim, nghostzones.data(), "nghostzones"); if (iret == UTIL_ERROR_TABLE_NO_SUCH_KEY) { @@ -459,7 +461,7 @@ array get_group_nghostzones(const int gi) { return nghostzones; } -vector > get_group_parities(const int gi) { +std::vector > get_group_parities(const int gi) { DECLARE_CCTK_PARAMETERS; assert(gi >= 0); const int tags = CCTK_GroupTagsTableI(gi); @@ -473,19 +475,19 @@ vector > get_group_parities(const int gi) { } else { assert(0); } - vector parities1(nelems); + std::vector parities1(nelems); const int iret = Util_TableGetIntArray(tags, nelems, parities1.data(), "parities"); assert(iret == nelems); assert(nelems % dim == 0); - vector > parities(nelems / dim); - for (size_t n = 0; n < parities.size(); ++n) + std::vector > parities(nelems / dim); + for (std::size_t n = 0; n < parities.size(); ++n) for (int d = 0; d < dim; ++d) parities.at(n).at(d) = parities1.at(dim * n + d); return parities; } -vector get_group_dirichlet_values(const int gi) { +std::vector get_group_dirichlet_values(const int gi) { DECLARE_CCTK_PARAMETERS; assert(gi >= 0); const int tags = CCTK_GroupTagsTableI(gi); @@ -500,14 +502,14 @@ vector get_group_dirichlet_values(const int gi) { } else { assert(0); } - vector dirichlet_values(nelems); + std::vector dirichlet_values(nelems); const int iret = Util_TableGetRealArray(tags, nelems, dirichlet_values.data(), "dirichlet_values"); assert(iret == nelems); return dirichlet_values; } -vector get_group_robin_values(const int gi) { +std::vector get_group_robin_values(const int gi) { DECLARE_CCTK_PARAMETERS; assert(gi >= 0); const int tags = CCTK_GroupTagsTableI(gi); @@ -521,14 +523,14 @@ vector get_group_robin_values(const int gi) { } else { assert(0); } - vector robin_values(nelems); + std::vector robin_values(nelems); const int iret = Util_TableGetRealArray(tags, nelems, robin_values.data(), "robin_values"); assert(iret == nelems); return robin_values; } -amrex::Interpolater *get_interpolator(const array indextype) { +amrex::Interpolater *get_interpolator(const std::array indextype) { DECLARE_CCTK_PARAMETERS; enum class interp_t { @@ -540,6 +542,7 @@ amrex::Interpolater *get_interpolator(const array indextype) { hermite, natural, poly_cons3lfb, + poly_eno3lfb, }; static interp_t interp = [&]() { if (CCTK_EQUALS(prolongation_type, "interpolate")) @@ -1319,7 +1322,7 @@ GHExt::PatchData::LevelData::LevelData(const int patch, const int level, for (int d = 0; d < dim; ++d) { assert(groupdata.fluxes[d] != groupdata.groupindex); const auto &flux_groupdata = *this->groupdata.at(groupdata.fluxes[d]); - array flux_indextype{1, 1, 1}; + std::array flux_indextype{1, 1, 1}; flux_indextype[d] = 0; assert(flux_groupdata.indextype == flux_indextype); assert(flux_groupdata.numvars == groupdata.numvars); @@ -1386,7 +1389,7 @@ GHExt::PatchData::LevelData::GroupData::GroupData( boundaries = get_group_boundaries(gi); parities = get_group_parities(gi); if (parities.empty()) { - array parity; + std::array parity; for (int d = 0; d < dim; ++d) // parity[d] = indextype[d] == 0 ? +1 : -1; parity[d] = +1; @@ -1710,7 +1713,7 @@ void SetupGlobals() { void CactusAmrCore::SetupLevel(const int level, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, - const function &why) { + const std::function &why) { DECLARE_CCTK_PARAMETERS; if (verbose) @@ -2026,16 +2029,18 @@ void CactusAmrCore::ClearLevel(const int level) { //////////////////////////////////////////////////////////////////////////////// -template inline vector seq(const array &v) { - vector r; +template +inline std::vector seq(const std::array &v) { + std::vector r; for (const auto &x : v) r.push_back(x); return r; } template -inline vector > seqs(const vector > &v) { - vector > r; +inline std::vector > +seqs(const std::vector > &v) { + std::vector > r; for (const auto &x : v) r.push_back(seq(x)); return r; @@ -2045,7 +2050,7 @@ inline vector > seqs(const vector > &v) { namespace std { template -YAML::Emitter &operator<<(YAML::Emitter &yaml, const array &arr) { +YAML::Emitter &operator<<(YAML::Emitter &yaml, const std::array &arr) { yaml << YAML::Flow << YAML::BeginSeq; for (const auto &elt : arr) yaml << elt; @@ -2249,7 +2254,7 @@ YAML::Emitter &operator<<(YAML::Emitter &yaml, const GHExt &ghext) { return yaml; } -ostream &operator<<(ostream &os, const GHExt &ghext) { +std::ostream &operator<<(std::ostream &os, const GHExt &ghext) { YAML::Emitter yaml; yaml << ghext; os << yaml.c_str() << "\n"; @@ -2289,7 +2294,7 @@ extern "C" int CarpetX_Startup() { "optimized", #endif }; - ostringstream buf; + std::ostringstream buf; buf << logo(); buf << "AMR driver provided by CarpetX,\n" << "using AMReX " << amrex::Version() << " ("; @@ -2611,16 +2616,16 @@ CCTK_INT CarpetX_GetBoundarySizesAndTypes( const cGH *restrict const cctkGH = static_cast(cctkGH_); assert(size == 2 * dim); - const array, 2> is_periodic{{ + const std::array, 2> is_periodic{{ {{bool(periodic_x), bool(periodic_y), bool(periodic_z)}}, {{bool(periodic_x), bool(periodic_y), bool(periodic_z)}}, }}; - const array, 2> is_reflection{{ + const std::array, 2> is_reflection{{ {{bool(reflection_x), bool(reflection_y), bool(reflection_z)}}, {{bool(reflection_upper_x), bool(reflection_upper_y), bool(reflection_upper_z)}}, }}; - const array, 2> is_boundary{{ + const std::array, 2> is_boundary{{ {{ bool(!CCTK_EQUALS(boundary_x, "none")), bool(!CCTK_EQUALS(boundary_y, "none")), diff --git a/CarpetX/src/driver.hxx b/CarpetX/src/driver.hxx index 4f94a7d5a..a452acd7a 100644 --- a/CarpetX/src/driver.hxx +++ b/CarpetX/src/driver.hxx @@ -27,7 +27,6 @@ #include namespace CarpetX { -using namespace std; using namespace Arith; using Loop::dim; @@ -72,7 +71,7 @@ class CactusAmrCore final : public amrex::AmrCore { public: bool cactus_is_initialized = false; - vector level_modified; + std::vector level_modified; CactusAmrCore(); CactusAmrCore(int patch, const amrex::RealBox *rb, int max_level_in, @@ -131,7 +130,7 @@ struct GHExt { }; cctkGHptr global_cctkGH; - vector level_cctkGHs; // [reflevel] + std::vector level_cctkGHs; // [reflevel] struct CommonGroupData { std::string groupname; @@ -142,7 +141,7 @@ struct GHExt { bool do_checkpoint; // whether to checkpoint bool do_restrict; // whether to restrict - vector > valid; // [time level][var index] + std::vector > valid; // [time level][var index] // TODO: add poison_invalid and check_valid functions @@ -158,7 +157,7 @@ struct GHExt { // we assume that grid scalars only hold "analysis" data. struct ArrayGroupData : public CommonGroupData { - vector > + std::vector > data; // [time level][var index + grid point index] int array_size; int dimension; @@ -190,7 +189,8 @@ struct GHExt { const ArrayGroupData &arraygroupdata); }; // TODO: right now this is sized for the total number of groups - vector > arraygroupdata; // [group index] + std::vector > + arraygroupdata; // [group index] friend YAML::Emitter &operator<<(YAML::Emitter &yaml, const GlobalData &globaldata); @@ -208,11 +208,11 @@ struct GHExt { int patch; - array, 2> symmetries; + std::array, 2> symmetries; // AMReX grid structure // TODO: convert this from unique_ptr to optional - unique_ptr amrcore; + std::unique_ptr amrcore; struct LevelData { LevelData() = delete; @@ -223,7 +223,7 @@ struct GHExt { LevelData(const int patch, const int level, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, - const function &why); + const std::function &why); int patch, level; @@ -237,10 +237,10 @@ struct GHExt { // Fabamrex::ArrayBase object holding a cell-centred BoxArray for // iterating over grid functions. This stores the grid structure // and its distribution over all processes, but holds no data. - unique_ptr fab; + std::unique_ptr fab; cctkGHptr patch_cctkGH; - vector local_cctkGHs; // [component] + std::vector local_cctkGHs; // [component] cGH *get_patch_cctkGH() const { return patch_cctkGH.get(); } cGH *get_local_cctkGH(const int component) const { @@ -256,30 +256,30 @@ struct GHExt { GroupData(int patch, int level, int gi, const amrex::BoxArray &ba, const amrex::DistributionMapping &dm, - const function &why); + const std::function &why); int patch, level; - array indextype; - array nghostzones; + std::array indextype; + std::array nghostzones; - array, 2> boundaries; + std::array, 2> boundaries; bool all_faces_have_symmetries_or_boundaries() const; - vector > parities; - vector dirichlet_values; - vector robin_values; + std::vector > parities; + std::vector dirichlet_values; + std::vector robin_values; amrex::Vector bcrecs; // Apply outer (physical) boundary conditions to a MultiFab void apply_boundary_conditions(amrex::MultiFab &mfab) const; // each amrex::MultiFab has numvars components - vector > mfab; // [time level] + std::vector > mfab; // [time level] // flux register between this and the next coarser level - unique_ptr freg; + std::unique_ptr freg; // associated flux group indices - array fluxes; // [dir] + std::array fluxes; // [dir] // CarpetX can allocate and free (temporary) multifabs that // are associated with a Cactus grid function group. These @@ -302,17 +302,17 @@ struct GHExt { const GroupData &groupdata); }; // TODO: right now this is sized for the total number of groups - vector > groupdata; // [group index] + std::vector > groupdata; // [group index] friend YAML::Emitter &operator<<(YAML::Emitter &yaml, const LevelData &leveldata); }; - vector leveldata; // [reflevel] + std::vector leveldata; // [reflevel] friend YAML::Emitter &operator<<(YAML::Emitter &yaml, const PatchData &patchdata); }; - vector patchdata; // [patch] + std::vector patchdata; // [patch] int num_patches() const { return patchdata.size(); } int num_levels() const { @@ -339,12 +339,12 @@ struct GHExt { } friend YAML::Emitter &operator<<(YAML::Emitter &yaml, const GHExt &ghext); - friend ostream &operator<<(ostream &os, const GHExt &ghext); + friend std::ostream &operator<<(std::ostream &os, const GHExt &ghext); }; -extern unique_ptr ghext; +extern std::unique_ptr ghext; -amrex::Interpolater *get_interpolator(const array indextype); +amrex::Interpolater *get_interpolator(const std::array indextype); } // namespace CarpetX diff --git a/CarpetX/src/io.cxx b/CarpetX/src/io.cxx index 4ce80c686..e6fdff93a 100644 --- a/CarpetX/src/io.cxx +++ b/CarpetX/src/io.cxx @@ -30,18 +30,18 @@ #include namespace CarpetX { -using namespace std; //////////////////////////////////////////////////////////////////////////////// namespace { -vector find_groups(const char *const method, const char *const out_vars) { +std::vector find_groups(const char *const method, + const char *const out_vars) { DECLARE_CCTK_PARAMETERS; - vector enabled(CCTK_NumGroups(), false); + std::vector enabled(CCTK_NumGroups(), false); const auto callback{ [](const int index, const char *const optstring, void *const arg) { - vector &enabled = *static_cast *>(arg); + std::vector &enabled = *static_cast *>(arg); enabled.at(CCTK_GroupIndexFromVarI(index)) = true; }}; CCTK_TraverseString(out_vars, callback, &enabled, CCTK_GROUP_OR_VAR); @@ -54,29 +54,29 @@ vector find_groups(const char *const method, const char *const out_vars) { return enabled; } -string get_parameter_filename() { - vector buf(10000); +std::string get_parameter_filename() { + std::vector buf(10000); int ilen = CCTK_ParameterFilename(buf.size(), buf.data()); assert(ilen < int(buf.size() - 1)); - string parfilename(buf.data()); + std::string parfilename(buf.data()); // Remove directory prefix, if any auto slash = parfilename.rfind('/'); - if (slash != string::npos) + if (slash != std::string::npos) parfilename = parfilename.substr(slash + 1); // Remove suffix, if it is there auto suffix = parfilename.rfind('.'); - if (suffix != string::npos && parfilename.substr(suffix) == ".par") + if (suffix != std::string::npos && parfilename.substr(suffix) == ".par") parfilename = parfilename.substr(0, suffix); return parfilename; } -string get_simulation_name() { - string name = get_parameter_filename(); +std::string get_simulation_name() { + std::string name = get_parameter_filename(); const size_t last_slash = name.rfind('/'); - if (last_slash != string::npos && last_slash < name.length()) + if (last_slash != std::string::npos && last_slash < name.length()) name = name.substr(last_slash + 1); const size_t last_dot = name.rfind('.'); - if (last_dot != string::npos && last_dot > 0) + if (last_dot != std::string::npos && last_dot > 0) name = name.substr(0, last_dot); return name; } @@ -170,8 +170,8 @@ void RecoverGH(const cGH *restrict cctkGH) { } // Find input groups - const vector group_enabled = [&] { - vector enabled(CCTK_NumGroups(), false); + const std::vector group_enabled = [&] { + std::vector enabled(CCTK_NumGroups(), false); for (int gi = 0; gi < CCTK_NumGroups(); ++gi) { const GHExt::GlobalData &globaldata = ghext->globaldata; if (globaldata.arraygroupdata.at(gi)) { @@ -235,8 +235,9 @@ void InputGH(const cGH *restrict cctkGH) { #ifdef HAVE_CAPABILITY_openPMD_api // TODO: handle multiple file names in `filereader_ID_files` - const vector input_group = find_groups("openPMD", filereader_ID_vars); - const string simulation_name = get_simulation_name(); + const std::vector input_group = + find_groups("openPMD", filereader_ID_vars); + const std::string simulation_name = get_simulation_name(); InputOpenPMD(cctkGH, input_group, filereader_ID_dir, filereader_ID_files); #else // TODO: Check this at paramcheck @@ -247,12 +248,13 @@ void InputGH(const cGH *restrict cctkGH) { } else if (CCTK_EQUALS(filereader_method, "silo")) { - const vector input_group = find_groups("Silo", filereader_ID_vars); + const std::vector input_group = + find_groups("Silo", filereader_ID_vars); #ifdef HAVE_CAPABILITY_Silo // TODO: Stop at paramcheck time when Silo input parameters are // set, but Silo is not available // TODO: handle multiple file names in `filereader_ID_files` - const string simulation_name = get_simulation_name(); + const std::string simulation_name = get_simulation_name(); InputSilo(cctkGH, input_group, filereader_ID_dir, filereader_ID_files); #else // TODO: Check this at paramcheck @@ -275,9 +277,10 @@ void OutputPlotfile(const cGH *restrict cctkGH) { Interval interval(timer); const int numgroups = CCTK_NumGroups(); - vector group_enabled(numgroups, false); + std::vector group_enabled(numgroups, false); auto enable_group{[](int index, const char *optstring, void *callback) { - vector &group_enabled = *static_cast *>(callback); + std::vector &group_enabled = + *static_cast *>(callback); // CCTK_TraverseString expands the given groups into their variables // so I condense it down again to groups only group_enabled.at(CCTK_GroupIndexFromVarI(index)) = true; @@ -300,26 +303,26 @@ void OutputPlotfile(const cGH *restrict cctkGH) { if (groupdata0.mfab.size() > 0) { const int tl = 0; - string groupname = CCTK_FullGroupName(gi); + std::string groupname = CCTK_FullGroupName(gi); groupname = regex_replace(groupname, regex("::"), "-"); for (auto &c : groupname) c = tolower(c); for (const auto &restrict patchdata : ghext->patchdata) { - const string basename = [&]() { - ostringstream buf; + const std::string basename = [&]() { + std::ostringstream buf; buf << groupname << ".it" << setw(8) << setfill('0') << cctk_iteration; if (ghext->num_patches() > 1) buf << ".m" << setw(2) << setfill('0') << patchdata.patch; return buf.str(); }(); - const string filename = string(out_dir) + "/" + basename; + const std::string filename = std::string(out_dir) + "/" + basename; - amrex::Vector varnames(groupdata0.numvars); + amrex::Vector varnames(groupdata0.numvars); for (int vi = 0; vi < groupdata0.numvars; ++vi) { - ostringstream buf; + std::ostringstream buf; buf << CCTK_VarName(groupdata0.firstvarindex + vi); for (int i = 0; i < tl; ++i) buf << "_p"; @@ -344,17 +347,17 @@ void OutputPlotfile(const cGH *restrict cctkGH) { const bool is_root = CCTK_MyProc(nullptr) == 0; if (is_root) { - const string visitname = [&]() { - ostringstream buf; + const std::string visitname = [&]() { + std::ostringstream buf; buf << out_dir << "/" << groupname << ".visit"; return buf.str(); }(); - ofstream visit(visitname, ios::app); + std::ofstream visit(visitname, ios::app); assert(visit.good()); visit << basename << "/Header\n"; visit.close(); } // if is_root - } // for patchdata + } // for patchdata } } } @@ -466,11 +469,11 @@ void OutputMetadata(const cGH *restrict cctkGH) { yaml << YAML::EndMap; yaml << YAML::EndDoc; - ostringstream buf; + std::ostringstream buf; buf << out_dir << "/carpetx-metadata" << ".it" << setw(8) << setfill('0') << cctk_iteration << ".yaml"; - const string filename = buf.str(); - ofstream file(filename.c_str(), std::ofstream::out); + const std::string filename = buf.str(); + std::ofstream file(filename.c_str(), std::ofstream::out); file << yaml.c_str(); } @@ -481,11 +484,11 @@ void OutputMetadata(const cGH *restrict cctkGH) { yaml << parameters(); yaml << YAML::EndDoc; - ostringstream buf; + std::ostringstream buf; buf << out_dir << "/parameters" << ".it" << setw(8) << setfill('0') << cctk_iteration << ".yaml"; - const string filename = buf.str(); - ofstream file(filename.c_str(), std::ofstream::out); + const std::string filename = buf.str(); + std::ofstream file(filename.c_str(), std::ofstream::out); file << yaml.c_str(); } } @@ -517,11 +520,12 @@ int OutputGH(const cGH *restrict cctkGH) { { const int every = out_adios2_every == -1 ? out_every : out_adios2_every; if (every > 0 && cctk_iteration % every == 0) { - const vector group_enabled = find_groups("ADIOS2", out_adios2_vars); + const std::vector group_enabled = + find_groups("ADIOS2", out_adios2_vars); #ifdef HAVE_CAPABILITY_ADIOS2 // TODO: Stop at paramcheck time when ADIOS2 output parameters // are set, but ADIOS2 is not available - const string simulation_name = get_simulation_name(); + const std::string simulation_name = get_simulation_name(); OutputADIOS2(cctkGH, group_enabled, out_dir, simulation_name); #else if (strlen(out_adios2_vars) != 0) @@ -534,12 +538,12 @@ int OutputGH(const cGH *restrict cctkGH) { { const int every = out_openpmd_every == -1 ? out_every : out_openpmd_every; if (every > 0 && cctk_iteration % every == 0) { - const vector group_enabled = + const std::vector group_enabled = find_groups("openPMD", out_openpmd_vars); #ifdef HAVE_CAPABILITY_openPMD_api // TODO: Stop at paramcheck time when openPMD output parameters // are set, but openPMD is not available - const string simulation_name = get_simulation_name(); + const std::string simulation_name = get_simulation_name(); OutputOpenPMD(cctkGH, group_enabled, out_dir, simulation_name); #else if (strlen(out_openpmd_vars) != 0) @@ -558,11 +562,12 @@ int OutputGH(const cGH *restrict cctkGH) { { const int every = out_silo_every == -1 ? out_every : out_silo_every; if (every > 0 && cctk_iteration % every == 0) { - const vector group_enabled = find_groups("Silo", out_silo_vars); + const std::vector group_enabled = + find_groups("Silo", out_silo_vars); #ifdef HAVE_CAPABILITY_Silo // TODO: Stop at paramcheck time when Silo output parameters are // set, but Silo is not available - const string simulation_name = get_simulation_name(); + const std::string simulation_name = get_simulation_name(); OutputSilo(cctkGH, group_enabled, out_dir, simulation_name); #else if (strlen(out_silo_vars) != 0) @@ -618,8 +623,8 @@ void Checkpoint(const cGH *const restrict cctkGH) { if (CCTK_EQUALS(checkpoint_method, "openpmd")) { #ifdef HAVE_CAPABILITY_openPMD_api - const vector checkpoint_group = [&] { - vector enabled(CCTK_NumGroups(), false); + const std::vector checkpoint_group = [&] { + std::vector enabled(CCTK_NumGroups(), false); for (int gi = 0; gi < CCTK_NumGroups(); ++gi) { const GHExt::GlobalData &globaldata = ghext->globaldata; if (globaldata.arraygroupdata.at(gi)) { @@ -649,8 +654,8 @@ void Checkpoint(const cGH *const restrict cctkGH) { } else if (CCTK_EQUALS(checkpoint_method, "silo")) { #ifdef HAVE_CAPABILITY_Silo - const vector checkpoint_group = [&] { - vector enabled(CCTK_NumGroups(), false); + const std::vector checkpoint_group = [&] { + std::vector enabled(CCTK_NumGroups(), false); for (int gi = 0; gi < CCTK_NumGroups(); ++gi) { const GHExt::GlobalData &globaldata = ghext->globaldata; if (globaldata.arraygroupdata.at(gi)) { diff --git a/CarpetX/src/io_silo.cxx b/CarpetX/src/io_silo.cxx index fcfefae2c..bddff27fe 100644 --- a/CarpetX/src/io_silo.cxx +++ b/CarpetX/src/io_silo.cxx @@ -44,7 +44,6 @@ using namespace std::experimental; #include namespace CarpetX { -using namespace std; namespace { @@ -107,13 +106,13 @@ std::string make_filename(const std::string &file_name, const int iteration, } int match_filename(const std::string &file_name) { - const regex filename_regex("[.]it(\\d+)[.]silo$", - regex_constants::ECMAScript); - smatch sm; + const std::regex filename_regex("[.]it(\\d+)[.]silo$", + regex_constants::ECMAScript); + std::smatch sm; regex_search(file_name, sm, filename_regex); if (sm.empty()) return -1; - return stoi(sm.str(1)); + return std::stoi(sm.str(1)); } std::string make_meshname(const int reflevel = -1, const int component = -1) { @@ -174,7 +173,7 @@ int InputSiloParameters(const std::string &input_dir, Interval interval(timer); static Timer timer_setup("InputSiloParameters.setup"); - auto interval_setup = make_unique(timer_setup); + auto interval_setup = std::make_unique(timer_setup); const MPI_Comm mpi_comm = MPI_COMM_WORLD; const int myproc = CCTK_MyProc(nullptr); @@ -188,7 +187,7 @@ int InputSiloParameters(const std::string &input_dir, // TODO: directories instead of carefully chosen names static Timer timer_parameters("InputSiloParameters.parameters"); - auto interval_parameters = make_unique(timer_parameters); + auto interval_parameters = std::make_unique(timer_parameters); // Find checkpoint input iteration int input_iteration = -1; @@ -196,12 +195,13 @@ int InputSiloParameters(const std::string &input_dir, // Find latest iteration (if any) try { - for (const auto &direntry : filesystem::directory_iterator(input_dir)) { + for (const auto &direntry : + std::filesystem::directory_iterator(input_dir)) { const auto &filename = direntry.path().filename().string(); const int iter = match_filename(filename); input_iteration = max(input_iteration, iter); } - } catch (const filesystem::filesystem_error &) { + } catch (const std::filesystem::filesystem_error &) { // do nothing if directory does not exist } } @@ -287,7 +287,7 @@ void InputSiloGridStructure(cGH *restrict const cctkGH, Interval interval(timer); static Timer timer_setup("InputSiloGridStructure.setup"); - auto interval_setup = make_unique(timer_setup); + auto interval_setup = std::make_unique(timer_setup); const MPI_Comm mpi_comm = MPI_COMM_WORLD; const int myproc = CCTK_MyProc(cctkGH); @@ -303,7 +303,7 @@ void InputSiloGridStructure(cGH *restrict const cctkGH, interval_setup = nullptr; static Timer timer_meta("InputSiloGridStructure.meta"); - auto interval_meta = make_unique(timer_meta); + auto interval_meta = std::make_unique(timer_meta); // TODO: Recover grid structure for grid arrays; call SetupGlobals for them? @@ -448,7 +448,7 @@ void InputSilo(const cGH *restrict const cctkGH, } static Timer timer_setup("InputSilo.setup"); - auto interval_setup = make_unique(timer_setup); + auto interval_setup = std::make_unique(timer_setup); const MPI_Comm mpi_comm = MPI_COMM_WORLD; const int myproc = CCTK_MyProc(cctkGH); @@ -479,7 +479,7 @@ void InputSilo(const cGH *restrict const cctkGH, interval_setup = nullptr; static Timer timer_data("InputSilo.data"); - auto interval_data = make_unique(timer_data); + auto interval_data = std::make_unique(timer_data); // Read data { @@ -507,7 +507,7 @@ void InputSilo(const cGH *restrict const cctkGH, leveldata.level); // Loop over groups - // set have_meshes; + // std::set have_meshes; for (int gi = 0; gi < CCTK_NumGroups(); ++gi) { if (!input_group.at(gi)) continue; @@ -543,17 +543,17 @@ void InputSilo(const cGH *restrict const cctkGH, const amrex::Box &fabbox = mfab.fabbox(component); // exterior - array dims; + std::array dims; for (int d = 0; d < ndims; ++d) dims[d] = fabbox.length(d); - ptrdiff_t zonecount = 1; + std::ptrdiff_t zonecount = 1; for (int d = 0; d < ndims; ++d) zonecount *= dims[d]; assert(zonecount >= 0 && zonecount <= INT_MAX); // Communicate variable, part 1 static Timer timer_mpi("InputSilo.mpi"); - auto interval_mpi = make_unique(timer_mpi); + auto interval_mpi = std::make_unique(timer_mpi); const int mpi_tag = 22901; // randomly chosen std::vector buffer; MPI_Request mpi_req; @@ -635,11 +635,11 @@ void InputSilo(const cGH *restrict const cctkGH, void *const data_ptr = data + vi * zonecount; memcpy(data_ptr, read_ptr, zonecount * sizeof(CCTK_REAL)); } // for vi - } // if read_file + } // if read_file // Communicate variable, part 2 static Timer timer_wait("InputSilo.wait"); - auto interval_wait = make_unique(timer_wait); + auto interval_wait = std::make_unique(timer_wait); if (recv_this_fab && read_this_fab) { // do nothing } else if (recv_this_fab) { @@ -659,8 +659,8 @@ void InputSilo(const cGH *restrict const cctkGH, } // for component } // for gi - } // for leveldata - } // write data + } // for leveldata + } // write data interval_data = nullptr; } @@ -686,7 +686,7 @@ void OutputSilo(const cGH *restrict const cctkGH, CCTK_VINFO("OutputSilo..."); static Timer timer_setup("OutputSilo.setup"); - auto interval_setup = make_unique(timer_setup); + auto interval_setup = std::make_unique(timer_setup); const MPI_Comm mpi_comm = MPI_COMM_WORLD; const int myproc = CCTK_MyProc(cctkGH); @@ -727,12 +727,12 @@ void OutputSilo(const cGH *restrict const cctkGH, interval_setup = nullptr; static Timer timer_data("OutputSilo.data"); - auto interval_data = make_unique(timer_data); + auto interval_data = std::make_unique(timer_data); // Write data { static Timer timer_mkdir("OutputSilo.mkdir"); - auto interval_mkdir = make_unique(timer_mkdir); + auto interval_mkdir = std::make_unique(timer_mkdir); const std::string subdirname = make_subdirname(output_file, cctk_iteration); const std::string pathname = std::string(output_dir) + "/" + subdirname; const int mode = 0755; @@ -786,7 +786,7 @@ void OutputSilo(const cGH *restrict const cctkGH, for (const auto &leveldata : patchdata.leveldata) { // Loop over groups - set have_meshes; + std::set have_meshes; for (int gi = 0; gi < CCTK_NumGroups(); ++gi) { if (!output_group.at(gi)) continue; @@ -818,10 +818,10 @@ void OutputSilo(const cGH *restrict const cctkGH, // TODO: Check whether data are valid const amrex::Box &fabbox = mfab.fabbox(component); // exterior - array dims; + std::array dims; for (int d = 0; d < ndims; ++d) dims[d] = fabbox.length(d); - ptrdiff_t zonecount = 1; + std::ptrdiff_t zonecount = 1; for (int d = 0; d < ndims; ++d) zonecount *= dims[d]; assert(zonecount >= 0 && zonecount <= INT_MAX); @@ -833,7 +833,7 @@ void OutputSilo(const cGH *restrict const cctkGH, const std::string meshname = make_meshname(leveldata.level, component); - array dims_vc; + std::array dims_vc; for (int d = 0; d < ndims; ++d) dims_vc[d] = dims[d] + int(indextype.cellCentered(d)); @@ -841,13 +841,13 @@ void OutputSilo(const cGH *restrict const cctkGH, patchdata.amrcore->Geom(leveldata.level); const amrex::Real *const x0 = geom.ProbLo(); const amrex::Real *const dx = geom.CellSize(); - array, ndims> coords; + std::array, ndims> coords; for (int d = 0; d < ndims; ++d) { coords[d].resize(dims_vc[d]); for (int i = 0; i < dims_vc[d]; ++i) coords[d][i] = x0[d] + (fabbox.smallEnd(d) + i) * dx[d]; } - array coord_ptrs; + std::array coord_ptrs; for (int d = 0; d < ndims; ++d) coord_ptrs[d] = coords[d].data(); @@ -862,7 +862,7 @@ void OutputSilo(const cGH *restrict const cctkGH, ierr = DBAddOption(optlist.get(), DBOPT_CYCLE, &cycle); assert(!ierr); - array min_index, max_index; + std::array min_index, max_index; for (int d = 0; d < ndims; ++d) { min_index[d] = ngrow[d]; max_index[d] = ngrow[d]; @@ -899,7 +899,7 @@ void OutputSilo(const cGH *restrict const cctkGH, // Communicate variable static Timer timer_mpi("OutputSilo.mpi"); - auto interval_mpi = make_unique(timer_mpi); + auto interval_mpi = std::make_unique(timer_mpi); const int mpi_tag = 22900; // randomly chosen std::vector buffer; const CCTK_REAL *data = nullptr; @@ -993,18 +993,18 @@ void OutputSilo(const cGH *restrict const cctkGH, ndims, nullptr, 0, db_datatype_v, centering, optlist.get()); } // for vi - } // if write_file + } // if write_file } // for component } // for gi - } // for leveldata - } // write data + } // for leveldata + } // write data interval_data = nullptr; static Timer timer_meta("OutputSilo.meta"); - auto interval_meta = make_unique(timer_meta); + auto interval_meta = std::make_unique(timer_meta); // Write metadata if (write_metafile) { @@ -1036,7 +1036,7 @@ void OutputSilo(const cGH *restrict const cctkGH, } // Loop over groups - set have_meshes; + std::set have_meshes; for (int gi = 0; gi < CCTK_NumGroups(); ++gi) { if (!output_group.at(gi)) continue; @@ -1307,12 +1307,12 @@ void OutputSilo(const cGH *restrict const cctkGH, for (const std::string &name : regionnames) regionname_ptrs.push_back(name.c_str()); - array, ndims> data; + std::array, ndims> data; for (int d = 0; d < ndims; ++d) { data[d].reserve(1); data[d].push_back(2); } - array data_ptrs; + std::array data_ptrs; for (int d = 0; d < ndims; ++d) data_ptrs[d] = data[d].data(); @@ -1323,8 +1323,8 @@ void OutputSilo(const cGH *restrict const cctkGH, assert(!ierr); } - typedef array, 2> iextent_t; - typedef array, 2> extent_t; + typedef std::array, 2> iextent_t; + typedef std::array, 2> extent_t; std::vector iextents; std::vector extents; iextents.reserve(ncomps_total); @@ -1377,8 +1377,8 @@ void OutputSilo(const cGH *restrict const cctkGH, for (const std::string &name : regionnames) regionname_ptrs.push_back(name.c_str()); - array, 2>, ndims> idata; - array, 2>, ndims> data; + std::array, 2>, ndims> idata; + std::array, 2>, ndims> data; for (int d = 0; d < ndims; ++d) { for (int f = 0; f < 2; ++f) { idata[d][f].reserve(ncomps_total); @@ -1393,8 +1393,8 @@ void OutputSilo(const cGH *restrict const cctkGH, } } } - array, ndims> idata_ptrs; - array, ndims> data_ptrs; + std::array, ndims> idata_ptrs; + std::array, ndims> data_ptrs; for (int d = 0; d < ndims; ++d) { for (int f = 0; f < 2; ++f) { idata_ptrs[d][f] = idata[d][f].data(); @@ -1466,7 +1466,7 @@ void OutputSilo(const cGH *restrict const cctkGH, int extents_size = 2 * ndims; // This needs to have type `double`, even if everything else is `float` - typedef array, 2> dextent_t; + typedef std::array, 2> dextent_t; #ifdef CCTK_REAL_PRECISION_8 std::vector &dextents = extents; #else @@ -1496,7 +1496,7 @@ void OutputSilo(const cGH *restrict const cctkGH, const int nfabs = mfab.size(); for (int c = 0; c < nfabs; ++c) { const amrex::Box &fabbox = mfab.fabbox(c); // exterior - array dims_vc; + std::array dims_vc; for (int d = 0; d < ndims; ++d) dims_vc[d] = fabbox.length(d) + int(indextype.cellCentered(d)); int zonecount = 1; @@ -1586,7 +1586,7 @@ void OutputSilo(const cGH *restrict const cctkGH, nullptr, optlist.get()); assert(!ierr); } // for vi - } // write multivar + } // write multivar } // for gi diff --git a/CarpetX/src/io_tsv.cxx b/CarpetX/src/io_tsv.cxx index 9576ae53d..c98447931 100644 --- a/CarpetX/src/io_tsv.cxx +++ b/CarpetX/src/io_tsv.cxx @@ -21,18 +21,18 @@ #include namespace CarpetX { -using namespace std; -void WriteTSVold(const cGH *restrict cctkGH, const string &filename, int gi, - const vector &varnames) { - ostringstream buf; +void WriteTSVold(const cGH *restrict cctkGH, const std::string &filename, + int gi, const std::vector &varnames) { + std::ostringstream buf; buf << filename << ".tsv"; - ofstream file(buf.str()); - const string sep = "\t"; + std::ofstream file(buf.str()); + const std::string sep = "\t"; // get more precision for floats, could also use // https://stackoverflow.com/a/30968371 - file << setprecision(numeric_limits::digits10 + 1) << scientific; + file << setprecision(std::numeric_limits::digits10 + 1) + << scientific; // Output header file << "# 1:iteration" << sep << "2:time" << sep << "3:patch" << sep @@ -56,8 +56,8 @@ void WriteTSVold(const cGH *restrict cctkGH, const string &filename, int gi, for (int k = imin.z; k < imax.z; ++k) { for (int j = imin.y; j < imax.y; ++j) { for (int i = imin.x; i < imax.x; ++i) { - const array I{i, j, k}; - array x; + const std::array I{i, j, k}; + std::array x; for (int d = 0; d < dim; ++d) x[d] = geom.ProbLo(d) + (I[d] + CCTK_REAL(0.5) * groupdata.indextype[d]) * @@ -103,19 +103,19 @@ void OutputTSVold(const cGH *restrict cctkGH) { if (groupdata0.mfab.size() > 0) { const int tl = 0; - string groupname = CCTK_FullGroupName(gi); + std::string groupname = CCTK_FullGroupName(gi); groupname = regex_replace(groupname, regex("::"), "-"); for (auto &c : groupname) c = tolower(c); - ostringstream buf; + std::ostringstream buf; buf << out_dir << "/" << groupname; buf << ".it" << setw(6) << setfill('0') << cctk_iteration; buf << ".p" << setw(4) << setfill('0') << CCTK_MyProc(nullptr); - const string filename = buf.str(); + const std::string filename = buf.str(); - amrex::Vector varnames(groupdata0.numvars); + amrex::Vector varnames(groupdata0.numvars); for (int vi = 0; vi < groupdata0.numvars; ++vi) { - ostringstream buf; + std::ostringstream buf; buf << CCTK_VarName(groupdata0.firstvarindex + vi); for (int i = 0; i < tl; ++i) buf << "_p"; @@ -129,7 +129,7 @@ void OutputTSVold(const cGH *restrict cctkGH) { //////////////////////////////////////////////////////////////////////////////// -void WriteTSVScalars(const cGH *restrict cctkGH, const string &filename, +void WriteTSVScalars(const cGH *restrict cctkGH, const std::string &filename, const int gi) { // Output only on root process if (CCTK_MyProc(nullptr) > 0) @@ -137,15 +137,16 @@ void WriteTSVScalars(const cGH *restrict cctkGH, const string &filename, const auto &arraygroupdata = *ghext->globaldata.arraygroupdata.at(gi); - vector varnames; + std::vector varnames; for (int vi = 0; vi < arraygroupdata.numvars; ++vi) varnames.push_back(CCTK_VarName(arraygroupdata.firstvarindex + vi)); - const string sep = "\t"; - ofstream file(filename); + const std::string sep = "\t"; + std::ofstream file(filename); // get more precision for floats, could also use // https://stackoverflow.com/a/30968371 - file << setprecision(numeric_limits::digits10 + 1) << scientific; + file << setprecision(std::numeric_limits::digits10 + 1) + << scientific; // Output header file << "# 1:iteration" << sep << "2:time"; @@ -162,7 +163,7 @@ void WriteTSVScalars(const cGH *restrict cctkGH, const string &filename, file << "\n"; } -void WriteTSVArrays(const cGH *restrict cctkGH, const string &filename, +void WriteTSVArrays(const cGH *restrict cctkGH, const std::string &filename, const int gi, const int out_dir) { // Output only on root process if (CCTK_MyProc(nullptr) > 0) @@ -173,15 +174,16 @@ void WriteTSVArrays(const cGH *restrict cctkGH, const string &filename, if (out_dir >= arraygroupdata.dimension) return; - vector varnames; + std::vector varnames; for (int vi = 0; vi < arraygroupdata.numvars; ++vi) varnames.push_back(CCTK_VarName(arraygroupdata.firstvarindex + vi)); - const string sep = "\t"; - ofstream file(filename); + const std::string sep = "\t"; + std::ofstream file(filename); // get more precision for floats, could also use // https://stackoverflow.com/a/30968371 - file << setprecision(numeric_limits::digits10 + 1) << scientific; + file << setprecision(std::numeric_limits::digits10 + 1) + << scientific; // Output header int col = 1; @@ -212,7 +214,7 @@ void WriteTSVArrays(const cGH *restrict cctkGH, const string &filename, } } -void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, +void WriteTSVGFs(const cGH *restrict cctkGH, const std::string &filename, const int gi, const vect &outdirs, const vect &outcoords) { const auto &groupdata0 = @@ -228,7 +230,7 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, + groupdata0.numvars; // grid function values // Data transmitted from this process - vector data; + std::vector data; data.reserve(10000); for (const auto &patchdata : ghext->patchdata) { for (const auto &leveldata : patchdata.leveldata) { @@ -322,9 +324,9 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, } } } // if output_something - } // for mfi - } // for leveldata - } // for patchdata + } // for mfi + } // for leveldata + } // for patchdata assert(data.size() % nvalues == 0); const MPI_Comm comm = amrex::ParallelDescriptor::Communicator(); @@ -335,14 +337,14 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, assert(data.size() <= INT_MAX); const int npoints = data.size(); - vector all_npoints; + std::vector all_npoints; if (myproc == ioproc) all_npoints.resize(nprocs); MPI_Gather(&npoints, 1, MPI_INT, all_npoints.data(), 1, MPI_INT, ioproc, comm); int total_npoints = 0; - vector all_offsets; + std::vector all_offsets; if (myproc == ioproc) { all_offsets.resize(nprocs); for (int p = 0; p < nprocs; ++p) { @@ -351,7 +353,7 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, total_npoints += all_npoints.at(p); } } - vector all_data; + std::vector all_data; if (myproc == ioproc) all_data.resize(total_npoints); MPI_Gatherv(data.data(), npoints, mpi_datatype::value, @@ -361,10 +363,10 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, if (myproc == ioproc) { assert(total_npoints % nvalues == 0); - vector iptr(total_npoints / nvalues); + std::vector iptr(total_npoints / nvalues); iota(iptr.begin(), iptr.end(), 0); const auto compare_eq = [&](const int i, const int j) { - array pi, pj; + std::array pi, pj; for (int d = 0; d < nintvalues; ++d) pi[d] = int(all_data.at(i * nvalues + d)); // Ignore `isghost` field @@ -376,7 +378,7 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, return pi == pj; }; const auto compare_lt = [&](const int i, const int j) { - array pi, pj; + std::array pi, pj; for (int d = 0; d < nintvalues; ++d) pi[d] = int(all_data.at(i * nvalues + d)); for (int d = 0; d < nintvalues; ++d) @@ -387,15 +389,16 @@ void WriteTSVGFs(const cGH *restrict cctkGH, const string &filename, const auto last = unique(iptr.begin(), iptr.end(), compare_eq); iptr.erase(last, iptr.end()); - vector varnames; + std::vector varnames; for (int vi = 0; vi < groupdata0.numvars; ++vi) varnames.push_back(CCTK_VarName(groupdata0.firstvarindex + vi)); - const string sep = "\t"; - ofstream file(filename); + const std::string sep = "\t"; + std::ofstream file(filename); // get more precision for floats, could also use // https://stackoverflow.com/a/30968371 - file << setprecision(numeric_limits::digits10 + 1) << scientific; + file << setprecision(std::numeric_limits::digits10 + 1) + << scientific; // Output header int col = 0; @@ -441,11 +444,11 @@ void OutputTSV(const cGH *restrict cctkGH) { Interval interval(timer); // Find output groups - const vector group_enabled = [&] { - vector enabled(CCTK_NumGroups(), false); + const std::vector group_enabled = [&] { + std::vector enabled(CCTK_NumGroups(), false); const auto callback{ [](const int index, const char *const optstring, void *const arg) { - vector &enabled = *static_cast *>(arg); + std::vector &enabled = *static_cast *>(arg); enabled.at(CCTK_GroupIndexFromVarI(index)) = true; }}; CCTK_TraverseString(out_tsv_vars, callback, &enabled, CCTK_GROUP_OR_VAR); @@ -465,14 +468,14 @@ void OutputTSV(const cGH *restrict cctkGH) { const int numgroups = CCTK_NumGroups(); for (int gi = 0; gi < numgroups; ++gi) { if (group_enabled.at(gi)) { - string groupname = CCTK_FullGroupName(gi); + std::string groupname = CCTK_FullGroupName(gi); groupname = regex_replace(groupname, regex("::"), "-"); for (auto &ch : groupname) ch = tolower(ch); - ostringstream buf; + std::ostringstream buf; buf << out_dir << "/" << groupname << ".it" << setw(6) << setfill('0') << cctk_iteration; - const string basename = buf.str(); + const std::string basename = buf.str(); switch (CCTK_GroupTypeI(gi)) { case CCTK_SCALAR: WriteTSVScalars(cctkGH, basename + ".tsv", gi); diff --git a/CarpetX/src/linsolve.cxx b/CarpetX/src/linsolve.cxx index a187edd4c..121c465c5 100644 --- a/CarpetX/src/linsolve.cxx +++ b/CarpetX/src/linsolve.cxx @@ -12,7 +12,6 @@ #include namespace CarpetX { -using namespace std; extern "C" void CarpetX_SolvePoisson(const CCTK_INT gi_sol, const CCTK_INT gi_rhs, diff --git a/CarpetX/src/logo.cxx b/CarpetX/src/logo.cxx index 860aef46a..cab44b17e 100644 --- a/CarpetX/src/logo.cxx +++ b/CarpetX/src/logo.cxx @@ -5,8 +5,8 @@ #include namespace CarpetX { -using namespace std; -string logo() { + +std::string logo() { // buf << " \n"; // buf << " ██████╗ █████╗ ██████╗ ██████╗ ███████╗████████╗██╗ ██╗ \n"; @@ -18,40 +18,40 @@ string logo() { // buf << " \n"; // colours - const string blk{"\e[30m"}; - const string red{"\e[31m"}; - const string grn{"\e[32m"}; - const string yel{"\e[33m"}; - const string blu{"\e[34m"}; - const string mag{"\e[35m"}; - const string cyn{"\e[36m"}; - const string whi{"\e[37m"}; - const string reset{"\e[39m"}; + const std::string blk{"\e[30m"}; + const std::string red{"\e[31m"}; + const std::string grn{"\e[32m"}; + const std::string yel{"\e[33m"}; + const std::string blu{"\e[34m"}; + const std::string mag{"\e[35m"}; + const std::string cyn{"\e[36m"}; + const std::string whi{"\e[37m"}; + const std::string reset{"\e[39m"}; // lines and boxes - const string space{" "}; - const string vline{"▕▏"}; - const string hline{"──"}; - const string hline2{"━━"}; - const string block{"██"}; + const std::string space{" "}; + const std::string vline{"▕▏"}; + const std::string hline{"──"}; + const std::string hline2{"━━"}; + const std::string block{"██"}; - const vector blu_box{ + const std::vector blu_box{ blu + space + vline + space, blu + hline + block + hline, blu + space + vline + space, }; - const vector grn_box{ + const std::vector grn_box{ grn + block + block + block, grn + block + block + block, grn + block + block + block, }; - const vector red_box{ + const std::vector red_box{ red + block + block + block, red + block + block + block, red + block + block + block, }; - const vector outer_box{ + const std::vector outer_box{ blu_box[0] + blu_box[0] + blu_box[0], blu_box[1] + blu_box[1] + blu_box[1], blu_box[2] + blu_box[2] + blu_box[2], @@ -62,7 +62,7 @@ string logo() { blu_box[1] + blu_box[1] + blu_box[1], blu_box[2] + blu_box[2] + blu_box[2], }; - const vector inner_box{ + const std::vector inner_box{ red_box[0] + red_box[0] + red_box[0], red_box[1] + red_box[1] + red_box[1], red_box[2] + red_box[2] + red_box[2], @@ -74,7 +74,7 @@ string logo() { red_box[2] + red_box[2] + red_box[2], }; - vector logo; + std::vector logo; for (int line = 0; line < 9; ++line) logo.push_back(outer_box[line] + outer_box[line] + outer_box[line]); for (int line = 0; line < 9; ++line) @@ -82,7 +82,7 @@ string logo() { for (int line = 0; line < 9; ++line) logo.push_back(outer_box[line] + outer_box[line] + outer_box[line]); - ostringstream buf; + std::ostringstream buf; buf << "\n"; for (const auto &str : logo) buf << " " << str << reset << " \n"; diff --git a/CarpetX/src/reduction.cxx b/CarpetX/src/reduction.cxx index 0acf55e30..f75684b35 100644 --- a/CarpetX/src/reduction.cxx +++ b/CarpetX/src/reduction.cxx @@ -16,7 +16,7 @@ #include namespace CarpetX { -using namespace std; + template MPI_Datatype reduction_mpi_datatype() { static MPI_Datatype datatype = MPI_DATATYPE_NULL; if (datatype == MPI_DATATYPE_NULL) { @@ -25,9 +25,9 @@ template MPI_Datatype reduction_mpi_datatype() { char name[MPI_MAX_OBJECT_NAME]; int namelen; MPI_Type_get_name(mpi_datatype::value, name, &namelen); - ostringstream buf; + std::ostringstream buf; buf << "reduction<" << name << "," << D << ">"; - string newname = buf.str(); + std::string newname = buf.str(); MPI_Type_set_name(datatype, newname.c_str()); MPI_Type_commit(&datatype); } @@ -54,9 +54,9 @@ void mpi_reduce(void *restrict x, void *restrict y, int *restrict length, assert(combiner == MPI_COMBINER_CONTIGUOUS); assert(num_integers == 1); assert(num_datatypes == 1); - vector integers(num_integers); - vector addresses(num_addresses); - vector datatypes(num_datatypes); + std::vector integers(num_integers); + std::vector addresses(num_addresses); + std::vector datatypes(num_datatypes); MPI_Type_get_contents(*datatype, num_integers, num_addresses, num_datatypes, integers.data(), addresses.data(), datatypes.data()); MPI_Datatype inner_datatype = datatypes.at(0); @@ -169,7 +169,7 @@ reduction reduce(int gi, int vi, int tl) { for (auto &restrict leveldata : patchdata.leveldata) { const auto &restrict groupdata = *leveldata.groupdata.at(gi); const amrex::MultiFab &mfab = *groupdata.mfab.at(tl); - unique_ptr finemask_imfab; + std::unique_ptr finemask_imfab; warn_if_invalid(groupdata, vi, tl, make_valid_int(), []() { return "Before reduction"; }); @@ -217,7 +217,7 @@ reduction reduce(int gi, int vi, int tl) { const amrex::Array4 &vars = mfab.array(mfi); - unique_ptr > finemask; + std::unique_ptr > finemask; if (finemask_imfab) { finemask = make_unique >( finemask_imfab->array(mfi)); diff --git a/CarpetX/src/reduction.hxx b/CarpetX/src/reduction.hxx index 6668f3741..e1b03121c 100644 --- a/CarpetX/src/reduction.hxx +++ b/CarpetX/src/reduction.hxx @@ -12,7 +12,6 @@ #include namespace CarpetX { -using namespace std; using namespace Arith; template struct reduction { @@ -48,7 +47,7 @@ template struct reduction { constexpr T norm_inf() const noexcept { return maxabs; } template - friend ostream &operator<<(ostream &os, const reduction &red); + friend std::ostream &operator<<(ostream &os, const reduction &red); }; template @@ -89,7 +88,7 @@ constexpr reduction::reduction(const reduction &x, const reduction &y) sumloc(x.sumloc + y.sumloc) {} template -ostream &operator<<(ostream &os, const reduction &red) { +std::ostream &operator<<(std::ostream &os, const reduction &red) { return os << "reduction{\n" << " min: " << red.min << "\n" << " max: " << red.max << "\n" diff --git a/CarpetX/src/regrid_error.cxx b/CarpetX/src/regrid_error.cxx index 8ea8cf1ab..39a7bb09c 100644 --- a/CarpetX/src/regrid_error.cxx +++ b/CarpetX/src/regrid_error.cxx @@ -7,7 +7,6 @@ #include namespace CarpetX { -using namespace std; extern "C" void CarpetX_InitError(CCTK_ARGUMENTS) { DECLARE_CCTK_ARGUMENTSX_CarpetX_InitError; diff --git a/CarpetX/src/schedule.cxx b/CarpetX/src/schedule.cxx index 0c05a77fc..0770dc142 100644 --- a/CarpetX/src/schedule.cxx +++ b/CarpetX/src/schedule.cxx @@ -44,7 +44,6 @@ static inline int omp_in_parallel() { return 0; } #include namespace CarpetX { -using namespace std; #ifndef CCTK_HAVE_CGH_LEVEL #error \ @@ -79,10 +78,10 @@ double gettime() { } // namespace // Used to pass active levels from AMReX's regridding functions -optional active_levels; +std::optional active_levels; void Reflux(const cGH *cctkGH, int level); -void Restrict(const cGH *cctkGH, int level, const vector &groups); +void Restrict(const cGH *cctkGH, int level, const std::vector &groups); void Restrict(const cGH *cctkGH, int level); namespace { @@ -955,7 +954,7 @@ mode_t decode_mode(const cFunctionData *restrict attribute) { } enum class rdwr_t { read, write, invalid }; -ostream &operator<<(ostream &os, const rdwr_t rdwr) { +std::ostream &operator<<(std::ostream &os, const rdwr_t rdwr) { switch (rdwr) { case rdwr_t::read: return os << "read"; @@ -981,15 +980,15 @@ struct clause_t { make_tuple(y.gi, y.vi, y.tl, y.valid); } - friend ostream &operator<<(ostream &os, const clause_t &cl) { + friend std::ostream &operator<<(std::ostream &os, const clause_t &cl) { return os << "clause_t{gi:" << cl.gi << ",vi:" << cl.vi << ",tl:" << cl.tl << ",valid:" << cl.valid << "}"; } }; -vector decode_clauses(const cFunctionData *restrict attribute, - const rdwr_t rdwr) { - vector result; +std::vector decode_clauses(const cFunctionData *restrict attribute, + const rdwr_t rdwr) { + std::vector result; result.reserve(attribute->n_RDWR); for (int n = 0; n < attribute->n_RDWR; ++n) { const RDWR_entry &restrict RDWR = attribute->RDWR[n]; diff --git a/CarpetX/src/schedule.hxx b/CarpetX/src/schedule.hxx index 49028abfa..7ac61406c 100644 --- a/CarpetX/src/schedule.hxx +++ b/CarpetX/src/schedule.hxx @@ -16,7 +16,6 @@ #include namespace CarpetX { -using namespace std; using namespace Loop; int Initialise(tFleshConfig *config); @@ -91,7 +90,7 @@ public: // The levels CallFunction should traverse // TODO: Move this into ghext -extern optional active_levels; +extern std::optional active_levels; //////////////////////////////////////////////////////////////////////////////// @@ -163,8 +162,8 @@ struct GridPtrDesc : GridDesc { struct GridPtrDesc1 : GridDesc { amrex::Dim3 cactus_offset; - array gimin, gimax; - array gash; + std::array gimin, gimax; + std::array gash; GridPtrDesc1() = delete; GridPtrDesc1(const GridPtrDesc1 &) = delete; @@ -189,7 +188,7 @@ struct GridPtrDesc1 : GridDesc { return GF3D1(ptr(vars, vi), gimin, gimax, gash); } - friend ostream &operator<<(ostream &os, const GridPtrDesc1 &p) { + friend std::ostream &operator<<(std::ostream &os, const GridPtrDesc1 &p) { os << "GridPtrDesc1{" << (const GridDescBase &)p << ", " << "cactus_offset:" << "{" << p.cactus_offset.x << "," << p.cactus_offset.y << ","