Skip to content

Commit

Permalink
Merge branch 'development' into mg_poisson
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSinn authored Feb 22, 2024
2 parents 063ff37 + 12eaba9 commit f54e8d6
Show file tree
Hide file tree
Showing 24 changed files with 405 additions and 185 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@ set_cxx17_superbuild()
# this is an optional tool that stores compiled object files; allows fast
# re-builds even with "make clean" in between. Mainly used to store AMReX
# objects
set_ccache()
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(HiPACE_CCACHE_DEFAULT ON)
else()
set(HiPACE_CCACHE_DEFAULT OFF) # we are a subproject in a superbuild
endif()
option(HiPACE_CCACHE "Enable ccache for faster rebuilds" ${HiPACE_CCACHE_DEFAULT})
if(HiPACE_CCACHE)
set_ccache()
endif()


# Output Directories ##########################################################
Expand Down
23 changes: 18 additions & 5 deletions docs/source/run/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,8 @@ Parameters starting with ``lasers.`` apply to all laser pulses, parameters start
* ``<laser name>.focal_distance`` (`float`)
Distance at which the laser pulse if focused (in the z direction, counted from laser initial position).

* ``<laser name>.propagation_angle_yz`` (`float`)
Propagation angle of the pulse in the yz plane (0 is the along the z axis)
Diagnostic parameters
---------------------

Expand Down Expand Up @@ -927,21 +929,26 @@ In-situ diagnostics
Besides the standard diagnostics, fast in-situ diagnostics are available. They are most useful when beams with large numbers of particles are used, as the important moments can be calculated in-situ (during the simulation) to largely reduce the simulation's analysis.
In-situ diagnostics compute slice quantities (1 number per quantity per longitudinal cell).
For particle beams, they can be used to calculate the main characterizing beam parameters (width, energy spread, emittance, etc.), from which most common beam parameters (e.g. slice and projected emittance, etc.) can be computed. Additionally, the plasma particle properties (e.g, the temperature) can be calculated.
For particle quantities, "[...]" stands for averaging over all particles in the current slice;
for grid quantities, "[...]" stands for integrating over all cells in the current slice.

For particle beams, the following quantities are calculated per slice and stored:
``sum(w), [x], [x^2], [y], [y^2], [z], [z^2], [ux], [ux^2], [uy], [uy^2], [uz], [uz^2], [x*ux], [y*uy], [z*uz], [ga], [ga^2], np``.
``sum(w), [x], [x^2], [y], [y^2], [z], [z^2], [ux], [ux^2], [uy], [uy^2], [uz], [uz^2], [x*ux], [y*uy], [z*uz], [x*uy], [y*ux], [ux/uz], [uy/uz], [ga], [ga^2], np``.
For plasma particles, the following quantities are calculated per slice and stored:
``sum(w), [x], [x^2], [y], [y^2], [ux], [ux^2], [uy], [uy^2], [uz], [uz^2], [ga], [ga^2], np``.
Thereby, "[]" stands for averaging over all particles in the current slice,
"w" stands for weight, "ux" is the normalized momentum in the x direction, "ga" is the Lorentz factor.
Thereby, "w" stands for weight, "ux" is the normalized momentum in the x direction, "ga" is the Lorentz factor.
Averages and totals over all slices are also provided for convenience under the
respective ``average`` and ``total`` subcategories.

For the field in-situ diagnostics, the following quantities are calculated per slice and stored:
``[Ex^2], [Ey^2], [Ez^2], [Bx^2], [By^2], [Bz^2], [ExmBy^2], [EypBx^2], [Ez*jz_beam]``.
Thereby, "[]" stands for averaging over all cells in the current slice.
``[Ex^2], [Ey^2], [Ez^2], [Bx^2], [By^2], [Bz^2], [ExmBy^2], [EypBx^2], [jz_beam], [Ez*jz_beam]``.
These quantities can be used to calculate the energy stored in the fields.

For the laser in-situ diagnostics, the following quantities are calculated per slice and stored:
``max(|a|^2), [|a|^2], [|a|^2*x], [|a|^2*x*x], [|a|^2*y], [|a|^2*y*y], axis(a)``.
Thereby, ``max(|a|^2)`` is the highest value of ``|a|^2`` in the current slice
and ``axis(a)`` gives the complex value of the laser envelope, in the center of every slice.

