Skip to content

Commit

Permalink
adding diag type to constructor and moving
Browse files Browse the repository at this point in the history
  • Loading branch information
RevathiJambunathan committed Sep 13, 2024
1 parent 1522688 commit 84e5261
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Source/Diagnostics/BTDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions Source/Diagnostics/BTDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Diagnostics/BoundaryScrapingDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions Source/Diagnostics/BoundaryScrapingDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 5 additions & 1 deletion Source/Diagnostics/Diagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <string>
#include <vector>

/** 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.
Expand All @@ -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 ();
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions Source/Diagnostics/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion Source/Diagnostics/FullDiagnostics.H
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
51 changes: 26 additions & 25 deletions Source/Diagnostics/FullDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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) );

}

Expand Down

0 comments on commit 84e5261

Please sign in to comment.