From 84e52610186b40d4c004f0ad04bd530c3fa128fd Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Fri, 13 Sep 2024 14:16:45 -0700 Subject: [PATCH] adding diag type to constructor and moving --- Source/Diagnostics/BTDiagnostics.H | 2 +- Source/Diagnostics/BTDiagnostics.cpp | 4 +- .../Diagnostics/BoundaryScrapingDiagnostics.H | 2 +- .../BoundaryScrapingDiagnostics.cpp | 4 +- Source/Diagnostics/Diagnostics.H | 6 ++- Source/Diagnostics/Diagnostics.cpp | 14 ++--- Source/Diagnostics/FullDiagnostics.H | 4 +- Source/Diagnostics/FullDiagnostics.cpp | 51 ++++++++++--------- 8 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Source/Diagnostics/BTDiagnostics.H b/Source/Diagnostics/BTDiagnostics.H index d5dd67226b7..0f695fb2029 100644 --- a/Source/Diagnostics/BTDiagnostics.H +++ b/Source/Diagnostics/BTDiagnostics.H @@ -28,7 +28,7 @@ class BTDiagnostics final : public Diagnostics { public: - BTDiagnostics (int i, const std::string& name); + BTDiagnostics (int i, const std::string& name, DiagTypes diag_type); private: /** Whether to plot raw (i.e., NOT cell-centered) fields */ diff --git a/Source/Diagnostics/BTDiagnostics.cpp b/Source/Diagnostics/BTDiagnostics.cpp index 1cee9909226..10618c9e246 100644 --- a/Source/Diagnostics/BTDiagnostics.cpp +++ b/Source/Diagnostics/BTDiagnostics.cpp @@ -54,8 +54,8 @@ namespace constexpr int permission_flag_rwxrxrx = 0755; } -BTDiagnostics::BTDiagnostics (int i, const std::string& name) - : Diagnostics{i, name} +BTDiagnostics::BTDiagnostics (int i, const std::string& name, DiagTypes diag_type) + : Diagnostics{i, name, diag_type} { ReadParameters(); } diff --git a/Source/Diagnostics/BoundaryScrapingDiagnostics.H b/Source/Diagnostics/BoundaryScrapingDiagnostics.H index 3e5fc1f19eb..f78e7b4574b 100644 --- a/Source/Diagnostics/BoundaryScrapingDiagnostics.H +++ b/Source/Diagnostics/BoundaryScrapingDiagnostics.H @@ -23,7 +23,7 @@ public: * @param i index of diagnostics in MultiDiagnostics::alldiags * @param name diagnostics name in the inputs file */ - BoundaryScrapingDiagnostics (int i, const std::string& name); + BoundaryScrapingDiagnostics (int i, const std::string& name, DiagTypes diag_type); private: /** Read relevant parameters for BoundaryScraping */ diff --git a/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp b/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp index 3757082ab4d..8df58b6fb28 100644 --- a/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp +++ b/Source/Diagnostics/BoundaryScrapingDiagnostics.cpp @@ -22,8 +22,8 @@ using namespace amrex::literals; -BoundaryScrapingDiagnostics::BoundaryScrapingDiagnostics (int i, const std::string& name) - : Diagnostics{i, name} +BoundaryScrapingDiagnostics::BoundaryScrapingDiagnostics (int i, const std::string& name, DiagTypes diag_type) + : Diagnostics{i, name, diag_type} { ReadParameters(); } diff --git a/Source/Diagnostics/Diagnostics.H b/Source/Diagnostics/Diagnostics.H index 68575bbd42c..d0c70e76c1f 100644 --- a/Source/Diagnostics/Diagnostics.H +++ b/Source/Diagnostics/Diagnostics.H @@ -21,6 +21,8 @@ #include #include +/** All types of diagnostics. */ +enum struct DiagTypes {Full, BackTransformed, BoundaryScraping, TimeAveraged}; /** * \brief base class for diagnostics. * Contains main routines to filter, compute and flush diagnostics. @@ -35,7 +37,7 @@ public: * @param i index of diagnostics in MultiDiagnostics::alldiags * @param name diagnostics name in the inputs file */ - Diagnostics (int i, std::string name); + Diagnostics (int i, std::string name, DiagTypes diag_type); /** Virtual Destructor to handle clean destruction of derived classes */ virtual ~Diagnostics (); @@ -45,6 +47,8 @@ public: Diagnostics(Diagnostics&& ) = default; Diagnostics& operator=(Diagnostics&& ) = default; + /** Stores the diag type */ + DiagTypes m_diag_type; /** Pack (stack) all fields in the cell-centered output MultiFab m_mf_output. * * Fields are computed (e.g., cell-centered or back-transformed) diff --git a/Source/Diagnostics/Diagnostics.cpp b/Source/Diagnostics/Diagnostics.cpp index ae40044adf9..97ab733c06e 100644 --- a/Source/Diagnostics/Diagnostics.cpp +++ b/Source/Diagnostics/Diagnostics.cpp @@ -38,8 +38,8 @@ using namespace amrex::literals; -Diagnostics::Diagnostics (int i, std::string name) - : m_diag_name(std::move(name)), m_diag_index(i) +Diagnostics::Diagnostics (int i, std::string name, DiagTypes diag_type) + : m_diag_type(diag_type), m_diag_name(std::move(name)), m_diag_index(i) { } @@ -564,7 +564,7 @@ Diagnostics::ComputeAndPack () auto & warpx = WarpX::GetInstance(); // We sum up fields for later averaging and output when we are inside the averaging period - bool do_sum_now = cur_step >= time_ave + //bool do_sum_now = cur_step >= time_ave // compute the necessary fields and store result in m_mf_output. for (int i_buffer = 0; i_buffer < m_num_buffers; ++i_buffer) { @@ -576,11 +576,11 @@ Diagnostics::ComputeAndPack () // a diagnostics and writes in one or more components of the output // multifab m_mf_output[lev]. m_all_field_functors[lev][icomp]->operator()(m_mf_output[i_buffer][lev], icomp_dst, i_buffer); - if (do_sum_now) - // update the index of the next component to fill - int scalar_a = 1; + //if (do_sum_now) + //// update the index of the next component to fill + //int scalar_a = 1; // call amrex sax operation to do the following - m_sum_mf_output[i_buffer][lev] += scalar_a * m_mf_output[i_buffer][lev] + //m_sum_mf_output[i_buffer][lev] += scalar_a * m_mf_output[i_buffer][lev] icomp_dst += m_all_field_functors[lev][icomp]->nComp(); } // Check that the proper number of components of mf_avg were updated. diff --git a/Source/Diagnostics/FullDiagnostics.H b/Source/Diagnostics/FullDiagnostics.H index e5788dbf20a..e605d5399af 100644 --- a/Source/Diagnostics/FullDiagnostics.H +++ b/Source/Diagnostics/FullDiagnostics.H @@ -11,7 +11,9 @@ class FullDiagnostics final : public Diagnostics { public: - FullDiagnostics (int i, const std::string& name); + FullDiagnostics (int i, const std::string& name, DiagTypes diag_type); +// bool m_do_timeaverage = false; +// enum TimeAverageType {None, Static, Dynamic}; private: /** Read user-requested parameters for full diagnostics */ void ReadParameters (); diff --git a/Source/Diagnostics/FullDiagnostics.cpp b/Source/Diagnostics/FullDiagnostics.cpp index da6b8523491..a2a411518af 100644 --- a/Source/Diagnostics/FullDiagnostics.cpp +++ b/Source/Diagnostics/FullDiagnostics.cpp @@ -45,8 +45,8 @@ using namespace amrex::literals; using namespace warpx::fields; -FullDiagnostics::FullDiagnostics (int i, const std::string& name): - Diagnostics{i, name}, +FullDiagnostics::FullDiagnostics (int i, const std::string& name, DiagTypes diag_type): + Diagnostics{i, name, diag_type}, m_solver_deposits_current{ (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::None) || (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic)} @@ -142,20 +142,20 @@ FullDiagnostics::Flush ( int i_buffer, bool /* force_flush */ ) m_output_species.at(i_buffer), nlev_output, m_file_prefix, m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards); - if (m_time_averaging == "fixed_start" || m_time_averaging == "dynamic_start") { - // Loop over the output levels and divide by the number of steps in the averaging period - for (int lev = 0; lev < nlev_output; ++lev) { - m_sum_mf_output.at(i_buffer).at(lev).mult(1./m_average_period_steps); - } - - m_flush_format->WriteToFile( - m_varnames, m_sum_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(), - warpx.gett_new(0), - m_output_species.at(i_buffer), nlev_output, m_file_prefix, - m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards); - - - } +// if (m_time_averaging == "fixed_start" || m_time_averaging == "dynamic_start") { +// // Loop over the output levels and divide by the number of steps in the averaging period +// for (int lev = 0; lev < nlev_output; ++lev) { +// m_sum_mf_output.at(i_buffer).at(lev).mult(1./m_average_period_steps); +// } +// +// m_flush_format->WriteToFile( +// m_varnames, m_sum_mf_output.at(i_buffer), m_geom_output.at(i_buffer), warpx.getistep(), +// warpx.gett_new(0), +// m_output_species.at(i_buffer), nlev_output, m_file_prefix, +// m_file_min_digits, m_plot_raw_fields, m_plot_raw_fields_guards); +// +// +// } FlushRaw(); } @@ -178,17 +178,18 @@ FullDiagnostics::DoDump (int step, int /*i_buffer*/, bool force_flush) bool FullDiagnostics::DoComputeAndPack (int step, bool force_flush) { - if (m_time_averaging == "dynamic_start") - m_average_start_step = m_intervals.nextContains(step) - m_average_period_steps; - - // add logic here to do compute and pack if m_intervals.contains (step+1-time_average_period) or if (cur_step>time_average_startstep) - bool in_averaging_period = false; - if (step > m_intervals.nextContains(step) - m_average_start_step && step <= m_intervals.nextContains(step)) - in_averaging_period = true; - +// if (m_time_averaging == "dynamic_start") +// m_average_start_step = m_intervals.nextContains(step) - m_average_period_steps; +// +// // add logic here to do compute and pack if m_intervals.contains (step+1-time_average_period) or if (cur_step>time_average_startstep) +// bool in_averaging_period = false; +// if (step > m_intervals.nextContains(step) - m_average_start_step && step <= m_intervals.nextContains(step)) +// in_averaging_period = true; +// // Data must be computed and packed for full diagnostics // whenever the data needs to be flushed. - return (force_flush || m_intervals.contains(step+1) || in_averaging_period); + //return (force_flush || m_intervals.contains(step+1) || in_averaging_period); + return (force_flush || m_intervals.contains(step+1) ); }