Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quasi-3D Integrated Green Functions solver #5089

Merged
merged 73 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a7f3c75
single process - fftw
aeriforme Jul 27, 2024
e4b0d6a
single process - cufft
aeriforme Jul 27, 2024
da7bf7e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 27, 2024
214c650
fix const and cufft
aeriforme Jul 30, 2024
0841372
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 30, 2024
42db7c2
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Sep 17, 2024
c334f39
two versions - clean up to be debugged
aeriforme Sep 18, 2024
e63eee4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 18, 2024
4223920
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Sep 18, 2024
f1cf0ee
add new igf flags
aeriforme Sep 19, 2024
3f463ea
add 2d sliced version
aeriforme Sep 19, 2024
ba0b02c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2024
9b72d95
add warpx.use_2d_slices_fft_solver to docs
aeriforme Sep 19, 2024
774de08
add ctest
aeriforme Sep 19, 2024
7553131
remove is_distributed as runtime param
aeriforme Sep 19, 2024
c0b3f4c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Sep 19, 2024
a7e3347
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Oct 1, 2024
39c5983
fix ElectrostaticSolver.cpp
aeriforme Oct 1, 2024
e0f7d86
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 1, 2024
131c1bb
add and fix test checksums
aeriforme Oct 4, 2024
4086903
add runtime input to select if 3d solver is distributed
aeriforme Oct 4, 2024
fc12321
update test
aeriforme Oct 4, 2024
15e6d82
add 2d, 3d global and 3d distributed solvers
aeriforme Oct 4, 2024
2ff840b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 4, 2024
e9f1bc2
remove useless silly function
aeriforme Oct 4, 2024
b674324
add support for single precision with fftw
aeriforme Oct 4, 2024
da41a05
remove const qualification of dim in CreateManyPlan declaration
aeriforme Oct 5, 2024
baaa72e
small clean up
aeriforme Oct 5, 2024
8f4684f
add preliminary Roc support
aeriforme Oct 5, 2024
e198414
fix Bz in checksums
aeriforme Oct 5, 2024
be4bbbc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 5, 2024
9184eba
temp workaround roc
aeriforme Oct 5, 2024
8c59a29
temp workaround roc
aeriforme Oct 5, 2024
bc7d71f
add strides to rocfft
aeriforme Oct 7, 2024
b9c32ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 7, 2024
0e68679
fix typos
aeriforme Oct 7, 2024
ca5eefc
Merge branch 'sliced_poisson' of github.com:aeriforme/WarpX into slic…
aeriforme Oct 7, 2024
dd29a40
remove const in function declaration
aeriforme Oct 8, 2024
8885d18
remove redundant include
aeriforme Oct 8, 2024
0675d48
tidy up
aeriforme Oct 8, 2024
309b04e
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Oct 9, 2024
5ff4fab
add 3d distributed fft flag to docs
aeriforme Oct 9, 2024
0407983
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
ba51c6d
fix rocfft
aeriforme Oct 30, 2024
1235219
remove unchanged files
aeriforme Oct 30, 2024
d1ec79a
improve docs
aeriforme Oct 30, 2024
0255210
switch heffte flag on in azure workflow
aeriforme Oct 30, 2024
7069ca4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 30, 2024
50f7b43
fix removing cached files
aeriforme Oct 30, 2024
571ec8d
fix heffte checksums using azure results
aeriforme Nov 2, 2024
2a96941
implement suggestions from reviewers
aeriforme Nov 2, 2024
d120936
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 2, 2024
da6ed73
use nullptr in batched ffts in igf
aeriforme Nov 4, 2024
fcd93aa
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Nov 26, 2024
b060a89
remove heffte, use amrex fft
aeriforme Dec 2, 2024
33435d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 2, 2024
cb53fb7
restore fft wrappers
aeriforme Dec 4, 2024
6caf0cc
better separate 2D and 3D solvers
aeriforme Dec 4, 2024
2b306fa
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Dec 4, 2024
f46e3e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
ea41d4e
add ignore unused in 2d
aeriforme Dec 4, 2024
75af6a0
temporary change to check azure results
aeriforme Dec 4, 2024
6fe9e07
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 4, 2024
f6b2b90
restore analysis
aeriforme Dec 4, 2024
ffae96d
use do_2d_slices
aeriforme Dec 4, 2024
a00f974
update amrex
aeriforme Dec 6, 2024
690eddd
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Dec 6, 2024
819f49a
update checksums
aeriforme Dec 6, 2024
688c4dc
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Dec 11, 2024
963c4f6
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Dec 12, 2024
b0686e7
Merge branch 'development' of github.com:ECP-WarpX/WarpX into sliced_…
aeriforme Dec 12, 2024
d2406f8
fix amrex version
aeriforme Dec 13, 2024
1e2a239
integrate suggestions
aeriforme Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Docs/source/usage/parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,19 @@ Overall simulation parameters
In electromagnetic mode, this solver can be used to initialize the species' self fields
(``<species_name>.initialize_self_fields=1``) provided that the field BCs are PML (``boundary.field_lo,hi = PML``).

