Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move Diagnostic class from Fields to Hipace class #513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Hipace.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "utils/AdaptiveTimeStep.H"
#include "utils/GridCurrent.H"
#include "utils/Constants.H"
#include "diagnostics/Diagnostic.H"

#include <AMReX_AmrCore.H>
#ifdef AMREX_USE_LINEAR_SOLVERS
Expand Down Expand Up @@ -306,6 +307,20 @@ private:
/** Used to sort the beam particles into boxes for pipelining */
amrex::Vector<BoxSorter> m_box_sorters;

/** Diagnostics */
Diagnostic m_diags;

void ResizeFDiagFAB (const amrex::Box box, const int lev) { m_diags.ResizeFDiagFAB(box, lev); };
void FillDiagnostics (int lev, int i_slice);
/** \brief get diagnostics Component names of Fields to output */
amrex::Vector<std::string>& getDiagComps () { return m_diags.getComps(); };
/** \brief get diagnostics multifab */
amrex::Vector<amrex::FArrayBox>& getDiagF () { return m_diags.getF(); };
/** \brief get diagnostics geometry */
amrex::Vector<amrex::Geometry>& getDiagGeom () { return m_diags.getGeom(); };
/** \brief get slicing direction of the diagnostics */
int getDiagSliceDir () { return m_diags.sliceDir(); };

/** \brief Predictor-corrector loop to calculate Bx and By.
* 1. an initial Bx and By value is guessed.
* 2. Using this Bx and By values, the plasma particles are advanced to the next slice,
Expand Down
22 changes: 16 additions & 6 deletions src/Hipace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ Hipace::GetInstance ()
Hipace::Hipace () :
m_fields(this),
m_multi_beam(this),
m_multi_plasma(this)
m_multi_plasma(this),
m_diags(this->maxLevel()+1)
{
m_instance = this;

Expand Down Expand Up @@ -268,6 +269,8 @@ Hipace::MakeNewLevelFromScratch (
}
SetDistributionMap(lev, dm); // Let AmrCore know
DefineSliceGDB(ba, dm);
// Note: we pass ba[0] as a dummy box, it will be resized properly in the loop over boxes in Evolve
m_diags.AllocData(lev, ba[0], Comps[WhichSlice::This]["N"], Geom(lev));
m_fields.AllocData(lev, ba, dm, Geom(lev), m_slice_ba, m_slice_dm);
}

Expand Down Expand Up @@ -353,7 +356,7 @@ Hipace::Evolve ()
if (it>0) m_multi_beam.PackLocalGhostParticles(it-1, m_box_sorters);

const amrex::Box& bx = boxArray(lev)[it];
m_fields.ResizeFDiagFAB(bx, lev);
ResizeFDiagFAB(bx, lev);

amrex::Vector<BeamBins> bins;
bins = m_multi_beam.findParticlesInEachSlice(lev, it, bx, geom[lev], m_box_sorters);
Expand Down Expand Up @@ -488,7 +491,7 @@ Hipace::SolveOneSlice (int islice, int lev, const int ibox,
// Push beam particles
m_multi_beam.AdvanceBeamParticlesSlice(m_fields, geom[lev], lev, islice, bx, bins, m_box_sorters, ibox);

m_fields.FillDiagnostics(lev, islice);
FillDiagnostics(lev, islice);

m_fields.ShiftSlices(lev);

Expand Down Expand Up @@ -1190,6 +1193,13 @@ Hipace::NotifyFinish (const int it, bool only_ghost)
#endif
}

void
Hipace::FillDiagnostics (int lev, int i_slice)
{
m_fields.Copy(lev, i_slice, FieldCopyType::StoF, 0, 0, Comps[WhichSlice::This]["N"],
m_diags.getF(lev), m_diags.sliceDir());
}

void
Hipace::WriteDiagnostics (int output_step, const int it, const OpenPMDWriterCallType call_type)
{
Expand All @@ -1200,13 +1210,13 @@ Hipace::WriteDiagnostics (int output_step, const int it, const OpenPMDWriterCall
(!(output_step == m_max_step) && output_step % m_output_period != 0) ) return;

// assumption: same order as in struct enum Field Comps
const amrex::Vector< std::string > varnames = m_fields.getDiagComps();
const amrex::Vector< std::string > varnames = getDiagComps();


#ifdef HIPACE_USE_OPENPMD
constexpr int lev = 0;
m_openpmd_writer.WriteDiagnostics(m_fields.getDiagF(), m_multi_beam, m_fields.getDiagGeom(),
m_physical_time, output_step, lev, m_fields.getDiagSliceDir(), varnames,
m_openpmd_writer.WriteDiagnostics(getDiagF(), m_multi_beam, getDiagGeom(),
m_physical_time, output_step, lev, getDiagSliceDir(), varnames,
it, m_box_sorters, geom[lev], call_type);
#else
amrex::Print()<<"WARNING: HiPACE++ compiled without openPMD support, the simulation has no I/O.\n";
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target_sources(HiPACE
PRIVATE
OpenPMDWriter.cpp
FieldDiagnostic.cpp
Diagnostic.cpp
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#ifndef FIELDDIAGNOSTIC_H_
#define FIELDDIAGNOSTIC_H_
#ifndef DIAGNOSTIC_H_
#define DIAGNOSTIC_H_

#include <AMReX_MultiFab.H>
#include <AMReX_Vector.H>

/** type of diagnostics: full xyz array or xz slice or yz slice */
enum struct DiagType{xyz, xz, yz};

