-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathWarpX.cpp
3365 lines (2954 loc) · 147 KB
/
WarpX.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright 2016-2020 Andrew Myers, Ann Almgren, Aurore Blelly
* Axel Huebl, Burlen Loring, David Grote
* Glenn Richardson, Jean-Luc Vay, Junmin Gu
* Mathieu Lobet, Maxence Thevenet, Michael Rowan
* Remi Lehe, Revathi Jambunathan, Weiqun Zhang
* Yinjian Zhao, levinem
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "WarpX.H"
#include "BoundaryConditions/PEC_Insulator.H"
#include "BoundaryConditions/PML.H"
#include "Diagnostics/MultiDiagnostics.H"
#include "Diagnostics/ReducedDiags/MultiReducedDiags.H"
#include "EmbeddedBoundary/Enabled.H"
#include "EmbeddedBoundary/WarpXFaceInfoBox.H"
#include "FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H"
#include "FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.H"
#include "FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.H"
#include "FieldSolver/ElectrostaticSolvers/EffectivePotentialES.H"
#include "FieldSolver/FiniteDifferenceSolver/FiniteDifferenceSolver.H"
#include "FieldSolver/FiniteDifferenceSolver/MacroscopicProperties/MacroscopicProperties.H"
#include "FieldSolver/FiniteDifferenceSolver/HybridPICModel/HybridPICModel.H"
#ifdef WARPX_USE_FFT
# include "FieldSolver/SpectralSolver/SpectralKSpace.H"
# ifdef WARPX_DIM_RZ
# include "FieldSolver/SpectralSolver/SpectralSolverRZ.H"
# include "BoundaryConditions/PML_RZ.H"
# else
# include "FieldSolver/SpectralSolver/SpectralSolver.H"
# endif // RZ ifdef
#endif // use PSATD ifdef
#include "FieldSolver/WarpX_FDTD.H"
#include "Filter/NCIGodfreyFilter.H"
#include "Initialization/ExternalField.H"
#include "Initialization/WarpXInit.H"
#include "Particles/MultiParticleContainer.H"
#include "Fluids/MultiFluidContainer.H"
#include "Fluids/WarpXFluidContainer.H"
#include "Particles/ParticleBoundaryBuffer.H"
#include "AcceleratorLattice/AcceleratorLattice.H"
#include "Utils/TextMsg.H"
#include "Utils/WarpXAlgorithmSelection.H"
#include "Utils/WarpXConst.H"
#include "Utils/WarpXProfilerWrapper.H"
#include "Utils/WarpXUtil.H"
#include "FieldSolver/ImplicitSolvers/ImplicitSolverLibrary.H"
#include <ablastr/math/FiniteDifference.H>
#include <ablastr/utils/SignalHandling.H>
#include <ablastr/warn_manager/WarnManager.H>
#ifdef AMREX_USE_SENSEI_INSITU
# include <AMReX_AmrMeshInSituBridge.H>
#endif
#include <AMReX_Array4.H>
#include <AMReX_BLassert.H>
#include <AMReX_Box.H>
#include <AMReX_BoxArray.H>
#include <AMReX_Dim3.H>
#ifdef AMREX_USE_EB
# include <AMReX_EBFabFactory.H>
# include <AMReX_EBSupport.H>
#endif
#include <AMReX_FArrayBox.H>
#include <AMReX_FabArray.H>
#include <AMReX_FabFactory.H>
#include <AMReX_Geometry.H>
#include <AMReX_GpuControl.H>
#include <AMReX_GpuDevice.H>
#include <AMReX_GpuLaunch.H>
#include <AMReX_GpuQualifiers.H>
#include <AMReX_IArrayBox.H>
#include <AMReX_LayoutData.H>
#include <AMReX_MFIter.H>
#include <AMReX_MakeType.H>
#include <AMReX_MultiFab.H>
#include <AMReX_ParallelDescriptor.H>
#include <AMReX_ParmParse.H>
#include <AMReX_Print.H>
#include <AMReX_Random.H>
#include <AMReX_SPACE.H>
#include <AMReX_iMultiFab.H>
#include <algorithm>
#include <cmath>
#include <limits>
#include <optional>
#include <random>
#include <stdexcept>
#include <string>
#include <utility>
using namespace amrex;
using warpx::fields::FieldType;
int WarpX::do_moving_window = 0;
int WarpX::start_moving_window_step = 0;
int WarpX::end_moving_window_step = -1;
int WarpX::moving_window_dir = -1;
Real WarpX::moving_window_v = std::numeric_limits<amrex::Real>::max();
bool WarpX::fft_do_time_averaging = false;
amrex::IntVect WarpX::m_fill_guards_fields = amrex::IntVect(0);
amrex::IntVect WarpX::m_fill_guards_current = amrex::IntVect(0);
Real WarpX::gamma_boost = 1._rt;
Real WarpX::beta_boost = 0._rt;
Vector<int> WarpX::boost_direction = {0,0,0};
bool WarpX::compute_max_step_from_btd = false;
Real WarpX::zmin_domain_boost_step_0 = 0._rt;
int WarpX::max_particle_its_in_implicit_scheme = 21;
ParticleReal WarpX::particle_tol_in_implicit_scheme = 1.e-10;
bool WarpX::do_dive_cleaning = false;
bool WarpX::do_divb_cleaning = false;
bool WarpX::do_single_precision_comms = false;
bool WarpX::do_shared_mem_charge_deposition = false;
bool WarpX::do_shared_mem_current_deposition = false;
#if defined(WARPX_DIM_3D)
amrex::IntVect WarpX::shared_tilesize(AMREX_D_DECL(6,6,8));
#elif (AMREX_SPACEDIM == 2)
amrex::IntVect WarpX::shared_tilesize(AMREX_D_DECL(14,14,0));
#else
//Have not experimented with good tilesize here because expect use case to be low
amrex::IntVect WarpX::shared_tilesize(AMREX_D_DECL(1,1,1));
#endif
int WarpX::shared_mem_current_tpb = 128;
int WarpX::n_rz_azimuthal_modes = 1;
int WarpX::ncomps = 1;
// This will be overwritten by setting nox = noy = noz = algo.particle_shape
int WarpX::nox = 0;
int WarpX::noy = 0;
int WarpX::noz = 0;
// Order of finite-order centering of fields (staggered to nodal)
int WarpX::field_centering_nox = 2;
int WarpX::field_centering_noy = 2;
int WarpX::field_centering_noz = 2;
// Order of finite-order centering of currents (nodal to staggered)
int WarpX::current_centering_nox = 2;
int WarpX::current_centering_noy = 2;
int WarpX::current_centering_noz = 2;
bool WarpX::use_fdtd_nci_corr = false;
bool WarpX::galerkin_interpolation = true;
bool WarpX::use_filter = true;
bool WarpX::use_kspace_filter = true;
bool WarpX::use_filter_compensation = false;
bool WarpX::serialize_initial_conditions = false;
bool WarpX::refine_plasma = false;
utils::parser::IntervalsParser WarpX::sort_intervals;
amrex::IntVect WarpX::sort_bin_size(AMREX_D_DECL(1,1,1));
#if defined(AMREX_USE_CUDA)
bool WarpX::sort_particles_for_deposition = true;
#else
bool WarpX::sort_particles_for_deposition = false;
#endif
amrex::IntVect WarpX::sort_idx_type(AMREX_D_DECL(0,0,0));
bool WarpX::do_dynamic_scheduling = true;
bool WarpX::do_multi_J = false;
int WarpX::do_multi_J_n_depositions;
IntVect WarpX::filter_npass_each_dir(1);
int WarpX::n_field_gather_buffer = -1;
int WarpX::n_current_deposition_buffer = -1;
amrex::IntVect m_rho_nodal_flag;
WarpX* WarpX::m_instance = nullptr;
namespace
{
[[nodiscard]] bool
isAnyBoundaryPML(
const amrex::Array<FieldBoundaryType,AMREX_SPACEDIM>& field_boundary_lo,
const amrex::Array<FieldBoundaryType,AMREX_SPACEDIM>& field_boundary_hi)
{
constexpr auto is_pml = [](const FieldBoundaryType fbt) {return (fbt == FieldBoundaryType::PML);};
const auto is_any_pml =
std::any_of(field_boundary_lo.begin(), field_boundary_lo.end(), is_pml) ||
std::any_of(field_boundary_hi.begin(), field_boundary_hi.end(), is_pml);
return is_any_pml;
}
/**
* \brief
* Set the dotMask container
*/
void SetDotMask( std::unique_ptr<amrex::iMultiFab>& field_dotMask,
ablastr::fields::ConstScalarField const& field,
amrex::Periodicity const& periodicity)
{
// Define the dot mask for this field_type needed to properly compute dotProduct()
// for field values that have shared locations on different MPI ranks
if (field_dotMask != nullptr) { return; }
const auto& this_ba = field->boxArray();
const auto tmp = amrex::MultiFab{
this_ba, field->DistributionMap(),
1, 0, amrex::MFInfo().SetAlloc(false)};
field_dotMask = tmp.OwnerMask(periodicity);
}
}
void WarpX::MakeWarpX ()
{
warpx::initialization::check_dims();
ReadMovingWindowParameters(
do_moving_window, start_moving_window_step, end_moving_window_step,
moving_window_dir, moving_window_v);
ConvertLabParamsToBoost();
ReadBCParams();
#ifdef WARPX_DIM_RZ
CheckGriddingForRZSpectral();
#endif
m_instance = new WarpX();
}
WarpX&
WarpX::GetInstance ()
{
if (!m_instance) {
MakeWarpX();
}
return *m_instance;
}
void
WarpX::ResetInstance ()
{
if (m_instance){
delete m_instance;
m_instance = nullptr;
}
}
void
WarpX::Finalize()
{
WarpX::ResetInstance();
}
WarpX::WarpX ()
{
warpx::initialization::initialize_warning_manager();
ReadParameters();
BackwardCompatibility();
if (EB::enabled()) { InitEB(); }
ablastr::utils::SignalHandling::InitSignalHandling();
// Geometry on all levels has been defined already.
// No valid BoxArray and DistributionMapping have been defined.
// But the arrays for them have been resized.
const int nlevs_max = maxLevel() + 1;
istep.resize(nlevs_max, 0);
nsubsteps.resize(nlevs_max, 1);
t_new.resize(nlevs_max, 0.0);
t_old.resize(nlevs_max, std::numeric_limits<Real>::lowest());
dt.resize(nlevs_max, std::numeric_limits<Real>::max());
mypc = std::make_unique<MultiParticleContainer>(this);
// Loop over species (particles and lasers)
// and set current injection position per species
if (do_moving_window){
const int n_containers = mypc->nContainers();
for (int i=0; i<n_containers; i++)
{
WarpXParticleContainer& pc = mypc->GetParticleContainer(i);
// Storing injection position for all species, regardless of whether
// they are continuously injected, since it makes looping over the
// elements of current_injection_position easier elsewhere in the code.
if (moving_window_v > 0._rt)
{
// Inject particles continuously from the right end of the box
pc.m_current_injection_position = geom[0].ProbHi(moving_window_dir);
}
else if (moving_window_v < 0._rt)
{
// Inject particles continuously from the left end of the box
pc.m_current_injection_position = geom[0].ProbLo(moving_window_dir);
}
}
}
// Particle Boundary Buffer (i.e., scraped particles on boundary)
m_particle_boundary_buffer = std::make_unique<ParticleBoundaryBuffer>();
// Fluid Container
if (do_fluid_species) {
myfl = std::make_unique<MultiFluidContainer>();
}
Efield_dotMask.resize(nlevs_max);
Bfield_dotMask.resize(nlevs_max);
Afield_dotMask.resize(nlevs_max);
phi_dotMask.resize(nlevs_max);
m_eb_update_E.resize(nlevs_max);
m_eb_update_B.resize(nlevs_max);
m_eb_reduce_particle_shape.resize(nlevs_max);
m_flag_info_face.resize(nlevs_max);
m_flag_ext_face.resize(nlevs_max);
m_borrowing.resize(nlevs_max);
// Create Electrostatic Solver object if needed
if ((WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame)
|| (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic))
{
m_electrostatic_solver = std::make_unique<LabFrameExplicitES>(nlevs_max);
}
// Initialize the effective potential electrostatic solver if required
else if (electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameEffectivePotential)
{
m_electrostatic_solver = std::make_unique<EffectivePotentialES>(nlevs_max);
}
else
{
m_electrostatic_solver = std::make_unique<RelativisticExplicitES>(nlevs_max);
}
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC)
{
// Create hybrid-PIC model object if needed
m_hybrid_pic_model = std::make_unique<HybridPICModel>();
}
current_buffer_masks.resize(nlevs_max);
gather_buffer_masks.resize(nlevs_max);
pml.resize(nlevs_max);
#if (defined WARPX_DIM_RZ) && (defined WARPX_USE_FFT)
pml_rz.resize(nlevs_max);
#endif
do_pml_Lo.resize(nlevs_max);
do_pml_Hi.resize(nlevs_max);
costs.resize(nlevs_max);
load_balance_efficiency.resize(nlevs_max);
m_field_factory.resize(nlevs_max);
if (m_em_solver_medium == MediumForEM::Macroscopic) {
// create object for macroscopic solver
m_macroscopic_properties = std::make_unique<MacroscopicProperties>();
}
// Set default values for particle and cell weights for costs update;
// Default values listed here for the case AMREX_USE_GPU are determined
// from single-GPU tests on Summit.
if (costs_heuristic_cells_wt<=0. && costs_heuristic_particles_wt<=0.
&& WarpX::load_balance_costs_update_algo==LoadBalanceCostsUpdateAlgo::Heuristic)
{
#ifdef AMREX_USE_GPU
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
switch (WarpX::nox)
{
case 1:
costs_heuristic_cells_wt = 0.575_rt;
costs_heuristic_particles_wt = 0.425_rt;
break;
case 2:
costs_heuristic_cells_wt = 0.405_rt;
costs_heuristic_particles_wt = 0.595_rt;
break;
case 3:
costs_heuristic_cells_wt = 0.250_rt;
costs_heuristic_particles_wt = 0.750_rt;
break;
case 4:
// this is only a guess
costs_heuristic_cells_wt = 0.200_rt;
costs_heuristic_particles_wt = 0.800_rt;
break;
}
} else { // FDTD
switch (WarpX::nox)
{
case 1:
costs_heuristic_cells_wt = 0.401_rt;
costs_heuristic_particles_wt = 0.599_rt;
break;
case 2:
costs_heuristic_cells_wt = 0.268_rt;
costs_heuristic_particles_wt = 0.732_rt;
break;
case 3:
costs_heuristic_cells_wt = 0.145_rt;
costs_heuristic_particles_wt = 0.855_rt;
break;
case 4:
// this is only a guess
costs_heuristic_cells_wt = 0.100_rt;
costs_heuristic_particles_wt = 0.900_rt;
break;
}
}
#else // CPU
costs_heuristic_cells_wt = 0.1_rt;
costs_heuristic_particles_wt = 0.9_rt;
#endif // AMREX_USE_GPU
}
// Allocate field solver objects
#ifdef WARPX_USE_FFT
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
spectral_solver_fp.resize(nlevs_max);
spectral_solver_cp.resize(nlevs_max);
}
#endif
if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) {
m_fdtd_solver_fp.resize(nlevs_max);
m_fdtd_solver_cp.resize(nlevs_max);
}
// NCI Godfrey filters can have different stencils
// at different levels (the stencil depends on c*dt/dz)
nci_godfrey_filter_exeybz.resize(nlevs_max);
nci_godfrey_filter_bxbyez.resize(nlevs_max);
// Sanity checks. Must be done after calling the MultiParticleContainer
// constructor, as it reads additional parameters
// (e.g., use_fdtd_nci_corr)
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
AMREX_ALWAYS_ASSERT(use_fdtd_nci_corr == 0);
AMREX_ALWAYS_ASSERT(m_do_subcycling == 0);
}
if (WarpX::current_deposition_algo != CurrentDepositionAlgo::Esirkepov) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
use_fdtd_nci_corr == 0,
"The NCI corrector should only be used with Esirkepov deposition");
}
m_accelerator_lattice.resize(nlevs_max);
}
WarpX::~WarpX ()
{
const int nlevs_max = maxLevel() +1;
for (int lev = 0; lev < nlevs_max; ++lev) {
ClearLevel(lev);
}
}
void
WarpX::ReadParameters ()
{
{
const ParmParse pp;// Traditionally, max_step and stop_time do not have prefix.
utils::parser::queryWithParser(pp, "max_step", max_step);
utils::parser::queryWithParser(pp, "stop_time", stop_time);
pp.query("authors", m_authors);
}
{
const ParmParse pp_amr("amr");
pp_amr.query("restart", restart_chkfile);
}
{
const ParmParse pp_algo("algo");
pp_algo.query_enum_sloppy("maxwell_solver", electromagnetic_solver_id, "-_");
if (electromagnetic_solver_id == ElectromagneticSolverAlgo::ECT && !EB::enabled()) {
throw std::runtime_error("ECP Solver requires to enable embedded boundaries at runtime.");
}
#ifdef WARPX_DIM_RZ
if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD)
{
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(Geom(0).ProbLo(0) == 0.,
"Lower bound of radial coordinate (prob_lo[0]) with RZ PSATD solver must be zero");
}
else
{
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(Geom(0).ProbLo(0) >= 0.,
"Lower bound of radial coordinate (prob_lo[0]) with RZ FDTD solver must be non-negative");
}
#endif
pp_algo.query_enum_sloppy("evolve_scheme", evolve_scheme, "-_");
}
{
ParmParse const pp_warpx("warpx");
std::vector<int> numprocs_in;
utils::parser::queryArrWithParser(
pp_warpx, "numprocs", numprocs_in, 0, AMREX_SPACEDIM);
if (not numprocs_in.empty()) {
#ifdef WARPX_DIM_RZ
if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(numprocs_in[0] == 1,
"Domain decomposition in RZ with spectral solvers works only along z direction");
}
#endif
WARPX_ALWAYS_ASSERT_WITH_MESSAGE
(numprocs_in.size() == AMREX_SPACEDIM,
"warpx.numprocs, if specified, must have AMREX_SPACEDIM numbers");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE
(ParallelDescriptor::NProcs() == AMREX_D_TERM(numprocs_in[0],
*numprocs_in[1],
*numprocs_in[2]),
"warpx.numprocs, if specified, its product must be equal to the number of processes");
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
numprocs[idim] = numprocs_in[idim];
}
}
using ablastr::utils::SignalHandling;
std::vector<std::string> signals_in;
pp_warpx.queryarr("break_signals", signals_in);
#if defined(__linux__) || defined(__APPLE__)
for (const std::string &str : signals_in) {
const int sig = SignalHandling::parseSignalNameToNumber(str);
SignalHandling::signal_conf_requests[SignalHandling::SIGNAL_REQUESTS_BREAK][sig] = true;
}
signals_in.clear();
#else
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(signals_in.empty(),
"Signal handling requested in input, but is not supported on this platform");
#endif
bool have_checkpoint_diagnostic = false;
const ParmParse pp("diagnostics");
std::vector<std::string> diags_names;
pp.queryarr("diags_names", diags_names);
for (const auto &diag : diags_names) {
const ParmParse dd(diag);
std::string format;
dd.query("format", format);
if (format == "checkpoint") {
have_checkpoint_diagnostic = true;
break;
}
}
pp_warpx.query("write_diagnostics_on_restart", write_diagnostics_on_restart);
pp_warpx.queryarr("checkpoint_signals", signals_in);
#if defined(__linux__) || defined(__APPLE__)
for (const std::string &str : signals_in) {
const int sig = SignalHandling::parseSignalNameToNumber(str);
SignalHandling::signal_conf_requests[SignalHandling::SIGNAL_REQUESTS_CHECKPOINT][sig] = true;
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(have_checkpoint_diagnostic,
"Signal handling was requested to checkpoint, but no checkpoint diagnostic is configured");
}
#else
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(signals_in.empty(),
"Signal handling requested in input, but is not supported on this platform");
#endif
// set random seed
std::string random_seed = "default";
pp_warpx.query("random_seed", random_seed);
if ( random_seed != "default" ) {
const unsigned long myproc_1 = ParallelDescriptor::MyProc() + 1;
if ( random_seed == "random" ) {
std::random_device rd;
std::uniform_int_distribution<int> dist(2, INT_MAX);
const unsigned long cpu_seed = myproc_1 * dist(rd);
const unsigned long gpu_seed = myproc_1 * dist(rd);
ResetRandomSeed(cpu_seed, gpu_seed);
} else if ( std::stoi(random_seed) > 0 ) {
const unsigned long nprocs = ParallelDescriptor::NProcs();
const unsigned long seed_long = std::stoul(random_seed);
const unsigned long cpu_seed = myproc_1 * seed_long;
const unsigned long gpu_seed = (myproc_1 + nprocs) * seed_long;
ResetRandomSeed(cpu_seed, gpu_seed);
} else {
WARPX_ABORT_WITH_MESSAGE(
"warpx.random_seed must be \"default\", \"random\" or an integer > 0.");
}
}
utils::parser::queryWithParser(pp_warpx, "cfl", cfl);
pp_warpx.query("verbose", verbose);
utils::parser::queryWithParser(pp_warpx, "regrid_int", regrid_int);
pp_warpx.query("do_subcycling", m_do_subcycling);
pp_warpx.query("do_multi_J", do_multi_J);
if (do_multi_J)
{
utils::parser::getWithParser(
pp_warpx, "do_multi_J_n_depositions", do_multi_J_n_depositions);
}
pp_warpx.query("use_hybrid_QED", use_hybrid_QED);
pp_warpx.query("safe_guard_cells", m_safe_guard_cells);
std::vector<std::string> override_sync_intervals_string_vec = {"1"};
pp_warpx.queryarr("override_sync_intervals", override_sync_intervals_string_vec);
override_sync_intervals =
utils::parser::IntervalsParser(override_sync_intervals_string_vec);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(m_do_subcycling != 1 || max_level <= 1,
"Subcycling method 1 only works for 2 levels.");
ReadBoostedFrameParameters(gamma_boost, beta_boost, boost_direction);
// queryWithParser returns 1 if argument zmax_plasma_to_compute_max_step is
// specified by the user, 0 otherwise.
if(auto temp = 0.0_rt; utils::parser::queryWithParser(pp_warpx, "zmax_plasma_to_compute_max_step",temp)){
m_zmax_plasma_to_compute_max_step = temp;
}
pp_warpx.query("compute_max_step_from_btd",
compute_max_step_from_btd);
if (do_moving_window) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
Geom(0).isPeriodic(moving_window_dir) == 0,
"The problem must be non-periodic in the moving window direction");
moving_window_x = geom[0].ProbLo(moving_window_dir);
}
m_p_ext_field_params = std::make_unique<ExternalFieldParams>(pp_warpx);
if (m_p_ext_field_params->B_ext_grid_type == ExternalFieldType::read_from_file ||
m_p_ext_field_params->E_ext_grid_type == ExternalFieldType::read_from_file){
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(max_level == 0,
"External field reading is not implemented for more than one level");
}
maxlevel_extEMfield_init = maxLevel();
pp_warpx.query("maxlevel_extEMfield_init", maxlevel_extEMfield_init);
pp_warpx.query_enum_sloppy("do_electrostatic", electrostatic_solver_id, "-_");
// if an electrostatic solver is used, set the Maxwell solver to None
if (electrostatic_solver_id != ElectrostaticSolverAlgo::None) {
electromagnetic_solver_id = ElectromagneticSolverAlgo::None;
}
pp_warpx.query_enum_sloppy("poisson_solver", poisson_solver_id, "-_");
#ifndef WARPX_DIM_3D
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
poisson_solver_id!=PoissonSolverAlgo::IntegratedGreenFunction,
"The FFT Poisson solver only works in 3D.");
#endif
#ifndef WARPX_USE_FFT
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
poisson_solver_id!=PoissonSolverAlgo::IntegratedGreenFunction,
"To use the FFT Poisson solver, compile with WARPX_USE_FFT=ON.");
#endif
utils::parser::queryWithParser(pp_warpx, "self_fields_max_iters", magnetostatic_solver_max_iters);
utils::parser::queryWithParser(pp_warpx, "self_fields_verbosity", magnetostatic_solver_verbosity);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
(
electrostatic_solver_id!=ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic ||
poisson_solver_id!=PoissonSolverAlgo::IntegratedGreenFunction
),
"The FFT Poisson solver is not implemented in labframe-electromagnetostatic mode yet."
);
[[maybe_unused]] bool const eb_enabled = EB::enabled();
#if !defined(AMREX_USE_EB)
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
!eb_enabled,
"Embedded boundaries are requested via warpx.eb_enabled but were not compiled!"
);
#endif
#ifdef WARPX_DIM_RZ
const ParmParse pp_boundary("boundary");
pp_boundary.query("verboncoeur_axis_correction", m_verboncoeur_axis_correction);
#endif
// Read timestepping options
utils::parser::queryWithParser(pp_warpx, "const_dt", m_const_dt);
utils::parser::queryWithParser(pp_warpx, "max_dt", m_max_dt);
std::vector<std::string> dt_interval_vec = {"-1"};
pp_warpx.queryarr("dt_update_interval", dt_interval_vec);
m_dt_update_interval = utils::parser::IntervalsParser(dt_interval_vec);
// Filter defaults to true for the explicit scheme, and false for the implicit schemes
if (evolve_scheme != EvolveScheme::Explicit) {
use_filter = false;
}
// Filter currently not working with FDTD solver in RZ geometry: turn OFF by default
// (see https://github.com/ECP-WarpX/WarpX/issues/1943)
#ifdef WARPX_DIM_RZ
if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD) { WarpX::use_filter = false; }
#endif
// Read filter and fill IntVect filter_npass_each_dir with
// proper size for AMREX_SPACEDIM
pp_warpx.query("use_filter", use_filter);
pp_warpx.query("use_filter_compensation", use_filter_compensation);
Vector<int> parse_filter_npass_each_dir(AMREX_SPACEDIM,1);
utils::parser::queryArrWithParser(
pp_warpx, "filter_npass_each_dir", parse_filter_npass_each_dir, 0, AMREX_SPACEDIM);
filter_npass_each_dir[0] = parse_filter_npass_each_dir[0];
#if (AMREX_SPACEDIM >= 2)
filter_npass_each_dir[1] = parse_filter_npass_each_dir[1];
#endif
#if defined(WARPX_DIM_3D)
filter_npass_each_dir[2] = parse_filter_npass_each_dir[2];
#endif
// TODO When k-space filtering will be implemented also for Cartesian geometries,
// this code block will have to be applied in all cases (remove #ifdef condition)
#ifdef WARPX_DIM_RZ
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) {
// With RZ spectral, only use k-space filtering
use_kspace_filter = use_filter;
use_filter = false;
}
else
{
if (WarpX::electromagnetic_solver_id != ElectromagneticSolverAlgo::HybridPIC) {
// Filter currently not working with FDTD solver in RZ geometry along R
// (see https://github.com/ECP-WarpX/WarpX/issues/1943)
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(!use_filter || filter_npass_each_dir[0] == 0,
"In RZ geometry with FDTD, filtering can only be applied along z. This can be controlled by setting warpx.filter_npass_each_dir");
} else {
if (use_filter && filter_npass_each_dir[0] > 0) {
ablastr::warn_manager::WMRecordWarning(
"HybridPIC ElectromagneticSolver",
"Radial Filtering in RZ is not currently using radial geometric weighting to conserve charge. Use at your own risk.",
ablastr::warn_manager::WarnPriority::low
);
}
}
}
#endif
utils::parser::queryWithParser(
pp_warpx, "num_mirrors", m_num_mirrors);
if (m_num_mirrors>0){
m_mirror_z.resize(m_num_mirrors);
utils::parser::getArrWithParser(
pp_warpx, "mirror_z", m_mirror_z, 0, m_num_mirrors);
m_mirror_z_width.resize(m_num_mirrors);
utils::parser::getArrWithParser(
pp_warpx, "mirror_z_width", m_mirror_z_width, 0, m_num_mirrors);
m_mirror_z_npoints.resize(m_num_mirrors);
utils::parser::getArrWithParser(
pp_warpx, "mirror_z_npoints", m_mirror_z_npoints, 0, m_num_mirrors);
}
pp_warpx.query("do_single_precision_comms", do_single_precision_comms);
#ifdef AMREX_USE_FLOAT
if (do_single_precision_comms) {
do_single_precision_comms = false;
ablastr::warn_manager::WMRecordWarning(
"comms",
"Overwrote warpx.do_single_precision_comms to be 0, since WarpX was built in single precision.",
ablastr::warn_manager::WarnPriority::low);
}
#endif
pp_warpx.query("do_shared_mem_charge_deposition", do_shared_mem_charge_deposition);
pp_warpx.query("do_shared_mem_current_deposition", do_shared_mem_current_deposition);
#if !(defined(AMREX_USE_HIP) || defined(AMREX_USE_CUDA))
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(!do_shared_mem_current_deposition,
"requested shared memory for current deposition, but shared memory is only available for CUDA or HIP");
#endif
pp_warpx.query("shared_mem_current_tpb", shared_mem_current_tpb);
// initialize the shared tilesize
Vector<int> vect_shared_tilesize(AMREX_SPACEDIM, 1);
const bool shared_tilesize_is_specified = utils::parser::queryArrWithParser(pp_warpx, "shared_tilesize",
vect_shared_tilesize, 0, AMREX_SPACEDIM);
if (shared_tilesize_is_specified){
for (int i=0; i<AMREX_SPACEDIM; i++) {
shared_tilesize[i] = vect_shared_tilesize[i];
}
}
pp_warpx.query("serialize_initial_conditions", serialize_initial_conditions);
pp_warpx.query("refine_plasma", refine_plasma);
pp_warpx.query("do_dive_cleaning", do_dive_cleaning);
pp_warpx.query("do_divb_cleaning", do_divb_cleaning);
utils::parser::queryWithParser(
pp_warpx, "n_field_gather_buffer", n_field_gather_buffer);
utils::parser::queryWithParser(
pp_warpx, "n_current_deposition_buffer", n_current_deposition_buffer);
//Default value for the quantum parameter used in Maxwell’s QED equations
m_quantum_xi_c2 = PhysConst::xi_c2;
amrex::Real quantum_xi_tmp;
const auto quantum_xi_is_specified =
utils::parser::queryWithParser(pp_warpx, "quantum_xi", quantum_xi_tmp);
if (quantum_xi_is_specified) {
double const quantum_xi = quantum_xi_tmp;
m_quantum_xi_c2 = static_cast<amrex::Real>(quantum_xi * PhysConst::c * PhysConst::c);
}
const auto at_least_one_boundary_is_pml =
(std::any_of(WarpX::field_boundary_lo.begin(), WarpX::field_boundary_lo.end(),
[](const auto& cc){return cc == FieldBoundaryType::PML;})
||
std::any_of(WarpX::field_boundary_hi.begin(), WarpX::field_boundary_hi.end(),
[](const auto& cc){return cc == FieldBoundaryType::PML;})
);
const auto at_least_one_boundary_is_silver_mueller =
(std::any_of(WarpX::field_boundary_lo.begin(), WarpX::field_boundary_lo.end(),
[](const auto& cc){return cc == FieldBoundaryType::Absorbing_SilverMueller;})
||
std::any_of(WarpX::field_boundary_hi.begin(), WarpX::field_boundary_hi.end(),
[](const auto& cc){return cc == FieldBoundaryType::Absorbing_SilverMueller;})
);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
!(at_least_one_boundary_is_pml && at_least_one_boundary_is_silver_mueller),
"PML and Silver-Mueller boundary conditions cannot be activated at the same time.");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
(!at_least_one_boundary_is_silver_mueller) ||
(electromagnetic_solver_id == ElectromagneticSolverAlgo::Yee),
"The Silver-Mueller boundary condition can only be used with the Yee solver.");
utils::parser::queryWithParser(pp_warpx, "pml_ncell", pml_ncell);
utils::parser::queryWithParser(pp_warpx, "pml_delta", pml_delta);
pp_warpx.query("pml_has_particles", pml_has_particles);
pp_warpx.query("do_pml_j_damping", do_pml_j_damping);
pp_warpx.query("do_pml_in_domain", do_pml_in_domain);
pp_warpx.query("do_similar_dm_pml", do_similar_dm_pml);
// Read `v_particle_pml` in units of the speed of light
v_particle_pml = 1._rt;
utils::parser::queryWithParser(pp_warpx, "v_particle_pml", v_particle_pml);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(0._rt < v_particle_pml && v_particle_pml <= 1._rt,
"Input value for the velocity warpx.v_particle_pml of the macroparticle must be in (0,1] (in units of c).");
// Scale by the speed of light
v_particle_pml = v_particle_pml * PhysConst::c;
// Default values of WarpX::do_pml_dive_cleaning and WarpX::do_pml_divb_cleaning:
// true for Cartesian PSATD solver, false otherwise
do_pml_dive_cleaning = false;
do_pml_divb_cleaning = false;
#ifndef WARPX_DIM_RZ
if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD)
{
do_pml_dive_cleaning = true;
do_pml_divb_cleaning = true;
}
// If WarpX::do_dive_cleaning = true, set also WarpX::do_pml_dive_cleaning = true
// (possibly overwritten by users in the input file, see query below)
if (do_dive_cleaning) { do_pml_dive_cleaning = true; }
// If WarpX::do_divb_cleaning = true, set also WarpX::do_pml_divb_cleaning = true
// (possibly overwritten by users in the input file, see query below)
// TODO Implement div(B) cleaning in PML with FDTD and remove second if condition
if (do_divb_cleaning && electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD) { do_pml_divb_cleaning = true; }
#endif
// Query input parameters to use div(E) and div(B) cleaning in PMLs
pp_warpx.query("do_pml_dive_cleaning", do_pml_dive_cleaning);
pp_warpx.query("do_pml_divb_cleaning", do_pml_divb_cleaning);
// TODO Implement div(B) cleaning in PML with FDTD and remove ASSERT
if (electromagnetic_solver_id != ElectromagneticSolverAlgo::PSATD)
{
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
do_pml_divb_cleaning == false,
"warpx.do_pml_divb_cleaning = true not implemented for FDTD solver");
}
// Divergence cleaning in PMLs for PSATD solver implemented only
// for both div(E) and div(B) cleaning
if (electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD)
{
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
do_pml_dive_cleaning == do_pml_divb_cleaning,
"warpx.do_pml_dive_cleaning = "
+ std::to_string(do_pml_dive_cleaning)
+" and warpx.do_pml_divb_cleaning = "
+ std::to_string(do_pml_divb_cleaning)
+ ": this case is not implemented yet,"
+ " please set both parameters to the same value"
);
}
#ifdef WARPX_DIM_RZ
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( ::isAnyBoundaryPML(field_boundary_lo, field_boundary_hi) == false || electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD,
"PML are not implemented in RZ geometry with FDTD; please set a different boundary condition using boundary.field_lo and boundary.field_hi.");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( field_boundary_lo[1] != FieldBoundaryType::PML && field_boundary_hi[1] != FieldBoundaryType::PML,
"PML are not implemented in RZ geometry along z; please set a different boundary condition using boundary.field_lo and boundary.field_hi.");
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( (do_pml_dive_cleaning == false && do_pml_divb_cleaning == false),
"do_pml_dive_cleaning and do_pml_divb_cleaning are not implemented in RZ geometry." );
#endif
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
(do_pml_j_damping==0)||(do_pml_in_domain==1),
"J-damping can only be done when PML are inside simulation domain (do_pml_in_domain=1)"
);
pp_warpx.query("synchronize_velocity_for_diagnostics", synchronize_velocity_for_diagnostics);
{
// Parameters below control all plotfile diagnostics
bool plotfile_min_max = true;
pp_warpx.query("plotfile_min_max", plotfile_min_max);
if (plotfile_min_max) {
plotfile_headerversion = amrex::VisMF::Header::Version_v1;
} else {
plotfile_headerversion = amrex::VisMF::Header::NoFabHeader_v1;
}
pp_warpx.query("usesingleread", use_single_read);
pp_warpx.query("usesinglewrite", use_single_write);
ParmParse pp_vismf("vismf");
pp_vismf.add("usesingleread", use_single_read);
pp_vismf.add("usesinglewrite", use_single_write);
utils::parser::queryWithParser(pp_warpx, "mffile_nstreams", mffile_nstreams);
VisMF::SetMFFileInStreams(mffile_nstreams);
utils::parser::queryWithParser(pp_warpx, "field_io_nfiles", field_io_nfiles);
VisMF::SetNOutFiles(field_io_nfiles);
utils::parser::queryWithParser(pp_warpx, "particle_io_nfiles", particle_io_nfiles);
ParmParse pp_particles("particles");
pp_particles.add("particles_nfiles", particle_io_nfiles);
}
if (maxLevel() > 0) {
Vector<Real> lo, hi;
const bool fine_tag_lo_specified = utils::parser::queryArrWithParser(pp_warpx, "fine_tag_lo", lo);
const bool fine_tag_hi_specified = utils::parser::queryArrWithParser(pp_warpx, "fine_tag_hi", hi);
std::string ref_patch_function;
const bool parser_specified = pp_warpx.query("ref_patch_function(x,y,z)",ref_patch_function);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( ((fine_tag_lo_specified && fine_tag_hi_specified) ||
parser_specified ),
"For max_level > 0, you need to either set\
warpx.fine_tag_lo and warpx.fine_tag_hi\
or warpx.ref_patch_function(x,y,z)");
if ( (fine_tag_lo_specified && fine_tag_hi_specified) && parser_specified) {
ablastr::warn_manager::WMRecordWarning("Refined patch", "Both fine_tag_lo,fine_tag_hi\
and ref_patch_function(x,y,z) are provided. Note that fine_tag_lo/fine_tag_hi will\
override the ref_patch_function(x,y,z) for defining the refinement patches");
}
if (fine_tag_lo_specified && fine_tag_hi_specified) {
fine_tag_lo = RealVect{lo};
fine_tag_hi = RealVect{hi};
} else {
utils::parser::Store_parserString(pp_warpx, "ref_patch_function(x,y,z)", ref_patch_function);
ref_patch_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(ref_patch_function,{"x","y","z"}));
}
}
pp_warpx.query("do_dynamic_scheduling", do_dynamic_scheduling);
// Integer that corresponds to the type of grid used in the simulation
// (collocated, staggered, hybrid)
pp_warpx.query_enum_sloppy("grid_type", grid_type, "-_");
// Use same shape factors in all directions, for gathering
if (grid_type == GridType::Collocated) { galerkin_interpolation = false; }
#ifdef WARPX_DIM_RZ
// Only needs to be set with WARPX_DIM_RZ, otherwise defaults to 1
utils::parser::queryWithParser(pp_warpx, "n_rz_azimuthal_modes", n_rz_azimuthal_modes);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE( n_rz_azimuthal_modes > 0,
"The number of azimuthal modes (n_rz_azimuthal_modes) must be at least 1");
#endif
// Check whether fluid species will be used
{
const ParmParse pp_fluids("fluids");
std::vector<std::string> fluid_species_names = {};