Skip to content

Commit 8537dc1

Browse files
Use lasers.lambda0 from openPMD file (#1320)
1 parent 5ef6bce commit 8537dc1

4 files changed

Lines changed: 57 additions & 20 deletions

File tree

docs/source/run/parameters.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,6 @@ Parameters starting with ``lasers.`` apply to all laser pulses, parameters start
924924
The names of the laser pulses, separated by a space.
925925
To run without a laser, choose the name ``no_laser``.
926926

927-
* ``lasers.lambda0`` (`float`)
928-
Wavelength of the laser pulses. Currently, all pulses must have the same wavelength.
929-
930927
* ``lasers.polarization`` (`linear` or `circular`) optional (default `linear`)
931928
Polarization of the laser pulse.
932929
For the same peak amplitude, the ponderomotive force is 2x larger in circular polarization than in linear polarization.
@@ -965,6 +962,9 @@ Parameters starting with ``lasers.`` apply to all laser pulses, parameters start
965962
* ``<laser name>.a0`` (`float`) optional (default `0`)
966963
Peak normalized vector potential of the laser pulse.
967964

965+
* ``lasers.lambda0`` (`float`)
966+
Wavelength of the laser pulses. Currently, all pulses must have the same wavelength.
967+
968968
* ``<laser name>.position_mean`` (3 `float`) optional (default `0 0 0`)
969969
The mean position of the laser in `x, y, z`.
970970

@@ -1017,6 +1017,11 @@ Parameters starting with ``lasers.`` apply to all laser pulses, parameters start
10171017
The laser pulse is injected in the HiPACE++ simulation so that the beginning of the temporal profile from the file corresponds to the head of the simulation box, and time (in the file) is converted to space (HiPACE++ longitudinal coordinate) with ``z = -c*t + const``.
10181018
If this parameter is set, then the file is used to initialize all lasers instead of using a gaussian profile.
10191019

1020+
* ``<laser name>.lambda0`` (`float`) optional (default `<read from file>`)
1021+
Wavelength of the laser pulses. Currently, all pulses must have the same wavelength.
1022+
The wavelength is already read in from the metadata of the openPMD file,
1023+
however it can be overwritten using this parameter.
1024+
10201025
* ``<laser name>.openPMD_laser_name`` (`string`) optional (default `laserEnvelope`)
10211026
Name of the laser envelope field inside the openPMD file to be read in.
10221027

@@ -1031,6 +1036,9 @@ Parameters starting with ``lasers.`` apply to all laser pulses, parameters start
10311036
* ``<laser name>.laser_imag(x,y,z)`` optional (`string`) (default `""`)
10321037
Expression for the imaginary part of the laser envelope `x, y, z`.
10331038

1039+
* ``lasers.lambda0`` (`float`)
1040+
Wavelength of the laser pulses. Currently, all pulses must have the same wavelength.
1041+
10341042
Diagnostic parameters
10351043
---------------------
10361044

src/laser/Laser.H

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public:
6767
int m_file_num_iteration = 0;
6868
/** Geometry of the laser file, 'rt' or 'xyt' */
6969
std::string m_file_geometry = "";
70-
/** Wavelength from file */
71-
amrex::Real m_lambda0_from_file {0.};
70+
/** central wavelength of the laser */
71+
amrex::Real m_init_lambda0 {0.};
7272
};
7373

7474
#endif // LASER_H_

