Skip to content

[WIP] Set time step with parser #1213

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

Open
wants to merge 54 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
044cdc1
move queryparser of dt into evolve loop
huixingjian Feb 24, 2025
a751ce8
add parmparser get physical time first
huixingjian Feb 24, 2025
643c322
unable calculating adaptive time step
huixingjian Mar 10, 2025
1ae90e9
change m_dt to Array3
huixingjian Apr 15, 2025
1bfb066
update laser solver
huixingjian Apr 15, 2025
9c338d0
Update Hipace.H
huixingjian Apr 16, 2025
650fbb2
update laser solver
huixingjian Apr 16, 2025
c258866
update acoeff
huixingjian Apr 16, 2025
6249c04
change to array2
huixingjian Apr 16, 2025
0ecae85
update fftsolver
huixingjian Apr 16, 2025
130a37d
change parameter to std::array<amrex::Real, 2>
huixingjian Apr 16, 2025
c67081d
update MG solver
huixingjian Apr 16, 2025
c2e273f
remove namespace
huixingjian Apr 16, 2025
62a55fa
missing :
huixingjian Apr 16, 2025
6b3fd85
update ats
huixingjian Apr 16, 2025
e9210de
SYNTAX error
huixingjian Apr 16, 2025
ca67377
change the dt in head file
huixingjian Apr 16, 2025
6e4672a
fix typo
huixingjian Apr 16, 2025
9703d0b
change data type of dt to amrex::GpuArray<amrex::Real, 3>
huixingjian Apr 16, 2025
85d5991
typo
huixingjian Apr 16, 2025
f9152fd
typo
huixingjian Apr 16, 2025
fcb83c4
argument missing
huixingjian Apr 16, 2025
14b69bb
misreplacement
huixingjian Apr 16, 2025
526893d
Update Hipace.cpp
huixingjian Apr 23, 2025
14c184d
Redo changes in laser pusher
huixingjian May 5, 2025
07a4e09
Update MultiLaser.cpp
huixingjian May 5, 2025
a2569d0
Update MultiLaser.cpp
huixingjian May 5, 2025
bdb44b9
Update MultiLaser.cpp
huixingjian May 5, 2025
266bc88
Update MultiLaser.cpp
huixingjian May 5, 2025
c06f00f
Update MultiLaser.cpp
huixingjian May 5, 2025
690217c
Update MultiLaser.cpp
huixingjian May 5, 2025
be48af6
add GPU array Advance slice
huixingjian May 5, 2025
a9cf55e
change condition for 1st order pusher
huixingjian May 21, 2025
b457ffd
Merge branch 'Hi-PACE:development' into parser_dt
huixingjian May 21, 2025
4d049f4
change GPUarray to two parameters
huixingjian May 22, 2025
982f55a
Merge branch 'parser_dt' of https://github.com/huixingjian/hipace- in…
huixingjian May 22, 2025
fdfb337
fix typo
huixingjian May 22, 2025
82a667c
debug
huixingjian May 22, 2025
8c618cb
remove const const
AlexanderSinn May 27, 2025
41475e7
fix whitespace
AlexanderSinn May 27, 2025
58e41b9
fix crash from uninitialized value
AlexanderSinn May 27, 2025
15c022e
fix typo
huixingjian Jun 16, 2025
d6e43fd
revert change in FFT solver to debug CI
huixingjian Jun 16, 2025
09ad47a
fix typo
huixingjian Jun 16, 2025
2e38bc2
Update MultiLaser.cpp
huixingjian Jun 17, 2025
75ae31f
Update MultiLaser.cpp
huixingjian Jun 17, 2025
c9a94b4
Update Hipace.H
huixingjian Jun 17, 2025
5761989
add contion in MG solve
huixingjian Jun 17, 2025
4f1c3a6
add MPI to send time steps
huixingjian Jun 24, 2025
04e0fb3
delete redundant variable
huixingjian Jun 24, 2025
e3eb3b6
add parameter
huixingjian Jun 24, 2025
ab1ac53
add parameter in document
huixingjian Jun 24, 2025
a221966
parameter for pre_dt
huixingjian Jun 24, 2025
1b31e19
add MPIwait
huixingjian Jun 24, 2025
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
8 changes: 7 additions & 1 deletion src/Hipace.H
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,13 @@ public:
* or radiation reaction in normalized units */
inline static amrex::Real m_background_density_SI = 0.;
/** Time step for the beam evolution */
amrex::Real m_dt = +0.0;
amrex::Parser m_parser_dt;/**< owns data for dt_str */
/** stores the output function of makeFunctionWithParser for profile_real_str */
amrex::ParserExecutor<1> m_exe_dt;
/** stores time step of current time steps */
amrex::Real m_dt = 0;
/** stores time step of previous time steps */
amrex::Real m_dt_pre = 0;
/** Number of binary collisions */
inline static int m_ncollisions = 0;
/** Adaptive time step instance */
Expand Down
57 changes: 45 additions & 12 deletions src/Hipace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ Hipace::Hipace () :