Additionally, some metadata is also available:
``time, step, n_slices, charge, mass, z_lo, z_hi, normalized_density_factor``.
``time`` and ``step`` refers to the physical time of the simulation and step number of the
Expand Down Expand Up @@ -989,6 +996,12 @@ Use ``hipace/tools/read_insitu_diagnostics.py`` to read the files using this for
* ``fields.insitu_file_prefix`` (`string`) optional (default ``"diags/field_insitu"``)
Path of the field in-situ output. Must not be the same as `hipace.file_prefix`.

* ``lasers.insitu_period`` (`int`) optional (default ``0``)
Period of the laser in-situ diagnostics. `0` means no laser in-situ diagnostics.

* ``lasers.insitu_file_prefix`` (`string`) optional (default ``"diags/laser_insitu"``)
Path of the laser in-situ output. Must not be the same as `hipace.file_prefix`.

Additional physics
------------------

Expand Down
6 changes: 5 additions & 1 deletion src/Hipace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ Hipace::Evolve ()
m_fields.InSituWriteToFile(step, m_physical_time, m_3D_geom[0], m_max_step, m_max_time);
m_multi_beam.InSituWriteToFile(step, m_physical_time, m_3D_geom[0], m_max_step, m_max_time);
m_multi_plasma.InSituWriteToFile(step, m_physical_time, m_3D_geom[0], m_max_step, m_max_time);
m_multi_laser.InSituWriteToFile(step, m_physical_time, m_3D_geom[0], m_max_step, m_max_time);

if (!m_explicit) {
// averaging predictor corrector loop diagnostics
Expand Down Expand Up @@ -564,7 +565,10 @@ Hipace::SolveOneSlice (int islice, int step)
// get field insitu diagnostics after all fields are computed & SALAME
m_fields.InSituComputeDiags(step, m_physical_time, islice, m_3D_geom[0], m_max_step, m_max_time);

// copy fields to diagnostic array
// get laser insitu diagnostics
m_multi_laser.InSituComputeDiags(step, m_physical_time, islice, m_3D_geom[0], m_max_step, m_max_time);

// copy fields (and laser) to diagnostic array
for (int lev=0; lev<current_N_level; ++lev) {
FillFieldDiagnostics(lev, islice);
}
Expand Down
2 changes: 1 addition & 1 deletion src/fields/Fields.H
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ private:
/** If any plasma species has a neutralizing background */
bool m_any_neutral_background = false;
/** Number of real field properties for in-situ per-slice reduced diagnostics. */
static constexpr int m_insitu_nrp = 9;
static constexpr int m_insitu_nrp = 10;
/** How often the insitu field diagnostics should be computed and written
* Default is 0, meaning no output */
int m_insitu_period {0};
Expand Down
13 changes: 8 additions & 5 deletions src/fields/Fields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,8 @@ Fields::InSituComputeDiags (int step, amrex::Real time, int islice, const amrex:
pow<2>(arr(i,j,Bz)), // 5 [Bz^2]
pow<2>(arr(i,j,ExmBy)), // 6 [ExmBy^2]
pow<2>(arr(i,j,EypBx)), // 7 [EypBx^2]
arr(i,j,Ez)*arr(i,j,jz_beam) // 8 [Ez*jz_beam]
arr(i,j,jz_beam), // 8 [jz_beam]
arr(i,j,Ez)*arr(i,j,jz_beam) // 9 [Ez*jz_beam]
};
});
}
Expand Down Expand Up @@ -1368,7 +1369,8 @@ Fields::InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& ge
{"[Bz^2]" , &m_insitu_rdata[5*nslices], nslices},
{"[ExmBy^2]", &m_insitu_rdata[6*nslices], nslices},
{"[EypBx^2]", &m_insitu_rdata[7*nslices], nslices},
{"[Ez*jz_beam]", &m_insitu_rdata[8*nslices], nslices},
{"[jz_beam]", &m_insitu_rdata[8*nslices], nslices},
{"[Ez*jz_beam]", &m_insitu_rdata[9*nslices], nslices},
{"integrated", {
{"[Ex^2]" , &m_insitu_sum_rdata[0]},
{"[Ey^2]" , &m_insitu_sum_rdata[1]},
Expand All @@ -1378,7 +1380,8 @@ Fields::InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& ge
{"[Bz^2]" , &m_insitu_sum_rdata[5]},
{"[ExmBy^2]", &m_insitu_sum_rdata[6]},
{"[EypBx^2]", &m_insitu_sum_rdata[7]},
{"[Ez*jz_beam]", &m_insitu_sum_rdata[8]}
{"[jz_beam]", &m_insitu_sum_rdata[8]},
{"[Ez*jz_beam]", &m_insitu_sum_rdata[9]}
}}
};