* warpx.use_2d_slices_fft_solver (`bool`, default: 0): Select the type of Integrated Green Function solver.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* warpx.use_2d_slices_fft_solver (`bool`, default: 0): Select the type of Integrated Green Function solver.
* ``warpx.use_2d_slices_fft_solver`` (`bool`, default: 0): Select the type of Integrated Green Function solver.

If 0, solve Poisson equation in full 3D geometry.
If 1, solve Poisson equation in a quasi 3D geometry, neglecting the :math:`z` derivatives in the Laplacian of the Poisson equation.
In practice, in this case, the code performes many 2D Poisson solves on all :math:`(x,y)` slices, each slice at a given :math:`z`.
This is often a good approximation for ultra-relativistic beams propagating along the :math:`z` direction, with the relativistic solver.
As a consequence, this solver does not need to do an FFT along the :math:`z` direction,
and instead uses only transverse FFTs (along :math:`x` and :math:`y`) at each :math:`z` position (or :math:`z` "slice").

* warpx.use_distributed_3d_fft_solver (`bool`, default: 0): Choose whether the 3D FFTs performed in the
full 3D Integrated Green Function solver are distributed.
If 0, the FFTs are performed on a single MPI rank (the rest of the code is still fully parallel).
If 1, the FFTs are distributed using the heFFTe library. The code must be compiled with `-DWarpX_HEFFTE=ON`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this? It seems that it is not actually used in the code.


* ``warpx.self_fields_required_precision`` (`float`, default: 1.e-11)
The relative precision with which the electrostatic space-charge fields should
be calculated. More specifically, the space-charge fields are
Expand Down
12 changes: 12 additions & 0 deletions Examples/Tests/open_bc_poisson_solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ if(WarpX_FFT)
OFF # dependency
)
endif()

if(WarpX_FFT)
add_warpx_test(
test_3d_open_bc_poisson_solver_sliced # name
3 # dims
2 # nprocs
inputs_test_3d_open_bc_poisson_solver_sliced # inputs
analysis.py # analysis
diags/diag1000001 # output
OFF # dependency
)
endif()
1 change: 0 additions & 1 deletion Examples/Tests/open_bc_poisson_solver/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def evaluate_E(x, y, z):
assert np.allclose(Ex_warpx, Ex_theory, rtol=0.032, atol=0)
assert np.allclose(Ey_warpx, Ey_theory, rtol=0.029, atol=0)