amrex::ParmParse pph("hipace");

std::string str_dt {""};
queryWithParser(pph, "dt", str_dt);
if (str_dt != "adaptive") {
queryWithParser(pph, "dt", m_dt);
m_max_time = std::copysign(m_max_time, m_dt);
}
queryWithParser(pph, "max_time", m_max_time);
queryWithParser(pph, "verbose", m_verbose);
m_numprocs = amrex::ParallelDescriptor::NProcs();
Expand Down Expand Up @@ -407,30 +401,69 @@ Hipace::Evolve ()
HIPACE_PROFILE("Hipace::Evolve()");
const double start_time = amrex::second();
const int rank = amrex::ParallelDescriptor::MyProc();

m_comm = amrex::ParallelDescriptor::Communicator();
amrex::ParmParse pph("hipace");
// now each rank starts with its own time step and writes to its own file. The first rank starts with step 0
for (int step = rank; step <= m_max_step; step += m_numprocs)
{
ResetAllQuantities();
m_physical_time = step == 0 ? m_initial_time : m_multi_buffer.get_time();

const amrex::Box& bx = m_3D_ba[0][0];

if (m_multi_laser.UseLaser()) {
AMREX_ALWAYS_ASSERT(!m_adaptive_time_step.m_do_adaptive_time_step);
}

m_physical_time = step == 0 ? m_initial_time : m_multi_buffer.get_time();

if (m_physical_time == std::numeric_limits<amrex::Real>::infinity()) {
if (step+1 <= m_max_step && !m_has_last_step) {
m_multi_buffer.put_time(m_physical_time);
}
break;
}
std::string str_dt {"0."};
queryWithParser(pph, "dt", str_dt);
constexpr int tag_time_step = 100; // Use an integer for the tag

if (str_dt != "adaptive") {
m_exe_dt = makeFunctionWithParser<1>(str_dt, m_parser_dt, {"t"});

if (step == 0) {
m_dt = m_exe_dt(m_physical_time);
} else {
MPI_Request recv_request;
MPI_Irecv(
&m_dt_pre,
1,
amrex::Real,
rank - 1,
tag_time_step,
amrex::ParallelDescriptor::m_comm,
&recv_request);
// You should later call MPI_Wait or MPI_Test to complete it
}

m_adaptive_time_step.CalculateFromDensity(m_physical_time, m_dt, m_multi_plasma);
m_dt = m_exe_dt(m_physical_time);

MPI_Request send_request;
MPI_Isend(
&m_dt,
1,
amrex::Real,
rank + 1,
tag_time_step,
amrex::ParallelDescriptor::m_comm,
&send_request);
// You should also wait or test this one
MPI_Wait(&recv_request, MPI_STATUS_IGNORE);
MPI_Wait(&send_request, MPI_STATUS_IGNORE);
m_max_time = std::copysign(m_max_time, m_dt);
}
else{
m_adaptive_time_step.CalculateFromDensity(m_physical_time, m_dt, m_multi_plasma);
}

amrex::Real next_time = 0.;
amrex::Real next_time = 0. ;

// adjust time step to reach max_time
if (m_physical_time == m_max_time) {
Expand Down Expand Up @@ -645,7 +678,7 @@ Hipace::SolveOneSlice (int islice, int step)

// Advance laser slice by 1 step using chi
// no MR for laser
m_multi_laser.AdvanceSlice(islice, m_fields, m_dt, step, m_3D_geom[0]);
m_multi_laser.AdvanceSlice(islice, m_fields, m_dt, m_dt_pre, step, m_3D_geom[0]);

if (islice-1 >= m_3D_geom[0].Domain().smallEnd(2)) {
m_multi_buffer.get_data(islice-1, m_multi_beam, m_multi_laser, WhichBeamSlice::Next);
Expand Down
15 changes: 9 additions & 6 deletions src/laser/MultiLaser.H
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,31 @@ public:
/** Wrapper function to advance a laser slice by 1 time step.
* \param[in] islice slice index
* \param[in] fields Field object
* \param[in] dt time step of the simulation
* \param[in] dt time step of the simulation of the current rank
* \param[in] step current iteration. Needed because step 0 needs a specific treatment.
* \param[in] geom_field_lev0 Geometry of the fields on MR level 0
* \param[in] dt_pre time step of the previous rank
*/
void AdvanceSlice (const int islice, const Fields& fields, amrex::Real dt, int step,
void AdvanceSlice (const int islice, const Fields& fields, const amrex::Real dt, const amrex::Real dt_pre, int step,
amrex::Geometry const& geom_field_lev0);

/** Advance a laser slice by 1 time step using a multigrid solver.
* The complex phase of the envelope is evaluated on-axis only, but can be generalized to everywhere.
*
* \param[in] dt time step of the simulation
* \param[in] dt time step of the simulation of the current rank
* \param[in] step current iteration. Needed because step 0 needs a specific treatment.
* \param[in] dt_pre time step of the previous rank
*/
void AdvanceSliceMG (amrex::Real dt, int step);
void AdvanceSliceMG (const amrex::Real dt, const amrex::Real dt_pre, int step);

/** Advance a laser slice by 1 time step using a FFT solver.
* The complex phase of the envelope is evaluated on-axis only.
*
* \param[in] dt time step of the simulation
* \param[in] dt time step of the simulation of the current rank
* \param[in] step current iteration. Needed because step 0 needs a specific treatment.
* \param[in] dt_pre time step of the previous rank
*/
void AdvanceSliceFFT (amrex::Real dt, int step);
void AdvanceSliceFFT (const amrex::Real dt, const amrex::Real dt_pre, int step);

/** Initialize 1 longitudinal slice of the laser, and store it in n00j00 (current time step)
* and nm1j00 (previous time step).
Expand Down
14 changes: 7 additions & 7 deletions src/laser/MultiLaser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ MultiLaser::InterpolateChi (const Fields& fields, amrex::Geometry const& geom_fi
}

void
MultiLaser::AdvanceSlice (const int islice, const Fields& fields, amrex::Real dt, int step,
MultiLaser::AdvanceSlice (const int islice, const Fields& fields,const amrex::Real dt, const amrex::Real dt_pre, int step,
amrex::Geometry const& geom_field_lev0)
{

Expand All @@ -426,16 +426,16 @@ MultiLaser::AdvanceSlice (const int islice, const Fields& fields, amrex::Real dt
InterpolateChi(fields, geom_field_lev0);

if (m_solver_type == "multigrid") {
AdvanceSliceMG(dt, step);
AdvanceSliceMG(dt, dt_pre, step);
} else if (m_solver_type == "fft") {
AdvanceSliceFFT(dt, step);
AdvanceSliceFFT(dt, dt_pre, step);
} else {
amrex::Abort("laser.solver_type must be fft or multigrid");
}
}

void
MultiLaser::AdvanceSliceMG (amrex::Real dt, int step)
MultiLaser::AdvanceSliceMG (const amrex::Real dt, const amrex::Real dt_pre, int step)
{

HIPACE_PROFILE("MultiLaser::AdvanceSliceMG()");
Expand Down Expand Up @@ -543,7 +543,7 @@ MultiLaser::AdvanceSliceMG (amrex::Real dt, int step)
using namespace WhichLaserSlice;
// Transverse Laplacian of real and imaginary parts of A_j^n-1
amrex::Real lapR, lapI;
if (step == 0) {
if (step == 0 || dt_pre!= dt) {
lapR = i>imin && i<imax && j>jmin && j<jmax ?
(arr(i+1, j, n00j00_r)+arr(i-1, j, n00j00_r)-2._rt*arr(i, j, n00j00_r))/(dx*dx) +
(arr(i, j+1, n00j00_r)+arr(i, j-1, n00j00_r)-2._rt*arr(i, j, n00j00_r))/(dy*dy) : 0._rt;
Expand All @@ -566,7 +566,7 @@ MultiLaser::AdvanceSliceMG (amrex::Real dt, int step)
acoeff_real_scalar + arr(i, j, chi) : acoeff_real_scalar;

Complex rhs;
if (step == 0) {
if (step == 0 || dt_pre!= dt) {
// First time step: non-centered push to go
// from step 0 to step 1 without knowing -1.
const Complex an00jp1 = arr(i, j, n00jp1_r) + I * arr(i, j, n00jp1_i);
Expand Down Expand Up @@ -615,7 +615,7 @@ MultiLaser::AdvanceSliceMG (amrex::Real dt, int step)
}

void
MultiLaser::AdvanceSliceFFT (const amrex::Real dt, int step)
MultiLaser::AdvanceSliceFFT (const amrex::Real dt, const amrex::Real dt_pre, int step)
{

HIPACE_PROFILE("MultiLaser::AdvanceSliceFFT()");
Expand Down
Loading