/** \brief This class holds data for 1 diagnostics (full or slice) */
class FieldDiagnostic
class Diagnostic
{

public:

/** \brief Constructor */
explicit FieldDiagnostic (int nlev);
explicit Diagnostic (int nlev);

/** \brief allocate arrays of this MF
*
Expand Down Expand Up @@ -66,4 +67,4 @@ private:
amrex::Vector<amrex::Geometry> m_geom_io; /**< Diagnostics geometry */
};

#endif // FIELDDIAGNOSTIC_H_
#endif // DIAGNOSTIC_H_
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "FieldDiagnostic.H"
#include "fields/Fields.H"
#include "Diagnostic.H"
#include "Hipace.H"
#include <AMReX_ParmParse.H>

FieldDiagnostic::FieldDiagnostic (int nlev)
Diagnostic::Diagnostic (int nlev)
: m_F(nlev),
m_geom_io(nlev)
{
Expand Down Expand Up @@ -50,7 +49,7 @@ FieldDiagnostic::FieldDiagnostic (int nlev)
}

void
FieldDiagnostic::AllocData (int lev, const amrex::Box& bx, int nfields, amrex::Geometry const& geom)
Diagnostic::AllocData (int lev, const amrex::Box& bx, int nfields, amrex::Geometry const& geom)
{
m_nfields = nfields;

Expand All @@ -72,14 +71,14 @@ FieldDiagnostic::AllocData (int lev, const amrex::Box& bx, int nfields, amrex::G
}

void
FieldDiagnostic::ResizeFDiagFAB (const amrex::Box box, const int lev)
Diagnostic::ResizeFDiagFAB (const amrex::Box box, const int lev)
{
amrex::Box io_box = TrimIOBox(box);
m_F[lev].resize(io_box, m_nfields);
}

amrex::Box
FieldDiagnostic::TrimIOBox (const amrex::Box box_3d)
Diagnostic::TrimIOBox (const amrex::Box box_3d)
{
// Create a xz slice Box
amrex::Box slice_bx = box_3d;
Expand Down
21 changes: 2 additions & 19 deletions src/fields/Fields.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define FIELDS_H_

#include "fft_poisson_solver/FFTPoissonSolver.H"
#include "diagnostics/FieldDiagnostic.H"
#include "diagnostics/Diagnostic.H"

#include <AMReX_MultiFab.H>
#include <AMReX_Vector.H>
Expand Down Expand Up @@ -85,8 +85,6 @@ public:
amrex::Geometry const& geom, const amrex::BoxArray& slice_ba,
const amrex::DistributionMapping& slice_dm);

void ResizeFDiagFAB (const amrex::Box box, const int lev) { m_diags.ResizeFDiagFAB(box, lev); };

/** Class to handle transverse FFT Poisson solver on 1 slice */
std::unique_ptr<FFTPoissonSolver> m_poisson_solver;
/** get function for the main 3D array F */
Expand All @@ -105,20 +103,7 @@ public:
* \param[in] islice slice index
*/
amrex::MultiFab& getSlices (int lev, int islice) {return m_slices[lev][islice]; }
/** \brief get diagnostics Component names of Fields to output */
amrex::Vector<std::string>& getDiagComps () { return m_diags.getComps(); };
/** \brief get diagnostics multifab */
amrex::Vector<amrex::FArrayBox>& getDiagF () { return m_diags.getF(); };
/** \brief get diagnostics geometry */
amrex::Vector<amrex::Geometry>& getDiagGeom () { return m_diags.getGeom(); };
/** \brief get slicing direction of the diagnostics */
int getDiagSliceDir () { return m_diags.sliceDir(); };
/** \brief Copy the data from xy slices to the field diagnostics.
*
* \param[in] lev MR leve
* \param[in] i_slice z slice in which to write the data
*/
void FillDiagnostics(int lev, int i_slice);

/** \brief Copy between the full FArrayBox and slice MultiFab.
*
* \param[in] lev MR level
Expand Down Expand Up @@ -261,8 +246,6 @@ private:
amrex::IntVect m_slices_nguards {-1, -1, -1};
/** Whether to use Dirichlet BC for the Poisson solver. Otherwise, periodic */
bool m_do_dirichlet_poisson = true;
/** Diagnostics */
FieldDiagnostic m_diags;
};

#endif
12 changes: 1 addition & 11 deletions src/fields/Fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

Fields::Fields (Hipace const* a_hipace)
: m_F(a_hipace->maxLevel()+1),
m_slices(a_hipace->maxLevel()+1),
m_diags(a_hipace->maxLevel()+1)
m_slices(a_hipace->maxLevel()+1)
{
amrex::ParmParse ppf("fields");
ppf.query("do_dirichlet_poisson", m_do_dirichlet_poisson);
Expand All @@ -29,8 +28,6 @@ Fields::AllocData (

// The Arena uses pinned memory.
m_F[lev].define(ba, dm, Comps[WhichSlice::This]["N"], nguards_F, amrex::MFInfo().SetAlloc(false));
// Note: we pass ba[0] as a dummy box, it will be resized properly in the loop over boxes in Evolve
m_diags.AllocData(lev, ba[0], Comps[WhichSlice::This]["N"], geom);

for (int islice=0; islice<WhichSlice::N; islice++) {
m_slices[lev][islice].define(
Expand Down Expand Up @@ -187,13 +184,6 @@ Fields::Copy (int lev, int i_slice, FieldCopyType copy_type, int slice_comp, int
}
}

void
Fields::FillDiagnostics (int lev, int i_slice)
{
Copy(lev, i_slice, FieldCopyType::StoF, 0, 0, Comps[WhichSlice::This]["N"],
m_diags.getF(lev), m_diags.sliceDir());
}

void
Fields::ShiftSlices (int lev)
{
Expand Down