src/laser/Laser.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ void
2828
Laser::ReadParameters (const amrex::Geometry& laser_geom_3D)
2929
{
3030
amrex::ParmParse pp(m_name);
31+
amrex::ParmParse pp_lasers("lasers");
32+
3133
queryWithParser(pp, "init_type", m_laser_init_type);
3234
if (m_laser_init_type == "from_file") {
3335
queryWithParser(pp, "input_file", m_input_file_path);
@@ -37,6 +39,23 @@ Laser::ReadParameters (const amrex::Geometry& laser_geom_3D)
3739
m_F_input_file.resize(laser_geom_3D.Domain(), 2, amrex::The_Pinned_Arena());
3840
GetEnvelopeFromFileHelper(laser_geom_3D);
3941
}
42+
43+
// m_init_lambda0 is only read by the HeadRank, so we need to communicate it
44+
#ifdef AMREX_USE_MPI
45+
MPI_Bcast(&m_init_lambda0,
46+
1,
47+
amrex::ParallelDescriptor::Mpi_typemap<decltype(m_init_lambda0)>::type(),
48+
Hipace::HeadRankID(),
49+
amrex::ParallelDescriptor::Communicator());
50+
#endif
51+
52+
if (m_init_lambda0 != 0.) {
53+
// lambda0 is read from input file, but it can be overwritten explicitly here
54+
queryWithParser(pp, "lambda0", m_init_lambda0);
55+
} else {
56+
// lambda0 not defined in file
57+
getWithParserAlt(pp, "lambda0", m_init_lambda0, pp_lasers);
58+
}
4059
return;
4160
}
4261
else if (m_laser_init_type == "gaussian") {
@@ -56,6 +75,7 @@ Laser::ReadParameters (const amrex::Geometry& laser_geom_3D)
5675
queryWithParser(pp, "zeta", m_zeta);
5776
queryWithParser(pp, "beta", m_beta);
5877
queryWithParser(pp, "phi2", m_phi2);
78+
getWithParser(pp_lasers, "lambda0", m_init_lambda0);
5979
return;
6080
}
6181
else if (m_laser_init_type == "parser") {
@@ -65,6 +85,7 @@ Laser::ReadParameters (const amrex::Geometry& laser_geom_3D)
6585
getWithParser(pp, "laser_imag(x,y,z)", profile_imag_str);
6686
m_profile_real = makeFunctionWithParser<3>( profile_real_str, m_parser_lr, {"x", "y", "z"});
6787
m_profile_imag = makeFunctionWithParser<3>( profile_imag_str, m_parser_li, {"x", "y", "z"});
88+
getWithParser(pp_lasers, "lambda0", m_init_lambda0);
6889
return;
6990
}
7091
else {
@@ -133,15 +154,10 @@ Laser::GetEnvelopeFromFileHelper (amrex::Geometry laser_geom_3D) {
133154
<< help_msg << '\n';
134155
}
135156

136-
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
137-
mesh.containsAttribute("angularFrequency"),
138-
"Could not find Attribute 'angularFrequency' of iteration "
139-
+ std::to_string(m_file_num_iteration) + " in file "
140-
+ m_input_file_path + "\n"
141-
);
142-
143-
m_lambda0_from_file = 2.*MathConst::pi*PhysConstSI::c
144-
/ mesh.getAttribute("angularFrequency").get<double>();
157+
if (mesh.containsAttribute("angularFrequency")) {
158+
m_init_lambda0 = 2.*MathConst::pi*PhysConstSI::c
159+
/ mesh.getAttribute("angularFrequency").get<double>();
160+
}
145161

146162
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
147163
mesh.contains(openPMD::RecordComponent::SCALAR),

src/laser/MultiLaser.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ MultiLaser::ReadParameters ()
3232
m_use_laser = m_names[0] != "no_laser";
3333

3434
if (!m_use_laser) return;
35-
queryWithParser(pp, "lambda0", m_lambda0);
3635
DeprecatedInput("lasers", "3d_on_host", "comms_buffer.on_gpu", "", true);
3736
std::string polarization = "linear";
3837
queryWithParser(pp, "polarization", polarization);
@@ -119,6 +118,25 @@ MultiLaser::MakeLaserGeometry (const amrex::Geometry& field_geom_3D)
119118
amrex::Print()<<"Laser "+ m_names[i] + " loaded" << "\n";
120119
}
121120

121+
if (m_nlasers > 0) {
122+
for (int i = 0; i < m_nlasers; ++i) {
123+
if (i == 0) {
124+
m_lambda0 = m_all_lasers[i].m_init_lambda0;
125+
} else {
126+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
127+
m_all_lasers[i].m_init_lambda0 == m_lambda0,
128+
"The central wavelength (lambda0) of all lasers must be identical. Note that "
129+
"for lasers read from an openPMD file, lambda0 is also read from the file.\n" +
130+
m_names[0] + " lambda0: " + amrex::ToString(m_lambda0) + "\n" +
131+
m_names[1] + " lambda0: " + amrex::ToString(m_all_lasers[i].m_init_lambda0) +
132+
"\ndifference: " + amrex::ToString(m_lambda0 - m_all_lasers[i].m_init_lambda0)
133+
);
134+
}
135+
}
136+
} else {
137+
getWithParser(pp, "lambda0", m_lambda0);
138+
}
139+
122140
m_slice_box = domain_3D_laser;
123141
m_slice_box.setSmall(2, 0);
124142
m_slice_box.setBig(2, 0);
@@ -855,11 +873,6 @@ MultiLaser::InitLaserSlice (const int islice, const int comp)
855873
arr(i, j, k, comp + 1 ) += arr_ff(i, j, islice, 1 );
856874
}
857875
);
858-
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(
859-
laser.m_lambda0_from_file == m_lambda0 && m_lambda0 != 0,
860-
"The central wavelength of laser from openPMD file and "
861-
"other lasers must be identical"
862-
);
863876
}
864877
if (laser.m_laser_init_type == "parser") {
865878
auto profile_real = laser.m_profile_real;

0 commit comments

Comments
 (0)