From bdef308e6c5b4aeed8190b6ecdb25b00a51ca5f9 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 6 Nov 2019 16:22:41 -0800 Subject: Implement space-charge initialization (non-relativistic, single-level) --- Source/Particles/PhysicalParticleContainer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 51690d659..6c2aef8a6 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -41,6 +41,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("split_type", split_type); pp.query("do_continuous_injection", do_continuous_injection); + pp.query("initialize_self_fields", initialize_self_fields); // Whether to plot back-transformed (lab-frame) diagnostics // for this species. pp.query("do_back_transformed_diagnostics", do_back_transformed_diagnostics); -- cgit v1.2.3 From 6f74a7ac262c26a276fe4b818ceb1e8ca26e5575 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 15 Nov 2019 11:22:50 -0800 Subject: Add option to set relative precision --- Docs/source/running_cpp/parameters.rst | 8 ++++++++ Examples/Modules/relativistic_space_charge_initialization/inputs | 1 + Source/Initialization/InitSpaceChargeField.cpp | 8 ++++---- Source/Particles/PhysicalParticleContainer.cpp | 1 + Source/Particles/WarpXParticleContainer.H | 1 + Source/WarpX.H | 3 ++- 6 files changed, 17 insertions(+), 5 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 50803560d..2aee22344 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -228,6 +228,14 @@ Particle initialization Whether to calculate the space-charge fields associated with this species at the beginning of the simulation. +* ``.self_fields_required_precision`` (`float`, default: 1.e-11) + The relative precision with which the initial space-charge fields should + be calculated. More specifically, the initial space-charge fields are + computed with an iterative Multi-Level Multi-Grid (MLMG) solver. + For highly-relativistic beams, this solver can fail to reach the default + precision within a reasonable time ; in that case, users can set a + relaxed precision requirement through ``self_fields_required_precision``. + * ``.profile`` (`string`) Density profile for this species. The options are: diff --git a/Examples/Modules/relativistic_space_charge_initialization/inputs b/Examples/Modules/relativistic_space_charge_initialization/inputs index 6d936aa27..eca38e074 100644 --- a/Examples/Modules/relativistic_space_charge_initialization/inputs +++ b/Examples/Modules/relativistic_space_charge_initialization/inputs @@ -15,6 +15,7 @@ beam.charge = -q_e beam.mass = m_e beam.injection_style = "gaussian_beam" beam.initialize_self_fields = 1 +beam.self_fields_required_precision = 1.e-4 beam.x_rms = 2.e-6 beam.y_rms = 2.e-6 beam.z_rms = 2.e-6 diff --git a/Source/Initialization/InitSpaceChargeField.cpp b/Source/Initialization/InitSpaceChargeField.cpp index f0225e5d3..2ae3e181a 100644 --- a/Source/Initialization/InitSpaceChargeField.cpp +++ b/Source/Initialization/InitSpaceChargeField.cpp @@ -39,7 +39,7 @@ WarpX::InitSpaceChargeField (WarpXParticleContainer& pc) for (Real& beta_comp : beta) beta_comp /= PhysConst::c; // Normalize // Compute the potential phi, by solving the Poisson equation - computePhi( rho, phi, beta ); + computePhi( rho, phi, beta, pc.self_fields_required_precision ); // Compute the corresponding electric and magnetic field, from the potential phi computeE( Efield_fp, phi, beta ); @@ -63,7 +63,8 @@ WarpX::InitSpaceChargeField (WarpXParticleContainer& pc) void WarpX::computePhi (const amrex::Vector >& rho, amrex::Vector >& phi, - std::array const beta) const + std::array const beta, + Real const required_precision) const { // Define the boundary conditions Array lobc, hibc; @@ -94,8 +95,7 @@ WarpX::computePhi (const amrex::Vector >& rho, // Solve the Poisson equation MLMG mlmg(linop); mlmg.setVerbose(2); - const Real reltol = 1.e-11; - mlmg.solve( GetVecOfPtrs(phi), GetVecOfConstPtrs(rho), reltol, 0.0); + mlmg.solve( GetVecOfPtrs(phi), GetVecOfConstPtrs(rho), required_precision, 0.0); // Normalize by the correct physical constant for (int lev=0; lev < rho.size(); lev++){ diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index cb2a7c0e8..9dc9db2c5 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -42,6 +42,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_continuous_injection", do_continuous_injection); pp.query("initialize_self_fields", initialize_self_fields); + pp.query("self_fields_required_precision", self_fields_required_precision); // Whether to plot back-transformed (lab-frame) diagnostics // for this species. pp.query("do_back_transformed_diagnostics", do_back_transformed_diagnostics); diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 7da25b452..49fa09262 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -255,6 +255,7 @@ public: bool do_splitting = false; bool initialize_self_fields = false; + bool self_fields_required_precision = 1.e-11; // split along diagonals (0) or axes (1) int split_type = 0; diff --git a/Source/WarpX.H b/Source/WarpX.H index b04f56993..37e2427a5 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -305,7 +305,8 @@ public: void InitSpaceChargeField (WarpXParticleContainer& pc); void computePhi (const amrex::Vector >& rho, amrex::Vector >& phi, - std::array const beta = {{0,0,0}} ) const; + std::array const beta = {{0,0,0}}, + amrex::Real const required_precision=1.e-11 ) const; void computeE (amrex::Vector, 3> >& E, const amrex::Vector >& phi, std::array const beta = {{0,0,0}} ) const; -- cgit v1.2.3 From 25a614fe9e3bdbae8008b408976e65232286b1c5 Mon Sep 17 00:00:00 2001 From: Yinjian Zhao Date: Mon, 25 Nov 2019 11:16:01 -0700 Subject: Change do_not_depoist to be species related. --- Docs/source/running_cpp/parameters.rst | 8 ++++---- Source/Particles/PhysicalParticleContainer.cpp | 1 + Source/Particles/WarpXParticleContainer.cpp | 1 - 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 59c4be5fd..a16e0bfec 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -363,15 +363,15 @@ Particle initialization Split particles of the species when crossing the boundary from a lower resolution domain to a higher resolution domain. -* ``.do_not_deposit`` (`0` or `1` optional; default `0`) - If `1` is given, both charge deposition and current deposition will - not be done, so the fields due to particles remain zero. - * ``.split_type`` (`int`) optional (default `0`) Splitting technique. When `0`, particles are split along the simulation axes (4 particles in 2D, 6 particles in 3D). When `1`, particles are split along the diagonals (4 particles in 2D, 8 particles in 3D). +* ``.do_not_deposit`` (`0` or `1` optional; default `0`) + If `1` is given, both charge deposition and current deposition will + not be done, thus that species does not contribute to the fields. + * ``.plot_species`` (`0` or `1` optional; default `1`) Whether to plot particle quantities for this species. diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 4f6d032e9..55290cf1f 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -39,6 +39,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp // Initialize splitting pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); + pp.query("do_not_deposit", do_not_deposit); pp.query("do_continuous_injection", do_continuous_injection); pp.query("initialize_self_fields", initialize_self_fields); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index c256df6aa..7b5bf16d1 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -122,7 +122,6 @@ WarpXParticleContainer::ReadParameters () #endif pp.query("do_tiling", do_tiling); pp.query("do_not_push", do_not_push); - pp.query("do_not_deposit", do_not_deposit); initialized = true; } -- cgit v1.2.3