From 2b881dce8eac358d9aee18efefaa1ef8283ac70b Mon Sep 17 00:00:00 2001 From: Tools Date: Mon, 27 Jan 2020 12:47:47 -0800 Subject: Automatically add copyright header with update_copyright.sh --- Source/Python/WarpXWrappers.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Source/Python/WarpXWrappers.h') diff --git a/Source/Python/WarpXWrappers.h b/Source/Python/WarpXWrappers.h index 4de885b88..ec6635449 100644 --- a/Source/Python/WarpXWrappers.h +++ b/Source/Python/WarpXWrappers.h @@ -1,3 +1,10 @@ +/* Copyright 2019 Andrew Myers, David Grote, Maxence Thevenet + * Remi Lehe, Weiqun Zhang + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ #ifndef WARPX_WRAPPERS_H_ #define WARPX_WRAPPERS_H_ -- cgit v1.2.3 From 3dabb5801eacc36ca9fa6205534b374df9f7f5ea Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Thu, 23 Jan 2020 16:26:55 -0800 Subject: Simplify Plot Options Remove the `dump_plotfile` switch and only control via interval value in `plot_int` for plotfiles. Remove the `dump_openpmd` switch and only control via interval value in `plot_openpmd` for openPMD data dumps. openPMD: pick first available backend if unspecified. --- Docs/source/building/openpmd.rst | 2 + Docs/source/running_cpp/parameters.rst | 32 ++++++------ Docs/source/visualization/visualization.rst | 8 +-- Examples/Tests/particles_in_PML/inputs_2d | 2 - Examples/Tests/particles_in_PML/inputs_3d | 2 - Python/pywarpx/timestepper.py | 4 +- Source/Diagnostics/FieldIO.cpp | 2 +- Source/Diagnostics/WarpXIO.cpp | 76 ++++++++++++++++++----------- Source/Diagnostics/WarpXOpenPMD.cpp | 14 +++++- Source/Evolve/WarpXEvolveEM.cpp | 14 ++++-- Source/Initialization/WarpXInitData.cpp | 3 ++ Source/Python/WarpXWrappers.cpp | 9 ++++ Source/Python/WarpXWrappers.h | 2 + Source/WarpX.H | 21 ++++---- Source/WarpX.cpp | 3 +- 15 files changed, 120 insertions(+), 74 deletions(-) (limited to 'Source/Python/WarpXWrappers.h') diff --git a/Docs/source/building/openpmd.rst b/Docs/source/building/openpmd.rst index 4c71a11a4..1c05c5194 100644 --- a/Docs/source/building/openpmd.rst +++ b/Docs/source/building/openpmd.rst @@ -1,3 +1,5 @@ +.. _building-openpmd: + Building WarpX with support for openPMD output ============================================== diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 3cd7af96c..4e4095c56 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -969,25 +969,21 @@ Boundary conditions Diagnostics and output ---------------------- -* ``amr.plot_int`` (`integer`) - The number of PIC cycles inbetween two consecutive data dumps. Use a - negative number to disable data dumping. - -* ``warpx.dump_plotfiles`` (`0` or `1`) optional - Whether to dump the simulation data in - `AMReX plotfile `__ - format. This is ``1`` by default, unless WarpX is compiled with openPMD support. - -* ``warpx.dump_openpmd`` (`0` or `1`) optional - Whether to dump the simulation data in - `openPMD `__ format. - When WarpX is compiled with openPMD support, this is ``1`` by default. - -* ``warpx.openpmd_backend`` (``h5``, ``bp`` or ``json``) optional - I/O backend for - `openPMD `__ dumps. - When WarpX is compiled with openPMD support, this is ``h5`` by default. +* ``amr.plot_int`` (`integer`) optional + The number of PIC cycles (interval) in between two consecutive `plotfile` data dumps. + Use a negative number to disable data dumping. + This is ``-1`` (disabled) by default. + +* ``warpx.openpmd_int`` (`integer`) optional + The number of PIC cycles (interval) in between two consecutive `openPMD `_ data dumps. + Requires to build WarpX with ``USE_OPENPMD=TRUE`` (see :ref:`instructions `). + This is ``-1`` (disabled) by default. + +* ``warpx.openpmd_backend`` (``bp``, ``h5`` or ``json``) optional + `I/O backend `_ for `openPMD `_ data dumps. + ``bp`` is the `ADIOS I/O library `_, ``h5`` is the `HDF5 format `, and ``json`` is a `simple text format `_. ``json`` only works with serial/single-rank jobs. + When WarpX is compiled with openPMD support, the first available backend in the order given above is taken. * ``warpx.do_back_transformed_diagnostics`` (`0` or `1`) Whether to use the **back-transformed diagnostics** (i.e. diagnostics that diff --git a/Docs/source/visualization/visualization.rst b/Docs/source/visualization/visualization.rst index 54da6d5c4..04785f0e5 100644 --- a/Docs/source/visualization/visualization.rst +++ b/Docs/source/visualization/visualization.rst @@ -2,13 +2,13 @@ Visualizing the simulation results ================================== WarpX can write data either in `plotfile` format (AMReX's native format), or -in `openPMD format `_ (a common data format for -Particle-In-Cell codes). +in `openPMD format `_ (a common data schema on top of +HDF5 or ADIOS files for particle-in-cell codes). .. note:: - This is controlled by the parameters ``warpx.dump_plotfiles`` and - ``warpx.dump_openpmd`` & ``warpx.openpmd_backend`` in the section + This is controlled by the parameters ``warpx.plot_int`` (AMReX) or the + ``warpx.openpmd_int`` & ``warpx.openpmd_backend`` options in the section :doc:`../running_cpp/parameters`. This section describes some of the tools available to visualize the data: diff --git a/Examples/Tests/particles_in_PML/inputs_2d b/Examples/Tests/particles_in_PML/inputs_2d index 9c5a64921..56705ca4d 100644 --- a/Examples/Tests/particles_in_PML/inputs_2d +++ b/Examples/Tests/particles_in_PML/inputs_2d @@ -6,8 +6,6 @@ amr.blocking_factor = 8 amr.max_grid_size = 1024 amr.max_level = 0 -warpx.dump_plotfiles = 1 - # Geometry geometry.coord_sys = 0 # 0: Cartesian geometry.is_periodic = 0 0 # Is periodic? diff --git a/Examples/Tests/particles_in_PML/inputs_3d b/Examples/Tests/particles_in_PML/inputs_3d index a1bda17bc..97e60184a 100644 --- a/Examples/Tests/particles_in_PML/inputs_3d +++ b/Examples/Tests/particles_in_PML/inputs_3d @@ -6,8 +6,6 @@ amr.blocking_factor = 8 amr.max_grid_size = 1024 amr.max_level = 0 -warpx.dump_plotfiles = 1 - # Geometry geometry.coord_sys = 0 # 0: Cartesian geometry.is_periodic = 0 0 0 # Is periodic? diff --git a/Python/pywarpx/timestepper.py b/Python/pywarpx/timestepper.py index 3068cbc82..0e6846edd 100644 --- a/Python/pywarpx/timestepper.py +++ b/Python/pywarpx/timestepper.py @@ -66,8 +66,10 @@ class TimeStepper(object): max_time_reached = ((self.cur_time >= libwarpx.warpx_stopTime() - 1.e-6*dt) or (self.istep >= libwarpx.warpx_maxStep())) - if libwarpx.warpx_plotInt() > 0 and (self.istep+1)%libwarpx.warpx_plotInt() == 0 or max_time_reached: + if (libwarpx.warpx_plotInt() > 0 and (self.istep+1)%libwarpx.warpx_plotInt() == 0) or max_time_reached: libwarpx.warpx_WritePlotFile() + if (libwarpx.warpx_openpmdInt() > 0 and (self.istep+1)%libwarpx.warpx_openpmdInt() == 0) or max_time_reached: + libwarpx.warpx_WriteOpenPMDFile() if libwarpx.warpx_checkInt() > 0 and (self.istep+1)%libwarpx.warpx_plotInt() == 0 or max_time_reached: libwarpx.warpx_WriteCheckPointFile() diff --git a/Source/Diagnostics/FieldIO.cpp b/Source/Diagnostics/FieldIO.cpp index 9c38f1d68..130b0b256 100644 --- a/Source/Diagnostics/FieldIO.cpp +++ b/Source/Diagnostics/FieldIO.cpp @@ -2,7 +2,7 @@ #include #include #ifdef WARPX_USE_OPENPMD -#include +# include #endif #include diff --git a/Source/Diagnostics/WarpXIO.cpp b/Source/Diagnostics/WarpXIO.cpp index d7a46f7b7..b79a38a64 100644 --- a/Source/Diagnostics/WarpXIO.cpp +++ b/Source/Diagnostics/WarpXIO.cpp @@ -19,7 +19,7 @@ #endif #ifdef WARPX_USE_OPENPMD -#include "WarpXOpenPMD.H" +# include "WarpXOpenPMD.H" #endif @@ -499,45 +499,68 @@ WarpX::UpdateInSitu () const } void -WarpX::WritePlotFile () const -{ - BL_PROFILE("WarpX::WritePlotFile()"); - - const std::string& plotfilename = amrex::Concatenate(plot_file,istep[0]); - amrex::Print() << " Writing plotfile " << plotfilename << "\n"; - +WarpX::prepareFields( + int const step, + Vector& varnames, + Vector& mf_avg, + Vector& output_mf, + Vector& output_geom +) const { // Average the fields from the simulation grid to the cell centers const int ngrow = 0; - Vector varnames; // Name of the written fields - // mf_avg will contain the averaged, cell-centered fields - Vector mf_avg; WarpX::AverageAndPackFields( varnames, mf_avg, ngrow ); // Coarsen the fields, if requested by the user - Vector output_mf; // will point to the data to be written Vector coarse_mf; // will remain empty if there is no coarsening - Vector output_geom; if (plot_coarsening_ratio != 1) { coarsenCellCenteredFields( coarse_mf, output_geom, mf_avg, Geom(), - plot_coarsening_ratio, finest_level ); + plot_coarsening_ratio, finest_level ); output_mf = amrex::GetVecOfConstPtrs(coarse_mf); } else { // No averaging necessary, simply point to mf_avg output_mf = amrex::GetVecOfConstPtrs(mf_avg); output_geom = Geom(); } +} + +void +WarpX::WriteOpenPMDFile () const +{ + BL_PROFILE("WarpX::WriteOpenPMDFile()"); #ifdef WARPX_USE_OPENPMD - if (dump_openpmd) { - m_OpenPMDPlotWriter->SetStep(istep[0]); - // fields: only dumped for coarse level - m_OpenPMDPlotWriter->WriteOpenPMDFields( - varnames, *output_mf[0], output_geom[0], istep[0], t_new[0]); - // particles: all (reside only on locally finest level) - m_OpenPMDPlotWriter->WriteOpenPMDParticles(mypc); - } + const auto step = istep[0]; + + Vector varnames; // Name of the written fields + Vector mf_avg; // contains the averaged, cell-centered fields + Vector output_mf; // will point to the data to be written + Vector output_geom; + + prepareFields(step, varnames, mf_avg, output_mf, output_geom); + + m_OpenPMDPlotWriter->SetStep(step); + // fields: only dumped for coarse level + m_OpenPMDPlotWriter->WriteOpenPMDFields( + varnames, *output_mf[0], output_geom[0], step, t_new[0]); + // particles: all (reside only on locally finest level) + m_OpenPMDPlotWriter->WriteOpenPMDParticles(mypc); #endif +} + +void +WarpX::WritePlotFile () const +{ + BL_PROFILE("WarpX::WritePlotFile()"); - if (dump_plotfiles) { + const auto step = istep[0]; + const std::string& plotfilename = amrex::Concatenate(plot_file,step); + amrex::Print() << " Writing plotfile " << plotfilename << "\n"; + + Vector varnames; // Name of the written fields + Vector mf_avg; // contains the averaged, cell-centered fields + Vector output_mf; // will point to the data to be written + Vector output_geom; + + prepareFields(step, varnames, mf_avg, output_mf, output_geom); // Write the fields contained in `mf_avg`, and corresponding to the // names `varnames`, into a plotfile. @@ -620,18 +643,13 @@ WarpX::WritePlotFile () const } } - // leaving the option of binary output through AMREx around - // regardless of openPMD. This can be adjusted later - { - mypc->WritePlotFile(plotfilename); - } + mypc->WritePlotFile(plotfilename); WriteJobInfo(plotfilename); WriteWarpXHeader(plotfilename); VisMF::SetHeaderVersion(current_version); - } // endif: dump_plotfiles } diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index ed2bf8020..40ce08d4b 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -90,7 +90,19 @@ WarpXOpenPMDPlot::WarpXOpenPMDPlot(bool oneFilePerTS, m_OneFilePerTS(oneFilePerTS), m_OpenPMDFileType(std::move(openPMDFileType)), m_fieldPMLdirections(std::move(fieldPMLdirections)) -{} +{ + // pick first available backend if default is chosen + if( m_OpenPMDFileType == "default" ) +#if openPMD_HAVE_ADIOS1==1 + m_OpenPMDFileType = "bp"; +#elif openPMD_HAVE_ADIOS2==1 + m_OpenPMDFileType = "bp"; +#elif openPMD_HAVE_HDF5==1 + m_OpenPMDFileType = "h5"; +#else + m_OpenPMDFileType = "json"; +#endif +} WarpXOpenPMDPlot::~WarpXOpenPMDPlot() { diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 1cb17287b..428e06780 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -146,7 +146,8 @@ WarpX::EvolveEM (int numsteps) cur_time += dt[0]; - bool to_make_plot = (plot_int > 0) && ((step+1) % plot_int == 0); + bool to_make_plot = ( (plot_int > 0) && ((step+1) % plot_int == 0) ); + bool to_write_openPMD = ( (openpmd_int > 0) && ((step+1) % openpmd_int == 0) ); // slice generation // bool to_make_slice_plot = (slice_plot_int > 0) && ( (step+1)% slice_plot_int == 0); @@ -162,7 +163,7 @@ WarpX::EvolveEM (int numsteps) myBFD->writeLabFrameData(cell_centered_data.get(), *mypc, geom[0], cur_time, dt[0]); } - bool move_j = is_synchronized || to_make_plot || do_insitu; + bool move_j = is_synchronized || to_make_plot || to_write_openPMD || do_insitu; // If is_synchronized we need to shift j too so that next step we can evolve E by dt/2. // We might need to move j because we are going to make a plotfile. @@ -196,7 +197,7 @@ WarpX::EvolveEM (int numsteps) } // slice gen // - if (to_make_plot || do_insitu || to_make_slice_plot) + if (to_make_plot || to_write_openPMD || do_insitu || to_make_slice_plot) { // This is probably overkill, but it's not called often FillBoundaryE(guard_cells.ng_alloc_EB, guard_cells.ng_Extra); @@ -219,6 +220,8 @@ WarpX::EvolveEM (int numsteps) if (to_make_plot) WritePlotFile(); + if (to_write_openPMD) + WriteOpenPMDFile(); if (to_make_slice_plot) { @@ -250,11 +253,12 @@ WarpX::EvolveEM (int numsteps) bool write_plot_file = plot_int > 0 && istep[0] > last_plot_file_step && (max_time_reached || istep[0] >= max_step); + bool write_openPMD = openpmd_int > 0 && (max_time_reached || istep[0] >= max_step); bool do_insitu = (insitu_start >= istep[0]) && (insitu_int > 0) && (istep[0] > last_insitu_step) && (max_time_reached || istep[0] >= max_step); - if (write_plot_file || do_insitu) + if (write_plot_file || write_openPMD || do_insitu) { // This is probably overkill, but it's not called often FillBoundaryE(guard_cells.ng_alloc_EB, guard_cells.ng_Extra); @@ -276,6 +280,8 @@ WarpX::EvolveEM (int numsteps) if (write_plot_file) WritePlotFile(); + if (write_openPMD) + WriteOpenPMDFile(); if (do_insitu) UpdateInSitu(); diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 48c30ae93..998e654c9 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -74,6 +74,9 @@ WarpX::InitData () if (plot_int > 0) WritePlotFile(); + if (openpmd_int > 0) + WriteOpenPMDFile(); + if (check_int > 0) WriteCheckPointFile(); diff --git a/Source/Python/WarpXWrappers.cpp b/Source/Python/WarpXWrappers.cpp index e72d467d7..0be59b765 100644 --- a/Source/Python/WarpXWrappers.cpp +++ b/Source/Python/WarpXWrappers.cpp @@ -404,6 +404,11 @@ extern "C" return warpx.plotInt (); } + int warpx_openpmdInt () { + WarpX& warpx = WarpX::GetInstance(); + return warpx.openpmdInt (); + } + void warpx_WriteCheckPointFile () { WarpX& warpx = WarpX::GetInstance(); warpx.WriteCheckPointFile (); @@ -412,6 +417,10 @@ extern "C" WarpX& warpx = WarpX::GetInstance(); warpx.WritePlotFile (); } + void warpx_WriteOpenPMDFile () { + WarpX& warpx = WarpX::GetInstance(); + warpx.WriteOpenPMDFile (); + } int warpx_finestLevel () { WarpX& warpx = WarpX::GetInstance(); diff --git a/Source/Python/WarpXWrappers.h b/Source/Python/WarpXWrappers.h index 4de885b88..d0be87402 100644 --- a/Source/Python/WarpXWrappers.h +++ b/Source/Python/WarpXWrappers.h @@ -95,9 +95,11 @@ extern "C" { int warpx_checkInt (); int warpx_plotInt (); + int warpx_openpmdInt (); void warpx_WriteCheckPointFile (); void warpx_WritePlotFile (); + void warpx_WriteOpenPMDFile (); int warpx_finestLevel (); diff --git a/Source/WarpX.H b/Source/WarpX.H index 1549dded2..4bba89454 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -33,7 +33,7 @@ #endif #ifdef WARPX_USE_OPENPMD -#include +# include #endif #include @@ -277,12 +277,18 @@ public: int checkInt () const {return check_int;} int plotInt () const {return plot_int;} + int openpmdInt () const {return openpmd_int;} void WriteCheckPointFile () const; + void WriteOpenPMDFile () const; void WritePlotFile () const; void UpdateInSitu () const; void AverageAndPackFields( amrex::Vector& varnames, amrex::Vector& mf_avg, const int ngrow) const; + void prepareFields( int const step, amrex::Vector& varnames, + amrex::Vector& mf_avg, + amrex::Vector& output_mf, + amrex::Vector& output_geom ) const; void WritePlotFileES(const amrex::Vector >& rho, const amrex::Vector >& phi, @@ -628,18 +634,13 @@ private: int check_int = -1; int plot_int = -1; - std::string openpmd_backend {"bp"}; + std::string openpmd_backend {"default"}; + int openpmd_int = -1; + bool openpmd_tspf = true; //!< one file per timestep (or one file for all steps) #ifdef WARPX_USE_OPENPMD - bool dump_plotfiles = false; - bool dump_openpmd = true; - bool openpmd_tspf = true; // one file per timestep - //bool openpmd_tspf = false; // one file all timesteps WarpXOpenPMDPlot* m_OpenPMDPlotWriter = nullptr; - -#else - bool dump_plotfiles = true; - bool dump_openpmd = false; #endif + bool plot_rho = false; bool plot_costs = true; bool plot_finepatch = false; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 5f6f2b2e5..bf0cdd5b5 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -466,12 +466,11 @@ WarpX::ReadParameters () amrex::Abort("J-damping can only be done when PML are inside simulation domain (do_pml_in_domain=1)"); } - pp.query("dump_openpmd", dump_openpmd); + pp.query("openpmd_int", openpmd_int); pp.query("openpmd_backend", openpmd_backend); #ifdef WARPX_USE_OPENPMD pp.query("openpmd_tspf", openpmd_tspf); #endif - pp.query("dump_plotfiles", dump_plotfiles); pp.query("plot_costs", plot_costs); pp.query("plot_raw_fields", plot_raw_fields); pp.query("plot_raw_fields_guards", plot_raw_fields_guards); -- cgit v1.2.3