# compare checksums
evaluate_checksum(
test_name=os.path.split(os.getcwd())[1],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FILE = inputs_test_3d_open_bc_poisson_solver

warpx.use_2d_slices_fft_solver = 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Didn't we already have a checksum file for this test before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too, but there isn't one in development right now.
Something must have happened when we moved to ctest, maybe?
Anyway, the main problem here is that the heffte test never runs in CI, so that's why we didn't notice.

Copy link
Member Author

@aeriforme aeriforme Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, from here it seems like that the checksums were saved in the wrong file, overwriting the ones for the test without heffte.

That also explains why I had to change Regression/Checksum/benchmarks_json/test_3d_open_bc_poisson_solver.json too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this .json file? It seems that it is no longer needed/used.

"lev=0": {
"Bx": 100915933.44552392,
"By": 157610622.18550807,
"Bz": 8.739731456892512e-12,
"Ex": 4.725065270619816e+16,
"Ey": 3.025394898923131e+16,
"Ez": 3276573.95147766,
"rho": 10994013582437.193
},
"electron": {
"particle_momentum_x": 5.701277606055911e-19,
"particle_momentum_y": 3.650451663619896e-19,
"particle_momentum_z": 1.145432768297242e-10,
"particle_position_x": 17.314086912497864,
"particle_position_y": 0.2583691267187796,
"particle_position_z": 10066.329600000008,
"particle_weight": 19969036501.910976
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"lev=0": {
"Bx": 100915933.44551668,
"By": 157610622.18551716,
"Bz": 2.598515299403035e-15,
"Ex": 4.725065270620093e+16,
"Ey": 3.0253948989229424e+16,
"Ez": 2787743.3330717986,
"rho": 10994013582437.193
},
"electron": {
"particle_momentum_x": 5.701277606056779e-19,
"particle_momentum_y": 3.650451663675671e-19,
"particle_momentum_z": 1.145432768297242e-10,
"particle_position_x": 17.314086912497864,
"particle_position_y": 0.25836912671877954,
"particle_position_z": 10066.329600000008,
"particle_weight": 19969036501.910976
}
}

7 changes: 6 additions & 1 deletion Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.H
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public:
amrex::Real required_precision,
amrex::Real absolute_tolerance,
int max_iters,
int verbosity
int verbosity,
bool is_igf_2d_slices
) const;

/**
Expand Down Expand Up @@ -153,6 +154,10 @@ public:
* 2 : convergence progress at every MLMG iteration
*/
int self_fields_verbosity = 2;

/** Parameters for FFT Poisson solver aka IGF */
// 0: full 3D, 1: many 2D z-slices (quasi-3D)
bool is_igf_2d_slices = false;
};

#endif // WARPX_ELECTROSTATICSOLVER_H_
12 changes: 10 additions & 2 deletions Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ void ElectrostaticSolver::ReadParameters () {
pp_warpx, "self_fields_absolute_tolerance", self_fields_absolute_tolerance);
utils::parser::queryWithParser(
pp_warpx, "self_fields_max_iters", self_fields_max_iters);
pp_warpx.query("self_fields_verbosity", self_fields_verbosity);
utils::parser::queryWithParser(
pp_warpx, "self_fields_verbosity", self_fields_verbosity);

// FFT solver flags
utils::parser::queryWithParser(
pp_warpx, "use_2d_slices_fft_solver", is_igf_2d_slices);
}

