From 16d1ca457abaa8d057018b69adaa1c3b54d6f995 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Mon, 28 Jun 2021 16:09:04 -0700 Subject: Multi-J scheme (#1828) * Introduce new option skip_deposition * Properly implement the option to skip deposition * Skip deposition for electrostatic solver * Correct typo * Add Index Enumerator and Equations for F/G Without Averaging * Define new functions for current deposition and charge deposition * Disable interpolation between levels * Correct compilation error in RZ mode * Add argument for relative time * Add Index Enumerator and Equations for F/G With Averaging * [skip ci] Add new OneStep function * Fix compilation errors * Correct more compilation errors * [skip ci] Fix compilation * Split the PSATD push into separate functions * Add guards for rho field * [skip ci] Use new functions in OneStep * [skip ci] Separate the inverse transform of E_avg, B_avg * Add deposition of rho * [skip ci] Prevent deposition of rho if unallocated * Fix error in deposition function * Add subcycling of current deposition * [skip ci] Add inverse transform of averaged fields * [skip ci] Move component of rho * Add function to copy J * Temporarily deactivate contribution from F * [skip ci] Implement call to linear in J * Add psatd time averaging for multiJ * [skip ci] Fix implementation of averaging * [skip ci] Implement divE cleaning * Fix Bug for RZ Builds * Fix Bug for RZ Builds * Fix Bug in Init of PML Spectral Solvers * Cleaning * Cleaning * Add div(B) Cleaning (G Equation) * Multi-J Not Implemented with Galilean PSATD or PMLs * Add 2D CI Test Using Multi-J Scheme * Add More Inline Comments * Add More Inline Comments & Doxygen * Add Doxygen for Constructor of SpectralSolver * More Doxygen in Class SpectralSolver * Add Doxygen for New Functions in WarpXPushFieldsEM.cpp * Add Doxygen for New Functions in WarpX/MultiParticleContainer * do_dive/b_cleaning Must Be True With linear_in_J Option * Cast multij_n_depose to Real in Divisions * New Input Syntax * Add const where Possible, Fix Warnings * Docs for New Input Syntax, Fix Abort Messages * Consistent Use of Idx, IdxAvg, IdxLin * Improve Documentation of psatd.J_linear_in_time * Use const Type Qualifier whenever Possible * Simplify Initialization of Pointer ion_lev * Improve Doxygen * Update documentation * Add Note on NCI to Docs * Make warpx.do_multi_J_n_depositions Not Optional * Simplify Logic in getRequiredNumberOfFields * Use More const Type Qualifiers Co-authored-by: Edoardo Zoni --- Source/WarpX.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'Source/WarpX.cpp') diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index d4f9b5de1..a31c0c1e3 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -171,6 +171,9 @@ Real WarpX::self_fields_required_precision = 1.e-11_rt; int WarpX::self_fields_max_iters = 200; int WarpX::do_subcycling = 0; +int WarpX::do_multi_J = 0; +int WarpX::do_multi_J_n_depositions; +int WarpX::J_linear_in_time = 0; bool WarpX::safe_guard_cells = 0; IntVect WarpX::filter_npass_each_dir(1); @@ -447,6 +450,11 @@ WarpX::ReadParameters () pp_warpx.query("verbose", verbose); pp_warpx.query("regrid_int", regrid_int); pp_warpx.query("do_subcycling", do_subcycling); + pp_warpx.query("do_multi_J", do_multi_J); + if (do_multi_J) + { + pp_warpx.get("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", safe_guard_cells); std::vector override_sync_intervals_string_vec = {"1"}; @@ -616,12 +624,18 @@ WarpX::ReadParameters () pp_warpx.query("do_pml_j_damping", do_pml_j_damping); pp_warpx.query("do_pml_in_domain", do_pml_in_domain); + if (do_multi_J && do_pml) + { + amrex::Abort("Multi-J algorithm not implemented with PMLs"); + } + // div(E) cleaning not implemented for PSATD solver if (maxwell_solver_id == MaxwellSolverAlgo::PSATD) { - AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - do_dive_cleaning == 0, - "warpx.do_dive_cleaning = 1 not implemented for PSATD solver"); + if (do_multi_J == 0 && do_dive_cleaning == 1) + { + amrex::Abort("warpx.do_dive_cleaning = 1 not implemented for PSATD solver"); + } } // Default values of WarpX::do_pml_dive_cleaning and WarpX::do_pml_divb_cleaning: @@ -958,6 +972,7 @@ WarpX::ReadParameters () pp_psatd.query("current_correction", current_correction); pp_psatd.query("v_comoving", m_v_comoving); pp_psatd.query("do_time_averaging", fft_do_time_averaging); + pp_psatd.query("J_linear_in_time", J_linear_in_time); if (!fft_periodic_single_box && current_correction) amrex::Abort( @@ -1021,6 +1036,24 @@ WarpX::ReadParameters () "psatd.update_with_rho must be equal to 1 for comoving PSATD"); } + if (do_multi_J) + { + if (m_v_galilean[0] != 0. || m_v_galilean[1] != 0. || m_v_galilean[2] != 0.) + { + amrex::Abort("Multi-J algorithm not implemented with Galilean PSATD"); + } + } + + if (J_linear_in_time) + { + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(update_with_rho, + "psatd.update_with_rho must be set to 1 when psatd.J_linear_in_time = 1"); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(do_dive_cleaning, + "warpx.do_dive_cleaning must be set to 1 when psatd.J_linear_in_time = 1"); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(do_divb_cleaning, + "warpx.do_divb_cleaning must be set to 1 when psatd.J_linear_in_time = 1"); + } + constexpr int zdir = AMREX_SPACEDIM - 1; if (WarpX::field_boundary_lo[zdir] == FieldBoundaryType::Damped || WarpX::field_boundary_hi[zdir] == FieldBoundaryType::Damped ) { @@ -1776,6 +1809,9 @@ void WarpX::AllocLevelSpectralSolver (amrex::Vector(WarpX::do_multi_J_n_depositions); + auto pss = std::make_unique(lev, realspace_ba, dm, @@ -1786,11 +1822,12 @@ void WarpX::AllocLevelSpectralSolver (amrex::Vector