From be77c7680409cf7654dc492129ad1413e781c906 Mon Sep 17 00:00:00 2001 From: Justin Ray Angus Date: Mon, 25 Nov 2024 15:27:03 -0800 Subject: [PATCH] Setting laser particle positions to be time-centered for implicit solvers (#5485) The current deposition schemes expect the particle positions to be time-centered when using the implicit solvers. This is not currently the case for the laser particles. This PR fixes this issue. It should be commented that there is really no need for the current deposition schemes to expect the particle positions to be time centered for the implicit solvers. This is somewhat of a legacy thing from PICNIC. This can and should be changed in a future PR. Here are results of Ey generated from the analysis script for the 1D CI test using the semi-implicit method: ![plt_Ey](https://github.com/user-attachments/assets/6c925872-66e0-4d7c-85ac-94800d49c71d) Here are results of Ey generated from the analysis script for the 2D CI test using the semi-implicit method: ![plt_Ey](https://github.com/user-attachments/assets/32813bba-1074-4beb-85f8-da9289436c32) Here are results generated from the analysis script for the 3D CI test using the semi-implicit method: ![laser_analysis](https://github.com/user-attachments/assets/0e3a8505-a039-4e79-99d1-496ff23cd498) --- Examples/Tests/laser_injection/CMakeLists.txt | 20 +++++ .../inputs_test_1d_laser_injection_implicit | 79 +++++++++++++++++++ .../inputs_test_2d_laser_injection_implicit | 75 ++++++++++++++++++ .../test_1d_laser_injection_implicit.json | 13 +++ .../test_2d_laser_injection_implicit.json | 13 +++ Source/Particles/LaserParticleContainer.cpp | 24 ++++-- 6 files changed, 216 insertions(+), 8 deletions(-) create mode 100644 Examples/Tests/laser_injection/inputs_test_1d_laser_injection_implicit create mode 100644 Examples/Tests/laser_injection/inputs_test_2d_laser_injection_implicit create mode 100644 Regression/Checksum/benchmarks_json/test_1d_laser_injection_implicit.json create mode 100644 Regression/Checksum/benchmarks_json/test_2d_laser_injection_implicit.json diff --git a/Examples/Tests/laser_injection/CMakeLists.txt b/Examples/Tests/laser_injection/CMakeLists.txt index cec027deb70..a15075bb43e 100644 --- a/Examples/Tests/laser_injection/CMakeLists.txt +++ b/Examples/Tests/laser_injection/CMakeLists.txt @@ -30,3 +30,23 @@ add_warpx_test( diags/diag1000020 # output OFF # dependency ) + +add_warpx_test( + test_1d_laser_injection_implicit # name + 1 # dims + 2 # nprocs + inputs_test_1d_laser_injection_implicit # inputs + analysis_1d.py # analysis + diags/diag1000240 # output + OFF # dependency +) + +add_warpx_test( + test_2d_laser_injection_implicit # name + 2 # dims + 2 # nprocs + inputs_test_2d_laser_injection_implicit # inputs + analysis_2d.py # analysis + diags/diag1000240 # output + OFF # dependency +) diff --git a/Examples/Tests/laser_injection/inputs_test_1d_laser_injection_implicit b/Examples/Tests/laser_injection/inputs_test_1d_laser_injection_implicit new file mode 100644 index 00000000000..758e2cebaa1 --- /dev/null +++ b/Examples/Tests/laser_injection/inputs_test_1d_laser_injection_implicit @@ -0,0 +1,79 @@ +# Maximum number of time steps +max_step = 240 + +# number of grid points +amr.n_cell = 352 + +# Maximum allowable size of each subdomain in the problem domain; +# this is used to decompose the domain for parallel calculations. +amr.max_grid_size = 32 + +# Maximum level in hierarchy (for now must be 0, i.e., one level in total) +amr.max_level = 0 + +# Geometry +geometry.dims = 1 +geometry.prob_lo = -15.e-6 # physical domain +geometry.prob_hi = 15.e-6 + +boundary.field_lo = pec +boundary.field_hi = pec + +warpx.serialize_initial_conditions = 1 + +# Verbosity +warpx.verbose = 1 + +# Algorithms +algo.current_deposition = esirkepov +warpx.use_filter = 0 + +# implicit evolve scheme +algo.evolve_scheme = "semi_implicit_em" +# +implicit_evolve.nonlinear_solver = "newton" +newton.verbose = true +newton.max_iterations = 21 +newton.relative_tolerance = 1.0e-8 +newton.require_convergence = true +# +gmres.verbose_int = 2 +gmres.max_iterations = 1000 +gmres.relative_tolerance = 1.0e-4 + +# CFL +warpx.cfl = 0.9 + +# Order of particle shape factors +algo.particle_shape = 1 + +# Laser +lasers.names = laser1 +laser1.profile = Gaussian +laser1.position = 0.e-6 0.e-6 0.e-6 # This point is on the laser plane +laser1.direction = 0. 0. 1. # The plane normal direction +laser1.polarization = 1. 1. 0. # The main polarization vector +laser1.e_max = 4.e12 # Maximum amplitude of the laser field (in V/m) +laser1.wavelength = 1.0e-6 # The wavelength of the laser (in meters) +laser1.profile_waist = 5.e-6 # The waist of the laser (in meters) +laser1.profile_duration = 10.e-15 # The duration of the laser (in seconds) +laser1.profile_t_peak = 24.e-15 # The time at which the laser reaches its peak (in seconds) +laser1.profile_focal_distance = 13.109e-6 # Focal distance from the antenna (in meters) + # With this focal distance the laser is at focus + # at the end of the simulation. + +# Diagnostics +diagnostics.diags_names = diag1 openpmd +diag1.intervals = 20 +diag1.diag_type = Full + +openpmd.intervals = 20 +openpmd.diag_type = Full +openpmd.format = openpmd + +# Moving window +warpx.do_moving_window = 1 +warpx.moving_window_dir = z +warpx.moving_window_v = 1.0 # in units of the speed of light +warpx.start_moving_window_step = 20 +warpx.end_moving_window_step = 200 diff --git a/Examples/Tests/laser_injection/inputs_test_2d_laser_injection_implicit b/Examples/Tests/laser_injection/inputs_test_2d_laser_injection_implicit new file mode 100644 index 00000000000..be6a704b171 --- /dev/null +++ b/Examples/Tests/laser_injection/inputs_test_2d_laser_injection_implicit @@ -0,0 +1,75 @@ +# Maximum number of time steps +max_step = 240 + +# number of grid points +amr.n_cell = 480 352 + +# Maximum allowable size of each subdomain in the problem domain; +# this is used to decompose the domain for parallel calculations. +amr.max_grid_size = 32 + +# Maximum level in hierarchy (for now must be 0, i.e., one level in total) +amr.max_level = 0 + +# Geometry +geometry.dims = 2 +geometry.prob_lo = -20.e-6 -15.e-6 # physical domain +geometry.prob_hi = 20.e-6 15.e-6 + +boundary.field_lo = pec periodic +boundary.field_hi = pec periodic + +warpx.serialize_initial_conditions = 1 + +# Verbosity +warpx.verbose = 1 + +# Algorithms +algo.current_deposition = esirkepov +warpx.use_filter = 0 + +# implicit evolve scheme +algo.evolve_scheme = "semi_implicit_em" +# +implicit_evolve.nonlinear_solver = "newton" +newton.verbose = true +newton.max_iterations = 21 +newton.relative_tolerance = 1.0e-8 +newton.require_convergence = true +# +gmres.verbose_int = 2 +gmres.max_iterations = 1000 +gmres.relative_tolerance = 1.0e-4 + +# CFL +warpx.cfl = 1.0 + +# Order of particle shape factors +algo.particle_shape = 1 + +# Laser +lasers.names = laser1 +laser1.profile = Gaussian +laser1.position = 10.e-6 0.e-6 0.e-6 # This point is on the laser plane +laser1.direction = 2. 0. 1. # The plane normal direction +laser1.polarization = 1. 1. -2. # The main polarization vector +laser1.e_max = 4.e12 # Maximum amplitude of the laser field (in V/m) +laser1.wavelength = 1.0e-6 # The wavelength of the laser (in meters) +laser1.profile_waist = 5.e-6 # The waist of the laser (in meters) +laser1.profile_duration = 10.e-15 # The duration of the laser (in seconds) +laser1.profile_t_peak = 24.e-15 # The time at which the laser reaches its peak (in seconds) +laser1.profile_focal_distance = 13.109e-6 # Focal distance from the antenna (in meters) + # With this focal distance the laser is at focus + # at the end of the simulation. + +# Diagnostics +diagnostics.diags_names = diag1 +diag1.intervals = 240 +diag1.diag_type = Full + +# Moving window +warpx.do_moving_window = 1 +warpx.moving_window_dir = x +warpx.moving_window_v = 1.0 # in units of the speed of light +warpx.start_moving_window_step = 20 +warpx.end_moving_window_step = 200 diff --git a/Regression/Checksum/benchmarks_json/test_1d_laser_injection_implicit.json b/Regression/Checksum/benchmarks_json/test_1d_laser_injection_implicit.json new file mode 100644 index 00000000000..a89d6ccc2d4 --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_1d_laser_injection_implicit.json @@ -0,0 +1,13 @@ +{ + "lev=0": { + "Bx": 374596.7817425552, + "By": 374596.7817425552, + "Bz": 0.0, + "Ex": 111502789524279.0, + "Ey": 111502789524279.0, + "Ez": 0.0, + "jx": 73098054407.2772, + "jy": 73098054407.2772, + "jz": 0.0 + } +} diff --git a/Regression/Checksum/benchmarks_json/test_2d_laser_injection_implicit.json b/Regression/Checksum/benchmarks_json/test_2d_laser_injection_implicit.json new file mode 100644 index 00000000000..b77b951e92a --- /dev/null +++ b/Regression/Checksum/benchmarks_json/test_2d_laser_injection_implicit.json @@ -0,0 +1,13 @@ +{ + "lev=0": { + "Bx": 19699314.38858362, + "By": 101297372.8536657, + "Bz": 39796093.072294116, + "Ex": 1.3881256464656438e+16, + "Ey": 1.322100107139857e+16, + "Ez": 2.6833518029118908e+16, + "jx": 3.669364941403736e+16, + "jy": 3.669364586262695e+16, + "jz": 7.338729883115621e+16 + } +} diff --git a/Source/Particles/LaserParticleContainer.cpp b/Source/Particles/LaserParticleContainer.cpp index c804bb12797..1954b822084 100644 --- a/Source/Particles/LaserParticleContainer.cpp +++ b/Source/Particles/LaserParticleContainer.cpp @@ -917,11 +917,13 @@ LaserParticleContainer::update_laser_particle (WarpXParIter& pti, puyp[i] = gamma * vy; puzp[i] = gamma * vz; - // Push the the particle positions + // Push the particle positions // When using the implicit solver, this function is called multiple times per timestep // (within the linear and nonlinear solver). Thus, the position of the particles needs to be reset - // to the initial position (at the beginning of the timestep), before updating the particle position + // to the initial position (at the beginning of the timestep), before updating the particle position. + // Also, the current deposition schemes expect the particle positions to be time centered + // (cur_time + 0.5*dt) for PushType::Implicit. ParticleReal x=0., y=0., z=0.; if (push_type == PushType::Explicit) { @@ -930,20 +932,26 @@ LaserParticleContainer::update_laser_particle (WarpXParIter& pti, #if !defined(WARPX_DIM_1D_Z) if (push_type == PushType::Implicit) { - x = x_n[i]; + x = x_n[i] + vx * dt*0.5_prt; + } + else { + x += vx * dt; } - x += vx * dt; #endif #if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ) if (push_type == PushType::Implicit) { - y = y_n[i]; + y = y_n[i] + vy * dt*0.5_prt; + } + else { + y += vy * dt; } - y += vy * dt; #endif if (push_type == PushType::Implicit) { - z = z_n[i]; + z = z_n[i] + vz * dt*0.5_prt; + } + else { + z += vz * dt; } - z += vz * dt; SetPosition(i, x, y, z); }