diff options
95 files changed, 1997 insertions, 1599 deletions
diff --git a/Source/BoundaryConditions/PML.cpp b/Source/BoundaryConditions/PML.cpp index 712e287f0..76dbd3fde 100644 --- a/Source/BoundaryConditions/PML.cpp +++ b/Source/BoundaryConditions/PML.cpp @@ -1,5 +1,5 @@ -/* Copyright 2019 Andrew Myers, Aurore Blelly, Axel Huebl - * Maxence Thevenet, Remi Lehe, Weiqun Zhang +/* Copyright 2019-2022 Andrew Myers, Aurore Blelly, Axel Huebl, + * Luca Fedeli, Maxence Thevenet, Remi Lehe, Weiqun Zhang * * * This file is part of WarpX. @@ -17,7 +17,7 @@ #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" +#include "Utils/Parser/ParserUtils.H" #include "WarpX.H" #include <ablastr/utils/Communication.H> @@ -618,9 +618,9 @@ PML::PML (const int lev, const BoxArray& grid_ba, const DistributionMapping& gri int ngFFt_z = do_nodal ? noz_fft : noz_fft/2; ParmParse pp_psatd("psatd"); - queryWithParser(pp_psatd, "nx_guard", ngFFt_x); - queryWithParser(pp_psatd, "ny_guard", ngFFt_y); - queryWithParser(pp_psatd, "nz_guard", ngFFt_z); + utils::parser::queryWithParser(pp_psatd, "nx_guard", ngFFt_x); + utils::parser::queryWithParser(pp_psatd, "ny_guard", ngFFt_y); + utils::parser::queryWithParser(pp_psatd, "nz_guard", ngFFt_z); #if defined(WARPX_DIM_3D) IntVect ngFFT = IntVect(ngFFt_x, ngFFt_y, ngFFt_z); diff --git a/Source/Diagnostics/BTDiagnostics.H b/Source/Diagnostics/BTDiagnostics.H index fcfc8f13b..ed8cd237b 100644 --- a/Source/Diagnostics/BTDiagnostics.H +++ b/Source/Diagnostics/BTDiagnostics.H @@ -10,7 +10,7 @@ #include "Diagnostics.H" #include "Diagnostics/ComputeDiagFunctors/ComputeDiagFunctor.H" #include "Utils/WarpXConst.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/IntervalsParser.H" #include <AMReX_Box.H> #include <AMReX_Geometry.H> @@ -39,7 +39,7 @@ private: /** Read relevant parameters for BTD */ void ReadParameters (); /** Determines timesteps at which BTD diagnostics are written to file */ - BTDIntervalsParser m_intervals; + utils::parser::BTDIntervalsParser m_intervals; /** \brief Flush m_mf_output and particles to file. * Currently, a temporary customized output format for the buffer * data is implemented and called in this function. diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index 77cc9a30d..dd82bcf0e 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -14,10 +14,11 @@ #include "Diagnostics/Diagnostics.H" #include "Diagnostics/FlushFormats/FlushFormat.H" #include "ComputeDiagFunctors/BackTransformParticleFunctor.H" +#include "Utils/Algorithms/IsIn.H" #include "Utils/CoarsenIO.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/utils/Communication.H> @@ -164,7 +165,8 @@ BTDiagnostics::ReadParameters () std::vector<std::string> intervals_string_vec = {"0"}; - bool const num_snapshots_specified = queryWithParser(pp_diag_name, "num_snapshots_lab", m_num_snapshots_lab); + bool const num_snapshots_specified = utils::parser::queryWithParser( + pp_diag_name, "num_snapshots_lab", m_num_snapshots_lab); bool const intervals_specified = pp_diag_name.queryarr("intervals", intervals_string_vec); if (num_snapshots_specified) { @@ -172,20 +174,20 @@ BTDiagnostics::ReadParameters () "For back-transformed diagnostics, user should specify either num_snapshots_lab or intervals, not both"); intervals_string_vec = {":" + std::to_string(m_num_snapshots_lab-1)}; } - m_intervals = BTDIntervalsParser(intervals_string_vec); + m_intervals = utils::parser::BTDIntervalsParser(intervals_string_vec); m_num_buffers = m_intervals.NumSnapshots(); // Read either dz_snapshots_lab or dt_snapshots_lab - bool snapshot_interval_is_specified = false; - snapshot_interval_is_specified = queryWithParser(pp_diag_name, "dt_snapshots_lab", m_dt_snapshots_lab); - if ( queryWithParser(pp_diag_name, "dz_snapshots_lab", m_dz_snapshots_lab) ) { + bool snapshot_interval_is_specified = utils::parser::queryWithParser( + pp_diag_name, "dt_snapshots_lab", m_dt_snapshots_lab); + if ( utils::parser::queryWithParser(pp_diag_name, "dz_snapshots_lab", m_dz_snapshots_lab) ) { m_dt_snapshots_lab = m_dz_snapshots_lab/PhysConst::c; snapshot_interval_is_specified = true; } WARPX_ALWAYS_ASSERT_WITH_MESSAGE(snapshot_interval_is_specified, "For back-transformed diagnostics, user should specify either dz_snapshots_lab or dt_snapshots_lab"); - if (queryWithParser(pp_diag_name, "buffer_size", m_buffer_size)) { + if (utils::parser::queryWithParser(pp_diag_name, "buffer_size", m_buffer_size)) { if(m_max_box_size < m_buffer_size) m_max_box_size = m_buffer_size; } @@ -194,8 +196,12 @@ BTDiagnostics::ReadParameters () "jx", "jy", "jz", "rho"}; for (const auto& var : m_varnames) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( (WarpXUtilStr::is_in(BTD_varnames_supported, var )), "Input error: field variable " + var + " in " + m_diag_name - + ".fields_to_plot is not supported for BackTransformed diagnostics. Currently supported field variables for BackTransformed diagnostics include Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, and rho"); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + (utils::algorithms::is_in(BTD_varnames_supported, var )), + "Input error: field variable " + var + " in " + m_diag_name + + ".fields_to_plot is not supported for BackTransformed diagnostics." + + " Currently supported field variables for BackTransformed diagnostics " + + "include Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, and rho"); } bool particle_fields_to_plot_specified = pp_diag_name.queryarr("particle_fields_to_plot", m_pfield_varnames); diff --git a/Source/Diagnostics/BackTransformedDiagnostic.cpp b/Source/Diagnostics/BackTransformedDiagnostic.cpp index 5b28d6100..7d148abf1 100644 --- a/Source/Diagnostics/BackTransformedDiagnostic.cpp +++ b/Source/Diagnostics/BackTransformedDiagnostic.cpp @@ -7,6 +7,7 @@ */ #include "BackTransformedDiagnostic.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" @@ -625,7 +626,7 @@ BackTransformedDiagnostic (Real zmin_lab, Real zmax_lab, Real v_window_lab, ParmParse pp_warpx("warpx"); bool do_user_fields = false; do_user_fields = pp_warpx.queryarr("back_transformed_diag_fields", user_fields_to_dump); - if (queryWithParser(pp_warpx, "buffer_size", m_num_buffer_)) { + if (utils::parser::queryWithParser(pp_warpx, "buffer_size", m_num_buffer_)) { if (m_max_box_size_ < m_num_buffer_) m_max_box_size_ = m_num_buffer_; } // If user specifies fields to dump, overwrite ncomp_to_dump, diff --git a/Source/Diagnostics/BoundaryScrapingDiagnostics.H b/Source/Diagnostics/BoundaryScrapingDiagnostics.H index 3428f8a4c..01b0e8305 100644 --- a/Source/Diagnostics/BoundaryScrapingDiagnostics.H +++ b/Source/Diagnostics/BoundaryScrapingDiagnostics.H @@ -8,7 +8,7 @@ #define WARPX_BOUNDARYSCRAPINGDIAGNOSTICS_H_ #include "Diagnostics.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/IntervalsParser.H" #include <string> @@ -31,7 +31,7 @@ private: void ReadParameters (); /** Determines timesteps at which the particles are written out */ - IntervalsParser m_intervals; + utils::parser::IntervalsParser m_intervals; /** \brief Flush data to file. */ void Flush (int i_buffer) override; diff --git a/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp b/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp index dcaad9129..a0fad7c7f 100644 --- a/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp +++ b/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp @@ -61,7 +61,7 @@ BoundaryScrapingDiagnostics::ReadParameters () amrex::ParmParse pp_diag_name(m_diag_name); std::vector<std::string> intervals_string_vec = {"0"}; pp_diag_name.queryarr("intervals", intervals_string_vec); - m_intervals = IntervalsParser(intervals_string_vec); + m_intervals = utils::parser::IntervalsParser(intervals_string_vec); } diff --git a/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp b/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp index 0b50e2d79..52952a373 100644 --- a/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp +++ b/Source/Diagnostics/ComputeDiagFunctors/ParticleReductionFunctor.cpp @@ -27,13 +27,15 @@ ParticleReductionFunctor::ParticleReductionFunctor (const amrex::MultiFab* mf_sr AMREX_ALWAYS_ASSERT(ncomp == 1); // Allocate and compile a parser based on the input string fn_str - m_map_fn_parser = std::make_unique<amrex::Parser>(makeParser( - fn_str, {"x", "y", "z", "ux", "uy", "uz"})); + m_map_fn_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser( + fn_str, {"x", "y", "z", "ux", "uy", "uz"})); m_map_fn = m_map_fn_parser->compile<6>(); // Do the same for filter function, if it exists if (m_do_filter) { - m_filter_fn_parser = std::make_unique<amrex::Parser>(makeParser( - filter_str, {"x", "y", "z", "ux", "uy", "uz"})); + m_filter_fn_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser( + filter_str, {"x", "y", "z", "ux", "uy", "uz"})); m_filter_fn = m_filter_fn_parser->compile<6>(); } } diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index 3259994bd..236985de4 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -12,10 +12,11 @@ #include "FlushFormats/FlushFormatPlotfile.H" #include "FlushFormats/FlushFormatSensei.H" #include "Particles/MultiParticleContainer.H" +#include "Utils/Algorithms/IsIn.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/utils/Communication.H> @@ -51,7 +52,8 @@ Diagnostics::BaseReadParameters () amrex::ParmParse pp_diag_name(m_diag_name); m_file_prefix = "diags/" + m_diag_name; pp_diag_name.query("file_prefix", m_file_prefix); - queryWithParser(pp_diag_name, "file_min_digits", m_file_min_digits); + utils::parser::queryWithParser( + pp_diag_name, "file_min_digits", m_file_min_digits); pp_diag_name.query("format", m_format); pp_diag_name.query("dump_last_timestep", m_dump_last_timestep); @@ -71,24 +73,25 @@ Diagnostics::BaseReadParameters () } // Sanity check if user requests to plot phi - if (WarpXUtilStr::is_in(m_varnames_fields, "phi")){ + if (utils::algorithms::is_in(m_varnames_fields, "phi")){ WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.do_electrostatic==ElectrostaticSolverAlgo::LabFrame, "plot phi only works if do_electrostatic = labframe"); } // Sanity check if user requests to plot F - if (WarpXUtilStr::is_in(m_varnames_fields, "F")){ + if (utils::algorithms::is_in(m_varnames_fields, "F")){ WARPX_ALWAYS_ASSERT_WITH_MESSAGE( warpx.do_dive_cleaning, "plot F only works if warpx.do_dive_cleaning = 1"); } // G can be written to file only if WarpX::do_divb_cleaning = 1 - if (WarpXUtilStr::is_in(m_varnames_fields, "G")) + if (utils::algorithms::is_in(m_varnames_fields, "G")) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - warpx.do_divb_cleaning, "G can be written to file only if warpx.do_divb_cleaning = 1"); + warpx.do_divb_cleaning, + "G can be written to file only if warpx.do_divb_cleaning = 1"); } // If user requests to plot proc_number for a serial run, @@ -120,7 +123,8 @@ Diagnostics::BaseReadParameters () bool do_average = true; pp_diag_pfield.query((var + ".do_average").c_str(), do_average); m_pfield_do_average.push_back(do_average); - Store_parserString(pp_diag_pfield, (var + "(x,y,z,ux,uy,uz)").c_str(), parser_str); + utils::parser::Store_parserString( + pp_diag_pfield, (var + "(x,y,z,ux,uy,uz)").c_str(), parser_str); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( parser_str != "", @@ -169,7 +173,7 @@ Diagnostics::BaseReadParameters () ); } - if (WarpXUtilStr::is_in(m_varnames_fields, "none")){ + if (utils::algorithms::is_in(m_varnames_fields, "none")){ m_varnames_fields.clear(); } @@ -185,14 +189,16 @@ Diagnostics::BaseReadParameters () m_lo.resize(AMREX_SPACEDIM); m_hi.resize(AMREX_SPACEDIM); - bool lo_specified = queryArrWithParser(pp_diag_name, "diag_lo", m_lo, 0, AMREX_SPACEDIM); + const bool lo_specified = utils::parser::queryArrWithParser( + pp_diag_name, "diag_lo", m_lo, 0, AMREX_SPACEDIM); if (!lo_specified) { for (int idim=0; idim < AMREX_SPACEDIM; ++idim) { m_lo[idim] = warpx.Geom(0).ProbLo(idim); } } - bool hi_specified = queryArrWithParser(pp_diag_name, "diag_hi", m_hi, 0, AMREX_SPACEDIM); + const bool hi_specified = utils::parser::queryArrWithParser( + pp_diag_name, "diag_hi", m_hi, 0, AMREX_SPACEDIM); if (!hi_specified) { for (int idim =0; idim < AMREX_SPACEDIM; ++idim) { m_hi[idim] = warpx.Geom(0).ProbHi(idim); @@ -220,7 +226,9 @@ Diagnostics::BaseReadParameters () // Initialize cr_ratio with default value of 1 for each dimension. amrex::Vector<int> cr_ratio(AMREX_SPACEDIM, 1); // Read user-defined coarsening ratio for the output MultiFab. - bool cr_specified = queryArrWithParser(pp_diag_name, "coarsening_ratio", cr_ratio, 0, AMREX_SPACEDIM); + const bool cr_specified = + utils::parser::queryArrWithParser( + pp_diag_name, "coarsening_ratio", cr_ratio, 0, AMREX_SPACEDIM); if (cr_specified) { for (int idim =0; idim < AMREX_SPACEDIM; ++idim) { m_crse_ratio[idim] = cr_ratio[idim]; @@ -228,7 +236,8 @@ Diagnostics::BaseReadParameters () } // Names of species to write to output - bool species_specified = pp_diag_name.queryarr("species", m_output_species_names); + const bool species_specified = + pp_diag_name.queryarr("species", m_output_species_names); // Auxiliary variables @@ -326,8 +335,10 @@ Diagnostics::InitData () m_output_species_names.clear(); } else { amrex::Vector <amrex::Real> dummy_val(AMREX_SPACEDIM); - if ( queryArrWithParser(pp_diag_name, "diag_lo", dummy_val, 0, AMREX_SPACEDIM) || - queryArrWithParser(pp_diag_name, "diag_hi", dummy_val, 0, AMREX_SPACEDIM) ) { + if ( utils::parser::queryArrWithParser( + pp_diag_name, "diag_lo", dummy_val, 0, AMREX_SPACEDIM) || + utils::parser::queryArrWithParser( + pp_diag_name, "diag_hi", dummy_val, 0, AMREX_SPACEDIM) ) { // set geometry filter for particle-diags to true when the diagnostic domain-extent // is specified by the user. // Note that the filter is set for every ith snapshot, and the number of snapshots diff --git a/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp b/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp index 9e325591e..39631afc8 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatAscent.cpp @@ -24,7 +24,6 @@ FlushFormatAscent::WriteToFile ( { #ifdef AMREX_USE_ASCENT WARPX_PROFILE("FlushFormatAscent::WriteToFile()"); - auto & warpx = WarpX::GetInstance(); // wrap mesh data diff --git a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp index c85c8cab2..031549836 100644 --- a/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp +++ b/Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp @@ -6,6 +6,7 @@ #include "Particles/WarpXParticleContainer.H" #include "Particles/PinnedMemoryParticleContainer.H" #include "Utils/Interpolate.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXProfilerWrapper.H" #include "WarpX.H" @@ -348,7 +349,7 @@ FlushFormatPlotfile::WriteParticles(const std::string& dir, UniformFilter const uniform_filter(particle_diags[i].m_do_uniform_filter, particle_diags[i].m_uniform_stride); ParserFilter parser_filter(particle_diags[i].m_do_parser_filter, - compileParser<ParticleDiag::m_nvars> + utils::parser::compileParser<ParticleDiag::m_nvars> (particle_diags[i].m_particle_filter_parser.get()), pc->getMass()); parser_filter.m_units = InputUnits::SI; diff --git a/Source/Diagnostics/FullDiagnostics.H b/Source/Diagnostics/FullDiagnostics.H index 5af5b4ea0..bf0b8b6a5 100644 --- a/Source/Diagnostics/FullDiagnostics.H +++ b/Source/Diagnostics/FullDiagnostics.H @@ -2,7 +2,7 @@ #define WARPX_FULLDIAGNOSTICS_H_ #include "Diagnostics.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/IntervalsParser.H" #include <string> @@ -15,7 +15,7 @@ private: /** Read user-requested parameters for full diagnostics */ void ReadParameters (); /** Determines timesteps at which full diagnostics are written to file */ - IntervalsParser m_intervals; + utils::parser::IntervalsParser m_intervals; /** Whether to plot raw (i.e., NOT cell-centered) fields */ bool m_plot_raw_fields = false; /** Whether to plot guard cells of raw fields */ diff --git a/Source/Diagnostics/FullDiagnostics.cpp b/Source/Diagnostics/FullDiagnostics.cpp index 7bdc2f171..cf71ce9f6 100644 --- a/Source/Diagnostics/FullDiagnostics.cpp +++ b/Source/Diagnostics/FullDiagnostics.cpp @@ -11,6 +11,7 @@ #include "Diagnostics/ParticleDiag/ParticleDiag.H" #include "FlushFormats/FlushFormat.H" #include "Particles/MultiParticleContainer.H" +#include "Utils/Algorithms/IsIn.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "WarpX.H" @@ -85,7 +86,7 @@ FullDiagnostics::ReadParameters () "<diag>.format must be plotfile or openpmd or checkpoint or ascent or sensei"); std::vector<std::string> intervals_string_vec = {"0"}; pp_diag_name.getarr("intervals", intervals_string_vec); - m_intervals = IntervalsParser(intervals_string_vec); + m_intervals = utils::parser::IntervalsParser(intervals_string_vec); bool plot_raw_fields_specified = pp_diag_name.query("plot_raw_fields", m_plot_raw_fields); bool plot_raw_fields_guards_specified = pp_diag_name.query("plot_raw_fields_guards", m_plot_raw_fields_guards); bool raw_specified = plot_raw_fields_specified || plot_raw_fields_guards_specified; @@ -353,7 +354,7 @@ FullDiagnostics::AddRZModesToDiags (int lev) } // If rho is requested, all components will be written out - bool rho_requested = WarpXUtilStr::is_in( m_varnames, "rho" ); + bool rho_requested = utils::algorithms::is_in( m_varnames, "rho" ); // First index of m_all_field_functors[lev] where RZ modes are stored int icomp = m_all_field_functors[0].size(); diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index deab2ba0b..f8c0f7b37 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -2,8 +2,8 @@ #include "Diagnostics/ParticleDiag/ParticleDiag.H" #include "Particles/WarpXParticleContainer.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <AMReX_ParmParse.H> @@ -51,19 +51,19 @@ ParticleDiag::ParticleDiag(std::string diag_name, std::string name, WarpXParticl #endif // build filter functors - m_do_random_filter = queryWithParser(pp_diag_name_species_name, "random_fraction", - m_random_fraction); - m_do_uniform_filter = queryWithParser(pp_diag_name_species_name, "uniform_stride", - m_uniform_stride); + m_do_random_filter = utils::parser::queryWithParser( + pp_diag_name_species_name, "random_fraction", m_random_fraction); + m_do_uniform_filter = utils::parser::queryWithParser( + pp_diag_name_species_name, "uniform_stride",m_uniform_stride); std::string buf; m_do_parser_filter = pp_diag_name_species_name.query("plot_filter_function(t,x,y,z,ux,uy,uz)", buf); if (m_do_parser_filter) { std::string function_string = ""; - Store_parserString(pp_diag_name_species_name,"plot_filter_function(t,x,y,z,ux,uy,uz)", - function_string); + utils::parser::Store_parserString( + pp_diag_name_species_name,"plot_filter_function(t,x,y,z,ux,uy,uz)", function_string); m_particle_filter_parser = std::make_unique<amrex::Parser>( - makeParser(function_string,{"t","x","y","z","ux","uy","uz"})); + utils::parser::makeParser(function_string,{"t","x","y","z","ux","uy","uz"})); } } diff --git a/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp b/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp index 4b4d404ba..f1ebd39fc 100644 --- a/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp +++ b/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp @@ -9,7 +9,6 @@ #include "Diagnostics/ReducedDiags/ReducedDiags.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "Utils/WarpXConst.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp b/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp index 5370077b1..6bedaee1b 100644 --- a/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldEnergy.cpp @@ -8,7 +8,6 @@ #include "FieldEnergy.H" #include "Diagnostics/ReducedDiags/ReducedDiags.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp b/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp index 2778d58ee..804d1641a 100644 --- a/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldMaximum.cpp @@ -8,7 +8,6 @@ #include "FieldMaximum.H" #include "Utils/CoarsenIO.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp b/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp index 8053dc1b4..45a5cc6cb 100644 --- a/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldMomentum.cpp @@ -8,7 +8,6 @@ #include "FieldMomentum.H" #include "Utils/CoarsenIO.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/FieldProbe.cpp b/Source/Diagnostics/ReducedDiags/FieldProbe.cpp index bd5d53611..17afcf62a 100644 --- a/Source/Diagnostics/ReducedDiags/FieldProbe.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldProbe.cpp @@ -11,10 +11,9 @@ #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/Pusher/UpdatePosition.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/warn_manager/WarnManager.H> @@ -90,12 +89,15 @@ FieldProbe::FieldProbe (std::string rd_name) x_probe = 0._rt; y_probe = 0._rt; #if !defined(WARPX_DIM_1D_Z) - getWithParser(pp_rd_name, "x_probe", x_probe); + utils::parser::getWithParser( + pp_rd_name, "x_probe", x_probe); #endif #if defined(WARPX_DIM_3D) - getWithParser(pp_rd_name, "y_probe", y_probe); + utils::parser::getWithParser( + pp_rd_name, "y_probe", y_probe); #endif - getWithParser(pp_rd_name, "z_probe", z_probe); + utils::parser::getWithParser( + pp_rd_name, "z_probe", z_probe); } else if (m_probe_geometry_str == "Line") { @@ -105,16 +107,16 @@ FieldProbe::FieldProbe (std::string rd_name) y_probe = 0._rt; y1_probe = 0._rt; #if !defined(WARPX_DIM_1D_Z) - getWithParser(pp_rd_name, "x_probe", x_probe); - getWithParser(pp_rd_name, "x1_probe", x1_probe); + utils::parser::getWithParser(pp_rd_name, "x_probe", x_probe); + utils::parser::getWithParser(pp_rd_name, "x1_probe", x1_probe); #endif #if defined(WARPX_DIM_3D) - getWithParser(pp_rd_name, "y_probe", y_probe); - getWithParser(pp_rd_name, "y1_probe", y1_probe); + utils::parser::getWithParser(pp_rd_name, "y_probe", y_probe); + utils::parser::getWithParser(pp_rd_name, "y1_probe", y1_probe); #endif - getWithParser(pp_rd_name, "z_probe", z_probe); - getWithParser(pp_rd_name, "z1_probe", z1_probe); - getWithParser(pp_rd_name, "resolution", m_resolution); + utils::parser::getWithParser(pp_rd_name, "z_probe", z_probe); + utils::parser::getWithParser(pp_rd_name, "z1_probe", z1_probe); + utils::parser::getWithParser(pp_rd_name, "resolution", m_resolution); } else if (m_probe_geometry_str == "Plane") { @@ -129,18 +131,18 @@ FieldProbe::FieldProbe (std::string rd_name) target_normal_z = 0._rt; target_up_y = 0._rt; #if defined(WARPX_DIM_3D) - getWithParser(pp_rd_name, "y_probe", y_probe); - getWithParser(pp_rd_name, "target_normal_x", target_normal_x); - getWithParser(pp_rd_name, "target_normal_y", target_normal_y); - getWithParser(pp_rd_name, "target_normal_z", target_normal_z); - getWithParser(pp_rd_name, "target_up_y", target_up_y); + utils::parser::getWithParser(pp_rd_name, "y_probe", y_probe); + utils::parser::getWithParser(pp_rd_name, "target_normal_x", target_normal_x); + utils::parser::getWithParser(pp_rd_name, "target_normal_y", target_normal_y); + utils::parser::getWithParser(pp_rd_name, "target_normal_z", target_normal_z); + utils::parser::getWithParser(pp_rd_name, "target_up_y", target_up_y); #endif - getWithParser(pp_rd_name, "x_probe", x_probe); - getWithParser(pp_rd_name, "z_probe", z_probe); - getWithParser(pp_rd_name, "target_up_x", target_up_x); - getWithParser(pp_rd_name, "target_up_z", target_up_z); - getWithParser(pp_rd_name, "detector_radius", detector_radius); - getWithParser(pp_rd_name, "resolution", m_resolution); + utils::parser::getWithParser(pp_rd_name, "x_probe", x_probe); + utils::parser::getWithParser(pp_rd_name, "z_probe", z_probe); + utils::parser::getWithParser(pp_rd_name, "target_up_x", target_up_x); + utils::parser::getWithParser(pp_rd_name, "target_up_z", target_up_z); + utils::parser::getWithParser(pp_rd_name, "detector_radius", detector_radius); + utils::parser::getWithParser(pp_rd_name, "resolution", m_resolution); } else { @@ -151,7 +153,7 @@ FieldProbe::FieldProbe (std::string rd_name) } pp_rd_name.query("integrate", m_field_probe_integrate); pp_rd_name.query("raw_fields", raw_fields); - queryWithParser(pp_rd_name, "interp_order", interp_order); + utils::parser::queryWithParser(pp_rd_name, "interp_order", interp_order); pp_rd_name.query("do_moving_window_FP", do_moving_window_FP); if (WarpX::gamma_boost > 1.0_rt) diff --git a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp index 1f98dca8c..23d1e76a8 100644 --- a/Source/Diagnostics/ReducedDiags/FieldReduction.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldReduction.cpp @@ -7,10 +7,9 @@ #include "FieldReduction.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" -#include "Utils/WarpXUtil.H" #include <AMReX_Algorithm.H> #include <AMReX_BLassert.H> @@ -49,10 +48,10 @@ FieldReduction::FieldReduction (std::string rd_name) // read reduced function with parser std::string parser_string = ""; - Store_parserString(pp_rd_name,"reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz)", + utils::parser::Store_parserString(pp_rd_name,"reduced_function(x,y,z,Ex,Ey,Ez,Bx,By,Bz)", parser_string); m_parser = std::make_unique<amrex::Parser>( - makeParser(parser_string,{"x","y","z","Ex","Ey","Ez","Bx","By","Bz"})); + utils::parser::makeParser(parser_string,{"x","y","z","Ex","Ey","Ez","Bx","By","Bz"})); // Replace all newlines and possible following whitespaces with a single whitespace. This // should avoid weird formatting when the string is written in the header of the output file. diff --git a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp index 5f3da09c2..ec01b4fc0 100644 --- a/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp +++ b/Source/Diagnostics/ReducedDiags/LoadBalanceCosts.cpp @@ -8,7 +8,6 @@ #include "Diagnostics/ReducedDiags/ReducedDiags.H" #include "Particles/MultiParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp b/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp index 6f5996537..e3b82ed2a 100644 --- a/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp +++ b/Source/Diagnostics/ReducedDiags/LoadBalanceEfficiency.cpp @@ -7,7 +7,6 @@ #include "LoadBalanceEfficiency.H" #include "Diagnostics/ReducedDiags/ReducedDiags.H" -#include "Utils/IntervalsParser.H" #include "WarpX.H" #include <AMReX_ParallelDescriptor.H> diff --git a/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp b/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp index 50b0dede0..9199d8231 100644 --- a/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp +++ b/Source/Diagnostics/ReducedDiags/MultiReducedDiags.cpp @@ -20,7 +20,6 @@ #include "ParticleMomentum.H" #include "ParticleNumber.H" #include "RhoMaximum.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "Utils/WarpXProfilerWrapper.H" diff --git a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp index 9d3a83eb2..b345e04bd 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleEnergy.cpp @@ -12,7 +12,6 @@ #include "Particles/MultiParticleContainer.H" #include "Particles/SpeciesPhysicalProperties.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "WarpX.H" #include <AMReX_GpuQualifiers.H> diff --git a/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp b/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp index ed2d2ea13..0eb9b9786 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleExtrema.cpp @@ -17,7 +17,6 @@ #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/SpeciesPhysicalProperties.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "Utils/WarpXConst.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp index f54f9bf37..019ad6d3c 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleHistogram.cpp @@ -11,10 +11,9 @@ #include "Particles/MultiParticleContainer.H" #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <AMReX.H> @@ -61,17 +60,17 @@ ParticleHistogram::ParticleHistogram (std::string rd_name) pp_rd_name.get("species",selected_species_name); // read bin parameters - getWithParser(pp_rd_name, "bin_number",m_bin_num); - getWithParser(pp_rd_name, "bin_max", m_bin_max); - getWithParser(pp_rd_name, "bin_min", m_bin_min); + utils::parser::getWithParser(pp_rd_name, "bin_number",m_bin_num); + utils::parser::getWithParser(pp_rd_name, "bin_max", m_bin_max); + utils::parser::getWithParser(pp_rd_name, "bin_min", m_bin_min); m_bin_size = (m_bin_max - m_bin_min) / m_bin_num; // read histogram function std::string function_string = ""; - Store_parserString(pp_rd_name,"histogram_function(t,x,y,z,ux,uy,uz)", + utils::parser::Store_parserString(pp_rd_name,"histogram_function(t,x,y,z,ux,uy,uz)", function_string); m_parser = std::make_unique<amrex::Parser>( - makeParser(function_string,{"t","x","y","z","ux","uy","uz"})); + utils::parser::makeParser(function_string,{"t","x","y","z","ux","uy","uz"})); // read normalization type std::string norm_string = "default"; @@ -113,9 +112,10 @@ ParticleHistogram::ParticleHistogram (std::string rd_name) m_do_parser_filter = pp_rd_name.query("filter_function(t,x,y,z,ux,uy,uz)", buf); if (m_do_parser_filter) { std::string filter_string = ""; - Store_parserString(pp_rd_name,"filter_function(t,x,y,z,ux,uy,uz)", filter_string); + utils::parser::Store_parserString( + pp_rd_name,"filter_function(t,x,y,z,ux,uy,uz)", filter_string); m_parser_filter = std::make_unique<amrex::Parser>( - makeParser(filter_string,{"t","x","y","z","ux","uy","uz"})); + utils::parser::makeParser(filter_string,{"t","x","y","z","ux","uy","uz"})); } // resize data array @@ -168,10 +168,12 @@ void ParticleHistogram::ComputeDiags (int step) auto & myspc = mypc.GetParticleContainer(m_selected_species_id); // get parser - auto fun_partparser = compileParser<m_nvars>(m_parser.get()); + auto fun_partparser = + utils::parser::compileParser<m_nvars>(m_parser.get()); // get filter parser - auto fun_filterparser = compileParser<m_nvars>(m_parser_filter.get()); + auto fun_filterparser = + utils::parser::compileParser<m_nvars>(m_parser_filter.get()); // declare local variables auto const num_bins = m_bin_num; diff --git a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp index 56487820e..e45577c36 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleMomentum.cpp @@ -10,7 +10,6 @@ #include "Particles/MultiParticleContainer.H" #include "Particles/SpeciesPhysicalProperties.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "Utils/WarpXConst.H" #include "WarpX.H" diff --git a/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp b/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp index 9a2a3c797..b1f140e21 100644 --- a/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp +++ b/Source/Diagnostics/ReducedDiags/ParticleNumber.cpp @@ -10,7 +10,6 @@ #include "Diagnostics/ReducedDiags/ReducedDiags.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "WarpX.H" #include <AMReX_GpuQualifiers.H> diff --git a/Source/Diagnostics/ReducedDiags/ReducedDiags.H b/Source/Diagnostics/ReducedDiags/ReducedDiags.H index ae7ea7d8c..43fb1b76b 100644 --- a/Source/Diagnostics/ReducedDiags/ReducedDiags.H +++ b/Source/Diagnostics/ReducedDiags/ReducedDiags.H @@ -8,7 +8,7 @@ #ifndef WARPX_DIAGNOSTICS_REDUCEDDIAGS_REDUCEDDIAGS_H_ #define WARPX_DIAGNOSTICS_REDUCEDDIAGS_REDUCEDDIAGS_H_ -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/IntervalsParser.H" #include <AMReX_REAL.H> @@ -34,7 +34,7 @@ public: std::string m_rd_name; /// output intervals - IntervalsParser m_intervals; + utils::parser::IntervalsParser m_intervals; /// check if it is a restart run int m_IsNotRestart = 1; diff --git a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp index 68111df72..aa6341dd9 100644 --- a/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp +++ b/Source/Diagnostics/ReducedDiags/ReducedDiags.cpp @@ -8,6 +8,7 @@ #include "ReducedDiags.H" #include "WarpX.H" +#include "Utils/Parser/IntervalsParser.H" #include "Utils/TextMsg.H" #include <AMReX.H> @@ -59,7 +60,7 @@ ReducedDiags::ReducedDiags (std::string rd_name) // read reduced diags intervals std::vector<std::string> intervals_string_vec = {"1"}; pp_rd_name.getarr("intervals", intervals_string_vec); - m_intervals = IntervalsParser(intervals_string_vec); + m_intervals = utils::parser::IntervalsParser(intervals_string_vec); // read separator pp_rd_name.query("separator", m_sep); diff --git a/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp b/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp index 0d6cd43cb..43c5efbd6 100644 --- a/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp +++ b/Source/Diagnostics/ReducedDiags/RhoMaximum.cpp @@ -11,7 +11,6 @@ #include "Diagnostics/ReducedDiags/ReducedDiags.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "WarpX.H" diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 6a2817e88..1a31db640 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -11,10 +11,10 @@ #include "FieldIO.H" #include "Particles/Filter/FilterFunctors.H" #include "Utils/TextMsg.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/RelativeCellPosition.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/particles/IndexHandling.H> @@ -611,7 +611,7 @@ WarpXOpenPMDPlot::WriteOpenPMDParticles (const amrex::Vector<ParticleDiag>& part UniformFilter const uniform_filter(particle_diags[i].m_do_uniform_filter, particle_diags[i].m_uniform_stride); ParserFilter parser_filter(particle_diags[i].m_do_parser_filter, - compileParser<ParticleDiag::m_nvars> + utils::parser::compileParser<ParticleDiag::m_nvars> (particle_diags[i].m_particle_filter_parser.get()), pc->getMass()); parser_filter.m_units = InputUnits::SI; diff --git a/Source/EmbeddedBoundary/WarpXInitEB.cpp b/Source/EmbeddedBoundary/WarpXInitEB.cpp index b3bb9699b..a3a315ae0 100644 --- a/Source/EmbeddedBoundary/WarpXInitEB.cpp +++ b/Source/EmbeddedBoundary/WarpXInitEB.cpp @@ -8,8 +8,8 @@ #include "WarpX.H" #ifdef AMREX_USE_EB +# include "Utils/Parser/ParserUtils.H" # include "Utils/TextMsg.H" -# include "Utils/WarpXUtil.H" # include <AMReX.H> # include <AMReX_Array.H> @@ -87,7 +87,7 @@ WarpX::InitEB () std::string impf; pp_warpx.query("eb_implicit_function", impf); if (! impf.empty()) { - auto eb_if_parser = makeParser(impf, {"x", "y", "z"}); + auto eb_if_parser = utils::parser::makeParser(impf, {"x", "y", "z"}); ParserIF pif(eb_if_parser.compile<3>()); auto gshop = amrex::EB2::makeShop(pif, eb_if_parser); // The last argument of amrex::EB2::Build is the maximum coarsening level diff --git a/Source/Evolve/WarpXEvolve.cpp b/Source/Evolve/WarpXEvolve.cpp index 717adbedd..7300b1e32 100644 --- a/Source/Evolve/WarpXEvolve.cpp +++ b/Source/Evolve/WarpXEvolve.cpp @@ -26,12 +26,11 @@ #include "Particles/MultiParticleContainer.H" #include "Particles/ParticleBoundaryBuffer.H" #include "Python/WarpX_py.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" +#include "Utils/WarpXUtil.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include <ablastr/utils/SignalHandling.H> #include <ablastr/warn_manager/WarnManager.H> diff --git a/Source/FieldSolver/ElectrostaticSolver.cpp b/Source/FieldSolver/ElectrostaticSolver.cpp index 3a16b8b70..64158d3a1 100644 --- a/Source/FieldSolver/ElectrostaticSolver.cpp +++ b/Source/FieldSolver/ElectrostaticSolver.cpp @@ -11,10 +11,10 @@ #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" #include "Python/WarpX_py.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpXProfilerWrapper.H" #include <ablastr/fields/PoissonSolver.H> @@ -937,13 +937,13 @@ void ElectrostaticSolver::PoissonBoundaryHandler::definePhiBCs ( ) void ElectrostaticSolver::PoissonBoundaryHandler::buildParsers () { - potential_xlo_parser = makeParser(potential_xlo_str, {"t"}); - potential_xhi_parser = makeParser(potential_xhi_str, {"t"}); - potential_ylo_parser = makeParser(potential_ylo_str, {"t"}); - potential_yhi_parser = makeParser(potential_yhi_str, {"t"}); - potential_zlo_parser = makeParser(potential_zlo_str, {"t"}); - potential_zhi_parser = makeParser(potential_zhi_str, {"t"}); - potential_eb_parser = makeParser(potential_eb_str, {"x", "y", "z", "t"}); + potential_xlo_parser = utils::parser::makeParser(potential_xlo_str, {"t"}); + potential_xhi_parser = utils::parser::makeParser(potential_xhi_str, {"t"}); + potential_ylo_parser = utils::parser::makeParser(potential_ylo_str, {"t"}); + potential_yhi_parser = utils::parser::makeParser(potential_yhi_str, {"t"}); + potential_zlo_parser = utils::parser::makeParser(potential_zlo_str, {"t"}); + potential_zhi_parser = utils::parser::makeParser(potential_zhi_str, {"t"}); + potential_eb_parser = utils::parser::makeParser(potential_eb_str, {"x", "y", "z", "t"}); potential_xlo = potential_xlo_parser.compile<1>(); potential_xhi = potential_xhi_parser.compile<1>(); @@ -960,7 +960,7 @@ void ElectrostaticSolver::PoissonBoundaryHandler::buildParsers () phi_EB_only_t = false; } else { - potential_eb_parser = makeParser(potential_eb_str, {"t"}); + potential_eb_parser = utils::parser::makeParser(potential_eb_str, {"t"}); potential_eb_t = potential_eb_parser.compile<1>(); } } diff --git a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/FieldAccessorFunctors.H b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/FieldAccessorFunctors.H index 8b39296f9..58c0837a8 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/FieldAccessorFunctors.H +++ b/Source/FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/FieldAccessorFunctors.H @@ -10,7 +10,6 @@ #include "WarpX.H" #include "Utils/CoarsenIO.H" -#include "Utils/WarpXUtil.H" #include "FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H" #include <AMReX_Array.H> diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp index 4b117aad3..7f0f99556 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp @@ -11,7 +11,6 @@ #include "Utils/CoarsenIO.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <AMReX.H> diff --git a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp index 438e237fb..0bd063beb 100644 --- a/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp +++ b/Source/FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.cpp @@ -1,7 +1,7 @@ #include "MacroscopicProperties.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/warn_manager/WarnManager.H> @@ -43,7 +43,7 @@ MacroscopicProperties::ReadParameters () // Query input for material conductivity, sigma. bool sigma_specified = false; - if (queryWithParser(pp_macroscopic, "sigma", m_sigma)) { + if (utils::parser::queryWithParser(pp_macroscopic, "sigma", m_sigma)) { m_sigma_s = "constant"; sigma_specified = true; } @@ -60,13 +60,14 @@ MacroscopicProperties::ReadParameters () } // initialization of sigma (conductivity) with parser if (m_sigma_s == "parse_sigma_function") { - Store_parserString(pp_macroscopic, "sigma_function(x,y,z)", m_str_sigma_function); + utils::parser::Store_parserString( + pp_macroscopic, "sigma_function(x,y,z)", m_str_sigma_function); m_sigma_parser = std::make_unique<amrex::Parser>( - makeParser(m_str_sigma_function,{"x","y","z"})); + utils::parser::makeParser(m_str_sigma_function,{"x","y","z"})); } bool epsilon_specified = false; - if (queryWithParser(pp_macroscopic, "epsilon", m_epsilon)) { + if (utils::parser::queryWithParser(pp_macroscopic, "epsilon", m_epsilon)) { m_epsilon_s = "constant"; epsilon_specified = true; } @@ -84,14 +85,15 @@ MacroscopicProperties::ReadParameters () // initialization of epsilon (permittivity) with parser if (m_epsilon_s == "parse_epsilon_function") { - Store_parserString(pp_macroscopic, "epsilon_function(x,y,z)", m_str_epsilon_function); + utils::parser::Store_parserString( + pp_macroscopic, "epsilon_function(x,y,z)", m_str_epsilon_function); m_epsilon_parser = std::make_unique<amrex::Parser>( - makeParser(m_str_epsilon_function,{"x","y","z"})); + utils::parser::makeParser(m_str_epsilon_function,{"x","y","z"})); } // Query input for material permittivity, epsilon. bool mu_specified = false; - if (queryWithParser(pp_macroscopic, "mu", m_mu)) { + if (utils::parser::queryWithParser(pp_macroscopic, "mu", m_mu)) { m_mu_s = "constant"; mu_specified = true; } @@ -109,9 +111,10 @@ MacroscopicProperties::ReadParameters () // initialization of mu (permeability) with parser if (m_mu_s == "parse_mu_function") { - Store_parserString(pp_macroscopic, "mu_function(x,y,z)", m_str_mu_function); + utils::parser::Store_parserString( + pp_macroscopic, "mu_function(x,y,z)", m_str_mu_function); m_mu_parser = std::make_unique<amrex::Parser>( - makeParser(m_str_mu_function,{"x","y","z"})); + utils::parser::makeParser(m_str_mu_function,{"x","y","z"})); } } diff --git a/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp b/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp index 5a2f1d643..59d7fb70e 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralFieldDataRZ.cpp @@ -6,8 +6,8 @@ */ #include "SpectralFieldDataRZ.H" -#include "WarpX.H" #include "Utils/WarpXUtil.H" +#include "WarpX.H" #include <ablastr/warn_manager/WarnManager.H> diff --git a/Source/Initialization/CustomDensityProb.H b/Source/Initialization/CustomDensityProb.H index fef514d95..bcd379707 100644 --- a/Source/Initialization/CustomDensityProb.H +++ b/Source/Initialization/CustomDensityProb.H @@ -8,7 +8,7 @@ #define CUSTOM_DENSITY_PROB_H_ #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" +#include "Utils/Parser/ParserUtils.H" #include <AMReX_Arena.H> #include <AMReX_Dim3.H> @@ -28,7 +28,8 @@ struct InjectorDensityCustom std::vector<amrex::Real> v; WARPX_ALWAYS_ASSERT_WITH_MESSAGE(v.size() <= 6, "Too many parameters for InjectorDensityCustom"); - getArrWithParser(pp_species_name, "custom_profile_params", v); + utils::parser::getArrWithParser( + pp_species_name, "custom_profile_params", v); for (int i = 0; i < static_cast<int>(v.size()); ++i) { p[i] = v[i]; } diff --git a/Source/Initialization/InjectorDensity.cpp b/Source/Initialization/InjectorDensity.cpp index e277ad1d5..e4b3523ec 100644 --- a/Source/Initialization/InjectorDensity.cpp +++ b/Source/Initialization/InjectorDensity.cpp @@ -8,8 +8,8 @@ #include "InjectorDensity.H" #include "Initialization/CustomDensityProb.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include <AMReX_BLassert.H> #include <AMReX_ParmParse.H> @@ -51,7 +51,8 @@ InjectorDensityPredefined::InjectorDensityPredefined ( std::vector<amrex::Real> v; // Read parameters for the predefined plasma profile. - getArrWithParser(pp_species_name, "predefined_profile_params", v); + utils::parser::getArrWithParser( + pp_species_name, "predefined_profile_params", v); WARPX_ALWAYS_ASSERT_WITH_MESSAGE(v.size() <= 6, "Too many parameters for InjectorDensityPredefined"); for (int i = 0; i < static_cast<int>(v.size()); ++i) { diff --git a/Source/Initialization/PlasmaInjector.cpp b/Source/Initialization/PlasmaInjector.cpp index 07526340f..b6f9ae9ad 100644 --- a/Source/Initialization/PlasmaInjector.cpp +++ b/Source/Initialization/PlasmaInjector.cpp @@ -15,9 +15,9 @@ #include "Initialization/InjectorMomentum.H" #include "Initialization/InjectorPosition.H" #include "Particles/SpeciesPhysicalProperties.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/warn_manager/WarnManager.H> @@ -112,15 +112,15 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) } # endif - queryWithParser(pp_species_name, "xmin", xmin); - queryWithParser(pp_species_name, "ymin", ymin); - queryWithParser(pp_species_name, "zmin", zmin); - queryWithParser(pp_species_name, "xmax", xmax); - queryWithParser(pp_species_name, "ymax", ymax); - queryWithParser(pp_species_name, "zmax", zmax); + utils::parser::queryWithParser(pp_species_name, "xmin", xmin); + utils::parser::queryWithParser(pp_species_name, "ymin", ymin); + utils::parser::queryWithParser(pp_species_name, "zmin", zmin); + utils::parser::queryWithParser(pp_species_name, "xmax", xmax); + utils::parser::queryWithParser(pp_species_name, "ymax", ymax); + utils::parser::queryWithParser(pp_species_name, "zmax", zmax); - queryWithParser(pp_species_name, "density_min", density_min); - queryWithParser(pp_species_name, "density_max", density_max); + utils::parser::queryWithParser(pp_species_name, "density_min", density_min); + utils::parser::queryWithParser(pp_species_name, "density_max", density_max); std::string physical_species_s; bool species_is_specified = pp_species_name.query("species_type", physical_species_s); @@ -142,8 +142,10 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) ::tolower); // parse charge and mass - bool charge_is_specified = queryWithParser(pp_species_name, "charge", charge); - bool mass_is_specified = queryWithParser(pp_species_name, "mass", mass); + const bool charge_is_specified = + utils::parser::queryWithParser(pp_species_name, "charge", charge); + const bool mass_is_specified = + utils::parser::queryWithParser(pp_species_name, "mass", mass); if ( charge_is_specified && species_is_specified ){ ablastr::warn_manager::WMRecordWarning("Species", @@ -180,22 +182,32 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) if (injection_style == "none") { return; } else if (injection_style == "singleparticle") { - getArrWithParser(pp_species_name, "single_particle_pos", single_particle_pos, 0, 3); - getArrWithParser(pp_species_name, "single_particle_vel", single_particle_vel, 0, 3); + utils::parser::getArrWithParser( + pp_species_name, "single_particle_pos", single_particle_pos, 0, 3); + utils::parser::getArrWithParser( + pp_species_name, "single_particle_vel", single_particle_vel, 0, 3); for (auto& x : single_particle_vel) { x *= PhysConst::c; } - getWithParser(pp_species_name, "single_particle_weight", single_particle_weight); + utils::parser::getWithParser( + pp_species_name, "single_particle_weight", single_particle_weight); add_single_particle = true; return; } else if (injection_style == "multipleparticles") { - getArrWithParser(pp_species_name, "multiple_particles_pos_x", multiple_particles_pos_x); - getArrWithParser(pp_species_name, "multiple_particles_pos_y", multiple_particles_pos_y); - getArrWithParser(pp_species_name, "multiple_particles_pos_z", multiple_particles_pos_z); - getArrWithParser(pp_species_name, "multiple_particles_vel_x", multiple_particles_vel_x); - getArrWithParser(pp_species_name, "multiple_particles_vel_y", multiple_particles_vel_y); - getArrWithParser(pp_species_name, "multiple_particles_vel_z", multiple_particles_vel_z); - getArrWithParser(pp_species_name, "multiple_particles_weight", multiple_particles_weight); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_pos_x", multiple_particles_pos_x); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_pos_y", multiple_particles_pos_y); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_pos_z", multiple_particles_pos_z); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_vel_x", multiple_particles_vel_x); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_vel_y", multiple_particles_vel_y); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_vel_z", multiple_particles_vel_z); + utils::parser::getArrWithParser( + pp_species_name, "multiple_particles_weight", multiple_particles_weight); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( ((multiple_particles_pos_x.size() == multiple_particles_pos_y.size()) && (multiple_particles_pos_x.size() == multiple_particles_pos_z.size()) && @@ -210,17 +222,18 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) add_multiple_particles = true; return; } else if (injection_style == "gaussian_beam") { - getWithParser(pp_species_name, "x_m", x_m); - getWithParser(pp_species_name, "y_m", y_m); - getWithParser(pp_species_name, "z_m", z_m); - getWithParser(pp_species_name, "x_rms", x_rms); - getWithParser(pp_species_name, "y_rms", y_rms); - getWithParser(pp_species_name, "z_rms", z_rms); - queryWithParser(pp_species_name, "x_cut", x_cut); - queryWithParser(pp_species_name, "y_cut", y_cut); - queryWithParser(pp_species_name, "z_cut", z_cut); - getWithParser(pp_species_name, "q_tot", q_tot); - getWithParser(pp_species_name, "npart", npart); + + utils::parser::getWithParser(pp_species_name, "x_m", x_m); + utils::parser::getWithParser(pp_species_name, "y_m", y_m); + utils::parser::getWithParser(pp_species_name, "z_m", z_m); + utils::parser::getWithParser(pp_species_name, "x_rms", x_rms); + utils::parser::getWithParser(pp_species_name, "y_rms", y_rms); + utils::parser::getWithParser(pp_species_name, "z_rms", z_rms); + utils::parser::queryWithParser(pp_species_name, "x_cut", x_cut); + utils::parser::queryWithParser(pp_species_name, "y_cut", y_cut); + utils::parser::queryWithParser(pp_species_name, "z_cut", z_cut); + utils::parser::getWithParser(pp_species_name, "q_tot", q_tot); + utils::parser::getWithParser(pp_species_name, "npart", npart); pp_species_name.query("do_symmetrize", do_symmetrize); gaussian_beam = true; parseMomentum(pp_species_name); @@ -242,7 +255,8 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) // so that inj_pos->getPositionUnitBox calls // InjectorPosition[Random or Regular].getPositionUnitBox. else if (injection_style == "nrandompercell") { - getWithParser(pp_species_name, "num_particles_per_cell", num_particles_per_cell); + utils::parser::getWithParser( + pp_species_name, "num_particles_per_cell", num_particles_per_cell); #if WARPX_DIM_RZ if (WarpX::n_rz_azimuthal_modes > 1) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -260,7 +274,8 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) parseMomentum(pp_species_name); } else if (injection_style == "nfluxpercell") { surface_flux = true; - getWithParser(pp_species_name, "num_particles_per_cell", num_particles_per_cell_real); + utils::parser::getWithParser( + pp_species_name, "num_particles_per_cell", num_particles_per_cell_real); #ifdef WARPX_DIM_RZ if (WarpX::n_rz_azimuthal_modes > 1) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -270,9 +285,12 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) "(Please visit PR#765 for more information.)"); } #endif - getWithParser(pp_species_name, "surface_flux_pos", surface_flux_pos); - queryWithParser(pp_species_name, "flux_tmin", flux_tmin); - queryWithParser(pp_species_name, "flux_tmax", flux_tmax); + utils::parser::getWithParser( + pp_species_name, "surface_flux_pos", surface_flux_pos); + utils::parser::queryWithParser( + pp_species_name, "flux_tmin", flux_tmin); + utils::parser::queryWithParser( + pp_species_name, "flux_tmax", flux_tmax); std::string flux_normal_axis_string; pp_species_name.get("flux_normal_axis", flux_normal_axis_string); flux_normal_axis = -1; @@ -332,8 +350,9 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) #else constexpr int num_required_ppc_each_dim = 3; #endif - getArrWithParser(pp_species_name, "num_particles_per_cell_each_dim", - num_particles_per_cell_each_dim, 0, num_required_ppc_each_dim); + utils::parser::getArrWithParser( + pp_species_name, "num_particles_per_cell_each_dim", + num_particles_per_cell_each_dim, 0, num_required_ppc_each_dim); #if WARPX_DIM_XZ num_particles_per_cell_each_dim.push_back(1); #endif @@ -372,8 +391,8 @@ PlasmaInjector::PlasmaInjector (int ispecies, const std::string& name) std::string str_injection_file; pp_species_name.get("injection_file", str_injection_file); // optional parameters - queryWithParser(pp_species_name, "q_tot", q_tot); - queryWithParser(pp_species_name, "z_shift",z_shift); + utils::parser::queryWithParser(pp_species_name, "q_tot", q_tot); + utils::parser::queryWithParser(pp_species_name, "z_shift",z_shift); #ifdef WARPX_USE_OPENPMD if (amrex::ParallelDescriptor::IOProcessor()) { @@ -519,7 +538,7 @@ void PlasmaInjector::parseDensity (amrex::ParmParse& pp) std::transform(rho_prof_s.begin(), rho_prof_s.end(), rho_prof_s.begin(), ::tolower); if (rho_prof_s == "constant") { - getWithParser(pp, "density", density); + utils::parser::getWithParser(pp, "density", density); // Construct InjectorDensity with InjectorDensityConstant. h_inj_rho.reset(new InjectorDensity((InjectorDensityConstant*)nullptr, density)); } else if (rho_prof_s == "custom") { @@ -529,12 +548,13 @@ void PlasmaInjector::parseDensity (amrex::ParmParse& pp) // Construct InjectorDensity with InjectorDensityPredefined. h_inj_rho.reset(new InjectorDensity((InjectorDensityPredefined*)nullptr,species_name)); } else if (rho_prof_s == "parse_density_function") { - Store_parserString(pp, "density_function(x,y,z)", str_density_function); + utils::parser::Store_parserString( + pp, "density_function(x,y,z)", str_density_function); // Construct InjectorDensity with InjectorDensityParser. - density_parser = std::make_unique<amrex::Parser>(makeParser( - str_density_function,{"x","y","z"})); + density_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(str_density_function,{"x","y","z"})); h_inj_rho.reset(new InjectorDensity((InjectorDensityParser*)nullptr, - density_parser->compile<3>())); + density_parser->compile<3>())); } else { //No need for profile definition if external file is used std::string injection_style = "none"; @@ -569,9 +589,9 @@ void PlasmaInjector::parseMomentum (amrex::ParmParse& pp) amrex::Real ux = 0._rt; amrex::Real uy = 0._rt; amrex::Real uz = 0._rt; - queryWithParser(pp, "ux", ux); - queryWithParser(pp, "uy", uy); - queryWithParser(pp, "uz", uz); + utils::parser::queryWithParser(pp, "ux", ux); + utils::parser::queryWithParser(pp, "uy", uy); + utils::parser::queryWithParser(pp, "uz", uz); // Construct InjectorMomentum with InjectorMomentumConstant. h_inj_mom.reset(new InjectorMomentum((InjectorMomentumConstant*)nullptr, ux, uy, uz)); } else if (mom_dist_s == "custom") { @@ -584,12 +604,12 @@ void PlasmaInjector::parseMomentum (amrex::ParmParse& pp) amrex::Real ux_th = 0._rt; amrex::Real uy_th = 0._rt; amrex::Real uz_th = 0._rt; - queryWithParser(pp, "ux_m", ux_m); - queryWithParser(pp, "uy_m", uy_m); - queryWithParser(pp, "uz_m", uz_m); - queryWithParser(pp, "ux_th", ux_th); - queryWithParser(pp, "uy_th", uy_th); - queryWithParser(pp, "uz_th", uz_th); + utils::parser::queryWithParser(pp, "ux_m", ux_m); + utils::parser::queryWithParser(pp, "uy_m", uy_m); + utils::parser::queryWithParser(pp, "uz_m", uz_m); + utils::parser::queryWithParser(pp, "ux_th", ux_th); + utils::parser::queryWithParser(pp, "uy_th", uy_th); + utils::parser::queryWithParser(pp, "uz_th", uz_th); // Construct InjectorMomentum with InjectorMomentumGaussian. h_inj_mom.reset(new InjectorMomentum((InjectorMomentumGaussian*)nullptr, ux_m, uy_m, uz_m, ux_th, uy_th, uz_th)); @@ -602,12 +622,12 @@ void PlasmaInjector::parseMomentum (amrex::ParmParse& pp) amrex::Real ux_th = 0._rt; amrex::Real uy_th = 0._rt; amrex::Real uz_th = 0._rt; - queryWithParser(pp, "ux_m", ux_m); - queryWithParser(pp, "uy_m", uy_m); - queryWithParser(pp, "uz_m", uz_m); - queryWithParser(pp, "ux_th", ux_th); - queryWithParser(pp, "uy_th", uy_th); - queryWithParser(pp, "uz_th", uz_th); + utils::parser::queryWithParser(pp, "ux_m", ux_m); + utils::parser::queryWithParser(pp, "uy_m", uy_m); + utils::parser::queryWithParser(pp, "uz_m", uz_m); + utils::parser::queryWithParser(pp, "ux_th", ux_th); + utils::parser::queryWithParser(pp, "uy_th", uy_th); + utils::parser::queryWithParser(pp, "uz_th", uz_th); // Construct InjectorMomentum with InjectorMomentumGaussianFlux. h_inj_mom.reset(new InjectorMomentum((InjectorMomentumGaussianFlux*)nullptr, ux_m, uy_m, uz_m, ux_th, uy_th, uz_th, @@ -628,24 +648,24 @@ void PlasmaInjector::parseMomentum (amrex::ParmParse& pp) h_inj_mom.reset(new InjectorMomentum((InjectorMomentumJuttner*)nullptr, getTemp, getVel)); } else if (mom_dist_s == "radial_expansion") { amrex::Real u_over_r = 0._rt; - queryWithParser(pp, "u_over_r", u_over_r); + utils::parser::queryWithParser(pp, "u_over_r", u_over_r); // Construct InjectorMomentum with InjectorMomentumRadialExpansion. h_inj_mom.reset(new InjectorMomentum ((InjectorMomentumRadialExpansion*)nullptr, u_over_r)); } else if (mom_dist_s == "parse_momentum_function") { - Store_parserString(pp, "momentum_function_ux(x,y,z)", - str_momentum_function_ux); - Store_parserString(pp, "momentum_function_uy(x,y,z)", - str_momentum_function_uy); - Store_parserString(pp, "momentum_function_uz(x,y,z)", - str_momentum_function_uz); + utils::parser::Store_parserString(pp, "momentum_function_ux(x,y,z)", + str_momentum_function_ux); + utils::parser::Store_parserString(pp, "momentum_function_uy(x,y,z)", + str_momentum_function_uy); + utils::parser::Store_parserString(pp, "momentum_function_uz(x,y,z)", + str_momentum_function_uz); // Construct InjectorMomentum with InjectorMomentumParser. - ux_parser = std::make_unique<amrex::Parser>(makeParser(str_momentum_function_ux, - {"x","y","z"})); - uy_parser = std::make_unique<amrex::Parser>(makeParser(str_momentum_function_uy, - {"x","y","z"})); - uz_parser = std::make_unique<amrex::Parser>(makeParser(str_momentum_function_uz, - {"x","y","z"})); + ux_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(str_momentum_function_ux, {"x","y","z"})); + uy_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(str_momentum_function_uy, {"x","y","z"})); + uz_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(str_momentum_function_uz, {"x","y","z"})); h_inj_mom.reset(new InjectorMomentum((InjectorMomentumParser*)nullptr, ux_parser->compile<3>(), uy_parser->compile<3>(), diff --git a/Source/Initialization/TemperatureProperties.H b/Source/Initialization/TemperatureProperties.H index 18e75be60..c62aec83e 100644 --- a/Source/Initialization/TemperatureProperties.H +++ b/Source/Initialization/TemperatureProperties.H @@ -9,8 +9,6 @@ #ifndef TEMPERATURE_PROPERTIES_H_ #define TEMPERATURE_PROPERTIES_H_ -#include <Utils/WarpXUtil.H> - #include <AMReX_ParmParse.H> #include <AMReX_Parser.H> #include <AMReX_REAL.H> diff --git a/Source/Initialization/TemperatureProperties.cpp b/Source/Initialization/TemperatureProperties.cpp index 901275b04..6414fd118 100644 --- a/Source/Initialization/TemperatureProperties.cpp +++ b/Source/Initialization/TemperatureProperties.cpp @@ -7,6 +7,7 @@ */ #include "TemperatureProperties.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include <ablastr/warn_manager/WarnManager.H> @@ -25,7 +26,8 @@ TemperatureProperties::TemperatureProperties (amrex::ParmParse& pp) { pp.query("theta_distribution_type", temp_dist_s); pp.query("momentum_distribution_type", mom_dist_s); if (temp_dist_s == "constant") { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(queryWithParser(pp, "theta", theta), + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + utils::parser::queryWithParser(pp, "theta", theta), "Temperature parameter theta not specified"); // Do validation on theta value @@ -56,9 +58,10 @@ TemperatureProperties::TemperatureProperties (amrex::ParmParse& pp) { } else if (temp_dist_s == "parser") { std::string str_theta_function; - Store_parserString(pp, "theta_function(x,y,z)", str_theta_function); + utils::parser::Store_parserString(pp, "theta_function(x,y,z)", str_theta_function); m_ptr_temperature_parser = - std::make_unique<amrex::Parser>(makeParser(str_theta_function,{"x","y","z"})); + std::make_unique<amrex::Parser>( + utils::parser::makeParser(str_theta_function,{"x","y","z"})); m_type = TempParserFunction; } else { diff --git a/Source/Initialization/VelocityProperties.H b/Source/Initialization/VelocityProperties.H index e9e6362bf..c8744fcfb 100644 --- a/Source/Initialization/VelocityProperties.H +++ b/Source/Initialization/VelocityProperties.H @@ -8,8 +8,6 @@ #ifndef VELOCITY_PROPERTIES_H_ #define VELOCITY_PROPERTIES_H_ -#include <Utils/WarpXUtil.H> - #include <AMReX_ParmParse.H> #include <AMReX_Parser.H> #include <AMReX_REAL.H> diff --git a/Source/Initialization/VelocityProperties.cpp b/Source/Initialization/VelocityProperties.cpp index 59788fc7e..95f41d403 100644 --- a/Source/Initialization/VelocityProperties.cpp +++ b/Source/Initialization/VelocityProperties.cpp @@ -8,6 +8,7 @@ #include "VelocityProperties.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" VelocityProperties::VelocityProperties (amrex::ParmParse& pp) { @@ -45,7 +46,7 @@ VelocityProperties::VelocityProperties (amrex::ParmParse& pp) { pp.query("beta_distribution_type", vel_dist_s); if (vel_dist_s == "constant") { - queryWithParser(pp, "beta", m_velocity); + utils::parser::queryWithParser(pp, "beta", m_velocity); m_type = VelConstantValue; WARPX_ALWAYS_ASSERT_WITH_MESSAGE( m_velocity > -1 && m_velocity < 1, @@ -55,9 +56,10 @@ VelocityProperties::VelocityProperties (amrex::ParmParse& pp) { } else if (vel_dist_s == "parser") { std::string str_beta_function; - Store_parserString(pp, "beta_function(x,y,z)", str_beta_function); + utils::parser::Store_parserString(pp, "beta_function(x,y,z)", str_beta_function); m_ptr_velocity_parser = - std::make_unique<amrex::Parser>(makeParser(str_beta_function,{"x","y","z"})); + std::make_unique<amrex::Parser>( + utils::parser::makeParser(str_beta_function,{"x","y","z"})); m_type = VelParserFunction; } else { diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index b28c9bd59..a6d959caf 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -23,11 +23,11 @@ #include "Particles/MultiParticleContainer.H" #include "Utils/Logo/GetLogo.H" #include "Utils/MPIInitHelpers.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include <ablastr/utils/Communication.H> #include <ablastr/utils/UsedInputsFile.H> @@ -699,12 +699,12 @@ WarpX::InitLevelData (int lev, Real /*time*/) // if the input string is "constant", the values for the // external grid must be provided in the input. if (B_ext_grid_s == "constant") - getArrWithParser(pp_warpx, "B_external_grid", B_external_grid); + utils::parser::getArrWithParser(pp_warpx, "B_external_grid", B_external_grid); // if the input string is "constant", the values for the // external grid must be provided in the input. if (E_ext_grid_s == "constant") - getArrWithParser(pp_warpx, "E_external_grid", E_external_grid); + utils::parser::getArrWithParser(pp_warpx, "E_external_grid", E_external_grid); // initialize the averaged fields only if the averaged algorithm // is activated ('psatd.do_time_averaging=1') @@ -775,18 +775,18 @@ WarpX::InitLevelData (int lev, Real /*time*/) amrex::Abort(Utils::TextMsg::Err( "E and B parser for external fields does not work with RZ -- TO DO")); #endif - Store_parserString(pp_warpx, "Bx_external_grid_function(x,y,z)", - str_Bx_ext_grid_function); - Store_parserString(pp_warpx, "By_external_grid_function(x,y,z)", - str_By_ext_grid_function); - Store_parserString(pp_warpx, "Bz_external_grid_function(x,y,z)", - str_Bz_ext_grid_function); + utils::parser::Store_parserString(pp_warpx, "Bx_external_grid_function(x,y,z)", + str_Bx_ext_grid_function); + utils::parser::Store_parserString(pp_warpx, "By_external_grid_function(x,y,z)", + str_By_ext_grid_function); + utils::parser::Store_parserString(pp_warpx, "Bz_external_grid_function(x,y,z)", + str_Bz_ext_grid_function); Bxfield_parser = std::make_unique<amrex::Parser>( - makeParser(str_Bx_ext_grid_function,{"x","y","z"})); + utils::parser::makeParser(str_Bx_ext_grid_function,{"x","y","z"})); Byfield_parser = std::make_unique<amrex::Parser>( - makeParser(str_By_ext_grid_function,{"x","y","z"})); + utils::parser::makeParser(str_By_ext_grid_function,{"x","y","z"})); Bzfield_parser = std::make_unique<amrex::Parser>( - makeParser(str_Bz_ext_grid_function,{"x","y","z"})); + utils::parser::makeParser(str_Bz_ext_grid_function,{"x","y","z"})); // Initialize Bfield_fp with external function InitializeExternalFieldsOnGridUsingParser(Bfield_fp[lev][0].get(), @@ -833,19 +833,19 @@ WarpX::InitLevelData (int lev, Real /*time*/) amrex::Abort(Utils::TextMsg::Err( "E and B parser for external fields does not work with RZ -- TO DO")); #endif - Store_parserString(pp_warpx, "Ex_external_grid_function(x,y,z)", - str_Ex_ext_grid_function); - Store_parserString(pp_warpx, "Ey_external_grid_function(x,y,z)", - str_Ey_ext_grid_function); - Store_parserString(pp_warpx, "Ez_external_grid_function(x,y,z)", - str_Ez_ext_grid_function); + utils::parser::Store_parserString(pp_warpx, "Ex_external_grid_function(x,y,z)", + str_Ex_ext_grid_function); + utils::parser::Store_parserString(pp_warpx, "Ey_external_grid_function(x,y,z)", + str_Ey_ext_grid_function); + utils::parser::Store_parserString(pp_warpx, "Ez_external_grid_function(x,y,z)", + str_Ez_ext_grid_function); Exfield_parser = std::make_unique<amrex::Parser>( - makeParser(str_Ex_ext_grid_function,{"x","y","z"})); + utils::parser::makeParser(str_Ex_ext_grid_function,{"x","y","z"})); Eyfield_parser = std::make_unique<amrex::Parser>( - makeParser(str_Ey_ext_grid_function,{"x","y","z"})); + utils::parser::makeParser(str_Ey_ext_grid_function,{"x","y","z"})); Ezfield_parser = std::make_unique<amrex::Parser>( - makeParser(str_Ez_ext_grid_function,{"x","y","z"})); + utils::parser::makeParser(str_Ez_ext_grid_function,{"x","y","z"})); // Initialize Efield_fp with external function InitializeExternalFieldsOnGridUsingParser(Efield_fp[lev][0].get(), diff --git a/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp b/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp index c69221c0d..bc0b4381d 100644 --- a/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp +++ b/Source/Laser/LaserProfilesImpl/LaserProfileFieldFunction.cpp @@ -6,9 +6,9 @@ */ #include "Laser/LaserProfiles.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpX_Complex.H" -#include "Utils/WarpXUtil.H" #include <AMReX.H> #include <AMReX_Extension.H> @@ -41,7 +41,7 @@ WarpXLaserProfiles::FieldFunctionLaserProfile::init ( symbols.erase("t"); // after removing variables, we are left with constants for (auto it = symbols.begin(); it != symbols.end(); ) { Real v; - if (queryWithParser(ppc, it->c_str(), v)) { + if (utils::parser::queryWithParser(ppc, it->c_str(), v)) { m_parser.setConstant(*it, v); it = symbols.erase(it); } else { diff --git a/Source/Laser/LaserProfilesImpl/LaserProfileFromTXYEFile.cpp b/Source/Laser/LaserProfilesImpl/LaserProfileFromTXYEFile.cpp index ef7950575..376ec9495 100644 --- a/Source/Laser/LaserProfilesImpl/LaserProfileFromTXYEFile.cpp +++ b/Source/Laser/LaserProfilesImpl/LaserProfileFromTXYEFile.cpp @@ -6,8 +6,10 @@ */ #include "Laser/LaserProfiles.H" +#include "Utils/Algorithms/LinearInterpolation.H" +#include "Utils/Algorithms/UpperBound.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpX_Complex.H" #include <ablastr/warn_manager/WarnManager.H> @@ -65,7 +67,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::init ( //Set time_chunk_size m_params.time_chunk_size = m_params.nt; int temp = 1; - if(queryWithParser(ppl ,"time_chunk_size", temp)){ + if(utils::parser::queryWithParser(ppl ,"time_chunk_size", temp)){ m_params.time_chunk_size = min( temp, m_params.time_chunk_size); } @@ -74,7 +76,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::init ( } //Reads the (optional) delay - queryWithParser(ppl, "delay", m_params.t_delay); + utils::parser::queryWithParser(ppl, "delay", m_params.t_delay); //Allocate memory for E_data Vector const int data_size = m_params.time_chunk_size* @@ -402,7 +404,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::internal_fill_amplitude_uniform( (i_interp-tmp_idx_first_time)*tmp_nx*tmp_ny+ j_interp*tmp_ny + k_interp; }; - amplitude[i] = WarpXUtilAlgo::trilinear_interp( + amplitude[i] = utils::algorithms::trilinear_interp( t_left, t_right, x_0, x_1, y_0, y_1, @@ -421,7 +423,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::internal_fill_amplitude_uniform( const auto idx = [=](int i_interp, int j_interp){ return (i_interp-tmp_idx_first_time) * tmp_nx + j_interp; }; - amplitude[i] = WarpXUtilAlgo::bilinear_interp( + amplitude[i] = utils::algorithms::bilinear_interp( t_left, t_right, x_0, x_1, p_E_data[idx(idx_t_left, idx_x_left)], @@ -491,14 +493,14 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::internal_fill_amplitude_nonuniform #endif //Find indices along x - auto const p_x_right = WarpXUtilAlgo::upper_bound( + auto const p_x_right = utils::algorithms::upper_bound( p_x_coords, p_x_coords+tmp_x_coords_size, Xp[ip]); const int idx_x_right = p_x_right - p_x_coords; const int idx_x_left = idx_x_right - 1; #if (defined(WARPX_DIM_3D) || (defined WARPX_DIM_RZ)) //Find indices along y - auto const p_y_right = WarpXUtilAlgo::upper_bound( + auto const p_y_right = utils::algorithms::upper_bound( p_y_coords, p_y_coords+tmp_y_coords_size, Yp[ip]); const int idx_y_right = p_y_right - p_y_coords; const int idx_y_left = idx_y_right - 1; @@ -509,7 +511,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::internal_fill_amplitude_nonuniform (i-tmp_idx_first_time)*tmp_x_coords_size*tmp_y_coords_size+ j*tmp_y_coords_size + k; }; - amplitude[ip] = WarpXUtilAlgo::trilinear_interp( + amplitude[ip] = utils::algorithms::trilinear_interp( t_left, t_right, p_x_coords[idx_x_left], p_x_coords[idx_x_right], p_y_coords[idx_y_left], p_y_coords[idx_y_right], @@ -528,7 +530,7 @@ WarpXLaserProfiles::FromTXYEFileLaserProfile::internal_fill_amplitude_nonuniform const auto idx = [=](int i, int j){ return (i-tmp_idx_first_time) * tmp_x_coords_size + j; }; - amplitude[ip] = WarpXUtilAlgo::bilinear_interp( + amplitude[ip] = utils::algorithms::bilinear_interp( t_left, t_right, p_x_coords[idx_x_left], p_x_coords[idx_x_right], p_E_data[idx(idx_t_left, idx_x_left)], diff --git a/Source/Laser/LaserProfilesImpl/LaserProfileGaussian.cpp b/Source/Laser/LaserProfilesImpl/LaserProfileGaussian.cpp index 33de9c1da..c1dca774a 100644 --- a/Source/Laser/LaserProfilesImpl/LaserProfileGaussian.cpp +++ b/Source/Laser/LaserProfilesImpl/LaserProfileGaussian.cpp @@ -7,9 +7,9 @@ */ #include "Laser/LaserProfiles.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpX_Complex.H" #include <AMReX_BLassert.H> @@ -39,17 +39,17 @@ WarpXLaserProfiles::GaussianLaserProfile::init ( m_common_params = params; // Parse the properties of the Gaussian profile - getWithParser(ppl, "profile_waist", m_params.waist); - getWithParser(ppl, "profile_duration", m_params.duration); - getWithParser(ppl, "profile_t_peak", m_params.t_peak); - getWithParser(ppl, "profile_focal_distance", m_params.focal_distance); - queryWithParser(ppl, "zeta", m_params.zeta); - queryWithParser(ppl, "beta", m_params.beta); - queryWithParser(ppl, "phi2", m_params.phi2); - queryWithParser(ppl, "phi0", m_params.phi0); + utils::parser::getWithParser(ppl, "profile_waist", m_params.waist); + utils::parser::getWithParser(ppl, "profile_duration", m_params.duration); + utils::parser::getWithParser(ppl, "profile_t_peak", m_params.t_peak); + utils::parser::getWithParser(ppl, "profile_focal_distance", m_params.focal_distance); + utils::parser::queryWithParser(ppl, "zeta", m_params.zeta); + utils::parser::queryWithParser(ppl, "beta", m_params.beta); + utils::parser::queryWithParser(ppl, "phi2", m_params.phi2); + utils::parser::queryWithParser(ppl, "phi0", m_params.phi0); m_params.stc_direction = m_common_params.p_X; - queryArrWithParser(ppl, "stc_direction", m_params.stc_direction); + utils::parser::queryArrWithParser(ppl, "stc_direction", m_params.stc_direction); auto const s = 1.0_rt / std::sqrt( m_params.stc_direction[0]*m_params.stc_direction[0] + m_params.stc_direction[1]*m_params.stc_direction[1] + diff --git a/Source/Laser/LaserProfilesImpl/LaserProfileHarris.cpp b/Source/Laser/LaserProfilesImpl/LaserProfileHarris.cpp index 6ea8070db..2fe1a2341 100644 --- a/Source/Laser/LaserProfilesImpl/LaserProfileHarris.cpp +++ b/Source/Laser/LaserProfilesImpl/LaserProfileHarris.cpp @@ -6,8 +6,8 @@ */ #include "Laser/LaserProfiles.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpX_Complex.H" #include <AMReX_Extension.H> @@ -26,9 +26,12 @@ WarpXLaserProfiles::HarrisLaserProfile::init ( CommonLaserParameters params) { // Parse the properties of the Harris profile - getWithParser(ppl, "profile_waist", m_params.waist); - getWithParser(ppl, "profile_duration", m_params.duration); - getWithParser(ppl, "profile_focal_distance", m_params.focal_distance); + utils::parser::getWithParser( + ppl, "profile_waist", m_params.waist); + utils::parser::getWithParser( + ppl, "profile_duration", m_params.duration); + utils::parser::getWithParser( + ppl, "profile_focal_distance", m_params.focal_distance); //Copy common params m_common_params = params; } diff --git a/Source/Parallelization/GuardCellManager.cpp b/Source/Parallelization/GuardCellManager.cpp index d32d69619..d01230e4b 100644 --- a/Source/Parallelization/GuardCellManager.cpp +++ b/Source/Parallelization/GuardCellManager.cpp @@ -15,10 +15,10 @@ # include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceAlgorithms/CylindricalYeeAlgorithm.H" #endif #include "Filter/NCIGodfreyFilter.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include <AMReX_Config.H> #include <AMReX_INT.H> @@ -201,9 +201,9 @@ guardCellManager::Init ( int ngFFt_z = (do_nodal || galilean) ? noz_fft : noz_fft / 2; ParmParse pp_psatd("psatd"); - queryWithParser(pp_psatd, "nx_guard", ngFFt_x); - queryWithParser(pp_psatd, "ny_guard", ngFFt_y); - queryWithParser(pp_psatd, "nz_guard", ngFFt_z); + utils::parser::queryWithParser(pp_psatd, "nx_guard", ngFFt_x); + utils::parser::queryWithParser(pp_psatd, "ny_guard", ngFFt_y); + utils::parser::queryWithParser(pp_psatd, "nz_guard", ngFFt_z); #if defined(WARPX_DIM_3D) IntVect ngFFT = IntVect(ngFFt_x, ngFFt_y, ngFFt_z); diff --git a/Source/Parallelization/WarpXComm.cpp b/Source/Parallelization/WarpXComm.cpp index 373cb281a..cee53031c 100644 --- a/Source/Parallelization/WarpXComm.cpp +++ b/Source/Parallelization/WarpXComm.cpp @@ -14,7 +14,6 @@ #endif #include "Filter/BilinearFilter.H" #include "Utils/CoarsenMR.H" -#include "Utils/IntervalsParser.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXProfilerWrapper.H" diff --git a/Source/Particles/Collision/BackgroundMCC/BackgroundMCCCollision.cpp b/Source/Particles/Collision/BackgroundMCC/BackgroundMCCCollision.cpp index 1f45062b7..8bc0d6dba 100644 --- a/Source/Particles/Collision/BackgroundMCC/BackgroundMCCCollision.cpp +++ b/Source/Particles/Collision/BackgroundMCC/BackgroundMCCCollision.cpp @@ -5,12 +5,13 @@ * License: BSD-3-Clause-LBNL */ #include "BackgroundMCCCollision.H" + #include "ImpactIonization.H" #include "Particles/ParticleCreation/FilterCopyTransform.H" #include "Particles/ParticleCreation/SmartCopy.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/ParticleUtils.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpXProfilerWrapper.H" #include "WarpX.H" @@ -29,36 +30,42 @@ BackgroundMCCCollision::BackgroundMCCCollision (std::string const collision_name amrex::ParmParse pp_collision_name(collision_name); amrex::ParticleReal background_density = 0; - if (queryWithParser(pp_collision_name, "background_density", background_density)) { + if (utils::parser::queryWithParser(pp_collision_name, "background_density", background_density)) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - (background_density > 0), "The background density must be greater than 0." - ); - m_background_density_parser = makeParser(std::to_string(background_density), {"x", "y", "z", "t"}); + (background_density > 0), + "The background density must be greater than 0."); + m_background_density_parser = + utils::parser::makeParser( + std::to_string(background_density), {"x", "y", "z", "t"}); } else { std::string background_density_str; pp_collision_name.get("background_density(x,y,z,t)", background_density_str); - m_background_density_parser = makeParser(background_density_str, {"x", "y", "z", "t"}); + m_background_density_parser = + utils::parser::makeParser(background_density_str, {"x", "y", "z", "t"}); } amrex::ParticleReal background_temperature; - if (queryWithParser(pp_collision_name, "background_temperature", background_temperature)) { + if (utils::parser::queryWithParser(pp_collision_name, "background_temperature", background_temperature)) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE( (background_temperature >= 0), "The background temperature must be positive." ); - m_background_temperature_parser = makeParser(std::to_string(background_temperature), {"x", "y", "z", "t"}); + m_background_temperature_parser = + utils::parser::makeParser(std::to_string(background_temperature), {"x", "y", "z", "t"}); } else { std::string background_temperature_str; pp_collision_name.get("background_temperature(x,y,z,t)", background_temperature_str); - m_background_temperature_parser = makeParser(background_temperature_str, {"x", "y", "z", "t"}); + m_background_temperature_parser = + utils::parser::makeParser(background_temperature_str, {"x", "y", "z", "t"}); } // compile parsers for background density and temperature m_background_density_func = m_background_density_parser.compile<4>(); m_background_temperature_func = m_background_temperature_parser.compile<4>(); - queryWithParser(pp_collision_name, "max_background_density", m_max_background_density); + utils::parser::queryWithParser( + pp_collision_name, "max_background_density", m_max_background_density); // if the background density is constant we can use that number to calculate // the maximum collision probability, if `max_background_density` was not // specified @@ -75,7 +82,8 @@ BackgroundMCCCollision::BackgroundMCCCollision (std::string const collision_name // will be used. If no neutral mass is specified and ionization is not // included the mass of the colliding species will be used m_background_mass = -1; - queryWithParser(pp_collision_name, "background_mass", m_background_mass); + utils::parser::queryWithParser( + pp_collision_name, "background_mass", m_background_mass); // query for a list of collision processes // these could be elastic, excitation, charge_exchange, back, etc. @@ -95,7 +103,8 @@ BackgroundMCCCollision::BackgroundMCCCollision (std::string const collision_name if (scattering_process.find("excitation") != std::string::npos || scattering_process.find("ionization") != std::string::npos) { std::string kw_energy = scattering_process + "_energy"; - getWithParser(pp_collision_name, kw_energy.c_str(), energy); + utils::parser::getWithParser( + pp_collision_name, kw_energy.c_str(), energy); } MCCProcess process(scattering_process, cross_section_file, energy); diff --git a/Source/Particles/Collision/BackgroundStopping/BackgroundStopping.cpp b/Source/Particles/Collision/BackgroundStopping/BackgroundStopping.cpp index dbfc1b1d4..2f438c8d6 100644 --- a/Source/Particles/Collision/BackgroundStopping/BackgroundStopping.cpp +++ b/Source/Particles/Collision/BackgroundStopping/BackgroundStopping.cpp @@ -5,8 +5,9 @@ * License: BSD-3-Clause-LBNL */ #include "BackgroundStopping.H" + +#include "Utils/Parser/ParserUtils.H" #include "Utils/ParticleUtils.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpXProfilerWrapper.H" #include "WarpX.H" @@ -35,12 +36,14 @@ BackgroundStopping::BackgroundStopping (std::string const collision_name) amrex::ParticleReal background_density; std::string background_density_str; - if (queryWithParser(pp_collision_name, "background_density", background_density)) { + if (utils::parser::queryWithParser(pp_collision_name, "background_density", background_density)) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(background_density > 0, "For background stopping, the background density must be greater than 0"); - m_background_density_parser = makeParser(std::to_string(background_density), {"x", "y", "z", "t"}); + m_background_density_parser = + utils::parser::makeParser(std::to_string(background_density), {"x", "y", "z", "t"}); } else if (pp_collision_name.query("background_density(x,y,z,t)", background_density_str)) { - m_background_density_parser = makeParser(background_density_str, {"x", "y", "z", "t"}); + m_background_density_parser = + utils::parser::makeParser(background_density_str, {"x", "y", "z", "t"}); } else { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(false, "For background stopping, the background density must be specified."); @@ -48,12 +51,14 @@ BackgroundStopping::BackgroundStopping (std::string const collision_name) amrex::ParticleReal background_temperature; std::string background_temperature_str; - if (queryWithParser(pp_collision_name, "background_temperature", background_temperature)) { + if (utils::parser::queryWithParser(pp_collision_name, "background_temperature", background_temperature)) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(background_temperature > 0, "For background stopping, the background temperature must be greater than 0"); - m_background_temperature_parser = makeParser(std::to_string(background_temperature), {"x", "y", "z", "t"}); + m_background_temperature_parser = + utils::parser::makeParser(std::to_string(background_temperature), {"x", "y", "z", "t"}); } else if (pp_collision_name.query("background_temperature(x,y,z,t)", background_temperature_str)) { - m_background_temperature_parser = makeParser(background_temperature_str, {"x", "y", "z", "t"}); + m_background_temperature_parser = + utils::parser::makeParser(background_temperature_str, {"x", "y", "z", "t"}); } else { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(false, "For background stopping, the background temperature must be specified."); @@ -65,10 +70,13 @@ BackgroundStopping::BackgroundStopping (std::string const collision_name) if (m_background_type == BackgroundStoppingType::ELECTRONS) { m_background_mass = PhysConst::m_e; - queryWithParser(pp_collision_name, "background_mass", m_background_mass); + utils::parser::queryWithParser( + pp_collision_name, "background_mass", m_background_mass); } else if (m_background_type == BackgroundStoppingType::IONS) { - getWithParser(pp_collision_name, "background_mass", m_background_mass); - getWithParser(pp_collision_name, "background_charge_state", m_background_charge_state); + utils::parser::getWithParser( + pp_collision_name, "background_mass", m_background_mass); + utils::parser::getWithParser( + pp_collision_name, "background_charge_state", m_background_charge_state); } AMREX_ALWAYS_ASSERT_WITH_MESSAGE(m_background_mass > 0, "For background stopping, the background mass must be greater than 0"); diff --git a/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H b/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H index 0acdc9af8..a1b8979e8 100644 --- a/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H @@ -11,7 +11,7 @@ #include "ElasticCollisionPerez.H" #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/WarpXUtil.H" +#include "Utils/Parser/ParserUtils.H" #include <AMReX_DenseBins.H> #include <AMReX_ParmParse.H> @@ -49,7 +49,8 @@ public: amrex::ParmParse pp_collision_name(collision_name); // default Coulomb log, if < 0, will be computed automatically m_CoulombLog = -1.0_prt; - queryWithParser(pp_collision_name, "CoulombLog", m_CoulombLog); + utils::parser::queryWithParser( + pp_collision_name, "CoulombLog", m_CoulombLog); } /** diff --git a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H index 391682b46..25624469d 100644 --- a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H @@ -14,8 +14,8 @@ #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <AMReX_Algorithm.H> @@ -94,15 +94,17 @@ public: // default fusion multiplier m_fusion_multiplier = 1.0_prt; - queryWithParser(pp_collision_name, "fusion_multiplier", m_fusion_multiplier); + utils::parser::queryWithParser( + pp_collision_name, "fusion_multiplier", m_fusion_multiplier); // default fusion probability threshold m_probability_threshold = 0.02_prt; - queryWithParser(pp_collision_name, "fusion_probability_threshold", - m_probability_threshold); + utils::parser::queryWithParser( + pp_collision_name, "fusion_probability_threshold", m_probability_threshold); // default fusion probability target_value m_probability_target_value = 0.002_prt; - queryWithParser(pp_collision_name, "fusion_probability_target_value", - m_probability_target_value); + utils::parser::queryWithParser( + pp_collision_name, "fusion_probability_target_value", + m_probability_target_value); } /** diff --git a/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H b/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H index 510c59094..be77ae9e0 100644 --- a/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H +++ b/Source/Particles/Collision/BinaryCollision/ParticleCreationFunc.H @@ -15,7 +15,6 @@ #include "Particles/ParticleCreation/SmartCopy.H" #include "Particles/MultiParticleContainer.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <AMReX_DenseBins.H> diff --git a/Source/Particles/Collision/CollisionBase.cpp b/Source/Particles/Collision/CollisionBase.cpp index 948f277c3..08376d6fa 100644 --- a/Source/Particles/Collision/CollisionBase.cpp +++ b/Source/Particles/Collision/CollisionBase.cpp @@ -6,7 +6,7 @@ */ #include "CollisionBase.H" -#include "Utils/WarpXUtil.H" +#include "Utils/Parser/ParserUtils.H" #include <AMReX_ParmParse.H> @@ -19,6 +19,7 @@ CollisionBase::CollisionBase (std::string collision_name) // number of time steps between collisions m_ndt = 1; - queryWithParser(pp_collision_name, "ndt", m_ndt); + utils::parser::queryWithParser( + pp_collision_name, "ndt", m_ndt); } diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp index b56129dc0..b810723fe 100644 --- a/Source/Particles/LaserParticleContainer.cpp +++ b/Source/Particles/LaserParticleContainer.cpp @@ -13,11 +13,11 @@ #include "Particles/LaserParticleContainer.H" #include "Particles/Pusher/GetAndSetPosition.H" #include "Particles/WarpXParticleContainer.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include <ablastr/warn_manager/WarnManager.H> @@ -95,9 +95,9 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, std::transform(laser_type_s.begin(), laser_type_s.end(), laser_type_s.begin(), ::tolower); // Parse the properties of the antenna - getArrWithParser(pp_laser_name, "position", m_position); - getArrWithParser(pp_laser_name, "direction", m_nvec); - getArrWithParser(pp_laser_name, "polarization", m_p_X); + utils::parser::getArrWithParser(pp_laser_name, "position", m_position); + utils::parser::getArrWithParser(pp_laser_name, "direction", m_nvec); + utils::parser::getArrWithParser(pp_laser_name, "polarization", m_p_X); WARPX_ALWAYS_ASSERT_WITH_MESSAGE(m_position.size() == 3, m_laser_name + ".position must have three components."); @@ -106,12 +106,14 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, WARPX_ALWAYS_ASSERT_WITH_MESSAGE(m_p_X.size() == 3, m_laser_name + ".polarization must have three components."); - getWithParser(pp_laser_name, "wavelength", m_wavelength); + utils::parser::getWithParser(pp_laser_name, "wavelength", m_wavelength); AMREX_ALWAYS_ASSERT_WITH_MESSAGE( m_wavelength > 0, "The laser wavelength must be >0."); - const bool e_max_is_specified = queryWithParser(pp_laser_name, "e_max", m_e_max); + const bool e_max_is_specified = + utils::parser::queryWithParser(pp_laser_name, "e_max", m_e_max); Real a0; - const bool a0_is_specified = queryWithParser(pp_laser_name, "a0", a0); + const bool a0_is_specified = + utils::parser::queryWithParser(pp_laser_name, "a0", a0); if (a0_is_specified){ Real omega = 2._rt*MathConst::pi*PhysConst::c/m_wavelength; m_e_max = PhysConst::m_e * omega * PhysConst::c * a0 / PhysConst::q_e; @@ -122,7 +124,8 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, ); pp_laser_name.query("do_continuous_injection", do_continuous_injection); - queryWithParser(pp_laser_name, "min_particles_per_mode", m_min_particles_per_mode); + utils::parser::queryWithParser(pp_laser_name, + "min_particles_per_mode", m_min_particles_per_mode); if (m_e_max == amrex::Real(0.)){ ablastr::warn_manager::WMRecordWarning("Laser", @@ -194,10 +197,12 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, m_laser_injection_box= Geom(0).ProbDomain(); { Vector<Real> lo, hi; - if (queryArrWithParser(pp_laser_name, "prob_lo", lo, 0, AMREX_SPACEDIM)) { + if (utils::parser::queryArrWithParser( + pp_laser_name, "prob_lo", lo, 0, AMREX_SPACEDIM)) { m_laser_injection_box.setLo(lo); } - if (queryArrWithParser(pp_laser_name, "prob_hi", hi, 0, AMREX_SPACEDIM)) { + if (utils::parser::queryArrWithParser( + pp_laser_name, "prob_hi", hi, 0, AMREX_SPACEDIM)) { m_laser_injection_box.setHi(hi); } } diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index e2edc4dd7..7f355810e 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -22,7 +22,6 @@ #include "PhysicalParticleContainer.H" #include "Utils/TextMsg.H" #include "Utils/WarpXConst.H" -#include "Utils/WarpXUtil.H" #include "WarpXParticleContainer.H" #include "ParticleBoundaries.H" diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 662e0b45f..9c7563a3f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -32,8 +32,10 @@ #include "Particles/RigidInjectedParticleContainer.H" #include "Particles/WarpXParticleContainer.H" #include "SpeciesPhysicalProperties.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXProfilerWrapper.H" +#include "Utils/WarpXUtil.H" #ifdef AMREX_USE_EB # include "EmbeddedBoundary/ParticleScraper.H" # include "EmbeddedBoundary/ParticleBoundaryProcess.H" @@ -169,13 +171,15 @@ MultiParticleContainer::ReadParameters () // then the values for the external B on particles must // be provided in the input file. if (m_B_ext_particle_s == "constant") - getArrWithParser(pp_particles, "B_external_particle", m_B_external_particle); + utils::parser::getArrWithParser( + pp_particles, "B_external_particle", m_B_external_particle); // if the input string for E_external on particles is "constant" // then the values for the external E on particles must // be provided in the input file. if (m_E_ext_particle_s == "constant") - getArrWithParser(pp_particles, "E_external_particle", m_E_external_particle); + utils::parser::getArrWithParser( + pp_particles, "E_external_particle", m_E_external_particle); // if the input string for B_ext_particle_s is // "parse_b_ext_particle_function" then the mathematical expression @@ -186,20 +190,23 @@ MultiParticleContainer::ReadParameters () std::string str_Bx_ext_particle_function; std::string str_By_ext_particle_function; std::string str_Bz_ext_particle_function; - Store_parserString(pp_particles, "Bx_external_particle_function(x,y,z,t)", - str_Bx_ext_particle_function); - Store_parserString(pp_particles, "By_external_particle_function(x,y,z,t)", - str_By_ext_particle_function); - Store_parserString(pp_particles, "Bz_external_particle_function(x,y,z,t)", - str_Bz_ext_particle_function); + utils::parser::Store_parserString( + pp_particles, "Bx_external_particle_function(x,y,z,t)", + str_Bx_ext_particle_function); + utils::parser::Store_parserString( + pp_particles, "By_external_particle_function(x,y,z,t)", + str_By_ext_particle_function); + utils::parser::Store_parserString( + pp_particles, "Bz_external_particle_function(x,y,z,t)", + str_Bz_ext_particle_function); // Parser for B_external on the particle m_Bx_particle_parser = std::make_unique<amrex::Parser>( - makeParser(str_Bx_ext_particle_function,{"x","y","z","t"})); + utils::parser::makeParser(str_Bx_ext_particle_function,{"x","y","z","t"})); m_By_particle_parser = std::make_unique<amrex::Parser>( - makeParser(str_By_ext_particle_function,{"x","y","z","t"})); + utils::parser::makeParser(str_By_ext_particle_function,{"x","y","z","t"})); m_Bz_particle_parser = std::make_unique<amrex::Parser>( - makeParser(str_Bz_ext_particle_function,{"x","y","z","t"})); + utils::parser::makeParser(str_Bz_ext_particle_function,{"x","y","z","t"})); } @@ -212,19 +219,22 @@ MultiParticleContainer::ReadParameters () std::string str_Ex_ext_particle_function; std::string str_Ey_ext_particle_function; std::string str_Ez_ext_particle_function; - Store_parserString(pp_particles, "Ex_external_particle_function(x,y,z,t)", - str_Ex_ext_particle_function); - Store_parserString(pp_particles, "Ey_external_particle_function(x,y,z,t)", - str_Ey_ext_particle_function); - Store_parserString(pp_particles, "Ez_external_particle_function(x,y,z,t)", - str_Ez_ext_particle_function); + utils::parser::Store_parserString( + pp_particles, "Ex_external_particle_function(x,y,z,t)", + str_Ex_ext_particle_function); + utils::parser::Store_parserString( + pp_particles, "Ey_external_particle_function(x,y,z,t)", + str_Ey_ext_particle_function); + utils::parser::Store_parserString( + pp_particles, "Ez_external_particle_function(x,y,z,t)", + str_Ez_ext_particle_function); // Parser for E_external on the particle m_Ex_particle_parser = std::make_unique<amrex::Parser>( - makeParser(str_Ex_ext_particle_function,{"x","y","z","t"})); + utils::parser::makeParser(str_Ex_ext_particle_function,{"x","y","z","t"})); m_Ey_particle_parser = std::make_unique<amrex::Parser>( - makeParser(str_Ey_ext_particle_function,{"x","y","z","t"})); + utils::parser::makeParser(str_Ey_ext_particle_function,{"x","y","z","t"})); m_Ez_particle_parser = std::make_unique<amrex::Parser>( - makeParser(str_Ez_ext_particle_function,{"x","y","z","t"})); + utils::parser::makeParser(str_Ez_ext_particle_function,{"x","y","z","t"})); } @@ -233,11 +243,17 @@ MultiParticleContainer::ReadParameters () // must be provided in the input file. if (m_E_ext_particle_s == "repeated_plasma_lens" || m_B_ext_particle_s == "repeated_plasma_lens") { - getWithParser(pp_particles, "repeated_plasma_lens_period", m_repeated_plasma_lens_period); + utils::parser::getWithParser( + pp_particles, "repeated_plasma_lens_period", + m_repeated_plasma_lens_period); WARPX_ALWAYS_ASSERT_WITH_MESSAGE(m_repeated_plasma_lens_period > 0._rt, "The period of the repeated plasma lens must be greater than zero"); - getArrWithParser(pp_particles, "repeated_plasma_lens_starts", h_repeated_plasma_lens_starts); - getArrWithParser(pp_particles, "repeated_plasma_lens_lengths", h_repeated_plasma_lens_lengths); + utils::parser::getArrWithParser( + pp_particles, "repeated_plasma_lens_starts", + h_repeated_plasma_lens_starts); + utils::parser::getArrWithParser( + pp_particles, "repeated_plasma_lens_lengths", + h_repeated_plasma_lens_lengths); int n_lenses = static_cast<int>(h_repeated_plasma_lens_starts.size()); d_repeated_plasma_lens_starts.resize(n_lenses); @@ -253,10 +269,14 @@ MultiParticleContainer::ReadParameters () h_repeated_plasma_lens_strengths_B.resize(n_lenses); if (m_E_ext_particle_s == "repeated_plasma_lens") { - getArrWithParser(pp_particles, "repeated_plasma_lens_strengths_E", h_repeated_plasma_lens_strengths_E); + utils::parser::getArrWithParser( + pp_particles, "repeated_plasma_lens_strengths_E", + h_repeated_plasma_lens_strengths_E); } if (m_B_ext_particle_s == "repeated_plasma_lens") { - getArrWithParser(pp_particles, "repeated_plasma_lens_strengths_B", h_repeated_plasma_lens_strengths_B); + utils::parser::getArrWithParser( + pp_particles, "repeated_plasma_lens_strengths_B", + h_repeated_plasma_lens_strengths_B); } d_repeated_plasma_lens_strengths_E.resize(n_lenses); @@ -373,18 +393,26 @@ MultiParticleContainer::ReadParameters () pp_qed_schwinger.get("ele_product_species", m_qed_schwinger_ele_product_name); pp_qed_schwinger.get("pos_product_species", m_qed_schwinger_pos_product_name); #if defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ) - getWithParser(pp_qed_schwinger, "y_size",m_qed_schwinger_y_size); + utils::parser::getWithParser( + pp_qed_schwinger, "y_size",m_qed_schwinger_y_size); #endif - queryWithParser(pp_qed_schwinger, "threshold_poisson_gaussian", - m_qed_schwinger_threshold_poisson_gaussian); - queryWithParser(pp_qed_schwinger, "xmin", m_qed_schwinger_xmin); - queryWithParser(pp_qed_schwinger, "xmax", m_qed_schwinger_xmax); + utils::parser::queryWithParser( + pp_qed_schwinger, "threshold_poisson_gaussian", + m_qed_schwinger_threshold_poisson_gaussian); + utils::parser::queryWithParser( + pp_qed_schwinger, "xmin", m_qed_schwinger_xmin); + utils::parser::queryWithParser( + pp_qed_schwinger, "xmax", m_qed_schwinger_xmax); #if defined(WARPX_DIM_3D) - queryWithParser(pp_qed_schwinger, "ymin", m_qed_schwinger_ymin); - queryWithParser(pp_qed_schwinger, "ymax", m_qed_schwinger_ymax); + utils::parser::queryWithParser( + pp_qed_schwinger, "ymin", m_qed_schwinger_ymin); + utils::parser::queryWithParser( + pp_qed_schwinger, "ymax", m_qed_schwinger_ymax); #endif - queryWithParser(pp_qed_schwinger, "zmin", m_qed_schwinger_zmin); - queryWithParser(pp_qed_schwinger, "zmax", m_qed_schwinger_zmax); + utils::parser::queryWithParser( + pp_qed_schwinger, "zmin", m_qed_schwinger_zmin); + utils::parser::queryWithParser( + pp_qed_schwinger, "zmax", m_qed_schwinger_zmax); } #endif initialized = true; @@ -1055,7 +1083,8 @@ void MultiParticleContainer::InitQuantumSync () //If specified, use a user-defined energy threshold for photon creation ParticleReal temp; constexpr auto mec2 = PhysConst::c * PhysConst::c * PhysConst::m_e; - if(queryWithParser(pp_qed_qs, "photon_creation_energy_threshold", temp)){ + if(utils::parser::queryWithParser( + pp_qed_qs, "photon_creation_energy_threshold", temp)){ temp *= mec2; m_quantum_sync_photon_creation_energy_threshold = temp; } @@ -1069,7 +1098,7 @@ void MultiParticleContainer::InitQuantumSync () // considered for Synchrotron emission. If a lepton has chi < chi_min, // the optical depth is not evolved and photon generation is ignored amrex::Real qs_minimum_chi_part; - getWithParser(pp_qed_qs, "chi_min", qs_minimum_chi_part); + utils::parser::getWithParser(pp_qed_qs, "chi_min", qs_minimum_chi_part); pp_qed_qs.query("lookup_table_mode", lookup_table_mode); @@ -1127,7 +1156,7 @@ void MultiParticleContainer::InitBreitWheeler () // considered for pair production. If a photon has chi < chi_min, // the optical depth is not evolved and photon generation is ignored amrex::Real bw_minimum_chi_part; - if(!queryWithParser(pp_qed_bw, "chi_min", bw_minimum_chi_part)) + if(!utils::parser::queryWithParser(pp_qed_bw, "chi_min", bw_minimum_chi_part)) amrex::Abort("qed_bw.chi_min should be provided!"); pp_qed_bw.query("lookup_table_mode", lookup_table_mode); @@ -1189,7 +1218,7 @@ MultiParticleContainer::QuantumSyncGenerateTable () // considered for Synchrotron emission. If a lepton has chi < chi_min, // the optical depth is not evolved and photon generation is ignored amrex::Real qs_minimum_chi_part; - getWithParser(pp_qed_qs, "chi_min", qs_minimum_chi_part); + utils::parser::getWithParser(pp_qed_qs, "chi_min", qs_minimum_chi_part); if(ParallelDescriptor::IOProcessor()){ PicsarQuantumSyncCtrl ctrl; @@ -1202,14 +1231,17 @@ MultiParticleContainer::QuantumSyncGenerateTable () //Minimun chi for the table. If a lepton has chi < tab_dndt_chi_min, //chi is considered as if it were equal to tab_dndt_chi_min - getWithParser(pp_qed_qs, "tab_dndt_chi_min", ctrl.dndt_params.chi_part_min); + utils::parser::getWithParser( + pp_qed_qs, "tab_dndt_chi_min", ctrl.dndt_params.chi_part_min); //Maximum chi for the table. If a lepton has chi > tab_dndt_chi_max, //chi is considered as if it were equal to tab_dndt_chi_max - getWithParser(pp_qed_qs, "tab_dndt_chi_max", ctrl.dndt_params.chi_part_max); + utils::parser::getWithParser( + pp_qed_qs, "tab_dndt_chi_max", ctrl.dndt_params.chi_part_max); //How many points should be used for chi in the table - getWithParser(pp_qed_qs, "tab_dndt_how_many", ctrl.dndt_params.chi_part_how_many); + utils::parser::getWithParser( + pp_qed_qs, "tab_dndt_how_many", ctrl.dndt_params.chi_part_how_many); //------ //--- sub-table 2 (2D) @@ -1219,23 +1251,28 @@ MultiParticleContainer::QuantumSyncGenerateTable () //Minimun chi for the table. If a lepton has chi < tab_em_chi_min, //chi is considered as if it were equal to tab_em_chi_min - getWithParser(pp_qed_qs, "tab_em_chi_min", ctrl.phot_em_params.chi_part_min); + utils::parser::getWithParser( + pp_qed_qs, "tab_em_chi_min", ctrl.phot_em_params.chi_part_min); //Maximum chi for the table. If a lepton has chi > tab_em_chi_max, //chi is considered as if it were equal to tab_em_chi_max - getWithParser(pp_qed_qs, "tab_em_chi_max", ctrl.phot_em_params.chi_part_max); + utils::parser::getWithParser( + pp_qed_qs, "tab_em_chi_max", ctrl.phot_em_params.chi_part_max); //How many points should be used for chi in the table - getWithParser(pp_qed_qs, "tab_em_chi_how_many", ctrl.phot_em_params.chi_part_how_many); + utils::parser::getWithParser( + pp_qed_qs, "tab_em_chi_how_many", ctrl.phot_em_params.chi_part_how_many); //The other axis of the table is the ratio between the quantum //parameter of the emitted photon and the quantum parameter of the //lepton. This parameter is the minimum ratio to consider for the table. - getWithParser(pp_qed_qs, "tab_em_frac_min", ctrl.phot_em_params.frac_min); + utils::parser::getWithParser( + pp_qed_qs, "tab_em_frac_min", ctrl.phot_em_params.frac_min); //This parameter is the number of different points to consider for the second //axis - getWithParser(pp_qed_qs, "tab_em_frac_how_many", ctrl.phot_em_params.frac_how_many); + utils::parser::getWithParser( + pp_qed_qs, "tab_em_frac_how_many", ctrl.phot_em_params.frac_how_many); //==================== m_shr_p_qs_engine->compute_lookup_tables(ctrl, qs_minimum_chi_part); @@ -1270,7 +1307,7 @@ MultiParticleContainer::BreitWheelerGenerateTable () // considered for pair production. If a photon has chi < chi_min, // the optical depth is not evolved and photon generation is ignored amrex::Real bw_minimum_chi_part; - getWithParser(pp_qed_bw, "chi_min", bw_minimum_chi_part); + utils::parser::getWithParser(pp_qed_bw, "chi_min", bw_minimum_chi_part); if(ParallelDescriptor::IOProcessor()){ PicsarBreitWheelerCtrl ctrl; @@ -1283,14 +1320,17 @@ MultiParticleContainer::BreitWheelerGenerateTable () //Minimun chi for the table. If a photon has chi < tab_dndt_chi_min, //an analytical approximation is used. - getWithParser(pp_qed_bw, "tab_dndt_chi_min", ctrl.dndt_params.chi_phot_min); + utils::parser::getWithParser( + pp_qed_bw, "tab_dndt_chi_min", ctrl.dndt_params.chi_phot_min); //Maximum chi for the table. If a photon has chi > tab_dndt_chi_max, //an analytical approximation is used. - getWithParser(pp_qed_bw, "tab_dndt_chi_max", ctrl.dndt_params.chi_phot_max); + utils::parser::getWithParser( + pp_qed_bw, "tab_dndt_chi_max", ctrl.dndt_params.chi_phot_max); //How many points should be used for chi in the table - getWithParser(pp_qed_bw, "tab_dndt_how_many", ctrl.dndt_params.chi_phot_how_many); + utils::parser::getWithParser( + pp_qed_bw, "tab_dndt_how_many", ctrl.dndt_params.chi_phot_how_many); //------ //--- sub-table 2 (2D) @@ -1300,19 +1340,23 @@ MultiParticleContainer::BreitWheelerGenerateTable () //Minimun chi for the table. If a photon has chi < tab_pair_chi_min //chi is considered as it were equal to chi_phot_tpair_min - getWithParser(pp_qed_bw, "tab_pair_chi_min", ctrl.pair_prod_params.chi_phot_min); + utils::parser::getWithParser( + pp_qed_bw, "tab_pair_chi_min", ctrl.pair_prod_params.chi_phot_min); //Maximum chi for the table. If a photon has chi > tab_pair_chi_max //chi is considered as it were equal to chi_phot_tpair_max - getWithParser(pp_qed_bw, "tab_pair_chi_max", ctrl.pair_prod_params.chi_phot_max); + utils::parser::getWithParser( + pp_qed_bw, "tab_pair_chi_max", ctrl.pair_prod_params.chi_phot_max); //How many points should be used for chi in the table - getWithParser(pp_qed_bw, "tab_pair_chi_how_many", ctrl.pair_prod_params.chi_phot_how_many); + utils::parser::getWithParser( + pp_qed_bw, "tab_pair_chi_how_many", ctrl.pair_prod_params.chi_phot_how_many); //The other axis of the table is the fraction of the initial energy //'taken away' by the most energetic particle of the pair. //This parameter is the number of different fractions to consider - getWithParser(pp_qed_bw, "tab_pair_frac_how_many", ctrl.pair_prod_params.frac_how_many); + utils::parser::getWithParser( + pp_qed_bw, "tab_pair_frac_how_many", ctrl.pair_prod_params.frac_how_many); //==================== m_shr_p_bw_engine->compute_lookup_tables(ctrl, bw_minimum_chi_part); diff --git a/Source/Particles/ParticleBoundaries.H b/Source/Particles/ParticleBoundaries.H index 00b6368a5..1f4fb0372 100644 --- a/Source/Particles/ParticleBoundaries.H +++ b/Source/Particles/ParticleBoundaries.H @@ -8,7 +8,6 @@ #define PARTICLEBOUNDARIES_H_ #include "Utils/WarpXAlgorithmSelection.H" -#include "Utils/WarpXUtil.H" #include <AMReX_AmrCore.H> #include <AMReX_Parser.H> diff --git a/Source/Particles/ParticleBoundaries.cpp b/Source/Particles/ParticleBoundaries.cpp index 2bdbd0d14..a6e80717e 100644 --- a/Source/Particles/ParticleBoundaries.cpp +++ b/Source/Particles/ParticleBoundaries.cpp @@ -7,6 +7,8 @@ #include "ParticleBoundaries.H" +#include "Utils/Parser/ParserUtils.H" + ParticleBoundaries::ParticleBoundaries () noexcept { SetAll(ParticleBoundaryType::Absorbing); @@ -64,18 +66,24 @@ ParticleBoundaries::CheckAll (ParticleBoundaryType bc) void ParticleBoundaries::BuildReflectionModelParsers () { - reflection_model_xlo_parser = std::make_unique<amrex::Parser>(makeParser(reflection_model_xlo_str, {"v"})); + reflection_model_xlo_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(reflection_model_xlo_str, {"v"})); data.reflection_model_xlo = reflection_model_xlo_parser->compile<1>(); - reflection_model_xhi_parser = std::make_unique<amrex::Parser>(makeParser(reflection_model_xhi_str, {"v"})); + reflection_model_xhi_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(reflection_model_xhi_str, {"v"})); data.reflection_model_xhi = reflection_model_xhi_parser->compile<1>(); #ifdef WARPX_DIM_3D - reflection_model_ylo_parser = std::make_unique<amrex::Parser>(makeParser(reflection_model_ylo_str, {"v"})); + reflection_model_ylo_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(reflection_model_ylo_str, {"v"})); data.reflection_model_ylo = reflection_model_ylo_parser->compile<1>(); - reflection_model_yhi_parser = std::make_unique<amrex::Parser>(makeParser(reflection_model_yhi_str, {"v"})); + reflection_model_yhi_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(reflection_model_yhi_str, {"v"})); data.reflection_model_yhi = reflection_model_yhi_parser->compile<1>(); #endif - reflection_model_zlo_parser = std::make_unique<amrex::Parser>(makeParser(reflection_model_zlo_str, {"v"})); + reflection_model_zlo_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(reflection_model_zlo_str, {"v"})); data.reflection_model_zlo = reflection_model_zlo_parser->compile<1>(); - reflection_model_zhi_parser = std::make_unique<amrex::Parser>(makeParser(reflection_model_zhi_str, {"v"})); + reflection_model_zhi_parser = std::make_unique<amrex::Parser>( + utils::parser::makeParser(reflection_model_zhi_str, {"v"})); data.reflection_model_zhi = reflection_model_zhi_parser->compile<1>(); } diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 97f890f33..fa9b0c647 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -31,12 +31,12 @@ #include "Particles/Pusher/UpdatePosition.H" #include "Particles/SpeciesPhysicalProperties.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/IonizationEnergiesTable.H" +#include "Utils/Parser/ParserUtils.H" +#include "Utils/Physics/IonizationEnergiesTable.H" #include "Utils/TextMsg.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <ablastr/warn_manager/WarnManager.H> @@ -257,9 +257,12 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp_species_name.query("do_continuous_injection", do_continuous_injection); pp_species_name.query("initialize_self_fields", initialize_self_fields); - queryWithParser(pp_species_name, "self_fields_required_precision", self_fields_required_precision); - queryWithParser(pp_species_name, "self_fields_absolute_tolerance", self_fields_absolute_tolerance); - queryWithParser(pp_species_name, "self_fields_max_iters", self_fields_max_iters); + utils::parser::queryWithParser( + pp_species_name, "self_fields_required_precision", self_fields_required_precision); + utils::parser::queryWithParser( + pp_species_name, "self_fields_absolute_tolerance", self_fields_absolute_tolerance); + utils::parser::queryWithParser( + pp_species_name, "self_fields_max_iters", self_fields_max_iters); pp_species_name.query("self_fields_verbosity", self_fields_verbosity); // Whether to plot back-transformed (lab-frame) diagnostics // for this species. @@ -310,9 +313,11 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp str_int_attrib_function.resize(n_user_int_attribs); m_user_int_attrib_parser.resize(n_user_int_attribs); for (int i = 0; i < n_user_int_attribs; ++i) { - Store_parserString(pp_species_name, "attribute."+m_user_int_attribs.at(i)+"(x,y,z,ux,uy,uz,t)", str_int_attrib_function.at(i)); + utils::parser::Store_parserString( + pp_species_name, "attribute."+m_user_int_attribs.at(i)+"(x,y,z,ux,uy,uz,t)", + str_int_attrib_function.at(i)); m_user_int_attrib_parser.at(i) = std::make_unique<amrex::Parser>( - makeParser(str_int_attrib_function.at(i),{"x","y","z","ux","uy","uz","t"})); + utils::parser::makeParser(str_int_attrib_function.at(i),{"x","y","z","ux","uy","uz","t"})); AddIntComp(m_user_int_attribs.at(i)); } @@ -323,9 +328,11 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp str_real_attrib_function.resize(n_user_real_attribs); m_user_real_attrib_parser.resize(n_user_real_attribs); for (int i = 0; i < n_user_real_attribs; ++i) { - Store_parserString(pp_species_name, "attribute."+m_user_real_attribs.at(i)+"(x,y,z,ux,uy,uz,t)", str_real_attrib_function.at(i)); + utils::parser::Store_parserString( + pp_species_name, "attribute."+m_user_real_attribs.at(i)+"(x,y,z,ux,uy,uz,t)", + str_real_attrib_function.at(i)); m_user_real_attrib_parser.at(i) = std::make_unique<amrex::Parser>( - makeParser(str_real_attrib_function.at(i),{"x","y","z","ux","uy","uz","t"})); + utils::parser::makeParser(str_real_attrib_function.at(i),{"x","y","z","ux","uy","uz","t"})); AddRealComp(m_user_real_attribs.at(i)); } @@ -2873,18 +2880,20 @@ PhysicalParticleContainer::InitIonizationModule () "overriding user value and setting charge = q_e."); charge = PhysConst::q_e; } - queryWithParser(pp_species_name, "ionization_initial_level", ionization_initial_level); + utils::parser::queryWithParser( + pp_species_name, "ionization_initial_level", ionization_initial_level); pp_species_name.get("ionization_product_species", ionization_product_name); pp_species_name.get("physical_element", physical_element); // Add runtime integer component for ionization level AddIntComp("ionizationLevel"); // Get atomic number and ionization energies from file - int const ion_element_id = ion_map_ids.at(physical_element); - ion_atomic_number = ion_atomic_numbers[ion_element_id]; + const int ion_element_id = utils::physics::ion_map_ids.at(physical_element); + ion_atomic_number = utils::physics::ion_atomic_numbers[ion_element_id]; Vector<Real> h_ionization_energies(ion_atomic_number); - int offset = ion_energy_offsets[ion_element_id]; + const int offset = utils::physics::ion_energy_offsets[ion_element_id]; for(int i=0; i<ion_atomic_number; i++){ - h_ionization_energies[i] = table_ionization_energies[i+offset]; + h_ionization_energies[i] = + utils::physics::table_ionization_energies[i+offset]; } // Compute ADK prefactors (See Chen, JCP 236 (2013), equation (2)) // For now, we assume l=0 and m=0. @@ -2892,11 +2901,11 @@ PhysicalParticleContainer::InitIonizationModule () // without Gamma function constexpr auto a3 = PhysConst::alpha*PhysConst::alpha*PhysConst::alpha; constexpr auto a4 = a3 * PhysConst::alpha; - Real wa = a3 * PhysConst::c / PhysConst::r_e; - Real Ea = PhysConst::m_e * PhysConst::c*PhysConst::c /PhysConst::q_e * + constexpr Real wa = a3 * PhysConst::c / PhysConst::r_e; + constexpr Real Ea = PhysConst::m_e * PhysConst::c*PhysConst::c /PhysConst::q_e * a4/PhysConst::r_e; - Real UH = table_ionization_energies[0]; - Real l_eff = std::sqrt(UH/h_ionization_energies[0]) - 1._rt; + constexpr Real UH = utils::physics::table_ionization_energies[0]; + const Real l_eff = std::sqrt(UH/h_ionization_energies[0]) - 1._rt; const Real dt = WarpX::GetInstance().getdt(0); diff --git a/Source/Particles/Resampling/LevelingThinning.cpp b/Source/Particles/Resampling/LevelingThinning.cpp index cf9ca9ba9..2db192f61 100644 --- a/Source/Particles/Resampling/LevelingThinning.cpp +++ b/Source/Particles/Resampling/LevelingThinning.cpp @@ -7,9 +7,9 @@ #include "LevelingThinning.H" #include "Particles/WarpXParticleContainer.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/ParticleUtils.H" #include "Utils/TextMsg.H" -#include "Utils/WarpXUtil.H" #include <ablastr/warn_manager/WarnManager.H> @@ -34,7 +34,8 @@ LevelingThinning::LevelingThinning (const std::string species_name) using namespace amrex::literals; amrex::ParmParse pp_species_name(species_name); - queryWithParser(pp_species_name, "resampling_algorithm_target_ratio", m_target_ratio); + utils::parser::queryWithParser( + pp_species_name, "resampling_algorithm_target_ratio", m_target_ratio); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( m_target_ratio > 0._rt, "Resampling target ratio should be strictly greater than 0"); if (m_target_ratio <= 1._rt) @@ -45,7 +46,8 @@ LevelingThinning::LevelingThinning (const std::string species_name) "It is possible that no particle will be removed during resampling"); } - queryWithParser(pp_species_name, "resampling_algorithm_min_ppc", m_min_ppc); + utils::parser::queryWithParser( + pp_species_name, "resampling_algorithm_min_ppc", m_min_ppc); WARPX_ALWAYS_ASSERT_WITH_MESSAGE(m_min_ppc >= 1, "Resampling min_ppc should be greater than or equal to 1"); } diff --git a/Source/Particles/Resampling/ResamplingTrigger.H b/Source/Particles/Resampling/ResamplingTrigger.H index 03850cf51..ce89adab8 100644 --- a/Source/Particles/Resampling/ResamplingTrigger.H +++ b/Source/Particles/Resampling/ResamplingTrigger.H @@ -7,7 +7,7 @@ #ifndef WARPX_RESAMPLING_TRIGGER_H_ #define WARPX_RESAMPLING_TRIGGER_H_ -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/IntervalsParser.H" #include <AMReX_REAL.H> @@ -54,7 +54,7 @@ public: private: // Intervals that define predetermined timesteps at which resampling is performed for all // species. - IntervalsParser m_resampling_intervals; + utils::parser::IntervalsParser m_resampling_intervals; // Average number of particles per cell above which resampling is performed for a given species amrex::Real m_max_avg_ppc = std::numeric_limits<amrex::Real>::max(); diff --git a/Source/Particles/Resampling/ResamplingTrigger.cpp b/Source/Particles/Resampling/ResamplingTrigger.cpp index 220b65f84..53883f1e9 100644 --- a/Source/Particles/Resampling/ResamplingTrigger.cpp +++ b/Source/Particles/Resampling/ResamplingTrigger.cpp @@ -6,7 +6,7 @@ */ #include "ResamplingTrigger.H" -#include "Utils/WarpXUtil.H" +#include "Utils/Parser/ParserUtils.H" #include "WarpX.H" #include <AMReX_BoxArray.H> @@ -20,9 +20,10 @@ ResamplingTrigger::ResamplingTrigger (const std::string species_name) std::vector<std::string> resampling_trigger_int_string_vec = {"0"}; pp_species_name.queryarr("resampling_trigger_intervals", resampling_trigger_int_string_vec); - m_resampling_intervals = IntervalsParser(resampling_trigger_int_string_vec); + m_resampling_intervals = utils::parser::IntervalsParser(resampling_trigger_int_string_vec); - queryWithParser(pp_species_name, "resampling_trigger_max_avg_ppc", m_max_avg_ppc); + utils::parser::queryWithParser( + pp_species_name, "resampling_trigger_max_avg_ppc", m_max_avg_ppc); } bool ResamplingTrigger::triggered (const int timestep, const amrex::Real global_numparts) const diff --git a/Source/Particles/RigidInjectedParticleContainer.cpp b/Source/Particles/RigidInjectedParticleContainer.cpp index 489f286b5..cc064538b 100644 --- a/Source/Particles/RigidInjectedParticleContainer.cpp +++ b/Source/Particles/RigidInjectedParticleContainer.cpp @@ -18,10 +18,10 @@ #include "Pusher/UpdateMomentumHigueraCary.H" #include "Pusher/UpdateMomentumVay.H" #include "RigidInjectedParticleContainer.H" +#include "Utils/Parser/ParserUtils.H" #include "Utils/WarpXAlgorithmSelection.H" #include "Utils/WarpXConst.H" #include "Utils/WarpXProfilerWrapper.H" -#include "Utils/WarpXUtil.H" #include "WarpX.H" #include <AMReX.H> @@ -63,7 +63,8 @@ RigidInjectedParticleContainer::RigidInjectedParticleContainer (AmrCore* amr_cor ParmParse pp_species_name(species_name); - getWithParser(pp_species_name, "zinject_plane", zinject_plane); + utils::parser::getWithParser( + pp_species_name, "zinject_plane", zinject_plane); pp_species_name.query("rigid_advance", rigid_advance); } diff --git a/Source/Python/WarpXWrappers.cpp b/Source/Python/WarpXWrappers.cpp index 2df989bba..61909cff7 100644 --- a/Source/Python/WarpXWrappers.cpp +++ b/Source/Python/WarpXWrappers.cpp @@ -11,8 +11,8 @@ #include "Particles/MultiParticleContainer.H" #include "Particles/ParticleBoundaryBuffer.H" #include "Particles/WarpXParticleContainer.H" -#include "Utils/WarpXUtil.H" #include "Utils/WarpXProfilerWrapper.H" +#include "Utils/WarpXUtil.H" #include "WarpX.H" #include "WarpXWrappers.H" #include "WarpX_py.H" diff --git a/Source/Utils/Algorithms/IsIn.H b/Source/Utils/Algorithms/IsIn.H new file mode 100644 index 000000000..c9d2f477e --- /dev/null +++ b/Source/Utils/Algorithms/IsIn.H @@ -0,0 +1,58 @@ +/* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet + * Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_UTILS_ALGORITHMS_ISIN_H_ +#define WARPX_UTILS_ALGORITHMS_ISIN_H_ + +#include <algorithm> +#include <vector> + +namespace utils::algorithms +{ + /** \brief Returns true if an item of type TE is in a vector + * of TV objects (provided that TE can be converted into TV), false otherwise + * + * @tparam TV the typename of the vector elements + * @tparam TE the typename of the item + * + * @param vect a vector of TV objects + * @param elem an object of type TE + * + * @return true if elem is in vect, false otherwise + */ + template <typename TV, typename TE, + class = typename std::enable_if<std::is_convertible<TE,TV>::value>::type> + bool is_in(const std::vector<TV>& vect, + const TE& elem) + { + return (std::find(vect.begin(), vect.end(), elem) != vect.end()); + } + + + /** \brief Returns true if any of the items of a vector<TE> is contained + * in another vector<TV> (provided that TE can be converted into TV) + * + * @tparam TV the typename of the first vector elements + * @tparam TV the typename of the second vector elements + * + * @param vect a vector of TV objects + * @param elems a vector of TE objects + * + * @return true if any element of elems is in vect, false otherwise + */ + template <typename TV, typename TE, + class = typename std::enable_if<std::is_convertible<TE,TV>::value>::type> + bool any_of_is_in(const std::vector<TV>& vect, + const std::vector<TE>& elems) + { + return std::any_of(elems.begin(), elems.end(), + [&](const auto elem){return is_in(vect, elem);}); + } +} + +#endif //WARPX_UTILS_ALGORITHMS_ISIN_H_ diff --git a/Source/Utils/Algorithms/LinearInterpolation.H b/Source/Utils/Algorithms/LinearInterpolation.H new file mode 100644 index 000000000..32fdf7a6e --- /dev/null +++ b/Source/Utils/Algorithms/LinearInterpolation.H @@ -0,0 +1,59 @@ +/* Copyright 2022 Luca Fedeli + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_ +#define WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_ + +#include <AMReX_Extension.H> +#include <AMReX_GpuQualifiers.H> + +namespace utils::algorithms +{ + /** \brief Performs a linear interpolation + * + * Performs a linear interpolation at x given the 2 points + * (x0, f0) and (x1, f1) + */ + template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE + T linear_interp(T x0, T x1, T f0, T f1, T x) + { + return ((x1-x)*f0 + (x-x0)*f1)/(x1-x0); + } + + /** \brief Performs a bilinear interpolation + * + * Performs a bilinear interpolation at (x,y) given the 4 points + * (x0, y0, f00), (x0, y1, f01), (x1, y0, f10), (x1, y1, f11). + */ + template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE + T bilinear_interp(T x0, T x1, T y0, T y1, T f00, T f01, T f10, T f11, T x, T y) + { + const T fx0 = linear_interp(x0, x1, f00, f10, x); + const T fx1 = linear_interp(x0, x1, f01, f11, x); + return linear_interp(y0, y1, fx0, fx1, y); + } + + /** \brief Performs a trilinear interpolation + * + * Performs a trilinear interpolation at (x,y,z) given the 8 points + * (x0, y0, z0, f000), (x0, y0, z1, f001), (x0, y1, z0, f010), (x0, y1, z1, f011), + * (x1, y0, z0, f100), (x1, y0, z1, f101), (x1, y1, z0, f110), (x1, y1, z1, f111) + */ + template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE + T trilinear_interp(T x0, T x1,T y0, T y1, T z0, T z1, + T f000, T f001, T f010, T f011, T f100, T f101, T f110, T f111, + T x, T y, T z) + { + const T fxy0 = bilinear_interp( + x0, x1, y0, y1, f000, f010, f100, f110, x, y); + const T fxy1 = bilinear_interp( + x0, x1, y0, y1, f001, f011, f101, f111, x, y); + return linear_interp(z0, z1, fxy0, fxy1, z); + } +} + +#endif //WARPX_UTILS_ALGORITHMS_LINEAR_INTERPOLATION_H_ diff --git a/Source/Utils/Algorithms/Make.package b/Source/Utils/Algorithms/Make.package new file mode 100644 index 000000000..04638494d --- /dev/null +++ b/Source/Utils/Algorithms/Make.package @@ -0,0 +1 @@ +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils/Algorithms diff --git a/Source/Utils/Algorithms/UpperBound.H b/Source/Utils/Algorithms/UpperBound.H new file mode 100644 index 000000000..8a528971a --- /dev/null +++ b/Source/Utils/Algorithms/UpperBound.H @@ -0,0 +1,49 @@ +/* Copyright 2022 Luca Fedeli + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_ +#define WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_ + +#include <AMReX_Extension.H> +#include <AMReX_GpuQualifiers.H> + +namespace utils::algorithms +{ + + /** \brief Returns a pointer to the first element in the range [first, last) that is greater than val + * + * A re-implementation of the upper_bound algorithm suitable for GPU kernels. + * + * @param first: pointer to left limit of the range to consider + * @param last: pointer to right limit of the range to consider + * @param val: value to compare the elements of [first, last) to + */ + template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE + const T* upper_bound(const T* first, const T* last, const T& val) + { + const T* it; + size_t count, step; + count = last-first; + while(count>0){ + it = first; + step = count/2; + it += step; + if (!(val<*it)){ + first = ++it; + count -= step + 1; + } + else{ + count = step; + } + } + + return first; + } + +} + +#endif //WARPX_UTILS_ALGORITHMS_UPPER_BOUND_H_ diff --git a/Source/Utils/CMakeLists.txt b/Source/Utils/CMakeLists.txt index 9253f3d0d..19fe6bc34 100644 --- a/Source/Utils/CMakeLists.txt +++ b/Source/Utils/CMakeLists.txt @@ -3,7 +3,6 @@ target_sources(WarpX CoarsenIO.cpp CoarsenMR.cpp Interpolate.cpp - IntervalsParser.cpp MPIInitHelpers.cpp ParticleUtils.cpp RelativeCellPosition.cpp @@ -15,3 +14,5 @@ target_sources(WarpX ) add_subdirectory(Logo) +add_subdirectory(Parser) +add_subdirectory(Strings) diff --git a/Source/Utils/IntervalsParser.H b/Source/Utils/IntervalsParser.H deleted file mode 100644 index 06258b109..000000000 --- a/Source/Utils/IntervalsParser.H +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef WARPX_INTERVALSPARSER_H_ -#define WARPX_INTERVALSPARSER_H_ - -#include <limits> -#include <string> -#include <vector> - -/** - * \brief This class is a parser for slices of the form i:j:k where i, j and k are integers - * representing respectively the starting point, the stopping point and the period. - */ -class SliceParser -{ -public: - /** - * \brief Constructor of the SliceParser class. - * - * @param[in] instr an input string of the form "i:j:k", "i:j" or "k" where i, j and k are - * integers representing respectively the starting point, the stopping point and the period. - * Any of these integers may be omitted in which case it will be equal to their default value - * (0 for the starting point, std::numeric_limits<int>::max() for the stopping point and 1 for - * the period). For example SliceParser(":1000:") is equivalent to SliceParser("0:1000:1"). - */ - SliceParser (const std::string& instr, bool isBTD=false); - - /** - * \brief A method that returns true if the input integer is contained in the slice. (e.g. if - * the list is initialized with "300:500:100", this method returns true if and only if n is - * 300, 400 or 500). If the period is negative or 0, the function always returns false. - * - * @param[in] n the input integer - */ - bool contains (const int n) const; - - /** - * \brief A method that returns the smallest integer strictly greater than n such that - * contains(n) is true. Returns std::numeric_limits<int>::max() if there is no such integer. - * - * @param[in] n the input integer - */ - int nextContains (const int n) const; - - /** - * \brief A method that returns the greatest integer strictly smaller than n such that - * contains(n) is true. Returns 0 if there is no such integer. - * - * @param[in] n the input integer - */ - int previousContains (const int n) const; - - /** - * \brief A method that returns the slice period. - * - */ - int getPeriod () const; - - /** - * \brief A method that returns the slice start. - * - */ - int getStart () const; - - /** - * \brief A method that returns the slice stop. - * - */ - int getStop () const; - - /** - * @brief A method that returns the number of integers contained by the slice. - * - */ - int numContained() const; - -private: - bool m_isBTD = false; - int m_start = 0; - int m_stop = std::numeric_limits<int>::max(); - int m_period = 1; - std::string m_separator = ":"; - -}; - -/** - * \brief This class is a parser for multiple slices of the form x,y,z,... where x, y and z are - * slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of - * SliceParsers. - */ -class IntervalsParser -{ -public: - /** - * \brief Default constructor of the IntervalsParser class. - */ - IntervalsParser () = default; - - /** - * \brief Constructor of the IntervalsParser class. - * - * @param[in] instr_vec an input vector string, which when concatenated is of the form - * "x,y,z,...". This will call the constructor of SliceParser using x, y and z as input - * arguments. - */ - IntervalsParser (const std::vector<std::string>& instr_vec); - - /** - * \brief A method that returns true if the input integer is contained in any of the slices - * contained by the IntervalsParser. - * - * @param[in] n the input integer - */ - bool contains (const int n) const; - - /** - * \brief A method that returns the smallest integer strictly greater than n such that - * contains(n) is true. Returns std::numeric_limits<int>::max() if there is no such integer. - * - * @param[in] n the input integer - */ - int nextContains (const int n) const; - - /** - * \brief A method that returns the greatest integer strictly smaller than n such that - * contains(n) is true. Returns 0 if there is no such integer. - * - * @param[in] n the input integer - */ - int previousContains (const int n) const; - - /** - * \brief A method that returns the greatest integer smaller than or equal to n such that - * contains(n) is true. Returns 0 if there is no such integer. - * - * @param[in] n the input integer - */ - int previousContainsInclusive (const int n) const; - - /** - * \brief A method the local period (in timesteps) of the IntervalsParser at timestep n. - * The period is defined by nextContains(n) - previousContainsInclusive(n) - * - * @param[in] n the input integer - */ - int localPeriod (const int n) const; - -/** - * \brief A method that returns true if any of the slices contained by the IntervalsParser - * has a strictly positive period. - */ - bool isActivated () const; - -private: - std::vector<SliceParser> m_slices; - std::string m_separator = ","; - bool m_activated = false; -}; - -/** - * \brief This class is a parser for multiple slices of the form x,y,z,... where x, y and z are - * slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of - * SliceParsers. The supported function set differs from the IntervalsParser - */ -class BTDIntervalsParser -{ -public: - /** - * \brief Default constructor of the BTDIntervalsParser class. - */ - BTDIntervalsParser () = default; - - /** - * \brief Constructor of the BTDIntervalsParser class. - * - * @param[in] instr_vec an input vector string, which when concatenated is of the form - * "x,y,z,...". This will call the constructor of SliceParser using x, y and z as input - * arguments. - */ - BTDIntervalsParser (const std::vector<std::string>& instr_vec); - - /** - * @brief Return the total number of unique labframe snapshots - */ - int NumSnapshots (); - - /** - * @brief Return the iteration number stored at index i_buffer - * - * @param i_buffer buffer or iteration index, between 0 and NumSnapshots - */ - int GetBTDIteration(int i_buffer); - - /** - * \brief A method that returns true if any of the slices contained by the IntervalsParser - * has a strictly positive period. - */ - bool isActivated () const; - -private: - std::vector<int> m_btd_iterations; - std::vector<SliceParser> m_slices; - std::vector<int> m_slice_starting_i_buffer; - int m_n_snapshots; - static constexpr char m_separator = ','; - bool m_activated = false; -}; - -#endif // WARPX_INTERVALSPARSER_H_ diff --git a/Source/Utils/IonizationEnergiesTable.H b/Source/Utils/IonizationEnergiesTable.H deleted file mode 100644 index bc2b6005a..000000000 --- a/Source/Utils/IonizationEnergiesTable.H +++ /dev/null @@ -1,228 +0,0 @@ -/* Copyright 2019-2021 Axel Huebl, Maxence Thevenet - * - * This file is part of WarpX. - * - * License: BSD-3-Clause-LBNL - */ -// This script was automatically generated! -// Edit dev/Source/Utils/write_atomic_data_cpp.py instead! -#ifndef WARPX_IONIZATION_TABLE_H_ -#define WARPX_IONIZATION_TABLE_H_ - -#include <AMReX_AmrCore.H> -#include <AMReX_REAL.H> - -#include <map> -#include <string> - -static std::map<std::string, int> const ion_map_ids = { - {"H", 0}, - {"He", 1}, - {"Li", 2}, - {"Be", 3}, - {"B", 4}, - {"C", 5}, - {"N", 6}, - {"O", 7}, - {"F", 8}, - {"Ne", 9}, - {"Na", 10}, - {"Mg", 11}, - {"Al", 12}, - {"Si", 13}, - {"P", 14}, - {"S", 15}, - {"Cl", 16}, - {"Ar", 17}, - {"Cu", 18}, - {"Kr", 19}, - {"Rb", 20}, - {"Xe", 21}, - {"Rn", 22} }; - -constexpr int nelements = 23; - -constexpr int ion_atomic_numbers[nelements] = { - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 29, 36, - 37, 54, 86}; - -constexpr int ion_energy_offsets[nelements] = { - 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, - 55, 66, 78, 91, 105, 120, 136, 153, 171, 200, - 236, 273, 327}; - -constexpr int energies_tab_length = 413; - -constexpr amrex::Real table_ionization_energies[energies_tab_length]{ - // H - amrex::Real(13.59843449), - // He - amrex::Real(24.58738880), amrex::Real(54.4177650), - // Li - amrex::Real(5.39171495), amrex::Real(75.6400964), amrex::Real(122.4543581), - // Be - amrex::Real(9.322699), amrex::Real(18.21115), amrex::Real(153.896203), - amrex::Real(217.7185843), - // B - amrex::Real(8.298019), amrex::Real(25.15483), amrex::Real(37.93058), - amrex::Real(259.3715), amrex::Real(340.226020), - // C - amrex::Real(11.2602880), amrex::Real(24.383154), amrex::Real(47.88778), - amrex::Real(64.49352), amrex::Real(392.090515), amrex::Real(489.993194), - // N - amrex::Real(14.53413), amrex::Real(29.60125), amrex::Real(47.4453), - amrex::Real(77.4735), amrex::Real(97.8901), amrex::Real(552.06732), - amrex::Real(667.046116), - // O - amrex::Real(13.618055), amrex::Real(35.12112), amrex::Real(54.93554), - amrex::Real(77.41350), amrex::Real(113.8990), amrex::Real(138.1189), - amrex::Real(739.32682), amrex::Real(871.40988), - // F - amrex::Real(17.42282), amrex::Real(34.97081), amrex::Real(62.70798), - amrex::Real(87.175), amrex::Real(114.249), amrex::Real(157.16311), - amrex::Real(185.1868), amrex::Real(953.89804), amrex::Real(1103.11747), - // Ne - amrex::Real(21.564540), amrex::Real(40.96297), amrex::Real(63.4233), - amrex::Real(97.1900), amrex::Real(126.247), amrex::Real(157.934), - amrex::Real(207.271), amrex::Real(239.0970), amrex::Real(1195.80783), - amrex::Real(1362.19915), - // Na - amrex::Real(5.1390769), amrex::Real(47.28636), amrex::Real(71.6200), - amrex::Real(98.936), amrex::Real(138.404), amrex::Real(172.23), - amrex::Real(208.504), amrex::Real(264.192), amrex::Real(299.856), - amrex::Real(1465.13449), amrex::Real(1648.70218), - // Mg - amrex::Real(7.646236), amrex::Real(15.035271), amrex::Real(80.1436), - amrex::Real(109.2654), amrex::Real(141.33), amrex::Real(186.76), - amrex::Real(225.02), amrex::Real(265.924), amrex::Real(327.99), - amrex::Real(367.489), amrex::Real(1761.80487), amrex::Real(1962.66365), - // Al - amrex::Real(5.985769), amrex::Real(18.82855), amrex::Real(28.447642), - amrex::Real(119.9924), amrex::Real(153.8252), amrex::Real(190.49), - amrex::Real(241.76), amrex::Real(284.64), amrex::Real(330.21), - amrex::Real(398.65), amrex::Real(442.005), amrex::Real(2085.97700), - amrex::Real(2304.14005), - // Si - amrex::Real(8.15168), amrex::Real(16.34585), amrex::Real(33.49300), - amrex::Real(45.14179), amrex::Real(166.767), amrex::Real(205.279), - amrex::Real(246.57), amrex::Real(303.59), amrex::Real(351.28), - amrex::Real(401.38), amrex::Real(476.273), amrex::Real(523.415), - amrex::Real(2437.65813), amrex::Real(2673.17753), - // P - amrex::Real(10.486686), amrex::Real(19.76949), amrex::Real(30.20264), - amrex::Real(51.44387), amrex::Real(65.02511), amrex::Real(220.430), - amrex::Real(263.57), amrex::Real(309.60), amrex::Real(372.31), - amrex::Real(424.40), amrex::Real(479.44), amrex::Real(560.62), - amrex::Real(611.741), amrex::Real(2816.90876), amrex::Real(3069.8415), - // S - amrex::Real(10.36001), amrex::Real(23.33788), amrex::Real(34.86), - amrex::Real(47.222), amrex::Real(72.5945), amrex::Real(88.0529), - amrex::Real(280.954), amrex::Real(328.794), amrex::Real(379.84), - amrex::Real(447.7), amrex::Real(504.55), amrex::Real(564.41), - amrex::Real(651.96), amrex::Real(706.994), amrex::Real(3223.7807), - amrex::Real(3494.1879), - // Cl - amrex::Real(12.967632), amrex::Real(23.81364), amrex::Real(39.80), - amrex::Real(53.24), amrex::Real(67.68), amrex::Real(96.94), - amrex::Real(114.2013), amrex::Real(348.306), amrex::Real(400.851), - amrex::Real(456.7), amrex::Real(530.0), amrex::Real(591.58), - amrex::Real(656.30), amrex::Real(750.23), amrex::Real(809.198), - amrex::Real(3658.3437), amrex::Real(3946.2909), - // Ar - amrex::Real(15.7596117), amrex::Real(27.62967), amrex::Real(40.735), - amrex::Real(59.58), amrex::Real(74.84), amrex::Real(91.290), - amrex::Real(124.41), amrex::Real(143.4567), amrex::Real(422.60), - amrex::Real(479.76), amrex::Real(540.4), amrex::Real(619.0), - amrex::Real(685.5), amrex::Real(755.13), amrex::Real(855.5), - amrex::Real(918.375), amrex::Real(4120.6656), amrex::Real(4426.2228), - // Cu - amrex::Real(7.726380), amrex::Real(20.29239), amrex::Real(36.841), - amrex::Real(57.38), amrex::Real(79.8), amrex::Real(103.0), - amrex::Real(139.0), amrex::Real(166.0), amrex::Real(198.0), - amrex::Real(232.2), amrex::Real(265.33), amrex::Real(367.0), - amrex::Real(401.0), amrex::Real(436.0), amrex::Real(483.1), - amrex::Real(518.7), amrex::Real(552.8), amrex::Real(632.5), - amrex::Real(670.608), amrex::Real(1690.5), amrex::Real(1800), - amrex::Real(1918), amrex::Real(2044), amrex::Real(2179.4), - amrex::Real(2307.3), amrex::Real(2479.1), amrex::Real(2586.954), - amrex::Real(11062.4313), amrex::Real(11567.613), - // Kr - amrex::Real(13.9996053), amrex::Real(24.35984), amrex::Real(35.838), - amrex::Real(50.85), amrex::Real(64.69), amrex::Real(78.49), - amrex::Real(109.13), amrex::Real(125.802), amrex::Real(233.0), - amrex::Real(268), amrex::Real(308), amrex::Real(350), - amrex::Real(391), amrex::Real(446), amrex::Real(492), - amrex::Real(540), amrex::Real(591), amrex::Real(640), - amrex::Real(785), amrex::Real(831.6), amrex::Real(882.8), - amrex::Real(945), amrex::Real(999.0), amrex::Real(1042), - amrex::Real(1155.0), amrex::Real(1205.23), amrex::Real(2928.9), - amrex::Real(3072), amrex::Real(3228), amrex::Real(3380), - amrex::Real(3584), amrex::Real(3752.0), amrex::Real(3971), - amrex::Real(4109.083), amrex::Real(17296.420), amrex::Real(17936.209), - // Rb - amrex::Real(4.1771280), amrex::Real(27.28954), amrex::Real(39.247), - amrex::Real(52.20), amrex::Real(68.44), amrex::Real(82.9), - amrex::Real(98.67), amrex::Real(132.79), amrex::Real(150.628), - amrex::Real(277.12), amrex::Real(313.1), amrex::Real(356.0), - amrex::Real(400), amrex::Real(443), amrex::Real(502), - amrex::Real(550), amrex::Real(601), amrex::Real(654), - amrex::Real(706.0), amrex::Real(857), amrex::Real(905.3), - amrex::Real(958.9), amrex::Real(1024), amrex::Real(1080), - amrex::Real(1125), amrex::Real(1242.5), amrex::Real(1294.57), - amrex::Real(3133.3), amrex::Real(3281), amrex::Real(3443), - amrex::Real(3600), amrex::Real(3815), amrex::Real(3988), - amrex::Real(4214), amrex::Real(4356.865), amrex::Real(18305.884), - amrex::Real(18965.516), - // Xe - amrex::Real(12.1298436), amrex::Real(20.975), amrex::Real(31.05), - amrex::Real(42.20), amrex::Real(54.1), amrex::Real(66.703), - amrex::Real(91.6), amrex::Real(105.9778), amrex::Real(179.84), - amrex::Real(202.0), amrex::Real(229.02), amrex::Real(255.0), - amrex::Real(281), amrex::Real(314), amrex::Real(343), - amrex::Real(374), amrex::Real(404), amrex::Real(434), - amrex::Real(549), amrex::Real(582), amrex::Real(616), - amrex::Real(650), amrex::Real(700), amrex::Real(736), - amrex::Real(818), amrex::Real(857.0), amrex::Real(1493), - amrex::Real(1571), amrex::Real(1653), amrex::Real(1742), - amrex::Real(1826), amrex::Real(1919), amrex::Real(2023), - amrex::Real(2113), amrex::Real(2209), amrex::Real(2300), - amrex::Real(2556), amrex::Real(2637), amrex::Real(2726), - amrex::Real(2811), amrex::Real(2975), amrex::Real(3068), - amrex::Real(3243), amrex::Real(3333.8), amrex::Real(7660), - amrex::Real(7889), amrex::Real(8144), amrex::Real(8382), - amrex::Real(8971), amrex::Real(9243), amrex::Real(9581), - amrex::Real(9810.37), amrex::Real(40271.724), amrex::Real(41299.71), - // Rn - amrex::Real(10.74850), amrex::Real(21.4), amrex::Real(29.4), - amrex::Real(36.9), amrex::Real(52.9), amrex::Real(64.0), - amrex::Real(88.0), amrex::Real(102.0), amrex::Real(154.0), - amrex::Real(173.9), amrex::Real(195.0), amrex::Real(218.0), - amrex::Real(240), amrex::Real(264), amrex::Real(293), - amrex::Real(317), amrex::Real(342), amrex::Real(367), - amrex::Real(488), amrex::Real(520), amrex::Real(550), - amrex::Real(580), amrex::Real(640), amrex::Real(680), - amrex::Real(760), amrex::Real(800), amrex::Real(850), - amrex::Real(920), amrex::Real(980), amrex::Real(1050), - amrex::Real(1110), amrex::Real(1180), amrex::Real(1250), - amrex::Real(1310), amrex::Real(1390), amrex::Real(1460), - amrex::Real(1520), amrex::Real(1590), amrex::Real(1660), - amrex::Real(1720), amrex::Real(2033), amrex::Real(2094), - amrex::Real(2158), amrex::Real(2227), amrex::Real(2293), - amrex::Real(2357), amrex::Real(2467), amrex::Real(2535), - amrex::Real(2606), amrex::Real(2674), amrex::Real(2944), - amrex::Real(3010), amrex::Real(3082), amrex::Real(3149), - amrex::Real(3433), amrex::Real(3510), amrex::Real(3699), - amrex::Real(3777), amrex::Real(6169), amrex::Real(6318), - amrex::Real(6476), amrex::Real(6646), amrex::Real(6807), - amrex::Real(6964), amrex::Real(7283), amrex::Real(7450), - amrex::Real(7630), amrex::Real(7800), amrex::Real(8260), - amrex::Real(8410), amrex::Real(8570), amrex::Real(8710), - amrex::Real(9610), amrex::Real(9780), amrex::Real(10120), - amrex::Real(10290), amrex::Real(21770), amrex::Real(22160), - amrex::Real(22600), amrex::Real(22990), amrex::Real(26310), - amrex::Real(26830), amrex::Real(27490), amrex::Real(27903.1), - amrex::Real(110842.0), amrex::Real(112843.7) -}; - -#endif // #ifndef WARPX_IONIZATION_TABLE_H_ diff --git a/Source/Utils/Make.package b/Source/Utils/Make.package index b20a1abe2..f43953720 100644 --- a/Source/Utils/Make.package +++ b/Source/Utils/Make.package @@ -11,6 +11,10 @@ CEXE_sources += MPIInitHelpers.cpp CEXE_sources += RelativeCellPosition.cpp CEXE_sources += ParticleUtils.cpp +include $(WARPX_HOME)/Source/Utils/Algorithms/Make.package include $(WARPX_HOME)/Source/Utils/Logo/Make.package +include $(WARPX_HOME)/Source/Utils/Parser/Make.package +include $(WARPX_HOME)/Source/Utils/Physics/Make.package +include $(WARPX_HOME)/Source/Utils/Strings/Make.package VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils diff --git a/Source/Utils/Parser/CMakeLists.txt b/Source/Utils/Parser/CMakeLists.txt new file mode 100644 index 000000000..620ee8dcd --- /dev/null +++ b/Source/Utils/Parser/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(WarpX + PRIVATE + IntervalsParser.cpp + ParserUtils.cpp +) diff --git a/Source/Utils/Parser/IntervalsParser.H b/Source/Utils/Parser/IntervalsParser.H new file mode 100644 index 000000000..e9fffce9e --- /dev/null +++ b/Source/Utils/Parser/IntervalsParser.H @@ -0,0 +1,220 @@ +/* Copyright 2022 Andrew Myers, Burlen Loring, Luca Fedeli + * Maxence Thevenet, Remi Lehe, Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_UTILS_PARSER_INTERVALSPARSER_H_ +#define WARPX_UTILS_PARSER_INTERVALSPARSER_H_ + +#include <limits> +#include <string> +#include <vector> + +namespace utils::parser +{ + + /** + * \brief This class is a parser for slices of the form i:j:k where i, j and k are integers + * representing respectively the starting point, the stopping point and the period. + */ + class SliceParser + { + public: + /** + * \brief Constructor of the SliceParser class. + * + * @param[in] instr an input string of the form "i:j:k", "i:j" or "k" where i, j and k are + * integers representing respectively the starting point, the stopping point and the period. + * Any of these integers may be omitted in which case it will be equal to their default value + * (0 for the starting point, std::numeric_limits<int>::max() for the stopping point and 1 for + * the period). For example SliceParser(":1000:") is equivalent to SliceParser("0:1000:1"). + */ + SliceParser (const std::string& instr, bool isBTD=false); + + /** + * \brief A method that returns true if the input integer is contained in the slice. (e.g. if + * the list is initialized with "300:500:100", this method returns true if and only if n is + * 300, 400 or 500). If the period is negative or 0, the function always returns false. + * + * @param[in] n the input integer + */ + bool contains (const int n) const; + + /** + * \brief A method that returns the smallest integer strictly greater than n such that + * contains(n) is true. Returns std::numeric_limits<int>::max() if there is no such integer. + * + * @param[in] n the input integer + */ + int nextContains (const int n) const; + + /** + * \brief A method that returns the greatest integer strictly smaller than n such that + * contains(n) is true. Returns 0 if there is no such integer. + * + * @param[in] n the input integer + */ + int previousContains (const int n) const; + + /** + * \brief A method that returns the slice period. + * + */ + int getPeriod () const; + + /** + * \brief A method that returns the slice start. + * + */ + int getStart () const; + + /** + * \brief A method that returns the slice stop. + * + */ + int getStop () const; + + /** + * @brief A method that returns the number of integers contained by the slice. + * + */ + int numContained() const; + + private: + bool m_isBTD = false; + int m_start = 0; + int m_stop = std::numeric_limits<int>::max(); + int m_period = 1; + std::string m_separator = ":"; + + }; + + + /** + * \brief This class is a parser for multiple slices of the form x,y,z,... where x, y and z are + * slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of + * SliceParsers. + */ + class IntervalsParser + { + public: + /** + * \brief Default constructor of the IntervalsParser class. + */ + IntervalsParser () = default; + + /** + * \brief Constructor of the IntervalsParser class. + * + * @param[in] instr_vec an input vector string, which when concatenated is of the form + * "x,y,z,...". This will call the constructor of SliceParser using x, y and z as input + * arguments. + */ + IntervalsParser (const std::vector<std::string>& instr_vec); + + /** + * \brief A method that returns true if the input integer is contained in any of the slices + * contained by the IntervalsParser. + * + * @param[in] n the input integer + */ + bool contains (const int n) const; + + /** + * \brief A method that returns the smallest integer strictly greater than n such that + * contains(n) is true. Returns std::numeric_limits<int>::max() if there is no such integer. + * + * @param[in] n the input integer + */ + int nextContains (const int n) const; + + /** + * \brief A method that returns the greatest integer strictly smaller than n such that + * contains(n) is true. Returns 0 if there is no such integer. + * + * @param[in] n the input integer + */ + int previousContains (const int n) const; + + /** + * \brief A method that returns the greatest integer smaller than or equal to n such that + * contains(n) is true. Returns 0 if there is no such integer. + * + * @param[in] n the input integer + */ + int previousContainsInclusive (const int n) const; + + /** + * \brief A method the local period (in timesteps) of the IntervalsParser at timestep n. + * The period is defined by nextContains(n) - previousContainsInclusive(n) + * + * @param[in] n the input integer + */ + int localPeriod (const int n) const; + + /** + * \brief A method that returns true if any of the slices contained by the IntervalsParser + * has a strictly positive period. + */ + bool isActivated () const; + + private: + std::vector<SliceParser> m_slices; + std::string m_separator = ","; + bool m_activated = false; + }; + + /** + * \brief This class is a parser for multiple slices of the form x,y,z,... where x, y and z are + * slices of the form i:j:k, as defined in the SliceParser class. This class contains a vector of + * SliceParsers. The supported function set differs from the IntervalsParser + */ + class BTDIntervalsParser + { + public: + /** + * \brief Default constructor of the BTDIntervalsParser class. + */ + BTDIntervalsParser () = default; + + /** + * \brief Constructor of the BTDIntervalsParser class. + * + * @param[in] instr_vec an input vector string, which when concatenated is of the form + * "x,y,z,...". This will call the constructor of SliceParser using x, y and z as input + * arguments. + */ + BTDIntervalsParser (const std::vector<std::string>& instr_vec); + + /** + * @brief Return the total number of unique labframe snapshots + */ + int NumSnapshots (); + + /** + * @brief Return the iteration number stored at index i_buffer + * + * @param i_buffer buffer or iteration index, between 0 and NumSnapshots + */ + int GetBTDIteration(int i_buffer); + + /** + * \brief A method that returns true if any of the slices contained by the IntervalsParser + * has a strictly positive period. + */ + bool isActivated () const; + + private: + std::vector<int> m_btd_iterations; + std::vector<SliceParser> m_slices; + std::vector<int> m_slice_starting_i_buffer; + int m_n_snapshots; + static constexpr char m_separator = ','; + bool m_activated = false; + }; +} + +#endif // WARPX_UTILS_PARSER_INTERVALSPARSER_H_ diff --git a/Source/Utils/IntervalsParser.cpp b/Source/Utils/Parser/IntervalsParser.cpp index 4da0142a0..d535edeb8 100644 --- a/Source/Utils/IntervalsParser.cpp +++ b/Source/Utils/Parser/IntervalsParser.cpp @@ -1,17 +1,28 @@ +/* Copyright 2022 Andrew Myers, Burlen Loring, Luca Fedeli + * Maxence Thevenet, Remi Lehe, Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + #include "IntervalsParser.H" -#include "TextMsg.H" -#include "WarpXUtil.H" + +#include "ParserUtils.H" +#include "Utils/Strings/StringUtils.H" +#include "Utils/TextMsg.H" #include <AMReX_Utility.H> #include <algorithm> -#include <memory> -SliceParser::SliceParser (const std::string& instr, const bool isBTD) +utils::parser::SliceParser::SliceParser (const std::string& instr, const bool isBTD) { + namespace utils_str = utils::strings; + m_isBTD = isBTD; // split string and trim whitespaces - auto insplit = WarpXUtilStr::split<std::vector<std::string>>(instr, m_separator, true); + auto insplit = utils_str::split<std::vector<std::string>>(instr, m_separator, true); if(insplit.size() == 1){ // no colon in input string. The input is the period. WARPX_ALWAYS_ASSERT_WITH_MESSAGE(!m_isBTD, "must specify interval stop for BTD"); @@ -39,13 +50,15 @@ SliceParser::SliceParser (const std::string& instr, const bool isBTD) } } -bool SliceParser::contains (const int n) const + +bool utils::parser::SliceParser::contains (const int n) const { if (m_period <= 0) {return false;} return (n - m_start) % m_period == 0 && n >= m_start && n <= m_stop; } -int SliceParser::nextContains (const int n) const + +int utils::parser::SliceParser::nextContains (const int n) const { if (m_period <= 0) {return std::numeric_limits<int>::max();} int next = m_start; @@ -54,7 +67,8 @@ int SliceParser::nextContains (const int n) const return next; } -int SliceParser::previousContains (const int n) const + +int utils::parser::SliceParser::previousContains (const int n) const { if (m_period <= 0) {return false;} int previous = ((std::min(n-1,m_stop)-m_start)/m_period)*m_period+m_start; @@ -62,20 +76,28 @@ int SliceParser::previousContains (const int n) const return previous; } -int SliceParser::getPeriod () const {return m_period;} -int SliceParser::getStart () const {return m_start;} +int utils::parser::SliceParser::getPeriod () const {return m_period;} -int SliceParser::getStop () const {return m_stop;} -int SliceParser::numContained () const {return (m_stop - m_start) / m_period + 1;} +int utils::parser::SliceParser::getStart () const {return m_start;} -IntervalsParser::IntervalsParser (const std::vector<std::string>& instr_vec) + +int utils::parser::SliceParser::getStop () const {return m_stop;} + + +int utils::parser::SliceParser::numContained () const { + return (m_stop - m_start) / m_period + 1;} + +utils::parser::IntervalsParser::IntervalsParser ( + const std::vector<std::string>& instr_vec) { + namespace utils_str = utils::strings; + std::string inconcatenated; for (const auto& instr_element : instr_vec) inconcatenated +=instr_element; - auto insplit = WarpXUtilStr::split<std::vector<std::string>>(inconcatenated, m_separator); + auto insplit = utils_str::split<std::vector<std::string>>(inconcatenated, m_separator); for(const auto& inslc : insplit) { @@ -86,13 +108,15 @@ IntervalsParser::IntervalsParser (const std::vector<std::string>& instr_vec) } } -bool IntervalsParser::contains (const int n) const + +bool utils::parser::IntervalsParser::contains (const int n) const { return std::any_of(m_slices.begin(), m_slices.end(), [&](const auto& slice){return slice.contains(n);}); } -int IntervalsParser::nextContains (const int n) const + +int utils::parser::IntervalsParser::nextContains (const int n) const { int next = std::numeric_limits<int>::max(); for(const auto& slice: m_slices){ @@ -101,7 +125,8 @@ int IntervalsParser::nextContains (const int n) const return next; } -int IntervalsParser::previousContains (const int n) const + +int utils::parser::IntervalsParser::previousContains (const int n) const { int previous = 0; for(const auto& slice: m_slices){ @@ -110,25 +135,31 @@ int IntervalsParser::previousContains (const int n) const return previous; } -int IntervalsParser::previousContainsInclusive (const int n) const + +int utils::parser::IntervalsParser::previousContainsInclusive ( + const int n) const { if (contains(n)){return n;} else {return previousContains(n);} } -int IntervalsParser::localPeriod (const int n) const + +int utils::parser::IntervalsParser::localPeriod (const int n) const { return nextContains(n) - previousContainsInclusive(n); } -bool IntervalsParser::isActivated () const {return m_activated;} -BTDIntervalsParser::BTDIntervalsParser (const std::vector<std::string>& instr_vec) +bool utils::parser::IntervalsParser::isActivated () const {return m_activated;} + + +utils::parser::BTDIntervalsParser::BTDIntervalsParser ( + const std::vector<std::string>& instr_vec) { std::string inconcatenated; for (const auto& instr_element : instr_vec) inconcatenated +=instr_element; - auto const insplit = WarpXUtilStr::split<std::vector<std::string>>(inconcatenated, std::string(1,m_separator)); + auto const insplit = utils::strings::split<std::vector<std::string>>(inconcatenated, std::string(1,m_separator)); // parse the Intervals string into Slices and store each slice in m_slices, // in order of increasing Slice start value @@ -207,9 +238,14 @@ BTDIntervalsParser::BTDIntervalsParser (const std::vector<std::string>& instr_ve } } -int BTDIntervalsParser::NumSnapshots () { return m_btd_iterations.size(); } -int BTDIntervalsParser::GetBTDIteration(int i_buffer) +int utils::parser::BTDIntervalsParser::NumSnapshots () +{ + return m_btd_iterations.size(); +} + + +int utils::parser::BTDIntervalsParser::GetBTDIteration (int i_buffer) { return m_btd_iterations[i_buffer]; } diff --git a/Source/Utils/Parser/Make.package b/Source/Utils/Parser/Make.package new file mode 100644 index 000000000..f5447bc50 --- /dev/null +++ b/Source/Utils/Parser/Make.package @@ -0,0 +1,4 @@ +CEXE_sources += IntervalsParser.cpp +CEXE_sources += ParserUtils.cpp + +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils/Parser diff --git a/Source/Utils/Parser/ParserUtils.H b/Source/Utils/Parser/ParserUtils.H new file mode 100644 index 000000000..4195bed1a --- /dev/null +++ b/Source/Utils/Parser/ParserUtils.H @@ -0,0 +1,298 @@ +/* Copyright 2022 Andrew Myers, Burlen Loring, Luca Fedeli + * Maxence Thevenet, Remi Lehe, Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_UTILS_PARSER_PARSERUTILS_H_ +#define WARPX_UTILS_PARSER_PARSERUTILS_H_ + +#include <AMReX_ParmParse.H> +#include <AMReX_Parser.H> +#include <AMReX_REAL.H> +#include <AMReX_Vector.H> + +#include <cmath> +#include <string> +#include <type_traits> + +namespace utils::parser +{ + /** + * \brief Do a safe cast of a real to an int + * This ensures that the float value is within the range of ints and if not, + * raises an exception. + * + * \param x Real value to cast + * \param real_name String, the name of the variable being casted to use in the error message + */ + int + safeCastToInt(amrex::Real x, const std::string& real_name); + + + /** + * \brief Do a safe cast of a real to a long + * This ensures that the float value is within the range of longs and if not, + * raises an exception. + * + * \param x Real value to cast + * \param real_name String, the name of the variable being casted to use in the error message + */ + long + safeCastToLong(amrex::Real x, const std::string& real_name); + + + /** + * \brief Initialize an amrex::Parser object from a string containing a math expression + * + * \param parse_function String to read to initialize the parser. + * \param varnames A list of predefined independent variables + */ + amrex::Parser makeParser ( + std::string const& parse_function, + amrex::Vector<std::string> const& varnames); + + + /** + * \brief Parse a string (typically a mathematical expression) from the + * input file and store it into a variable. + * + * \param pp used to read the query_string `pp.<function>=string` + * \param query_string ParmParse.query will look for this string + * \param stored_string variable in which the string to parse is stored + */ + void Store_parserString( + const amrex::ParmParse &pp, + std::string query_string, + std::string& stored_string); + + + /** Parse a string and return as a double precision floating point number + * + * In case the string cannot be interpreted as a double, + * this function ... <throws an exception? aborts with error message?> + * + * \param str The string to be parsed + * \return representation as a double + */ + double parseStringtoDouble(const std::string& str); + + + /** Parse a string and return an int + * + * In case the string cannot be interpreted as Real, + * this function ... <throws an exception? aborts with error message?> + * + * \param str The string to be parsed + * \param name For integers, the name, to be used in error messages + * \return rounded closest integer + */ + int parseStringtoInt(const std::string& str, const std::string& name); + + + template <int N> + amrex::ParserExecutor<N> compileParser (amrex::Parser const* parser) + { + if (parser) { + return parser->compile<N>(); + } else { + return amrex::ParserExecutor<N>{}; + } + } + + + /** Similar to amrex::ParmParse::query, but also supports math expressions for the value. + * + * amrex::ParmParse::query reads a name and a value from the input file. This function does the + * same, and applies the amrex::Parser to the value, so the user has the choice to specify a value or + * a math expression (including user-defined constants). + * Works for amrex::Real numbers and integers. + * + * \param[in] a_pp amrex::ParmParse object + * \param[in] str name of the parameter to read + * \param[out] val where the value queried and parsed is stored, either a scalar or vector + */ + template <typename T> + int queryWithParser (const amrex::ParmParse& a_pp, char const * const str, T& val) + { + // call amrex::ParmParse::query, check if the user specified str. + std::string tmp_str; + int is_specified = a_pp.query(str, tmp_str); + if (is_specified) + { + // If so, create a parser object and apply it to the value provided by the user. + std::string str_val; + Store_parserString(a_pp, str, str_val); + + auto parser = makeParser(str_val, {}); + + if (std::is_same<T, int>::value) { + + val = safeCastToInt(std::round(parser.compileHost<0>()()), str); + } + else { + val = static_cast<T>(parser.compileHost<0>()()); + } + } + // return the same output as amrex::ParmParse::query + return is_specified; + } + + + template <typename T> + int queryArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val) + { + // call amrex::ParmParse::query, check if the user specified str. + std::vector<std::string> tmp_str_arr; + int is_specified = a_pp.queryarr(str, tmp_str_arr); + if (is_specified) + { + // If so, create parser objects and apply them to the values provided by the user. + int const n = static_cast<int>(tmp_str_arr.size()); + val.resize(n); + for (int i=0 ; i < n ; i++) { + auto parser = makeParser(tmp_str_arr[i], {}); + if (std::is_same<T, int>::value) { + val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); + } + else { + val[i] = static_cast<T>(parser.compileHost<0>()()); + } + } + } + // return the same output as amrex::ParmParse::query + return is_specified; + } + + + /** Similar to amrex::ParmParse::query, but also supports math expressions for the value. + * + * amrex::ParmParse::query reads a name and a value from the input file. This function does the + * same, and applies the amrex::Parser to the value, so the user has the choice to specify a value or + * a math expression (including user-defined constants). + * Works for amrex::Real numbers and integers. + * + * \param[in] a_pp amrex::ParmParse object + * \param[in] str name of the parameter to read + * \param[out] val where the value queried and parsed is stored, either a scalar or vector + * \param[in] start_ix start index in the list of inputs values (optional with arrays, default is + * amrex::ParmParse::FIRST for starting with the first input value) + * \param[in] num_val number of input values to use (optional with arrays, default is + * amrex::ParmParse::LAST for reading until the last input value) + */ + template <typename T> + int queryArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val, + const int start_ix, const int num_val) + { + // call amrex::ParmParse::query, check if the user specified str. + std::vector<std::string> tmp_str_arr; + int is_specified = a_pp.queryarr(str, tmp_str_arr, start_ix, num_val); + if (is_specified) + { + // If so, create parser objects and apply them to the values provided by the user. + int const n = static_cast<int>(tmp_str_arr.size()); + val.resize(n); + for (int i=0 ; i < n ; i++) { + auto parser = makeParser(tmp_str_arr[i], {}); + if (std::is_same<T, int>::value) { + val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); + } + else { + val[i] = static_cast<T>(parser.compileHost<0>()()); + } + } + } + // return the same output as amrex::ParmParse::query + return is_specified; + } + + + /** Similar to amrex::ParmParse::get, but also supports math expressions for the value. + * + * amrex::ParmParse::get reads a name and a value from the input file. This function does the + * same, and applies the Parser to the value, so the user has the choice to specify a value or + * a math expression (including user-defined constants). + * Works for amrex::Real numbers and integers. + * + * \param[in] a_pp amrex::ParmParse object + * \param[in] str name of the parameter to read + * \param[out] val where the value queried and parsed is stored + */ + template <typename T> + void getWithParser (const amrex::ParmParse& a_pp, char const * const str, T& val) + { + // If so, create a parser object and apply it to the value provided by the user. + std::string str_val; + Store_parserString(a_pp, str, str_val); + + auto parser = makeParser(str_val, {}); + if (std::is_same<T, int>::value) { + val = safeCastToInt(std::round(parser.compileHost<0>()()), str); + } + else { + val = static_cast<T>(parser.compileHost<0>()()); + } + } + + template <typename T> + void getArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val) + { + // Create parser objects and apply them to the values provided by the user. + std::vector<std::string> tmp_str_arr; + a_pp.getarr(str, tmp_str_arr); + + int const n = static_cast<int>(tmp_str_arr.size()); + val.resize(n); + for (int i=0 ; i < n ; i++) { + auto parser = makeParser(tmp_str_arr[i], {}); + if (std::is_same<T, int>::value) { + val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); + } + else { + val[i] = static_cast<T>(parser.compileHost<0>()()); + } + } + } + + + /** Similar to amrex::ParmParse::get, but also supports math expressions for the value. + * + * amrex::ParmParse::get reads a name and a value from the input file. This function does the + * same, and applies the Parser to the value, so the user has the choice to specify a value or + * a math expression (including user-defined constants). + * Works for amrex::Real numbers and integers. + * + * \param[in] a_pp amrex::ParmParse object + * \param[in] str name of the parameter to read + * \param[out] val where the value queried and parsed is stored + * \param[in] start_ix start index in the list of inputs values (optional with arrays, default is + * amrex::ParmParse::FIRST for starting with the first input value) + * \param[in] num_val number of input values to use (optional with arrays, default is + * amrex::ParmParse::LAST for reading until the last input value) + */ + template <typename T> + void getArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val, + const int start_ix, const int num_val) + { + // Create parser objects and apply them to the values provided by the user. + std::vector<std::string> tmp_str_arr; + a_pp.getarr(str, tmp_str_arr, start_ix, num_val); + + int const n = static_cast<int>(tmp_str_arr.size()); + val.resize(n); + for (int i=0 ; i < n ; i++) { + auto parser = makeParser(tmp_str_arr[i], {}); + if (std::is_same<T, int>::value) { + val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); + } + else { + val[i] = static_cast<T>(parser.compileHost<0>()()); + } + } + } + +} + +#endif // WARPX_UTILS_PARSER_PARSERUTILS_H_ diff --git a/Source/Utils/Parser/ParserUtils.cpp b/Source/Utils/Parser/ParserUtils.cpp new file mode 100644 index 000000000..48cc9b248 --- /dev/null +++ b/Source/Utils/Parser/ParserUtils.cpp @@ -0,0 +1,165 @@ +/* Copyright 2022 Andrew Myers, Burlen Loring, Luca Fedeli + * Maxence Thevenet, Remi Lehe, Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#include "ParserUtils.H" + +#include "Utils/TextMsg.H" +#include "Utils/WarpXConst.H" + +#include <AMReX_Parser.H> +#include <AMReX_ParmParse.H> + +#include <limits> +#include <map> +#include <set> + +void utils::parser::Store_parserString( + const amrex::ParmParse& pp, + std::string query_string, + std::string& stored_string) +{ + std::vector<std::string> f; + pp.getarr(query_string.c_str(), f); + stored_string.clear(); + for (auto const& s : f) { + stored_string += s; + } + f.clear(); +} + + +namespace { + template< typename int_type > + AMREX_FORCE_INLINE + int_type safeCastTo(const amrex::Real x, const std::string& real_name) { + int_type result = int_type(0); + bool error_detected = false; + std::string assert_msg; + // (2.0*(numeric_limits<int>::max()/2+1)) converts numeric_limits<int>::max()+1 to a real ensuring accuracy to all digits + // This accepts x = 2**31-1 but rejects 2**31. + using namespace amrex::literals; + constexpr amrex::Real max_range = (2.0_rt*static_cast<amrex::Real>(std::numeric_limits<int_type>::max()/2+1)); + if (x < max_range) { + if (std::ceil(x) >= std::numeric_limits<int_type>::min()) { + result = static_cast<int_type>(x); + } else { + error_detected = true; + assert_msg = "Negative overflow detected when casting " + real_name + " = " + + std::to_string(x) + " to integer type"; + } + } else if (x > 0) { + error_detected = true; + assert_msg = "Overflow detected when casting " + real_name + " = " + std::to_string(x) + " to integer type"; + } else { + error_detected = true; + assert_msg = "NaN detected when casting " + real_name + " to integer type"; + } + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(!error_detected, assert_msg); + return result; + } +} + + +int utils::parser::safeCastToInt(const amrex::Real x, const std::string& real_name) { + return ::safeCastTo<int> (x, real_name); +} + + +long utils::parser::safeCastToLong(const amrex::Real x, const std::string& real_name) { + return ::safeCastTo<long> (x, real_name); +} + + +amrex::Parser utils::parser::makeParser ( + std::string const& parse_function, amrex::Vector<std::string> const& varnames) +{ + // Since queryWithParser recursively calls this routine, keep track of symbols + // in case an infinite recursion is found (a symbol's value depending on itself). + static std::set<std::string> recursive_symbols; + + amrex::Parser parser(parse_function); + parser.registerVariables(varnames); + + std::set<std::string> symbols = parser.symbols(); + for (auto const& v : varnames) symbols.erase(v.c_str()); + + // User can provide inputs under this name, through which expressions + // can be provided for arbitrary variables. PICMI inputs are aware of + // this convention and use the same prefix as well. This potentially + // includes variable names that match physical or mathematical + // constants, in case the user wishes to enforce a different + // system of units or some form of quasi-physical behavior in the + // simulation. Thus, this needs to override any built-in + // constants. + amrex::ParmParse pp_my_constants("my_constants"); + + // Physical / Numerical Constants available to parsed expressions + static std::map<std::string, amrex::Real> warpx_constants = + { + {"clight", PhysConst::c}, + {"epsilon0", PhysConst::ep0}, + {"mu0", PhysConst::mu0}, + {"q_e", PhysConst::q_e}, + {"m_e", PhysConst::m_e}, + {"m_p", PhysConst::m_p}, + {"m_u", PhysConst::m_u}, + {"kb", PhysConst::kb}, + {"pi", MathConst::pi}, + }; + + for (auto it = symbols.begin(); it != symbols.end(); ) { + // Always parsing in double precision avoids potential overflows that may occur when parsing + // user's expressions because of the limited range of exponentials in single precision + double v; + + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + recursive_symbols.count(*it)==0, + "Expressions contains recursive symbol "+*it); + recursive_symbols.insert(*it); + const bool is_input = queryWithParser(pp_my_constants, it->c_str(), v); + recursive_symbols.erase(*it); + + if (is_input) { + parser.setConstant(*it, v); + it = symbols.erase(it); + continue; + } + + const auto constant = warpx_constants.find(*it); + if (constant != warpx_constants.end()) { + parser.setConstant(*it, constant->second); + it = symbols.erase(it); + continue; + } + + ++it; + } + for (auto const& s : symbols) { + amrex::Abort(Utils::TextMsg::Err("makeParser::Unknown symbol "+s)); + } + return parser; +} + + +double +utils::parser::parseStringtoDouble(const std::string& str) +{ + const auto parser = makeParser(str, {}); + const auto exe = parser.compileHost<0>(); + const auto result = exe(); + return result; +} + + +int +utils::parser::parseStringtoInt(const std::string& str, const std::string& name) +{ + const auto rval = static_cast<amrex::Real>(parseStringtoDouble(str)); + const auto ival = safeCastToInt(std::round(rval), name); + return ival; +} diff --git a/Source/Utils/Physics/IonizationEnergiesTable.H b/Source/Utils/Physics/IonizationEnergiesTable.H new file mode 100644 index 000000000..b806340ca --- /dev/null +++ b/Source/Utils/Physics/IonizationEnergiesTable.H @@ -0,0 +1,226 @@ +// This script was automatically generated! +// Edit dev/Source/Utils/Physics/write_atomic_data_cpp.py instead! + +#ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_ +#define WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_ + +#include <AMReX_REAL.H> + +#include <map> +#include <string> + +namespace utils::physics +{ + static std::map<std::string, int> const ion_map_ids = { + {"H", 0}, + {"He", 1}, + {"Li", 2}, + {"Be", 3}, + {"B", 4}, + {"C", 5}, + {"N", 6}, + {"O", 7}, + {"F", 8}, + {"Ne", 9}, + {"Na", 10}, + {"Mg", 11}, + {"Al", 12}, + {"Si", 13}, + {"P", 14}, + {"S", 15}, + {"Cl", 16}, + {"Ar", 17}, + {"Cu", 18}, + {"Kr", 19}, + {"Rb", 20}, + {"Xe", 21}, + {"Rn", 22} }; + + constexpr int nelements = 23; + + constexpr int ion_atomic_numbers[nelements] = { + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 29, 36, + 37, 54, 86}; + + constexpr int ion_energy_offsets[nelements] = { + 0, 1, 3, 6, 10, 15, 21, 28, 36, 45, + 55, 66, 78, 91, 105, 120, 136, 153, 171, 200, + 236, 273, 327}; + + constexpr int energies_tab_length = 413; + + constexpr amrex::Real table_ionization_energies[energies_tab_length]{ + // H + amrex::Real(13.59843449), + // He + amrex::Real(24.58738880), amrex::Real(54.4177650), + // Li + amrex::Real(5.39171495), amrex::Real(75.6400964), amrex::Real(122.4543581), + // Be + amrex::Real(9.322699), amrex::Real(18.21115), amrex::Real(153.896203), + amrex::Real(217.7185843), + // B + amrex::Real(8.298019), amrex::Real(25.15483), amrex::Real(37.93058), + amrex::Real(259.3715), amrex::Real(340.226020), + // C + amrex::Real(11.2602880), amrex::Real(24.383154), amrex::Real(47.88778), + amrex::Real(64.49352), amrex::Real(392.090515), amrex::Real(489.993194), + // N + amrex::Real(14.53413), amrex::Real(29.60125), amrex::Real(47.4453), + amrex::Real(77.4735), amrex::Real(97.8901), amrex::Real(552.06732), + amrex::Real(667.046116), + // O + amrex::Real(13.618055), amrex::Real(35.12112), amrex::Real(54.93554), + amrex::Real(77.41350), amrex::Real(113.8990), amrex::Real(138.1189), + amrex::Real(739.32682), amrex::Real(871.40988), + // F + amrex::Real(17.42282), amrex::Real(34.97081), amrex::Real(62.70798), + amrex::Real(87.175), amrex::Real(114.249), amrex::Real(157.16311), + amrex::Real(185.1868), amrex::Real(953.89804), amrex::Real(1103.11747), + // Ne + amrex::Real(21.564540), amrex::Real(40.96297), amrex::Real(63.4233), + amrex::Real(97.1900), amrex::Real(126.247), amrex::Real(157.934), + amrex::Real(207.271), amrex::Real(239.0970), amrex::Real(1195.80783), + amrex::Real(1362.19915), + // Na + amrex::Real(5.1390769), amrex::Real(47.28636), amrex::Real(71.6200), + amrex::Real(98.936), amrex::Real(138.404), amrex::Real(172.23), + amrex::Real(208.504), amrex::Real(264.192), amrex::Real(299.856), + amrex::Real(1465.13449), amrex::Real(1648.70218), + // Mg + amrex::Real(7.646236), amrex::Real(15.035271), amrex::Real(80.1436), + amrex::Real(109.2654), amrex::Real(141.33), amrex::Real(186.76), + amrex::Real(225.02), amrex::Real(265.924), amrex::Real(327.99), + amrex::Real(367.489), amrex::Real(1761.80487), amrex::Real(1962.66365), + // Al + amrex::Real(5.985769), amrex::Real(18.82855), amrex::Real(28.447642), + amrex::Real(119.9924), amrex::Real(153.8252), amrex::Real(190.49), + amrex::Real(241.76), amrex::Real(284.64), amrex::Real(330.21), + amrex::Real(398.65), amrex::Real(442.005), amrex::Real(2085.97700), + amrex::Real(2304.14005), + // Si + amrex::Real(8.15168), amrex::Real(16.34585), amrex::Real(33.49300), + amrex::Real(45.14179), amrex::Real(166.767), amrex::Real(205.279), + amrex::Real(246.57), amrex::Real(303.59), amrex::Real(351.28), + amrex::Real(401.38), amrex::Real(476.273), amrex::Real(523.415), + amrex::Real(2437.65813), amrex::Real(2673.17753), + // P + amrex::Real(10.486686), amrex::Real(19.76949), amrex::Real(30.20264), + amrex::Real(51.44387), amrex::Real(65.02511), amrex::Real(220.430), + amrex::Real(263.57), amrex::Real(309.60), amrex::Real(372.31), + amrex::Real(424.40), amrex::Real(479.44), amrex::Real(560.62), + amrex::Real(611.741), amrex::Real(2816.90876), amrex::Real(3069.8415), + // S + amrex::Real(10.36001), amrex::Real(23.33788), amrex::Real(34.86), + amrex::Real(47.222), amrex::Real(72.5945), amrex::Real(88.0529), + amrex::Real(280.954), amrex::Real(328.794), amrex::Real(379.84), + amrex::Real(447.7), amrex::Real(504.55), amrex::Real(564.41), + amrex::Real(651.96), amrex::Real(706.994), amrex::Real(3223.7807), + amrex::Real(3494.1879), + // Cl + amrex::Real(12.967632), amrex::Real(23.81364), amrex::Real(39.80), + amrex::Real(53.24), amrex::Real(67.68), amrex::Real(96.94), + amrex::Real(114.2013), amrex::Real(348.306), amrex::Real(400.851), + amrex::Real(456.7), amrex::Real(530.0), amrex::Real(591.58), + amrex::Real(656.30), amrex::Real(750.23), amrex::Real(809.198), + amrex::Real(3658.3437), amrex::Real(3946.2909), + // Ar + amrex::Real(15.7596117), amrex::Real(27.62967), amrex::Real(40.735), + amrex::Real(59.58), amrex::Real(74.84), amrex::Real(91.290), + amrex::Real(124.41), amrex::Real(143.4567), amrex::Real(422.60), + amrex::Real(479.76), amrex::Real(540.4), amrex::Real(619.0), + amrex::Real(685.5), amrex::Real(755.13), amrex::Real(855.5), + amrex::Real(918.375), amrex::Real(4120.6656), amrex::Real(4426.2228), + // Cu + amrex::Real(7.726380), amrex::Real(20.29239), amrex::Real(36.841), + amrex::Real(57.38), amrex::Real(79.8), amrex::Real(103.0), + amrex::Real(139.0), amrex::Real(166.0), amrex::Real(198.0), + amrex::Real(232.2), amrex::Real(265.33), amrex::Real(367.0), + amrex::Real(401.0), amrex::Real(436.0), amrex::Real(483.1), + amrex::Real(518.7), amrex::Real(552.8), amrex::Real(632.5), + amrex::Real(670.608), amrex::Real(1690.5), amrex::Real(1800), + amrex::Real(1918), amrex::Real(2044), amrex::Real(2179.4), + amrex::Real(2307.3), amrex::Real(2479.1), amrex::Real(2586.954), + amrex::Real(11062.4313), amrex::Real(11567.613), + // Kr + amrex::Real(13.9996053), amrex::Real(24.35984), amrex::Real(35.838), + amrex::Real(50.85), amrex::Real(64.69), amrex::Real(78.49), + amrex::Real(109.13), amrex::Real(125.802), amrex::Real(233.0), + amrex::Real(268), amrex::Real(308), amrex::Real(350), + amrex::Real(391), amrex::Real(446), amrex::Real(492), + amrex::Real(540), amrex::Real(591), amrex::Real(640), + amrex::Real(785), amrex::Real(831.6), amrex::Real(882.8), + amrex::Real(945), amrex::Real(999.0), amrex::Real(1042), + amrex::Real(1155.0), amrex::Real(1205.23), amrex::Real(2928.9), + amrex::Real(3072), amrex::Real(3228), amrex::Real(3380), + amrex::Real(3584), amrex::Real(3752.0), amrex::Real(3971), + amrex::Real(4109.083), amrex::Real(17296.420), amrex::Real(17936.209), + // Rb + amrex::Real(4.1771280), amrex::Real(27.28954), amrex::Real(39.247), + amrex::Real(52.20), amrex::Real(68.44), amrex::Real(82.9), + amrex::Real(98.67), amrex::Real(132.79), amrex::Real(150.628), + amrex::Real(277.12), amrex::Real(313.1), amrex::Real(356.0), + amrex::Real(400), amrex::Real(443), amrex::Real(502), + amrex::Real(550), amrex::Real(601), amrex::Real(654), + amrex::Real(706.0), amrex::Real(857), amrex::Real(905.3), + amrex::Real(958.9), amrex::Real(1024), amrex::Real(1080), + amrex::Real(1125), amrex::Real(1242.5), amrex::Real(1294.57), + amrex::Real(3133.3), amrex::Real(3281), amrex::Real(3443), + amrex::Real(3600), amrex::Real(3815), amrex::Real(3988), + amrex::Real(4214), amrex::Real(4356.865), amrex::Real(18305.884), + amrex::Real(18965.516), + // Xe + amrex::Real(12.1298436), amrex::Real(20.975), amrex::Real(31.05), + amrex::Real(42.20), amrex::Real(54.1), amrex::Real(66.703), + amrex::Real(91.6), amrex::Real(105.9778), amrex::Real(179.84), + amrex::Real(202.0), amrex::Real(229.02), amrex::Real(255.0), + amrex::Real(281), amrex::Real(314), amrex::Real(343), + amrex::Real(374), amrex::Real(404), amrex::Real(434), + amrex::Real(549), amrex::Real(582), amrex::Real(616), + amrex::Real(650), amrex::Real(700), amrex::Real(736), + amrex::Real(818), amrex::Real(857.0), amrex::Real(1493), + amrex::Real(1571), amrex::Real(1653), amrex::Real(1742), + amrex::Real(1826), amrex::Real(1919), amrex::Real(2023), + amrex::Real(2113), amrex::Real(2209), amrex::Real(2300), + amrex::Real(2556), amrex::Real(2637), amrex::Real(2726), + amrex::Real(2811), amrex::Real(2975), amrex::Real(3068), + amrex::Real(3243), amrex::Real(3333.8), amrex::Real(7660), + amrex::Real(7889), amrex::Real(8144), amrex::Real(8382), + amrex::Real(8971), amrex::Real(9243), amrex::Real(9581), + amrex::Real(9810.37), amrex::Real(40271.724), amrex::Real(41299.71), + // Rn + amrex::Real(10.74850), amrex::Real(21.4), amrex::Real(29.4), + amrex::Real(36.9), amrex::Real(52.9), amrex::Real(64.0), + amrex::Real(88.0), amrex::Real(102.0), amrex::Real(154.0), + amrex::Real(173.9), amrex::Real(195.0), amrex::Real(218.0), + amrex::Real(240), amrex::Real(264), amrex::Real(293), + amrex::Real(317), amrex::Real(342), amrex::Real(367), + amrex::Real(488), amrex::Real(520), amrex::Real(550), + amrex::Real(580), amrex::Real(640), amrex::Real(680), + amrex::Real(760), amrex::Real(800), amrex::Real(850), + amrex::Real(920), amrex::Real(980), amrex::Real(1050), + amrex::Real(1110), amrex::Real(1180), amrex::Real(1250), + amrex::Real(1310), amrex::Real(1390), amrex::Real(1460), + amrex::Real(1520), amrex::Real(1590), amrex::Real(1660), + amrex::Real(1720), amrex::Real(2033), amrex::Real(2094), + amrex::Real(2158), amrex::Real(2227), amrex::Real(2293), + amrex::Real(2357), amrex::Real(2467), amrex::Real(2535), + amrex::Real(2606), amrex::Real(2674), amrex::Real(2944), + amrex::Real(3010), amrex::Real(3082), amrex::Real(3149), + amrex::Real(3433), amrex::Real(3510), amrex::Real(3699), + amrex::Real(3777), amrex::Real(6169), amrex::Real(6318), + amrex::Real(6476), amrex::Real(6646), amrex::Real(6807), + amrex::Real(6964), amrex::Real(7283), amrex::Real(7450), + amrex::Real(7630), amrex::Real(7800), amrex::Real(8260), + amrex::Real(8410), amrex::Real(8570), amrex::Real(8710), + amrex::Real(9610), amrex::Real(9780), amrex::Real(10120), + amrex::Real(10290), amrex::Real(21770), amrex::Real(22160), + amrex::Real(22600), amrex::Real(22990), amrex::Real(26310), + amrex::Real(26830), amrex::Real(27490), amrex::Real(27903.1), + amrex::Real(110842.0), amrex::Real(112843.7) + }; + +} + +#endif // #ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_ diff --git a/Source/Utils/Physics/Make.package b/Source/Utils/Physics/Make.package new file mode 100644 index 000000000..d8f7bab32 --- /dev/null +++ b/Source/Utils/Physics/Make.package @@ -0,0 +1 @@ +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils/Physics diff --git a/Source/Utils/atomic_data.txt b/Source/Utils/Physics/atomic_data.txt index ead20a623..ead20a623 100644 --- a/Source/Utils/atomic_data.txt +++ b/Source/Utils/Physics/atomic_data.txt diff --git a/Source/Utils/write_atomic_data_cpp.py b/Source/Utils/Physics/write_atomic_data_cpp.py index 3b0538aa1..11cd3b2c0 100644 --- a/Source/Utils/write_atomic_data_cpp.py +++ b/Source/Utils/Physics/write_atomic_data_cpp.py @@ -32,56 +32,59 @@ ion_offsets = np.concatenate(([0], np.cumsum(np.array(ion_atom_numbers)[:-1])), # Head of CPP file cpp_string = '// This script was automatically generated!\n' -cpp_string += '// Edit dev/Source/Utils/write_atomic_data_cpp.py instead!\n' -cpp_string += '#ifndef WARPX_IONIZATION_TABLE_H_\n' -cpp_string += '#define WARPX_IONIZATION_TABLE_H_\n\n' -cpp_string += '#include <AMReX_AmrCore.H>\n' +cpp_string += '// Edit dev/Source/Utils/Physics/write_atomic_data_cpp.py instead!\n\n' +cpp_string += '#ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n' +cpp_string += '#define WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n\n' cpp_string += '#include <AMReX_REAL.H>\n\n' cpp_string += '#include <map>\n' cpp_string += '#include <string>\n\n' +cpp_string += 'namespace utils::physics\n' +cpp_string += '{\n' # Map each element to ID in table -cpp_string += 'static std::map<std::string, int> const ion_map_ids = {' +cpp_string += ' static std::map<std::string, int> const ion_map_ids = {' for count, name in enumerate(ion_names): - cpp_string += '\n {"' + name + '", ' + str(count) + '},' + cpp_string += '\n {"' + name + '", ' + str(count) + '},' cpp_string = cpp_string[:-1] cpp_string += ' };\n\n' # Atomic number of each species -cpp_string += 'constexpr int nelements = ' + str(len(ion_names)) + ';\n\n' -cpp_string += 'constexpr int ion_atomic_numbers[nelements] = {\n ' +cpp_string += ' constexpr int nelements = ' + str(len(ion_names)) + ';\n\n' +cpp_string += ' constexpr int ion_atomic_numbers[nelements] = {\n ' for count, atom_num in enumerate(ion_atom_numbers): - if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' + if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' cpp_string += str(atom_num) + ', ' cpp_string = cpp_string[:-2] cpp_string += '};\n\n' # Offset of each element in table of ionization energies -cpp_string += 'constexpr int ion_energy_offsets[nelements] = {\n ' +cpp_string += ' constexpr int ion_energy_offsets[nelements] = {\n ' for count, offset in enumerate(ion_offsets): - if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' + if count%10==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' cpp_string += str(offset) + ', ' cpp_string = cpp_string[:-2] cpp_string += '};\n\n' # Table of ionization energies -cpp_string += 'constexpr int energies_tab_length = ' + str(len(list_of_tuples)) + ';\n\n' -cpp_string += 'constexpr amrex::Real table_ionization_energies[energies_tab_length]{' +cpp_string += ' constexpr int energies_tab_length = ' + str(len(list_of_tuples)) + ';\n\n' +cpp_string += ' constexpr amrex::Real table_ionization_energies[energies_tab_length]{' for element in ion_names: - cpp_string += '\n // ' + element + '\n ' + cpp_string += '\n // ' + element + '\n ' regex_command = \ '\n\s+(\d+)\s+\|\s+%s\s+\w+\s+\|\s+\+*(\d+)\s+\|\s+\(*\[*(\d+\.*\d*)' \ %element list_of_tuples = re.findall( regex_command, text_data ) for count, energy in enumerate([x[2] for x in list_of_tuples]): - if count%3==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' + if count%3==0 and count>0: cpp_string = cpp_string[:-2] + ',\n ' cpp_string += "amrex::Real(" + energy + '), ' cpp_string = cpp_string[:-1] cpp_string = cpp_string[:-1] -cpp_string += '\n};\n\n' +cpp_string += '\n };\n\n' + +cpp_string += '}\n\n' # Write the string to file -cpp_string += '#endif // #ifndef WARPX_IONIZATION_TABLE_H_\n' +cpp_string += '#endif // #ifndef WARPX_UTILS_PHYSICS_IONIZATION_TABLE_H_\n' f= open("IonizationEnergiesTable.H","w") f.write(cpp_string) f.close() diff --git a/Source/Utils/Strings/CMakeLists.txt b/Source/Utils/Strings/CMakeLists.txt new file mode 100644 index 000000000..918384f7a --- /dev/null +++ b/Source/Utils/Strings/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(WarpX + PRIVATE + StringUtils.cpp +) diff --git a/Source/Utils/Strings/Make.package b/Source/Utils/Strings/Make.package new file mode 100644 index 000000000..d6f578b8a --- /dev/null +++ b/Source/Utils/Strings/Make.package @@ -0,0 +1,3 @@ +CEXE_sources += StringUtils.cpp + +VPATH_LOCATIONS += $(WARPX_HOME)/Source/Utils/Strings diff --git a/Source/Utils/Strings/StringUtils.H b/Source/Utils/Strings/StringUtils.H new file mode 100644 index 000000000..5c21d1be1 --- /dev/null +++ b/Source/Utils/Strings/StringUtils.H @@ -0,0 +1,68 @@ +/* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet + * Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#ifndef WARPX_UTILS_STRINGS_STRINGUTILS_H_ +#define WARPX_UTILS_STRINGS_STRINGUTILS_H_ + +#include <AMReX_Utility.H> + +#include <string> +#include <vector> + +namespace utils::strings +{ + /** \brief Splits a string using a string separator. This is somewhat similar to + * amrex::Tokenize. The main difference is that, if the separator ":" is used, + * amrex::Tokenize will split ":3::2" into ["3","2"] while this functio will + * split ":3::2" into ["","3","","2"]. This function can also perform a trimming to + * remove whitespaces (or any other arbitrary string) from the split string. + * + * @tparam Container the type of the split string. + * + * @param[in] instr the input string + * @param[in] separator the separator string + * @param[in] trim true to trim the split string, false otherwise. + * @param[in] trim_space the string to trim if trim is true. + * @return cont the split string + */ + template <typename Container> + auto split (std::string const& instr, std::string const& separator, + bool const trim = false, std::string const& trim_space = " \t") + { + Container cont; + std::size_t current = instr.find(separator); + std::size_t previous = 0; + while (current != std::string::npos) { + if (trim){ + cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));} + else{ + cont.push_back(instr.substr(previous, current - previous));} + previous = current + separator.size(); + current = instr.find(separator, previous); + } + if (trim){ + cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));} + else{ + cont.push_back(instr.substr(previous, current - previous));} + return cont; + } + + /** \brief This function performs automatic text wrapping on a string, + * returning an array of strings each not exceeding the maximum line length + * (unless the text contains a word exceeding the maximum line length). + * + * @param[in] text the string containing the text to be wrapped + * @param[in] max_line_length the maximum line length + * @return an std::vector containing the lines of the wrapped text + */ + std::vector<std::string> automatic_text_wrap( + const std::string& text, const int max_line_length); + +} + +#endif //WARPX_UTILS_STRINGS_STRINGUTILS_H_ diff --git a/Source/Utils/Strings/StringUtils.cpp b/Source/Utils/Strings/StringUtils.cpp new file mode 100644 index 000000000..f095794c9 --- /dev/null +++ b/Source/Utils/Strings/StringUtils.cpp @@ -0,0 +1,51 @@ +/* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet + * Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#include "StringUtils.H" + +#include <sstream> + +std::vector<std::string> automatic_text_wrap( + const std::string& text, const int max_line_length){ + + auto ss_text = std::stringstream{text}; + auto wrapped_text_lines = std::vector<std::string>{}; + + std::string line; + while(std::getline(ss_text, line,'\n')){ + + auto ss_line = std::stringstream{line}; + int counter = 0; + std::stringstream ss_line_out; + std::string word; + + while (ss_line >> word){ + const auto wlen = static_cast<int>(word.length()); + + if(counter == 0){ + ss_line_out << word; + counter += wlen; + } + else{ + if (counter + wlen < max_line_length){ + ss_line_out << " " << word; + counter += (wlen+1); + } + else{ + wrapped_text_lines.push_back(ss_line_out.str()); + ss_line_out = std::stringstream{word}; + counter = wlen; + } + } + } + + wrapped_text_lines.push_back(ss_line_out.str()); + } + + return wrapped_text_lines; +} diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H index 275ce7e31..c306a5a64 100644 --- a/Source/Utils/WarpXUtil.H +++ b/Source/Utils/WarpXUtil.H @@ -56,16 +56,6 @@ void CheckGriddingForRZSpectral (); void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, amrex::Real zmax); -/** - * \brief Parse a string (typically a mathematical expression) from the - * input file and store it into a variable. - * - * \param pp used to read the query_string `pp.<function>=string` - * \param query_string ParmParse.query will look for this string - * \param stored_string variable in which the string to parse is stored - */ -void Store_parserString(const amrex::ParmParse &pp, std::string query_string, - std::string& stored_string); namespace WarpXUtilIO{ /** @@ -80,77 +70,6 @@ bool WriteBinaryDataOnFile(std::string filename, const amrex::Vector<char>& data namespace WarpXUtilAlgo{ -/** \brief Returns a pointer to the first element in the range [first, last) that is greater than val - * - * A re-implementation of the upper_bound algorithm suitable for GPU kernels. - * - * @param first: pointer to left limit of the range to consider - * @param last: pointer to right limit of the range to consider - * @param val: value to compare the elements of [first, last) to - */ -template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE -const T* upper_bound(const T* first, const T* last, const T& val) -{ - const T* it; - size_t count, step; - count = last-first; - while(count>0){ - it = first; - step = count/2; - it += step; - if (!(val<*it)){ - first = ++it; - count -= step + 1; - } - else{ - count = step; - } - } - return first; -} - -/** \brief Performs a linear interpolation - * - * Performs a linear interpolation at x given the 2 points - * (x0, f0) and (x1, f1) - */ -template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE -T linear_interp(T x0, T x1, T f0, T f1, T x) -{ - return ((x1-x)*f0 + (x-x0)*f1)/(x1-x0); -} - -/** \brief Performs a bilinear interpolation - * - * Performs a bilinear interpolation at (x,y) given the 4 points - * (x0, y0, f00), (x0, y1, f01), (x1, y0, f10), (x1, y1, f11). - */ -template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE -T bilinear_interp(T x0, T x1, T y0, T y1, T f00, T f01, T f10, T f11, T x, T y) -{ - const T fx0 = linear_interp(x0, x1, f00, f10, x); - const T fx1 = linear_interp(x0, x1, f01, f11, x); - return linear_interp(y0, y1, fx0, fx1, y); -} - -/** \brief Performs a trilinear interpolation - * - * Performs a trilinear interpolation at (x,y,z) given the 8 points - * (x0, y0, z0, f000), (x0, y0, z1, f001), (x0, y1, z0, f010), (x0, y1, z1, f011), - * (x1, y0, z0, f100), (x1, y0, z1, f101), (x1, y1, z0, f110), (x1, y1, z1, f111) - */ -template<typename T> AMREX_GPU_DEVICE AMREX_FORCE_INLINE -T trilinear_interp(T x0, T x1,T y0, T y1, T z0, T z1, - T f000, T f001, T f010, T f011, T f100, T f101, T f110, T f111, - T x, T y, T z) -{ - const T fxy0 = bilinear_interp( - x0, x1, y0, y1, f000, f010, f100, f110, x, y); - const T fxy1 = bilinear_interp( - x0, x1, y0, y1, f001, f011, f101, f111, x, y); - return linear_interp(z0, z1, fxy0, fxy1, z); -} - /** \brief Compute physical coordinates (x,y,z) that correspond to a given (i,j,k) and * the corresponding staggering, mf_type. * @@ -186,338 +105,6 @@ void getCellCoordinates (int i, int j, int k, } -/** -* \brief Do a safe cast of a real to an int -* This ensures that the float value is within the range of ints and if not, -* raises an exception. -* -* \param x Real value to cast -* \param real_name String, the name of the variable being casted to use in the error message -*/ -int -safeCastToInt(amrex::Real x, const std::string& real_name); - -/** -* \brief Do a safe cast of a real to a long -* This ensures that the float value is within the range of longs and if not, -* raises an exception. -* -* \param x Real value to cast -* \param real_name String, the name of the variable being casted to use in the error message -*/ -long -safeCastToLong(amrex::Real x, const std::string& real_name); - -/** -* \brief Initialize an amrex::Parser object from a string containing a math expression -* -* \param parse_function String to read to initialize the parser. -* \param varnames A list of predefined independent variables -*/ -amrex::Parser makeParser (std::string const& parse_function, amrex::Vector<std::string> const& varnames); - -/** Parse a string and return as a real - * - * In case the string cannot be interpreted as Real, - * this function ... <throws an exception? aborts with error message?> - * - * \param str The string to be parsed - * \return representation as real - */ -double parseStringtoReal(std::string str); - -/** Parse a string and return an int - * - * In case the string cannot be interpreted as Real, - * this function ... <throws an exception? aborts with error message?> - * - * \param str The string to be parsed - * \param name For integers, the name, to be used in error messages - * \return rounded closest integer - */ -int parseStringtoInt(std::string str, std::string name); - -template <int N> -amrex::ParserExecutor<N> compileParser (amrex::Parser const* parser) -{ - if (parser) { - return parser->compile<N>(); - } else { - return amrex::ParserExecutor<N>{}; - } -} - -/** Similar to amrex::ParmParse::query, but also supports math expressions for the value. - * - * amrex::ParmParse::query reads a name and a value from the input file. This function does the - * same, and applies the amrex::Parser to the value, so the user has the choice to specify a value or - * a math expression (including user-defined constants). - * Works for amrex::Real numbers and integers. - * - * \param[in] a_pp amrex::ParmParse object - * \param[in] str name of the parameter to read - * \param[out] val where the value queried and parsed is stored, either a scalar or vector - */ -template <typename T> -int queryWithParser (const amrex::ParmParse& a_pp, char const * const str, T& val) -{ - // call amrex::ParmParse::query, check if the user specified str. - std::string tmp_str; - int is_specified = a_pp.query(str, tmp_str); - if (is_specified) - { - // If so, create a parser object and apply it to the value provided by the user. - std::string str_val; - Store_parserString(a_pp, str, str_val); - - auto parser = makeParser(str_val, {}); - - if (std::is_same<T, int>::value) { - - val = safeCastToInt(std::round(parser.compileHost<0>()()), str); - } - else if (std::is_same<T, long>::value) { - - val = safeCastToLong(std::round(parser.compileHost<0>()()), str); - } - else { - val = static_cast<T>(parser.compileHost<0>()()); - } - } - // return the same output as amrex::ParmParse::query - return is_specified; -} - -template <typename T> -int queryArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val) -{ - // call amrex::ParmParse::query, check if the user specified str. - std::vector<std::string> tmp_str_arr; - int is_specified = a_pp.queryarr(str, tmp_str_arr); - if (is_specified) - { - // If so, create parser objects and apply them to the values provided by the user. - int const n = static_cast<int>(tmp_str_arr.size()); - val.resize(n); - for (int i=0 ; i < n ; i++) { - auto parser = makeParser(tmp_str_arr[i], {}); - if (std::is_same<T, int>::value) { - val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); - } - else if (std::is_same<T, long>::value) { - val[i] = safeCastToLong(std::round(parser.compileHost<0>()()), str); - } - else { - val[i] = static_cast<T>(parser.compileHost<0>()()); - } - } - } - // return the same output as amrex::ParmParse::query - return is_specified; -} - -/** Similar to amrex::ParmParse::query, but also supports math expressions for the value. - * - * amrex::ParmParse::query reads a name and a value from the input file. This function does the - * same, and applies the amrex::Parser to the value, so the user has the choice to specify a value or - * a math expression (including user-defined constants). - * Works for amrex::Real numbers and integers. - * - * \param[in] a_pp amrex::ParmParse object - * \param[in] str name of the parameter to read - * \param[out] val where the value queried and parsed is stored, either a scalar or vector - * \param[in] start_ix start index in the list of inputs values (optional with arrays, default is - * amrex::ParmParse::FIRST for starting with the first input value) - * \param[in] num_val number of input values to use (optional with arrays, default is - * amrex::ParmParse::LAST for reading until the last input value) - */ -template <typename T> -int queryArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val, - const int start_ix, const int num_val) -{ - // call amrex::ParmParse::query, check if the user specified str. - std::vector<std::string> tmp_str_arr; - int is_specified = a_pp.queryarr(str, tmp_str_arr, start_ix, num_val); - if (is_specified) - { - // If so, create parser objects and apply them to the values provided by the user. - int const n = static_cast<int>(tmp_str_arr.size()); - val.resize(n); - for (int i=0 ; i < n ; i++) { - auto parser = makeParser(tmp_str_arr[i], {}); - if (std::is_same<T, int>::value) { - val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); - } - else if (std::is_same<T, long>::value) { - val[i] = safeCastToLong(std::round(parser.compileHost<0>()()), str); - } - else { - val[i] = static_cast<T>(parser.compileHost<0>()()); - } - } - } - // return the same output as amrex::ParmParse::query - return is_specified; -} - -/** Similar to amrex::ParmParse::get, but also supports math expressions for the value. - * - * amrex::ParmParse::get reads a name and a value from the input file. This function does the - * same, and applies the Parser to the value, so the user has the choice to specify a value or - * a math expression (including user-defined constants). - * Works for amrex::Real numbers and integers. - * - * \param[in] a_pp amrex::ParmParse object - * \param[in] str name of the parameter to read - * \param[out] val where the value queried and parsed is stored - */ -template <typename T> -void getWithParser (const amrex::ParmParse& a_pp, char const * const str, T& val) -{ - // If so, create a parser object and apply it to the value provided by the user. - std::string str_val; - Store_parserString(a_pp, str, str_val); - - auto parser = makeParser(str_val, {}); - if (std::is_same<T, int>::value) { - val = safeCastToInt(std::round(parser.compileHost<0>()()), str); - } - else if (std::is_same<T, long>::value) { - val = safeCastToLong(std::round(parser.compileHost<0>()()), str); - } - else { - val = static_cast<T>(parser.compileHost<0>()()); - } -} - -template <typename T> -void getArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val) -{ - // Create parser objects and apply them to the values provided by the user. - std::vector<std::string> tmp_str_arr; - a_pp.getarr(str, tmp_str_arr); - - int const n = static_cast<int>(tmp_str_arr.size()); - val.resize(n); - for (int i=0 ; i < n ; i++) { - auto parser = makeParser(tmp_str_arr[i], {}); - if (std::is_same<T, int>::value) { - val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); - } - else if (std::is_same<T, long>::value) { - val[i] = safeCastToLong(std::round(parser.compileHost<0>()()), str); - } - else { - val[i] = static_cast<T>(parser.compileHost<0>()()); - } - } -} - -/** Similar to amrex::ParmParse::get, but also supports math expressions for the value. - * - * amrex::ParmParse::get reads a name and a value from the input file. This function does the - * same, and applies the Parser to the value, so the user has the choice to specify a value or - * a math expression (including user-defined constants). - * Works for amrex::Real numbers and integers. - * - * \param[in] a_pp amrex::ParmParse object - * \param[in] str name of the parameter to read - * \param[out] val where the value queried and parsed is stored - * \param[in] start_ix start index in the list of inputs values (optional with arrays, default is - * amrex::ParmParse::FIRST for starting with the first input value) - * \param[in] num_val number of input values to use (optional with arrays, default is - * amrex::ParmParse::LAST for reading until the last input value) - */ -template <typename T> -void getArrWithParser (const amrex::ParmParse& a_pp, char const * const str, std::vector<T>& val, - const int start_ix, const int num_val) -{ - // Create parser objects and apply them to the values provided by the user. - std::vector<std::string> tmp_str_arr; - a_pp.getarr(str, tmp_str_arr, start_ix, num_val); - - int const n = static_cast<int>(tmp_str_arr.size()); - val.resize(n); - for (int i=0 ; i < n ; i++) { - auto parser = makeParser(tmp_str_arr[i], {}); - if (std::is_same<T, int>::value) { - val[i] = safeCastToInt(std::round(parser.compileHost<0>()()), str); - } - else if (std::is_same<T, long>::value) { - val[i] = safeCastToLong(std::round(parser.compileHost<0>()()), str); - } - else { - val[i] = static_cast<T>(parser.compileHost<0>()()); - } - } -} - -namespace WarpXUtilStr -{ - /** Return true if elem is in vect, false otherwise - * @param[in] vect vector of strings, typically names - * @param[in] elem single string - * @return true if elem is in vect, false otherwise - */ - bool is_in(const std::vector<std::string>& vect, - const std::string& elem); - - /** Return true if any element in elems is in vect, false otherwise - * @param[in] vect vector of strings, typically names - * @param[in] elems vector of string - * @return true if any element in elems is in vect, false otherwise - */ - bool is_in(const std::vector<std::string>& vect, - const std::vector<std::string>& elems); - - /** \brief Splits a string using a string separator. This is somewhat similar to - * amrex::Tokenize. The main difference is that, if the separator ":" is used, - * amrex::Tokenize will split ":3::2" into ["3","2"] while this functio will - * split ":3::2" into ["","3","","2"]. This function can also perform a trimming to - * remove whitespaces (or any other arbitrary string) from the split string. - * - * @tparam Container the type of the split string. - * - * @param[in] instr the input string - * @param[in] separator the separator string - * @param[in] trim true to trim the split string, false otherwise. - * @param[in] trim_space the string to trim if trim is true. - * @return cont the split string - */ - template <typename Container> - auto split (std::string const& instr, std::string const& separator, - bool const trim = false, std::string const& trim_space = " \t") - { - Container cont; - std::size_t current = instr.find(separator); - std::size_t previous = 0; - while (current != std::string::npos) { - if (trim){ - cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));} - else{ - cont.push_back(instr.substr(previous, current - previous));} - previous = current + separator.size(); - current = instr.find(separator, previous); - } - if (trim){ - cont.push_back(amrex::trim(instr.substr(previous, current - previous),trim_space));} - else{ - cont.push_back(instr.substr(previous, current - previous));} - return cont; - } - - /** \brief This function performs automatic text wrapping on a string, - * returning an array of strings each not exceeding the maximum line length - * (unless the text contains a word exceeding the maximum line length). - * - * @param[in] text the string containing the text to be wrapped - * @param[in] max_line_length the maximum line length - * @return an std::vector containing the lines of the wrapped text - */ - std::vector<std::string> automatic_text_wrap( - const std::string& text, const int max_line_length); - -} namespace WarpXUtilLoadBalance { diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index eecc04b78..a36d31e93 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -7,6 +7,7 @@ */ #include "WarpX.H" +#include "Utils/Parser/ParserUtils.H" #include "TextMsg.H" #include "WarpXAlgorithmSelection.H" #include "WarpXConst.H" @@ -44,7 +45,7 @@ void PreparseAMReXInputIntArray(amrex::ParmParse& a_pp, char const * const input const int cnt = a_pp.countval(input_str); if (cnt > 0) { Vector<int> input_array; - getArrWithParser(a_pp, input_str, input_array); + utils::parser::getArrWithParser(a_pp, input_str, input_array); if (replace) { a_pp.remove(input_str); } @@ -64,9 +65,11 @@ void ParseGeometryInput() Vector<Real> prob_lo(AMREX_SPACEDIM); Vector<Real> prob_hi(AMREX_SPACEDIM); - getArrWithParser(pp_geometry, "prob_lo", prob_lo, 0, AMREX_SPACEDIM); + utils::parser::getArrWithParser( + pp_geometry, "prob_lo", prob_lo, 0, AMREX_SPACEDIM); AMREX_ALWAYS_ASSERT(prob_lo.size() == AMREX_SPACEDIM); - getArrWithParser(pp_geometry, "prob_hi", prob_hi, 0, AMREX_SPACEDIM); + utils::parser::getArrWithParser( + pp_geometry, "prob_hi", prob_hi, 0, AMREX_SPACEDIM); AMREX_ALWAYS_ASSERT(prob_hi.size() == AMREX_SPACEDIM); #ifdef WARPX_DIM_RZ @@ -108,7 +111,7 @@ void ReadBoostedFrameParameters(Real& gamma_boost, Real& beta_boost, Vector<int>& boost_direction) { ParmParse pp_warpx("warpx"); - queryWithParser(pp_warpx, "gamma_boost", gamma_boost); + utils::parser::queryWithParser(pp_warpx, "gamma_boost", gamma_boost); if( gamma_boost > 1. ) { beta_boost = std::sqrt(1._rt-1._rt/std::pow(gamma_boost,2._rt)); std::string s; @@ -155,19 +158,25 @@ void ConvertLabParamsToBoost() ParmParse pp_amr("amr"); ParmParse pp_slice("slice"); - getArrWithParser(pp_geometry, "prob_lo", prob_lo, 0, AMREX_SPACEDIM); - getArrWithParser(pp_geometry, "prob_hi", prob_hi, 0, AMREX_SPACEDIM); + utils::parser::getArrWithParser( + pp_geometry, "prob_lo", prob_lo, 0, AMREX_SPACEDIM); + utils::parser::getArrWithParser( + pp_geometry, "prob_hi", prob_hi, 0, AMREX_SPACEDIM); - queryArrWithParser(pp_slice, "dom_lo", slice_lo, 0, AMREX_SPACEDIM); + utils::parser::queryArrWithParser( + pp_slice, "dom_lo", slice_lo, 0, AMREX_SPACEDIM); AMREX_ALWAYS_ASSERT(slice_lo.size() == AMREX_SPACEDIM); - queryArrWithParser(pp_slice, "dom_hi", slice_hi, 0, AMREX_SPACEDIM); + utils::parser::queryArrWithParser( + pp_slice, "dom_hi", slice_hi, 0, AMREX_SPACEDIM); AMREX_ALWAYS_ASSERT(slice_hi.size() == AMREX_SPACEDIM); pp_amr.query("max_level", max_level); if (max_level > 0){ - getArrWithParser(pp_warpx, "fine_tag_lo", fine_tag_lo); - getArrWithParser(pp_warpx, "fine_tag_hi", fine_tag_hi); + utils::parser::getArrWithParser( + pp_warpx, "fine_tag_lo", fine_tag_lo); + utils::parser::getArrWithParser( + pp_warpx, "fine_tag_hi", fine_tag_hi); } @@ -264,143 +273,6 @@ namespace WarpXUtilIO{ } } -void Store_parserString(const amrex::ParmParse& pp, std::string query_string, - std::string& stored_string) -{ - std::vector<std::string> f; - pp.getarr(query_string.c_str(), f); - stored_string.clear(); - for (auto const& s : f) { - stored_string += s; - } - f.clear(); -} - -namespace WarpXUtilSafeCast { - template< typename int_type > - AMREX_FORCE_INLINE - int_type safeCastTo(const amrex::Real x, const std::string& real_name) { - int_type result = int_type(0); - bool error_detected = false; - std::string assert_msg; - // (2.0*(numeric_limits<int>::max()/2+1)) converts numeric_limits<int>::max()+1 to a real ensuring accuracy to all digits - // This accepts x = 2**31-1 but rejects 2**31. - using namespace amrex::literals; - constexpr amrex::Real max_range = (2.0_rt*static_cast<amrex::Real>(std::numeric_limits<int_type>::max()/2+1)); - if (x < max_range) { - if (std::ceil(x) >= std::numeric_limits<int_type>::min()) { - result = static_cast<int_type>(x); - } else { - error_detected = true; - assert_msg = "Negative overflow detected when casting " + real_name + " = " + - std::to_string(x) + " to integer type"; - } - } else if (x > 0) { - error_detected = true; - assert_msg = "Overflow detected when casting " + real_name + " = " + std::to_string(x) + " to integer type"; - } else { - error_detected = true; - assert_msg = "NaN detected when casting " + real_name + " to integer type"; - } - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(!error_detected, assert_msg); - return result; - } -} - -int safeCastToInt(const amrex::Real x, const std::string& real_name) { - return WarpXUtilSafeCast::safeCastTo<int> (x, real_name); -} - -long safeCastToLong(const amrex::Real x, const std::string& real_name) { - return WarpXUtilSafeCast::safeCastTo<long> (x, real_name); -} - -Parser makeParser (std::string const& parse_function, amrex::Vector<std::string> const& varnames) -{ - // Since queryWithParser recursively calls this routine, keep track of symbols - // in case an infinite recursion is found (a symbol's value depending on itself). - static std::set<std::string> recursive_symbols; - - Parser parser(parse_function); - parser.registerVariables(varnames); - - std::set<std::string> symbols = parser.symbols(); - for (auto const& v : varnames) symbols.erase(v.c_str()); - - // User can provide inputs under this name, through which expressions - // can be provided for arbitrary variables. PICMI inputs are aware of - // this convention and use the same prefix as well. This potentially - // includes variable names that match physical or mathematical - // constants, in case the user wishes to enforce a different - // system of units or some form of quasi-physical behavior in the - // simulation. Thus, this needs to override any built-in - // constants. - ParmParse pp_my_constants("my_constants"); - - // Physical / Numerical Constants available to parsed expressions - static std::map<std::string, amrex::Real> warpx_constants = - { - {"clight", PhysConst::c}, - {"epsilon0", PhysConst::ep0}, - {"mu0", PhysConst::mu0}, - {"q_e", PhysConst::q_e}, - {"m_e", PhysConst::m_e}, - {"m_p", PhysConst::m_p}, - {"m_u", PhysConst::m_u}, - {"kb", PhysConst::kb}, - {"pi", MathConst::pi}, - }; - - for (auto it = symbols.begin(); it != symbols.end(); ) { - // Always parsing in double precision avoids potential overflows that may occur when parsing - // user's expressions because of the limited range of exponentials in single precision - double v; - - WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - recursive_symbols.count(*it)==0, - "Expressions contains recursive symbol "+*it); - recursive_symbols.insert(*it); - const bool is_input = queryWithParser(pp_my_constants, it->c_str(), v); - recursive_symbols.erase(*it); - - if (is_input) { - parser.setConstant(*it, v); - it = symbols.erase(it); - continue; - } - - auto constant = warpx_constants.find(*it); - if (constant != warpx_constants.end()) { - parser.setConstant(*it, constant->second); - it = symbols.erase(it); - continue; - } - - ++it; - } - for (auto const& s : symbols) { - amrex::Abort(Utils::TextMsg::Err("makeParser::Unknown symbol "+s)); - } - return parser; -} - -double -parseStringtoReal(std::string str) -{ - auto parser = makeParser(str, {}); - auto exe = parser.compileHost<0>(); - double result = exe(); - return result; -} - -int -parseStringtoInt(std::string str, std::string name) -{ - auto const rval = static_cast<amrex::Real>(parseStringtoReal(str)); - int ival = safeCastToInt(std::round(rval), name); - return ival; -} - void CheckDims () { // Ensure that geometry.dims is set properly. @@ -592,61 +464,6 @@ void ReadBCParams () pp_geometry.addarr("is_periodic", geom_periodicity); } -namespace WarpXUtilStr -{ - bool is_in(const std::vector<std::string>& vect, - const std::string& elem) - { - return (std::find(vect.begin(), vect.end(), elem) != vect.end()); - } - - bool is_in(const std::vector<std::string>& vect, - const std::vector<std::string>& elems) - { - return std::any_of(elems.begin(), elems.end(), - [&](const auto elem){return is_in(vect, elem);}); - } - - std::vector<std::string> automatic_text_wrap( - const std::string& text, const int max_line_length){ - - auto ss_text = std::stringstream{text}; - auto wrapped_text_lines = std::vector<std::string>{}; - - std::string line; - while(std::getline(ss_text, line,'\n')){ - - auto ss_line = std::stringstream{line}; - int counter = 0; - std::stringstream ss_line_out; - std::string word; - - while (ss_line >> word){ - const auto wlen = static_cast<int>(word.length()); - - if(counter == 0){ - ss_line_out << word; - counter += wlen; - } - else{ - if (counter + wlen < max_line_length){ - ss_line_out << " " << word; - counter += (wlen+1); - } - else{ - wrapped_text_lines.push_back(ss_line_out.str()); - ss_line_out = std::stringstream{word}; - counter = wlen; - } - } - } - - wrapped_text_lines.push_back(ss_line_out.str()); - } - - return wrapped_text_lines; - } -} namespace WarpXUtilLoadBalance { diff --git a/Source/WarpX.H b/Source/WarpX.H index d4acf916e..86f7b57c5 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -35,7 +35,7 @@ #include "FieldSolver/ElectrostaticSolver.H" #include "Filter/BilinearFilter.H" #include "Parallelization/GuardCellManager.H" -#include "Utils/IntervalsParser.H" +#include "Utils/Parser/IntervalsParser.H" #include "Utils/WarpXAlgorithmSelection.H" #include <AMReX.H> @@ -306,7 +306,7 @@ public: static bool do_dynamic_scheduling; static bool refine_plasma; - static IntervalsParser sort_intervals; + static utils::parser::IntervalsParser sort_intervals; static amrex::IntVect sort_bin_size; static bool do_subcycling; @@ -530,7 +530,10 @@ public: /** \brief returns the load balance interval */ - IntervalsParser get_load_balance_intervals () const {return load_balance_intervals;} + utils::parser::IntervalsParser get_load_balance_intervals () const + { + return load_balance_intervals; + } /** * \brief Private function for spectral solver @@ -1270,7 +1273,7 @@ private: // Load balancing /** Load balancing intervals that reads the "load_balance_intervals" string int the input file * for getting steps at which load balancing is performed */ - IntervalsParser load_balance_intervals; + utils::parser::IntervalsParser load_balance_intervals; /** Collection of LayoutData to keep track of weights used in load balancing * routines. Contains timer-based or heuristic-based costs depending on input option */ amrex::Vector<std::unique_ptr<amrex::LayoutData<amrex::Real> > > costs; @@ -1303,7 +1306,7 @@ private: amrex::Real costs_heuristic_particles_wt = amrex::Real(0); // Determines timesteps for override sync - IntervalsParser override_sync_intervals; + utils::parser::IntervalsParser override_sync_intervals; // Other runtime parameters int verbose = 1; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index aa6301a6e..7f697f668 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -166,7 +166,7 @@ bool WarpX::refine_plasma = false; int WarpX::num_mirrors = 0; -IntervalsParser WarpX::sort_intervals; +utils::parser::IntervalsParser WarpX::sort_intervals; amrex::IntVect WarpX::sort_bin_size(AMREX_D_DECL(1,1,1)); bool WarpX::do_back_transformed_diagnostics = false; @@ -454,8 +454,8 @@ WarpX::ReadParameters () { ParmParse pp;// Traditionally, max_step and stop_time do not have prefix. - queryWithParser(pp, "max_step", max_step); - queryWithParser(pp, "stop_time", stop_time); + utils::parser::queryWithParser(pp, "max_step", max_step); + utils::parser::queryWithParser(pp, "stop_time", stop_time); pp.query("authors", authors); } @@ -500,7 +500,9 @@ WarpX::ReadParameters () } std::vector<int> numprocs_in; - queryArrWithParser(pp_warpx, "numprocs", numprocs_in, 0, AMREX_SPACEDIM); + utils::parser::queryArrWithParser( + pp_warpx, "numprocs", numprocs_in, 0, AMREX_SPACEDIM); + if (not numprocs_in.empty()) { WARPX_ALWAYS_ASSERT_WITH_MESSAGE (numprocs_in.size() == AMREX_SPACEDIM, @@ -578,20 +580,22 @@ WarpX::ReadParameters () } } - queryWithParser(pp_warpx, "cfl", cfl); + utils::parser::queryWithParser(pp_warpx, "cfl", cfl); pp_warpx.query("verbose", verbose); - queryWithParser(pp_warpx, "regrid_int", regrid_int); + utils::parser::queryWithParser(pp_warpx, "regrid_int", regrid_int); pp_warpx.query("do_subcycling", do_subcycling); pp_warpx.query("do_multi_J", do_multi_J); if (do_multi_J) { - getWithParser(pp_warpx, "do_multi_J_n_depositions", do_multi_J_n_depositions); + utils::parser::getWithParser( + pp_warpx, "do_multi_J_n_depositions", do_multi_J_n_depositions); } pp_warpx.query("use_hybrid_QED", use_hybrid_QED); pp_warpx.query("safe_guard_cells", safe_guard_cells); std::vector<std::string> override_sync_intervals_string_vec = {"1"}; pp_warpx.queryarr("override_sync_intervals", override_sync_intervals_string_vec); - override_sync_intervals = IntervalsParser(override_sync_intervals_string_vec); + override_sync_intervals = + utils::parser::IntervalsParser(override_sync_intervals_string_vec); WARPX_ALWAYS_ASSERT_WITH_MESSAGE(do_subcycling != 1 || max_level <= 1, "Subcycling method 1 only works for 2 levels."); @@ -602,15 +606,17 @@ WarpX::ReadParameters () // queryWithParser returns 1 if argument zmax_plasma_to_compute_max_step is // specified by the user, 0 otherwise. - do_compute_max_step_from_zmax = - queryWithParser(pp_warpx, "zmax_plasma_to_compute_max_step", - zmax_plasma_to_compute_max_step); + do_compute_max_step_from_zmax = utils::parser::queryWithParser( + pp_warpx, "zmax_plasma_to_compute_max_step", + zmax_plasma_to_compute_max_step); pp_warpx.query("do_moving_window", do_moving_window); if (do_moving_window) { - queryWithParser(pp_warpx, "start_moving_window_step", start_moving_window_step); - queryWithParser(pp_warpx, "end_moving_window_step", end_moving_window_step); + utils::parser::queryWithParser( + pp_warpx, "start_moving_window_step", start_moving_window_step); + utils::parser::queryWithParser( + pp_warpx, "end_moving_window_step", end_moving_window_step); std::string s; pp_warpx.get("moving_window_dir", s); if (s == "x" || s == "X") { @@ -633,7 +639,8 @@ WarpX::ReadParameters () moving_window_x = geom[0].ProbLo(moving_window_dir); - getWithParser(pp_warpx, "moving_window_v", moving_window_v); + utils::parser::getWithParser( + pp_warpx, "moving_window_v", moving_window_v); moving_window_v *= PhysConst::c; } @@ -650,20 +657,25 @@ WarpX::ReadParameters () WARPX_ALWAYS_ASSERT_WITH_MESSAGE( (s == "z" || s == "Z"), "The boosted frame diagnostic currently only works if the boost is in the z direction."); - queryWithParser(pp_warpx, "num_snapshots_lab", num_snapshots_lab); + utils::parser::queryWithParser( + pp_warpx, "num_snapshots_lab", num_snapshots_lab); // Read either dz_snapshots_lab or dt_snapshots_lab Real dz_snapshots_lab = 0; - bool snapshot_interval_is_specified = queryWithParser(pp_warpx, "dt_snapshots_lab", dt_snapshots_lab); - if ( queryWithParser(pp_warpx, "dz_snapshots_lab", dz_snapshots_lab) ){ - dt_snapshots_lab = dz_snapshots_lab/PhysConst::c; - snapshot_interval_is_specified = true; - } + const bool dt_snapshots_specified = + utils::parser::queryWithParser(pp_warpx, "dt_snapshots_lab", dt_snapshots_lab); + const bool dz_snapshots_specified = + utils::parser::queryWithParser(pp_warpx, "dz_snapshots_lab", dz_snapshots_lab); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - snapshot_interval_is_specified, + dt_snapshots_specified || dz_snapshots_specified, "When using back-transformed diagnostics, user should specify either dz_snapshots_lab or dt_snapshots_lab."); - getWithParser(pp_warpx, "gamma_boost", gamma_boost); + if (dz_snapshots_specified){ + dt_snapshots_lab = dz_snapshots_lab/PhysConst::c; + } + + utils::parser::getWithParser(pp_warpx, "gamma_boost", gamma_boost); pp_warpx.query("do_back_transformed_fields", do_back_transformed_fields); @@ -685,9 +697,12 @@ WarpX::ReadParameters () if (do_electrostatic == ElectrostaticSolverAlgo::LabFrame) { // Note that with the relativistic version, these parameters would be // input for each species. - queryWithParser(pp_warpx, "self_fields_required_precision", self_fields_required_precision); - queryWithParser(pp_warpx, "self_fields_absolute_tolerance", self_fields_absolute_tolerance); - queryWithParser(pp_warpx, "self_fields_max_iters", self_fields_max_iters); + utils::parser::queryWithParser( + pp_warpx, "self_fields_required_precision", self_fields_required_precision); + utils::parser::queryWithParser( + pp_warpx, "self_fields_absolute_tolerance", self_fields_absolute_tolerance); + utils::parser::queryWithParser( + pp_warpx, "self_fields_max_iters", self_fields_max_iters); pp_warpx.query("self_fields_verbosity", self_fields_verbosity); } // Parse the input file for domain boundary potentials @@ -701,7 +716,7 @@ WarpX::ReadParameters () pp_warpx.query("eb_potential(x,y,z,t)", m_poisson_boundary_handler.potential_eb_str); m_poisson_boundary_handler.buildParsers(); - queryWithParser(pp_warpx, "const_dt", const_dt); + utils::parser::queryWithParser(pp_warpx, "const_dt", const_dt); // Filter currently not working with FDTD solver in RZ geometry: turn OFF by default // (see https://github.com/ECP-WarpX/WarpX/issues/1943) @@ -714,7 +729,8 @@ WarpX::ReadParameters () pp_warpx.query("use_filter", use_filter); pp_warpx.query("use_filter_compensation", use_filter_compensation); Vector<int> parse_filter_npass_each_dir(AMREX_SPACEDIM,1); - queryArrWithParser(pp_warpx, "filter_npass_each_dir", parse_filter_npass_each_dir, 0, AMREX_SPACEDIM); + utils::parser::queryArrWithParser( + pp_warpx, "filter_npass_each_dir", parse_filter_npass_each_dir, 0, AMREX_SPACEDIM); filter_npass_each_dir[0] = parse_filter_npass_each_dir[0]; #if (AMREX_SPACEDIM >= 2) filter_npass_each_dir[1] = parse_filter_npass_each_dir[1]; @@ -740,14 +756,18 @@ WarpX::ReadParameters () } #endif - queryWithParser(pp_warpx, "num_mirrors", num_mirrors); + utils::parser::queryWithParser( + pp_warpx, "num_mirrors", num_mirrors); if (num_mirrors>0){ mirror_z.resize(num_mirrors); - getArrWithParser(pp_warpx, "mirror_z", mirror_z, 0, num_mirrors); + utils::parser::getArrWithParser( + pp_warpx, "mirror_z", mirror_z, 0, num_mirrors); mirror_z_width.resize(num_mirrors); - getArrWithParser(pp_warpx, "mirror_z_width", mirror_z_width, 0, num_mirrors); + utils::parser::getArrWithParser( + pp_warpx, "mirror_z_width", mirror_z_width, 0, num_mirrors); mirror_z_npoints.resize(num_mirrors); - getArrWithParser(pp_warpx, "mirror_z_npoints", mirror_z_npoints, 0, num_mirrors); + utils::parser::getArrWithParser( + pp_warpx, "mirror_z_npoints", mirror_z_npoints, 0, num_mirrors); } pp_warpx.query("do_single_precision_comms", do_single_precision_comms); @@ -765,11 +785,14 @@ WarpX::ReadParameters () pp_warpx.query("refine_plasma", refine_plasma); pp_warpx.query("do_dive_cleaning", do_dive_cleaning); pp_warpx.query("do_divb_cleaning", do_divb_cleaning); - queryWithParser(pp_warpx, "n_field_gather_buffer", n_field_gather_buffer); - queryWithParser(pp_warpx, "n_current_deposition_buffer", n_current_deposition_buffer); + utils::parser::queryWithParser( + pp_warpx, "n_field_gather_buffer", n_field_gather_buffer); + utils::parser::queryWithParser( + pp_warpx, "n_current_deposition_buffer", n_current_deposition_buffer); amrex::Real quantum_xi_tmp; - int quantum_xi_is_specified = queryWithParser(pp_warpx, "quantum_xi", quantum_xi_tmp); + const auto quantum_xi_is_specified = + utils::parser::queryWithParser(pp_warpx, "quantum_xi", quantum_xi_tmp); if (quantum_xi_is_specified) { double const quantum_xi = quantum_xi_tmp; quantum_xi_c2 = static_cast<amrex::Real>(quantum_xi * PhysConst::c * PhysConst::c); @@ -796,15 +819,15 @@ WarpX::ReadParameters () } } - queryWithParser(pp_warpx, "pml_ncell", pml_ncell); - queryWithParser(pp_warpx, "pml_delta", pml_delta); + utils::parser::queryWithParser(pp_warpx, "pml_ncell", pml_ncell); + utils::parser::queryWithParser(pp_warpx, "pml_delta", pml_delta); pp_warpx.query("pml_has_particles", pml_has_particles); pp_warpx.query("do_pml_j_damping", do_pml_j_damping); pp_warpx.query("do_pml_in_domain", do_pml_in_domain); pp_warpx.query("do_similar_dm_pml", do_similar_dm_pml); // Read `v_particle_pml` in units of the speed of light v_particle_pml = 1._rt; - queryWithParser(pp_warpx, "v_particle_pml", v_particle_pml); + utils::parser::queryWithParser(pp_warpx, "v_particle_pml", v_particle_pml); WARPX_ALWAYS_ASSERT_WITH_MESSAGE(0._rt < v_particle_pml && v_particle_pml <= 1._rt, "Input value for the velocity warpx.v_particle_pml of the macroparticle must be in (0,1] (in units of c)."); // Scale by the speed of light @@ -885,19 +908,19 @@ WarpX::ReadParameters () ParmParse pp_vismf("vismf"); pp_vismf.add("usesingleread", use_single_read); pp_vismf.add("usesinglewrite", use_single_write); - queryWithParser(pp_warpx, "mffile_nstreams", mffile_nstreams); + utils::parser::queryWithParser(pp_warpx, "mffile_nstreams", mffile_nstreams); VisMF::SetMFFileInStreams(mffile_nstreams); - queryWithParser(pp_warpx, "field_io_nfiles", field_io_nfiles); + utils::parser::queryWithParser(pp_warpx, "field_io_nfiles", field_io_nfiles); VisMF::SetNOutFiles(field_io_nfiles); - queryWithParser(pp_warpx, "particle_io_nfiles", particle_io_nfiles); + utils::parser::queryWithParser(pp_warpx, "particle_io_nfiles", particle_io_nfiles); ParmParse pp_particles("particles"); pp_particles.add("particles_nfiles", particle_io_nfiles); } if (maxLevel() > 0) { Vector<Real> lo, hi; - getArrWithParser(pp_warpx, "fine_tag_lo", lo); - getArrWithParser(pp_warpx, "fine_tag_hi", hi); + utils::parser::getArrWithParser(pp_warpx, "fine_tag_lo", lo); + utils::parser::getArrWithParser(pp_warpx, "fine_tag_hi", hi); fine_tag_lo = RealVect{lo}; fine_tag_hi = RealVect{hi}; } @@ -910,7 +933,7 @@ WarpX::ReadParameters () #ifdef WARPX_DIM_RZ // Only needs to be set with WARPX_DIM_RZ, otherwise defaults to 1 - queryWithParser(pp_warpx, "n_rz_azimuthal_modes", n_rz_azimuthal_modes); + utils::parser::queryWithParser(pp_warpx, "n_rz_azimuthal_modes", n_rz_azimuthal_modes); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( n_rz_azimuthal_modes > 0, "The number of azimuthal modes (n_rz_azimuthal_modes) must be at least 1"); #endif @@ -996,14 +1019,17 @@ WarpX::ReadParameters () // Load balancing parameters std::vector<std::string> load_balance_intervals_string_vec = {"0"}; pp_algo.queryarr("load_balance_intervals", load_balance_intervals_string_vec); - load_balance_intervals = IntervalsParser(load_balance_intervals_string_vec); + load_balance_intervals = utils::parser::IntervalsParser( + load_balance_intervals_string_vec); pp_algo.query("load_balance_with_sfc", load_balance_with_sfc); pp_algo.query("load_balance_knapsack_factor", load_balance_knapsack_factor); - queryWithParser(pp_algo, "load_balance_efficiency_ratio_threshold", + utils::parser::queryWithParser(pp_algo, "load_balance_efficiency_ratio_threshold", load_balance_efficiency_ratio_threshold); load_balance_costs_update_algo = GetAlgorithmInteger(pp_algo, "load_balance_costs_update"); - queryWithParser(pp_algo, "costs_heuristic_cells_wt", costs_heuristic_cells_wt); - queryWithParser(pp_algo, "costs_heuristic_particles_wt", costs_heuristic_particles_wt); + utils::parser::queryWithParser( + pp_algo, "costs_heuristic_cells_wt", costs_heuristic_cells_wt); + utils::parser::queryWithParser( + pp_algo, "costs_heuristic_particles_wt", costs_heuristic_particles_wt); // Parse algo.particle_shape and check that input is acceptable // (do this only if there is at least one particle or laser species) @@ -1018,7 +1044,7 @@ WarpX::ReadParameters () std::vector<std::string> sort_intervals_string_vec = {"-1"}; int particle_shape; if (!species_names.empty() || !lasers_names.empty()) { - if (queryWithParser(pp_algo, "particle_shape", particle_shape)){ + if (utils::parser::queryWithParser(pp_algo, "particle_shape", particle_shape)){ WARPX_ALWAYS_ASSERT_WITH_MESSAGE( (particle_shape >= 1) && (particle_shape <=3), @@ -1053,11 +1079,13 @@ WarpX::ReadParameters () amrex::ParmParse pp_warpx("warpx"); pp_warpx.queryarr("sort_intervals", sort_intervals_string_vec); - sort_intervals = IntervalsParser(sort_intervals_string_vec); + sort_intervals = utils::parser::IntervalsParser(sort_intervals_string_vec); Vector<int> vect_sort_bin_size(AMREX_SPACEDIM,1); - bool sort_bin_size_is_specified = queryArrWithParser(pp_warpx, "sort_bin_size", - vect_sort_bin_size, 0, AMREX_SPACEDIM); + bool sort_bin_size_is_specified = + utils::parser::queryArrWithParser( + pp_warpx, "sort_bin_size", + vect_sort_bin_size, 0, AMREX_SPACEDIM); if (sort_bin_size_is_specified){ for (int i=0; i<AMREX_SPACEDIM; i++) sort_bin_size[i] = vect_sort_bin_size[i]; @@ -1077,17 +1105,23 @@ WarpX::ReadParameters () if (WarpX::field_gathering_algo == GatheringAlgo::MomentumConserving && WarpX::do_nodal == 0) { - queryWithParser(pp_interpolation, "field_centering_nox", field_centering_nox); - queryWithParser(pp_interpolation, "field_centering_noy", field_centering_noy); - queryWithParser(pp_interpolation, "field_centering_noz", field_centering_noz); + utils::parser::queryWithParser( + pp_interpolation, "field_centering_nox", field_centering_nox); + utils::parser::queryWithParser( + pp_interpolation, "field_centering_noy", field_centering_noy); + utils::parser::queryWithParser( + pp_interpolation, "field_centering_noz", field_centering_noz); } // Read order of finite-order centering of currents (nodal to staggered) if (WarpX::do_current_centering) { - queryWithParser(pp_interpolation, "current_centering_nox", current_centering_nox); - queryWithParser(pp_interpolation, "current_centering_noy", current_centering_noy); - queryWithParser(pp_interpolation, "current_centering_noz", current_centering_noz); + utils::parser::queryWithParser( + pp_interpolation, "current_centering_nox", current_centering_nox); + utils::parser::queryWithParser( + pp_interpolation, "current_centering_noy", current_centering_noy); + utils::parser::queryWithParser( + pp_interpolation, "current_centering_noz", current_centering_noz); } // Finite-order centering is not implemented with mesh refinement @@ -1137,17 +1171,17 @@ WarpX::ReadParameters () if(nox_str == "inf") { nox_fft = -1; } else { - queryWithParser(pp_psatd, "nox", nox_fft); + utils::parser::queryWithParser(pp_psatd, "nox", nox_fft); } if(noy_str == "inf") { noy_fft = -1; } else { - queryWithParser(pp_psatd, "noy", noy_fft); + utils::parser::queryWithParser(pp_psatd, "noy", noy_fft); } if(noz_str == "inf") { noz_fft = -1; } else { - queryWithParser(pp_psatd, "noz", noz_fft); + utils::parser::queryWithParser(pp_psatd, "noz", noz_fft); } if (!fft_periodic_single_box) { @@ -1227,7 +1261,8 @@ WarpX::ReadParameters () } else { - queryArrWithParser(pp_psatd, "v_galilean", m_v_galilean, 0, 3); + utils::parser::queryArrWithParser( + pp_psatd, "v_galilean", m_v_galilean, 0, 3); } // Check whether the default comoving velocity should be used @@ -1245,7 +1280,8 @@ WarpX::ReadParameters () } else { - queryArrWithParser(pp_psatd, "v_comoving", m_v_comoving, 0, 3); + utils::parser::queryArrWithParser( + pp_psatd, "v_comoving", m_v_comoving, 0, 3); } // Scale the Galilean/comoving velocity by the speed of light @@ -1384,39 +1420,45 @@ WarpX::ReadParameters () // for slice generation // { - ParmParse pp_slice("slice"); - amrex::Vector<Real> slice_lo(AMREX_SPACEDIM); - amrex::Vector<Real> slice_hi(AMREX_SPACEDIM); - Vector<int> slice_crse_ratio(AMREX_SPACEDIM); - // set default slice_crse_ratio // - for (int idim=0; idim < AMREX_SPACEDIM; ++idim ) - { - slice_crse_ratio[idim] = 1; - } - queryArrWithParser(pp_slice, "dom_lo", slice_lo, 0, AMREX_SPACEDIM); - queryArrWithParser(pp_slice, "dom_hi", slice_hi, 0, AMREX_SPACEDIM); - queryArrWithParser(pp_slice, "coarsening_ratio",slice_crse_ratio,0,AMREX_SPACEDIM); - queryWithParser(pp_slice, "plot_int",slice_plot_int); - slice_realbox.setLo(slice_lo); - slice_realbox.setHi(slice_hi); - slice_cr_ratio = IntVect(AMREX_D_DECL(1,1,1)); - for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) - { - if (slice_crse_ratio[idim] > 1 ) { - slice_cr_ratio[idim] = slice_crse_ratio[idim]; - } - } - - if (do_back_transformed_diagnostics) { - WARPX_ALWAYS_ASSERT_WITH_MESSAGE(gamma_boost > 1.0, - "gamma_boost must be > 1 to use the boost frame diagnostic"); - queryWithParser(pp_slice, "num_slice_snapshots_lab", num_slice_snapshots_lab); - if (num_slice_snapshots_lab > 0) { - getWithParser(pp_slice, "dt_slice_snapshots_lab", dt_slice_snapshots_lab ); - getWithParser(pp_slice, "particle_slice_width_lab",particle_slice_width_lab); - } - } + ParmParse pp_slice("slice"); + amrex::Vector<Real> slice_lo(AMREX_SPACEDIM); + amrex::Vector<Real> slice_hi(AMREX_SPACEDIM); + Vector<int> slice_crse_ratio(AMREX_SPACEDIM); + // set default slice_crse_ratio // + for (int idim=0; idim < AMREX_SPACEDIM; ++idim ) + { + slice_crse_ratio[idim] = 1; + } + utils::parser::queryArrWithParser( + pp_slice, "dom_lo", slice_lo, 0, AMREX_SPACEDIM); + utils::parser::queryArrWithParser( + pp_slice, "dom_hi", slice_hi, 0, AMREX_SPACEDIM); + utils::parser::queryArrWithParser( + pp_slice, "coarsening_ratio",slice_crse_ratio,0,AMREX_SPACEDIM); + utils::parser::queryWithParser( + pp_slice, "plot_int",slice_plot_int); + slice_realbox.setLo(slice_lo); + slice_realbox.setHi(slice_hi); + slice_cr_ratio = IntVect(AMREX_D_DECL(1,1,1)); + for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) + { + if (slice_crse_ratio[idim] > 1 ) { + slice_cr_ratio[idim] = slice_crse_ratio[idim]; + } + } + if (do_back_transformed_diagnostics) { + WARPX_ALWAYS_ASSERT_WITH_MESSAGE(gamma_boost > 1.0, + "gamma_boost must be > 1 to use the boost frame diagnostic"); + utils::parser::queryWithParser( + pp_slice, "num_slice_snapshots_lab", num_slice_snapshots_lab); + if (num_slice_snapshots_lab > 0) { + utils::parser::getWithParser( + pp_slice, "dt_slice_snapshots_lab", dt_slice_snapshots_lab ); + utils::parser::getWithParser( + pp_slice, "particle_slice_width_lab",particle_slice_width_lab); + } + } } } |