From 0bf16365d614498147349f62f3095b998f5f804f Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Wed, 3 Jan 2024 13:29:49 -0800 Subject: [PATCH] Fix warnings --- .../openPMD-api/AMReX_ParticlesOPENPMD.H | 22 +-- .../openPMD-api/AMReX_PlotFileOPENPMD.cpp | 152 +++++++++-------- .../openPMD-api/AMReX_PlotFileOPENPMD_PTL.cpp | 6 +- .../openPMD-api/AMReX_PlotFileUtilOPENPMD.H | 79 +++++---- .../openPMD-api/AMReX_PlotFileUtilOPENPMD.cpp | 58 +++---- .../AMReX_PlotFileUtilOPENPMD_PTLImpl.H | 155 +++++++++--------- Tests/MultiBlock/Advection/main.cpp | 1 + Tests/openPMDTests/fields/main.cpp | 20 +-- Tests/openPMDTests/ptls/main.cpp | 45 ++--- Tests/openPMDTests/ptls/mypc.H | 3 +- Tests/openPMDTests/ptls/pseudo_warpx.H | 2 +- Tests/openPMDTests/ptls/warpxBTD.H | 39 ++--- Tests/openPMDTests/ptls/warpxWriter.H | 109 ++++++------ 13 files changed, 338 insertions(+), 353 deletions(-) diff --git a/Src/Extern/openPMD-api/AMReX_ParticlesOPENPMD.H b/Src/Extern/openPMD-api/AMReX_ParticlesOPENPMD.H index bfa0f1546b0..ba2371e33c3 100644 --- a/Src/Extern/openPMD-api/AMReX_ParticlesOPENPMD.H +++ b/Src/Extern/openPMD-api/AMReX_ParticlesOPENPMD.H @@ -18,7 +18,7 @@ struct AMReX_PtlCounter std::vector m_ParticleCounterByLevel; - unsigned long GetTotalNumParticles () const { return m_Total;} + [[nodiscard]] unsigned long long GetTotalNumParticles () const { return m_Total;} std::vector m_ParticleOffsetAtRank; std::vector m_ParticleSizeAtRank; @@ -35,31 +35,27 @@ void CountParticles() m_PtlCounter.m_ParticleOffsetAtRank.resize(this->finestLevel()+1); m_PtlCounter.m_ParticleSizeAtRank.resize(this->finestLevel()+1); - auto lf_GetParticleOffsetOfProcessor = [&](const long& numParticles, + auto lf_GetParticleOffsetOfProcessor = [&](const long long& numParticles, unsigned long long& offset, unsigned long long& sum) -> void { - std::vector result(m_PtlCounter.m_MPISize, 0); + std::vector result(m_PtlCounter.m_MPISize, 0); amrex::ParallelGather::Gather (numParticles, result.data(), -1, amrex::ParallelDescriptor::Communicator()); sum = 0; offset = 0; - for (int i=0; ifinestLevel(); currentLevel++) { - long numParticles = 0; // numParticles in this processor - - //for (ParIter pti(*this, currentLevel); pti.isValid(); ++pti) { - for (ParConstIterType pti(*this, currentLevel); pti.isValid(); ++pti) { - auto numParticleOnTile = pti.numParticles(); - numParticles += numParticleOnTile; - } + // numParticles in this processor + auto numParticles = static_cast(this->NumberOfParticlesAtLevel(currentLevel, false, false)); unsigned long long offset=0; // offset of this level unsigned long long sum=0; // numParticles in this level (sum from all processors) @@ -81,5 +77,3 @@ void CountParticles() AMReX_PtlCounter m_PtlCounter; #endif // AMREX_PTL_OPENPMD_API_H - - diff --git a/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD.cpp b/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD.cpp index 8d1e3a885cd..fa0862f8734 100644 --- a/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD.cpp +++ b/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD.cpp @@ -16,8 +16,7 @@ #include #include -namespace amrex { - namespace openpmd_api { +namespace amrex::openpmd_api { //////////////////////////////////////// @@ -27,8 +26,8 @@ namespace amrex { // //////////////////////////////////////// - AMReX_VarNameParser::AMReX_VarNameParser(std::string varname) - :m_CompName(openPMD::MeshRecordComponent::SCALAR) + AMReX_VarNameParser::AMReX_VarNameParser(std::string const& varname) + :m_CompName(openPMD::MeshRecordComponent::SCALAR) { //auto [varname_no_mode, mode_index] = GetFieldNameModeInt(varname); GetFieldNameModeInt(varname); @@ -50,36 +49,35 @@ namespace amrex { std::regex_match(varname, sm, e_real_imag, std::regex_constants::match_default); if (sm.size() != 4 ) - { + { m_ThetaMode = (m_ModeIndex != -1); // thetaMode or reconstructed Cartesian 2D slice m_FieldName = varname; - } + } else - { + { // sm = [varname, field_name, mode, real_imag] int mode = std::stoi(sm[2]); - if (mode == 0) - m_ModeIndex = 0; - else - { + if (mode == 0) { + m_ModeIndex = 0; + } else { if (sm[3] == "imag") { - m_ModeIndex += 1; + m_ModeIndex += 1; } m_ModeIndex += 2 * mode; - } + } m_ThetaMode = (m_ModeIndex != -1); // thetaMode or reconstructed Cartesian 2D slice m_FieldName = std::string(sm[1]); - } + } } void AMReX_VarNameParser::GetMeshCompNames (int meshLevel) { std::string varname = m_FieldName; - if (varname.size() >= 2u ) - { - std::string const varname_1st = varname.substr(0u, 1u); // 1st character - std::string const varname_2nd = varname.substr(1u, 1u); // 2nd character + if (varname.size() >= 2U ) + { + std::string const varname_1st = varname.substr(0U, 1U); // 1st character + std::string const varname_2nd = varname.substr(1U, 1U); // 2nd character // Check if this field is a vector. If so, then extract the field name @@ -87,21 +85,22 @@ namespace amrex { std::vector< std::string > const field_components = getFieldComponentLabels(); for( std::string const& vector_field : vector_fields ) - { + { for( std::string const& component : field_components ) - { - if( vector_field.compare( varname_1st ) == 0 && component.compare( varname_2nd ) == 0 ) - { + { + if( vector_field == varname_1st && component == varname_2nd ) + { m_FieldName = varname_1st + varname.substr(2); // Strip component m_CompName = varname_2nd; - } - } - } - } + } + } + } + } - if ( 0 == meshLevel ) - return; + if ( 0 == meshLevel ) { + return; + } m_FieldName += std::string("_lvl").append(std::to_string(meshLevel)); } @@ -115,8 +114,9 @@ namespace amrex { std::string const & engine_type, std::map< std::string, std::string > const & engine_parameters) { - if (operator_type.empty() && engine_type.empty()) + if (operator_type.empty() && engine_type.empty()) { return "{}"; + } std::string options; std::string top_block; @@ -126,7 +126,7 @@ namespace amrex { std::string op_parameters; for (const auto& kv : operator_parameters) { - if (!op_parameters.empty()) op_parameters.append(",\n"); + if (!op_parameters.empty()) { op_parameters.append(",\n"); } op_parameters.append(std::string(12, ' ')) /* just pretty alignment */ .append("\"").append(kv.first).append("\": ") /* key */ .append("\"").append(kv.second).append("\""); /* value (as string) */ @@ -134,7 +134,7 @@ namespace amrex { std::string en_parameters; for (const auto& kv : engine_parameters) { - if (!en_parameters.empty()) en_parameters.append(",\n"); + if (!en_parameters.empty()) { en_parameters.append(",\n"); } en_parameters.append(std::string(12, ' ')) /* just pretty alignment */ .append("\"").append(kv.first).append("\": ") /* key */ .append("\"").append(kv.second).append("\""); /* value (as string) */ @@ -166,8 +166,9 @@ namespace amrex { ] })END"; - if (!engine_type.empty() || !en_parameters.empty()) + if (!engine_type.empty() || !en_parameters.empty()) { op_block += ","; + } } if (!engine_type.empty() || !en_parameters.empty()) @@ -178,8 +179,9 @@ namespace amrex { en_block += R"END( "type": ")END"; en_block += engine_type + "\""; - if(!en_parameters.empty()) + if(!en_parameters.empty()) { en_block += ","; + } } if (!en_parameters.empty()) { en_block += R"END( @@ -204,21 +206,13 @@ namespace amrex { // //////////////////////////////////////// - AMReX_openPMDHandler::AMReX_openPMDHandler(const std::string& prefix) // match to diag_name in warpx + AMReX_openPMDHandler::AMReX_openPMDHandler(std::string const& prefix) // NOLINT(modernize-pass-by-value) // match to diag_name in warpx :m_Writer(nullptr) { BL_PROFILE("AMReX_openPMDHandler::()"); CreateWriter(prefix); } - AMReX_openPMDHandler::~AMReX_openPMDHandler () - { - if( m_Writer) - { - m_Writer.reset( nullptr ); - } - } - void AMReX_openPMDHandler::CreateWriter(const std::string& prefix) { ParmParse pp_prefix(prefix); @@ -231,12 +225,13 @@ namespace amrex { pp_prefix.query("openpmd_encoding", openpmd_encoding); openPMD::IterationEncoding encoding = openPMD::IterationEncoding::groupBased; - if ( 0 == openpmd_encoding.compare("v") ) + if ( openpmd_encoding == "v" ) { encoding = openPMD::IterationEncoding::variableBased; - else if ( 0 == openpmd_encoding.compare("g") ) + } else if ( openpmd_encoding == "g" ) { encoding = openPMD::IterationEncoding::groupBased; - else if ( 0 == openpmd_encoding.compare("f") ) + } else if ( openpmd_encoding == "f" ) { encoding = openPMD::IterationEncoding::fileBased; + } auto lf_collect = [&](const char* key, const std::string& parameter_tag, @@ -247,7 +242,7 @@ namespace amrex { pp_prefix.query(key, key_type); std::string const key_prefix = prefix + parameter_tag; ParmParse pp; - auto entr = pp.getEntries(key_prefix); + auto entr = ParmParse::getEntries(key_prefix); auto const prefix_len = key_prefix.size() + 1; for (std::string k : entr) { @@ -281,29 +276,28 @@ namespace amrex { // Class AMReX_openPMDWriter // //////////////////////////////////////// - AMReX_openPMDWriter::AMReX_openPMDWriter () - {} - AMReX_openPMDWriter::AMReX_openPMDWriter (const std::string& prefix, + AMReX_openPMDWriter::AMReX_openPMDWriter (std::string prefix, openPMD::IterationEncoding ie, std::string filetype, std::string options) - :m_openPMDPrefix(prefix), + :m_openPMDPrefix(std::move(prefix)), m_openPMDEncoding(ie), - m_openPMDFileType(filetype), - m_openPMDSeriesOptions(options) + m_openPMDFileType(std::move(filetype)), + m_openPMDSeriesOptions(std::move(options)) //std::vector fieldPMLdirections // warpx specific { -if( m_openPMDFileType == "default" ) + if( m_openPMDFileType == "default" ) { #if openPMD_HAVE_ADIOS2==1 - m_openPMDFileType = "bp"; + m_openPMDFileType = "bp"; #elif openPMD_HAVE_ADIOS1==1 - m_openPMDFileType = "bp"; + m_openPMDFileType = "bp"; #elif openPMD_HAVE_HDF5==1 - m_openPMDFileType = "h5"; + m_openPMDFileType = "h5"; #else - m_openPMDFileType = "json"; + m_openPMDFileType = "json"; #endif + } } AMReX_openPMDWriter::~AMReX_openPMDWriter () @@ -322,7 +316,7 @@ if( m_openPMDFileType == "default" ) Init(openPMD::Access::CREATE); } - void AMReX_openPMDWriter::CloseStep(int ts) + void AMReX_openPMDWriter::CloseStep(int /*ts*/) { if (m_Series) { GetIteration(m_CurrentStep).close(); @@ -334,10 +328,11 @@ if( m_openPMDFileType == "default" ) std::string filepath = m_openPMDPrefix; GetFileName(filepath); - if ( m_openPMDEncoding == openPMD::IterationEncoding::fileBased ) - m_Series = nullptr; - else if ( m_Series != nullptr ) - return; + if ( m_openPMDEncoding == openPMD::IterationEncoding::fileBased ) { + m_Series = nullptr; + } else if ( m_Series != nullptr ) { + return; + } if (amrex::ParallelDescriptor::NProcs() > 1) { @@ -361,7 +356,7 @@ if( m_openPMDFileType == "default" ) m_Series->setMeshesPath( "fields" ); // conform to ED-PIC extension of openPMD - uint32_t const openPMD_ED_PIC = 1u; + uint32_t const openPMD_ED_PIC = 1U; m_Series->setOpenPMDextension( openPMD_ED_PIC ); // meta info @@ -392,8 +387,9 @@ if( m_openPMDFileType == "default" ) else { auto mesh = meshes[curr.m_FieldName]; - if ( ! mesh.contains(curr.m_CompName) ) + if ( ! mesh.contains(curr.m_CompName) ) { SetupMeshComp( mesh, full_geom, *curr_mf, curr ); + } } } } // icomp setup loop @@ -403,7 +399,7 @@ if( m_openPMDFileType == "default" ) openPMD::Container< openPMD::Mesh >& meshes, amrex::Geometry& full_geom, const std::vector& varnames, - const amrex::MultiFab* curr_mf) const + const amrex::MultiFab* curr_mf) { int const ncomp = curr_mf->nComp(); amrex::Box const & global_box = full_geom.Domain(); @@ -472,15 +468,16 @@ if( m_openPMDFileType == "default" ) auto meshes = series_iteration.meshes; series_iteration.setTime( time ); - if ( 0 == varnames.size() ) return; + if ( varnames.empty() ) { return; } - int output_levels = geom.size(); + auto output_levels = int(geom.size()); for (int lev=0; lev < output_levels; lev++) { amrex::Geometry full_geom = geom[lev]; - if ( 0 == lev ) + if ( 0 == lev ) { SetupFields(meshes, full_geom); + } CompSetup(lev, meshes, full_geom, varnames, mf[lev]); CompStorage(lev, meshes, full_geom, varnames, mf[lev]); @@ -491,10 +488,11 @@ if( m_openPMDFileType == "default" ) } // for lev loop } - void AMReX_openPMDWriter::GetFileName(std::string& filepath) + void AMReX_openPMDWriter::GetFileName(std::string& filepath) const { - if (filepath.size() == 0) + if (filepath.empty()) { filepath.append("."); + } filepath.append("/"); // transform paths for Windows @@ -532,13 +530,14 @@ if( m_openPMDFileType == "default" ) particleBoundary.resize(4); #endif - for (auto i = 0u; i < fieldBoundary.size() / 2u; ++i) + for (int i = 0; i < int(fieldBoundary.size() / 2); ++i) { if (period.isPeriodic(i)) { - fieldBoundary.at(2u * i) = "periodic"; - fieldBoundary.at(2u * i + 1u) = "periodic"; - particleBoundary.at(2u * i) = "periodic"; - particleBoundary.at(2u * i + 1u) = "periodic"; + fieldBoundary.at(2 * i) = "periodic"; + fieldBoundary.at(2 * i + 1) = "periodic"; + particleBoundary.at(2 * i) = "periodic"; + particleBoundary.at(2 * i + 1) = "periodic"; } + } meshes.setAttribute("fieldBoundary", fieldBoundary); meshes.setAttribute("particleBoundary", particleBoundary); @@ -589,5 +588,4 @@ if( m_openPMDFileType == "default" ) } - } // namespace openpmd_api -} // namespace amrex +} // namespace amrex::openpmd_api diff --git a/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD_PTL.cpp b/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD_PTL.cpp index 051626aae3d..e5e70ef8203 100644 --- a/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD_PTL.cpp +++ b/Src/Extern/openPMD-api/AMReX_PlotFileOPENPMD_PTL.cpp @@ -17,8 +17,7 @@ #include -namespace amrex { - namespace openpmd_api { +namespace amrex::openpmd_api { bool AMReX_openPMDWriter::AllocatePtlProperties(openPMD::ParticleSpecies& currSpecies, const amrex::Vector& write_real_comp, @@ -64,7 +63,7 @@ namespace amrex { currSpecies["position"][comp].resetDataset( realType ); } - auto const scalar = openPMD::RecordComponent::SCALAR; + auto const * const scalar = openPMD::RecordComponent::SCALAR; currSpecies["id"][scalar].resetDataset( idType ); } @@ -100,5 +99,4 @@ namespace amrex { SetParticleSpecieAttributes(currSpecies); } - } // namespace } diff --git a/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.H b/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.H index b0731358bfd..ea4b511c9dc 100644 --- a/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.H +++ b/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.H @@ -7,8 +7,10 @@ #include #include +#ifdef AMREX_PARTICLES #include #include +#endif #ifdef AMREX_USE_OPENPMD_API #include @@ -17,14 +19,12 @@ #include #include -namespace amrex +namespace amrex::openpmd_api { - namespace openpmd_api - { namespace helper { inline void - setOpenPMDUnit ( openPMD::Mesh mesh, const std::string field_name ) + setOpenPMDUnit ( openPMD::Mesh mesh, std::string const& field_name ) { if (field_name[0] == 'E'){ mesh.setUnitDimension({ @@ -65,8 +65,9 @@ namespace amrex // WarpX::do_nodal means: all indices/directions on CellIndex::NODE for (int d = 0; d < AMREX_SPACEDIM; d++) { - if (idx_type.cellCentered(d)) + if (idx_type.cellCentered(d)) { relative_position.at(d) = 0.5; + } } return relative_position; } @@ -121,9 +122,9 @@ namespace amrex void UseCustomWriter(AMReX_openPMDWriter* w); std::unique_ptr InitUserHandler(const std::string& prefix); - void CloseUserHandler(std::unique_ptr& h); + void CloseUserHandler(std::unique_ptr& userHandler); - void InitHandler(const std::string& filePath); + void InitHandler(const std::string& prefix); //void SetCustomizer(AMReX_Optional* f); void SetStep(int ts); @@ -158,30 +159,35 @@ namespace amrex //////////////////////////// struct AMReX_VarNameParser { - AMReX_VarNameParser(std::string varname); + AMReX_VarNameParser(std::string const& varname); + virtual ~AMReX_VarNameParser () = default; + AMReX_VarNameParser (AMReX_VarNameParser const&) = default; + AMReX_VarNameParser (AMReX_VarNameParser &&) = delete; + AMReX_VarNameParser& operator= (AMReX_VarNameParser const&) = default; + AMReX_VarNameParser& operator= (AMReX_VarNameParser &&) = delete; void GetFieldNameModeInt(const std::string& varname); void GetMeshCompNames (int meshLevel); - inline std::vector< std::string > getFieldComponentLabels () + [[nodiscard]] std::vector< std::string > getFieldComponentLabels () const { using vs = std::vector< std::string >; if (m_ThetaMode) { // if we write individual modes - vs const fieldComponents{"r", "t", "z"}; + vs fieldComponents{"r", "t", "z"}; return fieldComponents; } else { // if we just write reconstructed fields at theta=0 or are Cartesian // note: 1D3V and 2D3V simulations still have 3 components for the fields - vs const fieldComponents{"x", "y", "z"}; + vs fieldComponents{"x", "y", "z"}; return fieldComponents; } } - virtual std::vector< std::string > + [[nodiscard]] virtual std::vector< std::string > getFieldAxisLabels () const { using vs = std::vector< std::string >; @@ -216,16 +222,20 @@ namespace amrex //////////////////////////// class AMReX_openPMDWriter { public: - AMReX_openPMDWriter(const std::string& prefix, + AMReX_openPMDWriter(std::string prefix, openPMD::IterationEncoding ie, std::string filetype, std::string openpmdOptions); - AMReX_openPMDWriter(); + AMReX_openPMDWriter() = default; + AMReX_openPMDWriter (AMReX_openPMDWriter const&) = delete; + AMReX_openPMDWriter (AMReX_openPMDWriter &&) = delete; + AMReX_openPMDWriter& operator= (AMReX_openPMDWriter const&) = delete; + AMReX_openPMDWriter& operator= (AMReX_openPMDWriter &&) = delete; virtual ~AMReX_openPMDWriter(); - virtual openPMD::Iteration GetIteration (int const iteration) const + [[nodiscard]] virtual openPMD::Iteration GetIteration (int const iteration) const { return m_Series->writeIterations()[iteration]; } @@ -239,7 +249,7 @@ namespace amrex const amrex::Vector& geom, //const Vector &iteration, //const int iteration, /* note: all levels are outputting the same step */ - const double time ) const; + double time ) const; template void DumpParticles(PC const& pc, @@ -259,36 +269,36 @@ namespace amrex const amrex::Vector& write_int_comp, // size = NStructInt + NArrayInt const amrex::Vector& real_comp_names, const amrex::Vector& int_comp_names, - FUNC_pc&& pcFunc, - FUNC_pit&& pitFunc + FUNC_pc&& pc_func, + FUNC_pit&& posId_func ) const; - virtual bool AllocatePtlProperties(openPMD::ParticleSpecies& currSpecies, + [[nodiscard]] virtual bool AllocatePtlProperties(openPMD::ParticleSpecies& currSpecies, const amrex::Vector& write_real_comp, const amrex::Vector& real_comp_names, const amrex::Vector& write_int_comp, const amrex::Vector& int_comp_names, - const unsigned long long np) const; + unsigned long long np) const; - virtual void SetParticleSpecieAttributes(openPMD::ParticleSpecies& currSpecies) const + virtual void SetParticleSpecieAttributes(openPMD::ParticleSpecies& /*currSpecies*/) const {} void SetupPos(openPMD::ParticleSpecies& species, const unsigned long long& np) const; - virtual unsigned long long GetGrandOffset() const; // to adjust offset/total with data already flushed, example use case: BTD + [[nodiscard]] virtual unsigned long long GetGrandOffset() const; // to adjust offset/total with data already flushed, example use case: BTD // called once because it is constant valued record virtual void SetupConstant(openPMD::ParticleSpecies& currSpecies, const unsigned long long& np) const; - virtual std::vector< std::string > + [[nodiscard]] virtual std::vector< std::string > getParticlePositionComponentLabels() const { #if (AMREX_SPACEDIM == 3) - std::vector< std::string > const positionComponents{"x", "y", "z"}; + std::vector< std::string > positionComponents{"x", "y", "z"}; #elif (AMREX_SPACEDIM == 2) - std::vector< std::string > const positionComponents{"x", "y"}; + std::vector< std::string > positionComponents{"x", "y"}; #elif (AMREX_SPACEDIM == 1) - std::vector< std::string > const positionComponents{"x"}; + std::vector< std::string > positionComponents{"x"}; #else # error Unknown dimensionality. #endif @@ -303,7 +313,7 @@ namespace amrex const amrex::Vector& real_comp_names, const amrex::Vector& write_int_comp, const amrex::Vector& int_comp_names, - const unsigned long long np) const; + unsigned long long np) const; /* */ template @@ -335,11 +345,11 @@ namespace amrex const std::vector& varnames, const amrex::MultiFab* mf) const; - void CompStorage(int lev, + static void CompStorage(int lev, openPMD::Container< openPMD::Mesh >& meshes, amrex::Geometry& full_geom, const std::vector& varnames, - const amrex::MultiFab* mf) const; + const amrex::MultiFab* mf); virtual void SetupFields (openPMD::Container< openPMD::Mesh >& meshes, @@ -350,7 +360,7 @@ namespace amrex amrex::MultiFab const& mf, const AMReX_VarNameParser& varName) const; - void GetFileName(std::string& filepath); + void GetFileName(std::string& filepath) const; template void StoreAoS_Real(PIt& pti, @@ -404,11 +414,9 @@ namespace amrex //////////////////////////// class AMReX_openPMDHandler { public: - AMReX_openPMDHandler(const std::string& prefix = std::string()); - - ~AMReX_openPMDHandler(); + AMReX_openPMDHandler(std::string const& prefix = std::string()); - std::unique_ptr m_Writer = nullptr; + std::unique_ptr m_Writer; private: void CreateWriter(const std::string& prefix = std::string()); @@ -416,8 +424,7 @@ namespace amrex }; // class AMReX_openPMDHandler - }// name space openpmd_api -} // namespace amrex +} // namespace amrex::openpmd_api #include diff --git a/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.cpp b/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.cpp index 31c543eda2c..c5fa8cba4ea 100644 --- a/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.cpp +++ b/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD.cpp @@ -14,17 +14,15 @@ #include #include -namespace amrex +namespace amrex::openpmd_api { - namespace openpmd_api - { /* global handler, activate with InitHandler() & deactivate with CloseHandler() */ std::unique_ptr< AMReX_openPMDHandler > m_OpenPMDHandler = nullptr; std::unique_ptr InitUserHandler(const std::string& prefix) { - std::string filePath {""}; - if (prefix.size() == 0) + std::string filePath; + if (prefix.empty()) { ParmParse pp; pp.query("openpmd_directory", filePath); @@ -33,23 +31,20 @@ namespace amrex filePath = prefix; } - std::unique_ptr< AMReX_openPMDHandler > userHandler; - userHandler.reset(new AMReX_openPMDHandler(filePath)); - return userHandler; + return std::make_unique(filePath); } void CloseUserHandler(std::unique_ptr& userHandler) { - if (userHandler == nullptr) - return; + if (userHandler == nullptr) { return; } userHandler.reset(nullptr); } void InitHandler(const std::string& prefix) { - std::string filePath {""}; - if (prefix.size() == 0) + std::string filePath; + if (prefix.empty()) { ParmParse pp; pp.query("openpmd_directory", filePath); @@ -58,11 +53,13 @@ namespace amrex filePath = prefix; } - if (m_OpenPMDHandler == nullptr) - m_OpenPMDHandler.reset(new AMReX_openPMDHandler(filePath)); - else if (m_OpenPMDHandler->m_Writer != nullptr) - if (m_OpenPMDHandler->m_Writer->m_openPMDPrefix != filePath) - m_OpenPMDHandler.reset(new AMReX_openPMDHandler(filePath)); + if (m_OpenPMDHandler == nullptr) { + m_OpenPMDHandler = std::make_unique(filePath); + } else if (m_OpenPMDHandler->m_Writer != nullptr) { + if (m_OpenPMDHandler->m_Writer->m_openPMDPrefix != filePath) { + m_OpenPMDHandler = std::make_unique(filePath); + } + } // already using the directory, no action needed } @@ -78,24 +75,23 @@ namespace amrex void CloseHandler() { - if (m_OpenPMDHandler == nullptr) - return; - - m_OpenPMDHandler.reset(nullptr); + m_OpenPMDHandler.reset(); } void SetStep(int ts) { - if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) + if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) { return; + } m_OpenPMDHandler->m_Writer->SetStep(ts); } void CloseStep(int ts) { - if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) + if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) { return; + } m_OpenPMDHandler->m_Writer->CloseStep(ts); } @@ -126,14 +122,13 @@ namespace amrex const Vector &geom, Real time, //const Vector &level_steps, - const Vector &ref_ratio, - const std::string &versionName, - const std::string &levelPrefix, - const std::string &mfPrefix, - const Vector& extra_dirs) + const Vector & /*ref_ratio*/, + const std::string & /*versionName*/, + const std::string & /*levelPrefix*/, + const std::string & /*mfPrefix*/, + const Vector& /*extra_dirs*/) { - if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) - return; + if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) { return; } BL_ASSERT ( geom.size() == mf.size() ); BL_ASSERT ( mf[0]->nComp() <= varnames.size() ); @@ -144,5 +139,4 @@ namespace amrex //level_steps[0], time); } - } // namespace openpmd_api -} // namespace amrex +} // namespace amrex::openpmd_api diff --git a/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD_PTLImpl.H b/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD_PTLImpl.H index 4b4e53b5618..d2dabc9e494 100644 --- a/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD_PTLImpl.H +++ b/Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD_PTLImpl.H @@ -2,10 +2,8 @@ #define AMREX_PLOTFILE_OPENPMD_PTLS_API_H //extern std::unique_ptr< amrex::openpmd_api::AMReX_openPMDHandler > amrex::openpmd_api::m_OpenPMDHandler; -namespace amrex +namespace amrex::openpmd_api { - namespace openpmd_api - { extern std::unique_ptr< amrex::openpmd_api::AMReX_openPMDHandler > m_OpenPMDHandler; //////////////////////////////////////////////////////////////////////// // @@ -31,8 +29,9 @@ namespace amrex amrex::Print()<<" Real: "<m_Writer == nullptr)) + if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) { return; + } AMREX_ASSERT( do_write_real_comp.size() <= real_comp_names.size() ); AMREX_ASSERT( do_write_int_comp.size() <= int_comp_names.size() ); @@ -58,8 +57,9 @@ namespace amrex amrex::Print()<<" Real: "<m_Writer == nullptr)) + if ((m_OpenPMDHandler == nullptr) || (m_OpenPMDHandler->m_Writer == nullptr)) { return; + } AMREX_ASSERT( do_write_real_comp.size() <= real_comp_names.size() ); AMREX_ASSERT( do_write_int_comp.size() <= int_comp_names.size() ); @@ -107,10 +107,11 @@ namespace amrex write_real_comp.push_back(1); std::stringstream ss; - if (i < pc.NStructReal) + if (i < pc.NStructReal) { ss << "aos-r_" << i; - else + } else { ss << "SoA-r" << i; + } real_comp_names.push_back(ss.str()); } @@ -122,10 +123,11 @@ namespace amrex write_int_comp.push_back(1); std::stringstream ss; - if (i < pc.NStructInt) + if (i < pc.NStructInt) { ss << "aos-i_" << i; - else + } else { ss << "SoA-i" << i; + } int_comp_names.push_back(ss.str()); } @@ -151,10 +153,11 @@ namespace amrex write_real_comp.push_back(1); std::stringstream ss; - if (i < pc.NStructReal) + if (i < pc.NStructReal) { ss << "aos-r_" << i; - else + } else { ss << "SoA-r" << i; + } real_comp_names.push_back(ss.str()); } @@ -166,10 +169,11 @@ namespace amrex write_int_comp.push_back(1); std::stringstream ss; - if (i < pc.NStructInt) + if (i < pc.NStructInt) { ss << "aos-i_" << i; - else + } else { ss << "SoA-i" << i; + } int_comp_names.push_back(ss.str()); } @@ -188,36 +192,31 @@ namespace amrex getUnitDimension ( std::string const & record_name ) { - if( record_name == "position" ) return { - {openPMD::UnitDimension::L, 1.} - }; - else if( record_name == "positionOffset" ) return { - {openPMD::UnitDimension::L, 1.} - }; - else if( record_name == "momentum" ) return { - {openPMD::UnitDimension::L, 1.}, - {openPMD::UnitDimension::M, 1.}, - {openPMD::UnitDimension::T, -1.} - }; - else if( record_name == "charge" ) return { - {openPMD::UnitDimension::T, 1.}, - {openPMD::UnitDimension::I, 1.} - }; - else if( record_name == "mass" ) return { - {openPMD::UnitDimension::M, 1.} - }; - else if( record_name == "E" ) return { - {openPMD::UnitDimension::L, 1.}, - {openPMD::UnitDimension::M, 1.}, - {openPMD::UnitDimension::T, -3.}, - {openPMD::UnitDimension::I, -1.}, - }; - else if( record_name == "B" ) return { - {openPMD::UnitDimension::M, 1.}, - {openPMD::UnitDimension::I, -1.}, - {openPMD::UnitDimension::T, -2.} - }; - else return {}; + if( record_name == "position" ) { + return {{openPMD::UnitDimension::L, 1.}}; + } else if( record_name == "positionOffset" ) { + return {{openPMD::UnitDimension::L, 1.}}; + } else if( record_name == "momentum" ) { + return {{openPMD::UnitDimension::L, 1.}, + {openPMD::UnitDimension::M, 1.}, + {openPMD::UnitDimension::T, -1.}}; + } else if( record_name == "charge" ) { + return {{openPMD::UnitDimension::T, 1.}, + {openPMD::UnitDimension::I, 1.}}; + } else if( record_name == "mass" ) { + return {{openPMD::UnitDimension::M, 1.}}; + } else if( record_name == "E" ) { + return {{openPMD::UnitDimension::L, 1.}, + {openPMD::UnitDimension::M, 1.}, + {openPMD::UnitDimension::T, -3.}, + {openPMD::UnitDimension::I, -1.}}; + } else if( record_name == "B" ) { + return {{openPMD::UnitDimension::M, 1.}, + {openPMD::UnitDimension::I, -1.}, + {openPMD::UnitDimension::T, -2.}}; + } else { + return {}; + } } // @@ -227,10 +226,10 @@ namespace amrex localIDtoGlobal(int const id, int const cpu) { // from WarpXUtilIO::localIDtoGlobal - static_assert(sizeof(int) * 2u <= sizeof(uint64_t), + static_assert(sizeof(int) * 2U <= sizeof(uint64_t), "int size might cause collisions in global IDs"); - return uint64_t(id) | uint64_t(cpu) << 32u; + return uint64_t(id) | uint64_t(cpu) << 32U; } @@ -241,10 +240,10 @@ namespace amrex std::string component_name = openPMD::RecordComponent::SCALAR; // we use "_" as separator in names to group vector records - std::size_t startComp = fullName.find_last_of("_"); + std::size_t startComp = fullName.find_last_of('_'); if( startComp != std::string::npos ) { // non-scalar record_name = fullName.substr(0, startComp); - component_name = fullName.substr(startComp + 1u); + component_name = fullName.substr(startComp + 1U); } return make_pair(record_name, component_name); } @@ -254,12 +253,12 @@ namespace amrex // inline auto getComponentRecord (openPMD::ParticleSpecies& currSpecies, - std::string const comp_name) + std::string const& comp_name) { // handle scalar and non-scalar records by name const auto [record_name, component_name] = name2openPMD(comp_name); return currSpecies[record_name][component_name]; - }; + } } // namespace helper @@ -278,7 +277,7 @@ namespace amrex { auto const& aos = pti.GetArrayOfStructs(); // size = numParticlesOnTile auto const numParticleOnTile = pti.numParticles(); - uint64_t const numParticleOnTile64 = static_cast( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); // first we concatenate the AoS into contiguous arrays { @@ -294,8 +293,9 @@ namespace amrex [](amrex::ParticleReal const *p){ delete[] p; } ); - for( auto kk=0; kk( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); // first we concatenate the AoS into contiguous arrays { @@ -330,8 +330,9 @@ namespace amrex [](int const *p){ delete[] p; } ); - for( auto kk=0; kk( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); auto const real_counter = std::min(write_real_comp.size(), real_comp_names.size()) - PIt::ContainerType::NStructReal; @@ -378,7 +379,7 @@ namespace amrex { auto const& soa = pti.GetStructOfArrays(); auto const numParticleOnTile = pti.numParticles(); - uint64_t const numParticleOnTile64 = static_cast( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); auto const int_counter = std::min(write_int_comp.size(), int_comp_names.size()) - PIt::ContainerType::NStructInt; for (auto idx=0; idx( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); // get position and particle ID from aos // note: this implementation iterates the AoS 4x... @@ -423,7 +424,7 @@ namespace amrex //amrex::AllPrint()<<" i = "<( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); // get position and particle ID from aos // note: this implementation iterates the AoS 4x... @@ -453,7 +454,7 @@ namespace amrex { ids.get()[i] = helper::localIDtoGlobal(aos[i].id(), aos[i].cpu()); } - auto const scalar = openPMD::RecordComponent::SCALAR; + auto const * const scalar = openPMD::RecordComponent::SCALAR; currSpecies["id"][scalar].storeChunk(ids, {offset + GetGrandOffset()}, {numParticleOnTile64}); } } @@ -497,7 +498,7 @@ namespace amrex ) const { DumpParticles(pc, name, write_real_comp, write_int_comp, real_comp_names, int_comp_names, - [=] (auto& pc, openPMD::ParticleSpecies& currSpecies, unsigned long long size) + [=] (auto& /*pc*/, openPMD::ParticleSpecies& /*currSpecies*/, unsigned long long /*size*/) { }, // no extra pc level info to save [=] (auto& pti, openPMD::ParticleSpecies& currSpecies, unsigned long long offset) @@ -548,19 +549,19 @@ namespace amrex bool emptyPC = true; for (auto currentLevel = 0; currentLevel <= pc.finestLevel(); currentLevel++) { - uint64_t offset = static_cast( pc.m_PtlCounter.m_ParticleOffsetAtRank[currentLevel] ); + auto offset = static_cast( pc.m_PtlCounter.m_ParticleOffsetAtRank[currentLevel] ); using ParIter = typename PC::ParConstIterType; //for (WarpXParIter pti(*pc, currentLevel); pti.isValid(); ++pti) { for (ParIter pti(pc, currentLevel); pti.isValid(); ++pti) { auto const numParticleOnTile = pti.numParticles(); - uint64_t const numParticleOnTile64 = static_cast( numParticleOnTile ); + auto const numParticleOnTile64 = static_cast( numParticleOnTile ); // Do not call storeChunk() with zero-sized particle tiles: // https://github.com/openPMD/openPMD-api/issues/1147 // https://github.com/ECP-WarpX/WarpX/pull/1898#discussion_r745008290 - if (numParticleOnTile == 0) continue; + if (numParticleOnTile == 0) { continue; } emptyPC = false; @@ -585,13 +586,13 @@ namespace amrex template - void AMReX_openPMDWriter::SetupRealProperties (PC const& pc, + void AMReX_openPMDWriter::SetupRealProperties (PC const& /*pc*/, openPMD::ParticleSpecies& currSpecies, const amrex::Vector& write_real_comp, const amrex::Vector& real_comp_names, const amrex::Vector& write_int_comp, const amrex::Vector& int_comp_names, - const unsigned long long np) const + const unsigned long long /*np*/) const { //AllocateRealProperties(currSpecies, write_real_comp, real_comp_names, write_int_comp, int_comp_names, np); @@ -615,14 +616,16 @@ namespace amrex if( newRecord ) { currRecord.setUnitDimension( helper::getUnitDimension(record_name) ); - if( record_name == "weighting" ) - currRecord.setAttribute( "macroWeighted", 1u ); - else - currRecord.setAttribute( "macroWeighted", 0u ); - if( record_name == "momentum" || record_name == "weighting" ) + if( record_name == "weighting" ) { + currRecord.setAttribute( "macroWeighted", 1U ); + } else { + currRecord.setAttribute( "macroWeighted", 0U ); + } + if( record_name == "momentum" || record_name == "weighting" ) { currRecord.setAttribute( "weightingPower", 1.0 ); - else + } else { currRecord.setAttribute( "weightingPower", 0.0 ); + } } } } @@ -642,17 +645,17 @@ namespace amrex if( newRecord ) { currRecord.setUnitDimension( helper::getUnitDimension(record_name) ); - currRecord.setAttribute( "macroWeighted", 0u ); - if( record_name == "momentum" || record_name == "weighting" ) + currRecord.setAttribute( "macroWeighted", 0U ); + if( record_name == "momentum" || record_name == "weighting" ) { currRecord.setAttribute( "weightingPower", 1.0 ); - else + } else { currRecord.setAttribute( "weightingPower", 0.0 ); + } } } } } - } // namespace openpmd_api -} // namespace amrex +} // namespace amrex::openpmd_api #endif // AMREX_PLOTFILE_OPENPMD_API_H diff --git a/Tests/MultiBlock/Advection/main.cpp b/Tests/MultiBlock/Advection/main.cpp index 74418ef9efc..96e1fb9a3a5 100644 --- a/Tests/MultiBlock/Advection/main.cpp +++ b/Tests/MultiBlock/Advection/main.cpp @@ -186,6 +186,7 @@ struct FillBoundaryFn { core_x.mass.FillBoundary(core_x.Geom(coarsest_level).periodicity()); core_y.mass.FillBoundary(core_y.Geom(coarsest_level).periodicity()); std::vector comms; + comms.reserve(boundaries.size()); for (auto& boundary : boundaries) { comms.push_back(boundary.FillBoundary_nowait()); } diff --git a/Tests/openPMDTests/fields/main.cpp b/Tests/openPMDTests/fields/main.cpp index 02c3ed80375..74d4650fead 100644 --- a/Tests/openPMDTests/fields/main.cpp +++ b/Tests/openPMDTests/fields/main.cpp @@ -52,8 +52,6 @@ struct TestField { TestField(const InputParams& inputs) { - m_Time = 0.0; - const int nghost = 0; Vector domains; @@ -66,10 +64,8 @@ struct TestField real_box.setHi(n, 1.0); } - int is_per[AMREX_SPACEDIM]; // This sets the boundary conditions to be doubly or triply periodic - for (int i = 0; i < AMREX_SPACEDIM; i++) - is_per[i] = 1; + int is_per[AMREX_SPACEDIM] = {AMREX_D_DECL(1,1,1)}; // This defines a Geometry object for each level m_Geom.resize(inputs.nlevs); @@ -83,15 +79,16 @@ struct TestField m_mf.resize(inputs.nlevs); for (int lev = 0; lev < inputs.nlevs; lev++) { - std::cout<(ba[lev], dmap[lev], inputs.ncomp, nghost); m_mf[lev]->setVal(lev); } - for (int i = 0; i < inputs.ncomp; ++i) + for (int i = 0; i < inputs.ncomp; ++i) { m_Varnames.push_back("component_" + std::to_string(i)); + } //Vector level_steps(inputs.nlevs, 0); m_Level_steps.assign(inputs.nlevs, 0); @@ -100,14 +97,14 @@ struct TestField Vector m_Level_steps; Vector m_Varnames; - Real m_Time; + Real m_Time = Real(0.0); Vector m_Ref_ratio; Vector m_Geom; Vector > m_mf; }; -void saveFile(char* fname, const InputParams& inputs, const TestField& testField) +void saveFile(char const* fname, const InputParams& inputs, const TestField& testField) { #ifdef AMREX_USE_OPENPMD_API openpmd_api::InitHandler(fname); @@ -167,8 +164,9 @@ void set_grids_nested (const InputParams& input, domains[0].setBig(domain_hi); ref_ratio.resize(input.nlevs-1); - for (int lev = 1; lev < input.nlevs; lev++) + for (int lev = 1; lev < input.nlevs; lev++) { ref_ratio[lev-1] = IntVect(AMREX_D_DECL(2, 2, 2)); + } grids.resize(input.nlevs); grids[0].define(domains[0]); diff --git a/Tests/openPMDTests/ptls/main.cpp b/Tests/openPMDTests/ptls/main.cpp index 217c5994b5a..74fb7450e7d 100644 --- a/Tests/openPMDTests/ptls/main.cpp +++ b/Tests/openPMDTests/ptls/main.cpp @@ -33,7 +33,7 @@ void checkMFBox(const TestParams& parms, { for (int lev=0; lev < parms.nlevs; lev++) { - auto curr_mf = outputMF[lev]; + auto const* curr_mf = outputMF[lev]; int const ncomp = curr_mf->nComp(); amrex::Print()<<" checking boxes, lev="< rr(parms.nlevs-1); - for (int lev = 1; lev < parms.nlevs; lev++) + for (int lev = 1; lev < parms.nlevs; lev++) { rr[lev-1] = IntVect(AMREX_D_DECL(2,2,2)); + } RealBox real_box; for (int n = 0; n < BL_SPACEDIM; n++) { @@ -254,9 +255,7 @@ void testBTD (TestParams& parms, int nghost) const Box base_domain(domain_lo, domain_hi); // This sets the boundary conditions to be doubly or triply periodic - int is_per[BL_SPACEDIM]; - for (int i = 0; i < BL_SPACEDIM; i++) - is_per[i] = 1; + int is_per[BL_SPACEDIM] = {AMREX_D_DECL(1,1,1)}; Vector geom(parms.nlevs); geom[0].define(base_domain, &real_box, CoordSys::cartesian, is_per); @@ -291,8 +290,9 @@ void testBTD (TestParams& parms, int nghost) myPC.SetVerbose(false); bool serialize = true; - if (ParallelDescriptor::NProcs() > 1) + if (ParallelDescriptor::NProcs() > 1) { serialize = false; + } amrex::Long num_particles = (amrex::Long)parms.nppc * parms.nx * parms.ny * parms.nz; amrex::Print() << serialize<< " Total number of particles :" << num_particles << '\n'; @@ -347,11 +347,11 @@ void testBTD (TestParams& parms, int nghost) // call count ptls to prepare ahead of time myPC.CountParticles(); - std::string fname = ""; + std::string fname; openpmd_api::InitHandler(fname); std::vector warpxPMLs(10); - AMReX_warpxBTDWriter* testWriter = new AMReX_warpxBTDWriter(warpxPMLs); + auto* testWriter = new AMReX_warpxBTDWriter(warpxPMLs); // xxxxx is there a memory leak? amrex::openpmd_api::UseCustomWriter(testWriter); // one specie per particle container @@ -375,20 +375,22 @@ void testBTD (TestParams& parms, int nghost) testWriter->AssignPtlOffset(num_particles); testWriter->SetLastFlush(); } +#if 0 if (0) { // test with default component names openpmd_api::WriteParticles(myPC, specieName); } else +#endif { // test with RZ style pos id openpmd_api::WriteParticles(myPC, specieName, - [=] (auto& pc, openPMD::ParticleSpecies& currSpecies, unsigned long long localTotal) + [=] (auto& /*pc*/, openPMD::ParticleSpecies& currSpecies, unsigned long long localTotal) { - amrex::ParticleReal charge = 0.01; // warpx: pc->getCharge() - amrex::ParticleReal mass = 0.5; // warpx: pc->getMass(); + amrex::ParticleReal lcharge = 0.01; // warpx: pc->getCharge() + amrex::ParticleReal lmass = 0.5; // warpx: pc->getMass(); - testWriter->SetConstantMassCharge(currSpecies, localTotal, charge, mass); + testWriter->SetConstantMassCharge(currSpecies, localTotal, lcharge, lmass); }, [=] (auto& pti, openPMD::ParticleSpecies& currSpecies, unsigned long long offset) { @@ -433,8 +435,9 @@ int main(int argc, char* argv[]) pp.get("nlevs", parms.nlevs); //pp.get("nplotfile", parms.nplotfile); - if (parms.nppc < 1 && ParallelDescriptor::IOProcessor()) + if (parms.nppc < 1 && ParallelDescriptor::IOProcessor()) { amrex::Abort("Must specify at least one particle per cell"); + } parms.verbose = false; pp.query("verbose", parms.verbose); diff --git a/Tests/openPMDTests/ptls/mypc.H b/Tests/openPMDTests/ptls/mypc.H index 3487a806637..826ffdb3216 100644 --- a/Tests/openPMDTests/ptls/mypc.H +++ b/Tests/openPMDTests/ptls/mypc.H @@ -1,7 +1,6 @@ #include -typedef amrex::ParticleContainer<20,3,7,9> MyParticleContainer; +using MyParticleContainer = amrex::ParticleContainer<20,3,7,9>; // change to two parameters so i can check with plotfile output //typedef amrex::ParticleContainer<3,4> MyParticleContainer; //typedef amrex::ParticleContainer<1> MyParticleContainer; - diff --git a/Tests/openPMDTests/ptls/pseudo_warpx.H b/Tests/openPMDTests/ptls/pseudo_warpx.H index 333d41718e2..ba8ee79d9c8 100644 --- a/Tests/openPMDTests/ptls/pseudo_warpx.H +++ b/Tests/openPMDTests/ptls/pseudo_warpx.H @@ -48,7 +48,7 @@ namespace WarpX }; }; -}; +} #endif diff --git a/Tests/openPMDTests/ptls/warpxBTD.H b/Tests/openPMDTests/ptls/warpxBTD.H index 3bf13eea3b7..8d7c47a5133 100644 --- a/Tests/openPMDTests/ptls/warpxBTD.H +++ b/Tests/openPMDTests/ptls/warpxBTD.H @@ -8,7 +8,6 @@ #include #include "warpxWriter.H" -using namespace amrex; //////////////////////////// @@ -21,16 +20,13 @@ class AMReX_warpxBTDWriter final : public AMReX_warpxWriter std::string filetype = "default", std::string openpmdOptions = "{}"); - //~AMReX_warpxBTDWriter() override = default; - ~AMReX_warpxBTDWriter() override; - // BTD does not support streams - openPMD::Iteration GetIteration (int const iteration) const override + [[nodiscard]] openPMD::Iteration GetIteration (int const iteration) const override { return m_Series->iterations[iteration]; } - unsigned long long GetGrandOffset() const override + [[nodiscard]] unsigned long long GetGrandOffset() const override { return m_AssignedPtlOffset; } @@ -42,7 +38,7 @@ class AMReX_warpxBTDWriter final : public AMReX_warpxWriter const amrex::Vector& real_comp_names, const amrex::Vector& write_int_comp, const amrex::Vector& int_comp_names, - const unsigned long long np) const override; + unsigned long long np) const override; void SetupConstant(openPMD::ParticleSpecies& currSpecies, @@ -63,11 +59,11 @@ class AMReX_warpxBTDWriter final : public AMReX_warpxWriter const amrex::Vector& mf, const amrex::Vector& geom, //const int iteration, - const double time ) const override; + double time ) const override; // BTD specific: - void SetLastFlush() {m_LastFlush = true;}; - bool IsLastFlush() {return m_LastFlush;} - void AssignPtlOffset(unsigned long long m) { m_AssignedPtlOffset = m; }; + void SetLastFlush() {m_LastFlush = true;} + [[nodiscard]] bool IsLastFlush() const {return m_LastFlush;} + void AssignPtlOffset(unsigned long long m) { m_AssignedPtlOffset = m; } template void SavePosId_RZ(PIt& pti, @@ -76,8 +72,8 @@ class AMReX_warpxBTDWriter final : public AMReX_warpxWriter void SetConstantMassCharge(openPMD::ParticleSpecies& currSpecies, const unsigned long long& np, - amrex::ParticleReal const charge, - amrex::ParticleReal const mass) const override; + amrex::ParticleReal charge, + amrex::ParticleReal mass) const override; private: bool m_LastFlush = false; @@ -94,7 +90,7 @@ AMReX_warpxBTDWriter::AMReX_warpxBTDWriter( std::string filetype, std::string openpmdOptions) // :AMReX_openPMDWriter("{}", ie, filetype, openpmdOptions) - :AMReX_warpxWriter(fieldPMLdirections, ie, filetype, openpmdOptions) + :AMReX_warpxWriter(std::move(fieldPMLdirections), ie, std::move(filetype), std::move(openpmdOptions)) { m_openPMDDatasetOptions="{ \"resizable\": true }"; @@ -105,16 +101,11 @@ AMReX_warpxBTDWriter::AMReX_warpxBTDWriter( } } -AMReX_warpxBTDWriter::~AMReX_warpxBTDWriter() -{ - -} - - void AMReX_warpxBTDWriter::CloseStep(int ts) { - if (!m_LastFlush) + if (!m_LastFlush) { return; + } AMReX_openPMDWriter::CloseStep(ts); m_LastFlush = false; // this step is over @@ -149,7 +140,8 @@ bool AMReX_warpxBTDWriter::AllocatePtlProperties(openPMD::ParticleSpecies& currS { // properties were never allocated //AMReX_openPMDWriter::SetupPos(currSpecies, np); - AMReX_openPMDWriter::AllocatePtlProperties(currSpecies, write_real_comp, real_comp_names, write_int_comp, int_comp_names, np); + auto r = AMReX_openPMDWriter::AllocatePtlProperties(currSpecies, write_real_comp, real_comp_names, write_int_comp, int_comp_names, np); + amrex::ignore_unused(r); } return false; } @@ -265,6 +257,3 @@ AMReX_warpxBTDWriter::SavePosId_RZ(PIt& pti, SavePosId(pti, currSpecies, offset); #endif } - - - diff --git a/Tests/openPMDTests/ptls/warpxWriter.H b/Tests/openPMDTests/ptls/warpxWriter.H index 1a8704ed404..b13c61a0b80 100644 --- a/Tests/openPMDTests/ptls/warpxWriter.H +++ b/Tests/openPMDTests/ptls/warpxWriter.H @@ -13,9 +13,6 @@ #include "pseudo_warpx.H" #include "AMReX_PlotFileUtilOPENPMD.H" -using namespace amrex; -using namespace WarpX; - class AMReX_warpxWriter: public amrex::openpmd_api::AMReX_openPMDWriter { public: @@ -23,9 +20,9 @@ public: openPMD::IterationEncoding ie = openPMD::IterationEncoding::variableBased, std::string filetype = "default", std::string openpmdOptions = "{}") - :AMReX_openPMDWriter("{}", ie, filetype, openpmdOptions), + :AMReX_openPMDWriter("{}", ie, std::move(filetype), std::move(openpmdOptions)), m_fieldPMLdirections(std::move(fieldPMLdirections)) - {}; + {} // // fields related funcitions @@ -38,19 +35,19 @@ public: void SetupFields (openPMD::Container< openPMD::Mesh >& meshes, amrex::Geometry& full_geom) const override; - inline std::vector< std::string > getParticlePositionComponentLabels() const override; + [[nodiscard]] inline std::vector< std::string > getParticlePositionComponentLabels() const override; virtual void SetConstantMassCharge(openPMD::ParticleSpecies& currSpecies, const unsigned long long& np, - amrex::ParticleReal const charge, - amrex::ParticleReal const mass) const; + amrex::ParticleReal charge, + amrex::ParticleReal mass) const; void SetParticleSpecieAttributes(openPMD::ParticleSpecies& currSpecies) const override; private: std::vector m_fieldPMLdirections; - std::vector< std::string > getFieldAxisLabels ( const amrex::openpmd_api::AMReX_VarNameParser& varName ) const; + [[nodiscard]] static std::vector< std::string > getFieldAxisLabels ( const amrex::openpmd_api::AMReX_VarNameParser& varName ); }; @@ -120,31 +117,33 @@ void AMReX_warpxWriter::SetupFields (openPMD::Container< openPMD::Mesh >& meshes particleBoundary.resize(4); #endif if (m_fieldPMLdirections.size() >= fieldBoundary.size()) - { - for (auto i = 0u; i < fieldBoundary.size() / 2u; ++i) - if (m_fieldPMLdirections.at(i)) - fieldBoundary.at(i) = "open"; - } + { + for (int i = 0; i < int(fieldBoundary.size() / 2); ++i) { + if (m_fieldPMLdirections.at(i)) { + fieldBoundary.at(i) = "open"; + } + } + } - for (auto i = 0u; i < fieldBoundary.size() / 2u; ++i) + for (int i = 0; i < int(fieldBoundary.size() / 2); ++i) { if (period.isPeriodic(i)) { - fieldBoundary.at(2u * i) = "periodic"; - fieldBoundary.at(2u * i + 1u) = "periodic"; - particleBoundary.at(2u * i) = "periodic"; - particleBoundary.at(2u * i + 1u) = "periodic"; + fieldBoundary.at(2 * i) = "periodic"; + fieldBoundary.at(2 * i + 1) = "periodic"; + particleBoundary.at(2 * i) = "periodic"; + particleBoundary.at(2 * i + 1) = "periodic"; } - + } meshes.setAttribute("fieldSolver", []() { switch (WarpX::electromagnetic_solver_id) { - case ElectromagneticSolverAlgo::Yee : - return "Yee"; - case ElectromagneticSolverAlgo::CKC : - return "CK"; - case ElectromagneticSolverAlgo::PSATD : - return "PSATD"; + case WarpX::ElectromagneticSolverAlgo::Yee : + { return "Yee"; } + case WarpX::ElectromagneticSolverAlgo::CKC : + { return "CK"; } + case WarpX::ElectromagneticSolverAlgo::PSATD : + { return "PSATD"; } default: - return "other"; + { return "other"; } } }()) ; @@ -153,11 +152,11 @@ void AMReX_warpxWriter::SetupFields (openPMD::Container< openPMD::Mesh >& meshes meshes.setAttribute("particleBoundary", particleBoundary); meshes.setAttribute("currentSmoothing", []() { - if (WarpX::use_filter) return "Binomial"; - else return "none"; + if (WarpX::use_filter) { return "Binomial"; } + else { return "none"; } }()); - if (WarpX::use_filter) + if (WarpX::use_filter) { meshes.setAttribute("currentSmoothingParameters", []() { std::stringstream ss; ss << "period=1;compensator=false"; @@ -179,19 +178,21 @@ void AMReX_warpxWriter::SetupFields (openPMD::Container< openPMD::Mesh >& meshes std::string currentSmoothingParameters = ss.str(); return currentSmoothingParameters; }()); + } meshes.setAttribute("chargeCorrection", []() { - if (WarpX::do_dive_cleaning) return "hyperbolic"; // TODO or "spectral" or something? double-check - else return "none"; + if (WarpX::do_dive_cleaning) { return "hyperbolic"; } // TODO or "spectral" or something? double-check + else { return "none"; } }()); - if (WarpX::do_dive_cleaning) + if (WarpX::do_dive_cleaning) { meshes.setAttribute("chargeCorrectionParameters", "period=1"); + } } -std::vector< std::string > AMReX_warpxWriter::getFieldAxisLabels ( const amrex::openpmd_api::AMReX_VarNameParser& varName ) const +std::vector< std::string > AMReX_warpxWriter::getFieldAxisLabels ( const amrex::openpmd_api::AMReX_VarNameParser& /*varName*/ ) { using vs = std::vector< std::string >; // Fortran order of the index labels for the AMReX FArrayBox @@ -223,9 +224,9 @@ AMReX_warpxWriter::getParticlePositionComponentLabels() const { using vs = std::vector< std::string >; #if defined(WARPX_DIM_1D_Z) - vs const positionComponents{"z"}; + vs positionComponents{"z"}; #elif defined(WARPX_DIM_XZ) - vs const positionComponents{"x", "z"}; + vs positionComponents{"x", "z"}; #elif defined(WARPX_DIM_RZ) // note: although we internally store particle positions // for AMReX in r,z and a theta attribute, we @@ -233,13 +234,13 @@ AMReX_warpxWriter::getParticlePositionComponentLabels() const // and I/O in Cartesian. // Other attributes like momentum are consequently // stored in x,y,z internally. - vs const positionComponents{"x", "y", "z"}; + vs positionComponents{"x", "y", "z"}; #elif (WARPX_DIM_3D) - vs const positionComponents{"x", "y", "z"}; + vs positionComponents{"x", "y", "z"}; #else //# error Unknown WarpX dimensionality. // default: - vs const positionComponents{"kk", "jj", "ii"}; + vs positionComponents{"kk", "jj", "ii"}; #endif return positionComponents; } @@ -251,7 +252,7 @@ void AMReX_warpxWriter::SetConstantMassCharge(openPMD::ParticleSpecies& currSpec amrex::ParticleReal const mass) const { auto realType = openPMD::Dataset(openPMD::determineDatatype(), {np}); - auto const scalar = openPMD::RecordComponent::SCALAR; + auto const * const scalar = openPMD::RecordComponent::SCALAR; currSpecies["charge"][scalar].resetDataset( realType ); currSpecies["mass"][scalar].resetDataset( realType ); @@ -262,9 +263,9 @@ void AMReX_warpxWriter::SetConstantMassCharge(openPMD::ParticleSpecies& currSpec currSpecies["charge"].setUnitDimension( amrex::openpmd_api::helper::getUnitDimension("charge") ); currSpecies["mass"].setUnitDimension( amrex::openpmd_api::helper::getUnitDimension("mass") ); - currSpecies["charge"].setAttribute( "macroWeighted", 0u ); + currSpecies["charge"].setAttribute( "macroWeighted", 0U ); currSpecies["charge"].setAttribute( "weightingPower", 1.0 ); - currSpecies["mass"].setAttribute( "macroWeighted", 0u ); + currSpecies["mass"].setAttribute( "macroWeighted", 0U ); currSpecies["mass"].setAttribute( "weightingPower", 1.0 ); } @@ -277,12 +278,12 @@ void AMReX_warpxWriter::SetParticleSpecieAttributes(openPMD::ParticleSpecies& cu { // ED-PIC extension - currSpecies["id"].setAttribute( "macroWeighted", 0u ); + currSpecies["id"].setAttribute( "macroWeighted", 0U ); currSpecies["id"].setAttribute( "weightingPower", 0.0 ); - currSpecies["position"].setAttribute( "macroWeighted", 0u ); + currSpecies["position"].setAttribute( "macroWeighted", 0U ); currSpecies["position"].setAttribute( "weightingPower", 0.0 ); - currSpecies["positionOffset"].setAttribute( "macroWeighted", 0u ); + currSpecies["positionOffset"].setAttribute( "macroWeighted", 0U ); currSpecies["positionOffset"].setAttribute( "weightingPower", 0.0 ); // meta data for ED-PIC extension @@ -300,24 +301,24 @@ void AMReX_warpxWriter::SetParticleSpecieAttributes(openPMD::ParticleSpecies& cu currSpecies.setAttribute( "particlePush", [](){ switch( WarpX::particle_pusher_algo ) { - case ParticlePusherAlgo::Boris : return "Boris"; - case ParticlePusherAlgo::Vay : return "Vay"; - case ParticlePusherAlgo::HigueraCary : return "HigueraCary"; - default: return "other"; + case WarpX::ParticlePusherAlgo::Boris : { return "Boris"; } + case WarpX::ParticlePusherAlgo::Vay : { return "Vay"; } + case WarpX::ParticlePusherAlgo::HigueraCary : { return "HigueraCary"; } + default: { return "other"; } } }() ); currSpecies.setAttribute( "particleInterpolation", [](){ switch( WarpX::field_gathering_algo ) { - case GatheringAlgo::EnergyConserving : return "energyConserving"; - case GatheringAlgo::MomentumConserving : return "momentumConserving"; - default: return "other"; + case WarpX::GatheringAlgo::EnergyConserving : { return "energyConserving"; } + case WarpX::GatheringAlgo::MomentumConserving : { return "momentumConserving"; } + default: { return "other"; } } }() ); currSpecies.setAttribute( "particleSmoothing", "none" ); currSpecies.setAttribute( "currentDeposition", [](){ switch( WarpX::current_deposition_algo ) { - case CurrentDepositionAlgo::Esirkepov : return "Esirkepov"; - default: return "directMorseNielson"; + case WarpX::CurrentDepositionAlgo::Esirkepov : { return "Esirkepov"; } + default: { return "directMorseNielson"; } } }() ); }