void
Expand Down Expand Up @@ -121,7 +126,9 @@ ElectrostaticSolver::computePhi (
Real const required_precision,
Real absolute_tolerance,
int const max_iters,
int const verbosity) const
int const verbosity,
bool const is_igf_2d
) const
{
using ablastr::fields::Direction;

Expand Down Expand Up @@ -202,6 +209,7 @@ ElectrostaticSolver::computePhi (
warpx.boxArray(),
WarpX::grid_type,
is_solver_igf_on_lev0,
is_igf_2d,
EB::enabled(),
WarpX::do_single_precision_comms,
warpx.refRatio(),
Expand Down
Empty file modified Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.H
100644 → 100755
aeriforme marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
2 changes: 1 addition & 1 deletion Source/FieldSolver/ElectrostaticSolvers/LabFrameExplicitES.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void LabFrameExplicitES::ComputeSpaceChargeField (
// Use the AMREX MLMG or the FFT (IGF) solver otherwise
computePhi(rho_fp, phi_fp, beta, self_fields_required_precision,
self_fields_absolute_tolerance, self_fields_max_iters,
self_fields_verbosity);
self_fields_verbosity, is_igf_2d_slices);
#endif

}
Expand Down
aeriforme marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
4 changes: 2 additions & 2 deletions Source/FieldSolver/ElectrostaticSolvers/RelativisticExplicitES.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void RelativisticExplicitES::AddSpaceChargeField (
computePhi( amrex::GetVecOfPtrs(rho), amrex::GetVecOfPtrs(phi),
beta, pc.self_fields_required_precision,
pc.self_fields_absolute_tolerance, pc.self_fields_max_iters,
pc.self_fields_verbosity );
pc.self_fields_verbosity, is_igf_2d_slices);

// Compute the corresponding electric and magnetic field, from the potential phi
computeE( Efield_fp, amrex::GetVecOfPtrs(phi), beta );
Expand Down Expand Up @@ -168,7 +168,7 @@ void RelativisticExplicitES::AddBoundaryField (ablastr::fields::MultiLevelVector
computePhi( amrex::GetVecOfPtrs(rho), amrex::GetVecOfPtrs(phi),
beta, self_fields_required_precision,
self_fields_absolute_tolerance, self_fields_max_iters,
self_fields_verbosity );
self_fields_verbosity, is_igf_2d_slices);

// Compute the corresponding electric field, from the potential phi.
computeE( Efield_fp, amrex::GetVecOfPtrs(phi), beta );
Expand Down
96 changes: 68 additions & 28 deletions Source/ablastr/fields/IntegratedGreenFunctionSolver.H
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
#include <AMReX_REAL.H>
#include <AMReX_Vector.H>


#include <array>
#include <cmath>


namespace ablastr::fields
{
using namespace amrex::literals;


/** @brief Implements equation 2 in https://doi.org/10.1103/PhysRevSTAB.10.129901
* with some modification to symmetrize the function.
Expand All @@ -30,54 +31,92 @@ namespace ablastr::fields
* @param[in] y y-coordinate of given location
* @param[in] z z-coordinate of given location
*
* @return the integrated Green function G
* @return the integrated Green function G in 3D
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
amrex::Real
IntegratedPotential (amrex::Real x, amrex::Real y, amrex::Real z)
IntegratedPotential3D (amrex::Real x, amrex::Real y, amrex::Real z)
{
using namespace amrex::literals;

amrex::Real const r = std::sqrt( x*x + y*y + z*z );
amrex::Real const G =
- 0.5_rt * z*z * std::atan( x*y/(z*r) )
- 0.5_rt * y*y * std::atan( x*z/(y*r) )
- 0.5_rt * x*x * std::atan( y*z/(x*r) )
+ y*z*std::asinh( x/std::sqrt(y*y + z*z) )
+ x*z*std::asinh( y/std::sqrt(x*x + z*z) )
+ x*y*std::asinh( z/std::sqrt(x*x + y*y) );
amrex::Real const G = - 0.5_rt * z*z * std::atan( x*y/(z*r) )
- 0.5_rt * y*y * std::atan( x*z/(y*r) )
- 0.5_rt * x*x * std::atan( y*z/(x*r) )
+ y*z*std::asinh( x/std::sqrt(y*y + z*z) )
+ x*z*std::asinh( y/std::sqrt(x*x + z*z) )
+ x*y*std::asinh( z/std::sqrt(x*x + y*y) );
return G;
}


/** @brief Implements minus equation 58 in https://doi.org/10.1016/j.jcp.2004.01.008
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** @brief Implements minus equation 58 in https://doi.org/10.1016/j.jcp.2004.01.008
/** @brief Implements equation 58 in https://doi.org/10.1016/j.jcp.2004.01.008

I think I understand what is meant here, but the term "minus equation" might be confusing. I think it is fine to simply say "equation 58".

*
* @param[in] x x-coordinate of given location
* @param[in] y y-coordinate of given location
*
* @return the integrated Green function G in 2D
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
amrex::Real
IntegratedPotential2D (amrex::Real x, amrex::Real y)
{
amrex::Real const G = 3_rt*x*y
- x*x * std::atan(y/x)
- y*y * std::atan(x/y)
- x*y * std::log(x*x + y*y);
return G;
}


/** @brief add
*
* @param[in] x x-coordinate of given location
* @param[in] y y-coordinate of given location
* @param[in] z z-coordinate of given location
* @param[in] dx cell size along x
* @param[in] dy cell size along y
* @param[in] dz cell size along z
*
* @return the sum of integrated Green function G
* @return the sum of integrated Green function G in 3D
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
amrex::Real
SumOfIntegratedPotential (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real dx, amrex::Real dy, amrex::Real dz)
SumOfIntegratedPotential3D (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real dx, amrex::Real dy, amrex::Real dz)
{
using namespace amrex::literals;

return 1._rt/(4._rt*ablastr::constant::math::pi*ablastr::constant::SI::ep0) * (
IntegratedPotential3D( x+0.5_rt*dx, y+0.5_rt*dy, z+0.5_rt*dz )
- IntegratedPotential3D( x-0.5_rt*dx, y+0.5_rt*dy, z+0.5_rt*dz )
- IntegratedPotential3D( x+0.5_rt*dx, y-0.5_rt*dy, z+0.5_rt*dz )
+ IntegratedPotential3D( x-0.5_rt*dx, y-0.5_rt*dy, z+0.5_rt*dz )
- IntegratedPotential3D( x+0.5_rt*dx, y+0.5_rt*dy, z-0.5_rt*dz )
+ IntegratedPotential3D( x-0.5_rt*dx, y+0.5_rt*dy, z-0.5_rt*dz )
+ IntegratedPotential3D( x+0.5_rt*dx, y-0.5_rt*dy, z-0.5_rt*dz )
- IntegratedPotential3D( x-0.5_rt*dx, y-0.5_rt*dy, z-0.5_rt*dz )
);
}

amrex::Real const G_value = 1._rt/(4._rt*ablastr::constant::math::pi*ablastr::constant::SI::ep0) * (
IntegratedPotential( x+0.5_rt*dx, y+0.5_rt*dy, z+0.5_rt*dz )
- IntegratedPotential( x-0.5_rt*dx, y+0.5_rt*dy, z+0.5_rt*dz )
- IntegratedPotential( x+0.5_rt*dx, y-0.5_rt*dy, z+0.5_rt*dz )
+ IntegratedPotential( x-0.5_rt*dx, y-0.5_rt*dy, z+0.5_rt*dz )
- IntegratedPotential( x+0.5_rt*dx, y+0.5_rt*dy, z-0.5_rt*dz )
+ IntegratedPotential( x-0.5_rt*dx, y+0.5_rt*dy, z-0.5_rt*dz )
+ IntegratedPotential( x+0.5_rt*dx, y-0.5_rt*dy, z-0.5_rt*dz )
- IntegratedPotential( x-0.5_rt*dx, y-0.5_rt*dy, z-0.5_rt*dz )
);

return G_value;
/** @brief add
*
* @param[in] x x-coordinate of given location
* @param[in] y y-coordinate of given location
* @param[in] dx cell size along x
* @param[in] dy cell size along y
*
* @return the sum of integrated Green function G in 2D
*/
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
amrex::Real
SumOfIntegratedPotential2D (amrex::Real x, amrex::Real y, amrex::Real dx, amrex::Real dy)
{
return 1._rt/(4._rt*ablastr::constant::math::pi*ablastr::constant::SI::ep0) * (
IntegratedPotential2D( x+0.5_rt*dx, y+0.5_rt*dy )
- IntegratedPotential2D( x+0.5_rt*dx, y-0.5_rt*dy )
- IntegratedPotential2D( x-0.5_rt*dx, y+0.5_rt*dy )
+ IntegratedPotential2D( x-0.5_rt*dx, y-0.5_rt*dy )
);
}


/** @brief Compute the electrostatic potential using the Integrated Green Function method
* as in http://dx.doi.org/10.1103/PhysRevSTAB.9.044204
*
Expand All @@ -90,7 +129,8 @@ namespace ablastr::fields
computePhiIGF (amrex::MultiFab const & rho,
amrex::MultiFab & phi,
std::array<amrex::Real, 3> const & cell_size,
amrex::BoxArray const & ba);
amrex::BoxArray const & ba,
bool do_2d_slices);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use the same name (is_igf_2d_slices) as in the other functions - instead of do_2d_slices?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure!


} // namespace ablastr::fields

Expand Down
33 changes: 25 additions & 8 deletions Source/ablastr/fields/IntegratedGreenFunctionSolver.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void
computePhiIGF ( amrex::MultiFab const & rho,
amrex::MultiFab & phi,
std::array<amrex::Real, 3> const & cell_size,
amrex::BoxArray const & ba)
amrex::BoxArray const & ba,
bool const do_2d_slices)
{
using namespace amrex::literals;

Expand All @@ -45,9 +46,6 @@ computePhiIGF ( amrex::MultiFab const & rho,
domain.surroundingNodes(); // get nodal points, since `phi` and `rho` are nodal
domain.grow( phi.nGrowVect() ); // include guard cells

// Do we grow the domain in the z-direction in the 2D mode?
bool const do_2d_fft = false;

int nprocs = amrex::ParallelDescriptor::NProcs();
{
amrex::ParmParse pp("ablastr");
Expand All @@ -61,7 +59,7 @@ computePhiIGF ( amrex::MultiFab const & rho,
}
if (!obc_solver || obc_solver->Domain() != domain) {
amrex::FFT::Info info{};
if (do_2d_fft) { info.setBatchMode(true); }
if (do_2d_slices) { info.setBatchMode(true); } // do 2D FFTs
info.setNumProcs(nprocs);
obc_solver = std::make_unique<amrex::FFT::OpenBCSolver<amrex::Real>>(domain, info);
}
Expand All @@ -71,7 +69,9 @@ computePhiIGF ( amrex::MultiFab const & rho,
amrex::Real const dy = cell_size[1];
amrex::Real const dz = cell_size[2];

obc_solver->setGreensFunction(
if (!do_2d_slices){
// 2D sliced solver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment here and the one in the else part are incorrect.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! I will fix it

obc_solver->setGreensFunction(
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> amrex::Real
{
int const i0 = i - lo[0];
Expand All @@ -80,9 +80,26 @@ computePhiIGF ( amrex::MultiFab const & rho,
amrex::Real const x = i0*dx;
amrex::Real const y = j0*dy;
amrex::Real const z = k0*dz;
return SumOfIntegratedPotential(x, y, z, dx, dy, dz);

return SumOfIntegratedPotential3D(x, y, z, dx, dy, dz);
});
}else{
// fully 3D solver
obc_solver->setGreensFunction(
[=] AMREX_GPU_DEVICE (int i, int j, int k) -> amrex::Real
{
int const i0 = i - lo[0];
int const j0 = j - lo[1];
amrex::Real const x = i0*dx;
amrex::Real const y = j0*dy;
amrex::ignore_unused(k);

return SumOfIntegratedPotential2D(x, y, dx, dy);
});

}

obc_solver->solve(phi, rho);
}
} // computePhiIGF

} // namespace ablastr::fields
Loading
Loading