Expand All @@ -1394,9 +1397,9 @@ Fields::InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& ge
ofs.close();
// assert no file errors
#ifdef HIPACE_USE_OPENPMD
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ofs, "Error while writing insitu beam diagnostics");
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ofs, "Error while writing insitu field diagnostics");
#else
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ofs, "Error while writing insitu beam diagnostics. "
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(ofs, "Error while writing insitu field diagnostics. "
"Maybe the specified subdirectory does not exist");
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/laser/Laser.H
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public:
std::string m_name {""};
amrex::Real m_a0 {0.}; /**< Laser peak normalized amplitude */
amrex::Real m_w0 {0.}; /**< Laser waist */
/** Propagation angle of the pulse in the yz plane (0 is the along the z axis) */
amrex::Real m_propagation_angle_yz {0.};
amrex::Real m_L0 {0.}; /**< Laser length (HW 1/e in amplitude) */
amrex::Real m_tau {0.}; /**< Laser duration (HW 1/e in amplitude) */
/** Focal distance of the laser pulse */
Expand Down
3 changes: 2 additions & 1 deletion src/laser/Laser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Laser::Laser (std::string name, bool laser_from_file)
amrex::ParmParse pp(m_name);
queryWithParser(pp, "a0", m_a0);
queryWithParser(pp, "w0", m_w0);
bool length_is_specified = queryWithParser(pp, "L0", m_L0);;
queryWithParser(pp, "propagation_angle_yz", m_propagation_angle_yz);
bool length_is_specified = queryWithParser(pp, "L0", m_L0);
bool duration_is_specified = queryWithParser(pp, "tau", m_tau);
AMREX_ALWAYS_ASSERT_WITH_MESSAGE( length_is_specified + duration_is_specified == 1,
"Please specify exlusively either the pulse length L0 or the duration tau of the laser");
Expand Down
38 changes: 38 additions & 0 deletions src/laser/MultiLaser.H
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ public:
*/
void InitLaserSlice (const amrex::Geometry& geom, const int islice, const int comp);

/** Compute in-situ laser diagnostics of current slice, store in member variable
* \param[in] step current time step
* \param[in] time physical time
* \param[in] islice current slice, on which diags are computed.
* \param[in] geom3D Geometry of the problem
* \param[in] max_step maximum time step of simulation
* \param[in] max_time maximum time of simulation
*/
void InSituComputeDiags (int step, amrex::Real time, int islice, const amrex::Geometry& geom3D,
int max_step, amrex::Real max_time);

/** Dump in-situ reduced diagnostics to file.
* \param[in] step current time step
* \param[in] time physical time
* \param[in] geom3D Geometry object for the whole domain
* \param[in] max_step maximum time step of simulation
* \param[in] max_time maximum time of simulation
*/
void InSituWriteToFile (int step, amrex::Real time, const amrex::Geometry& geom3D,
int max_step, amrex::Real max_time);

/** Get the central wavelength */
amrex::Real GetLambda0 () const { return m_lambda0; }

Expand Down Expand Up @@ -256,6 +277,23 @@ private:
cufftResult m_result_fwd;
cufftResult m_result_bkw;
#endif

// Data for in-situ diagnostics:
/** Number of real laser properties for in-situ per-slice reduced diagnostics. */
static constexpr int m_insitu_nrp = 6;
/** Number of real complex properties for in-situ per-slice reduced diagnostics. */
static constexpr int m_insitu_ncp = 1;
/** How often the insitu laser diagnostics should be computed and written
* Default is 0, meaning no output */
int m_insitu_period {0};
/** All per-slice real laser properties */
amrex::Vector<amrex::Real> m_insitu_rdata;
/** Sum of all per-slice real laser properties */
amrex::Vector<amrex::Real> m_insitu_sum_rdata;
/** All per-slice complex laser properties */
amrex::Vector<amrex::GpuComplex<amrex::Real>> m_insitu_cdata;
/** Prefix/path for the output files */
std::string m_insitu_file_prefix = "diags/laser_insitu";
};

#endif // MULTILASER_H_
Loading

0 comments on commit f54e8d6

Please sign in to comment.