Skip to content

Commit f2cbba4

Browse files
ax3lclaude
andauthored
FFT: expose OpenBCSolver's spectral Green's function (AMReX-Codes#5627)
`OpenBCSolver` rebuilds its spectral Green's function whenever `setGreensFunction()` is called, and there is no way to hand it one that was built earlier. Add `greensFunctionFFT()` accessors so a caller can keep its own set and move them into and out of the solver with `std::swap` rather than recomputing. `solve()` only reads the spectral Green's function, and `prepare_openbc()` concerns the R2C plans rather than the Green's function values, so one moved in this way needs no further preparation. The one caveat, documented at the accessor: in 2D, `m_G_fft` is an alias of the Green's function R2C's spectral data, which a later `setGreensFunction()` writes into. Callers may write through the reference there, but must not swap or otherwise re-seat it. Additive only, so nothing changes for existing users. Exercised downstream in BLAST-WarpX/warpx#7178 & BLAST-ImpactX/impactx#1621, where reusing Green's functions this way reproduces rebuilding them bit for bit, and where it takes an accelerating beam simulation from 100 Green's function builds to 10. - [x] 🤖 Generated with [Claude Code](https://claude.com/claude-code) - [x] tested with ABLASTR/WarpX and ImpactX - [x] manually self-reviewed --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 5b16e49 commit f2cbba4

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎Src/FFT/AMReX_FFT_OpenBCSolver.H‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ public:
6767
*/
6868
[[nodiscard]] IntVect const& PaddedLength () const { return m_padded_length; }
6969

70+
/**
71+
* \brief Access the spectral Green's function held by this solver.
72+
*
73+
* This lets a caller keep its own set of Green's functions and move them into and
74+
* out of the solver, for instance with std::swap, instead of recomputing them with
75+
* setGreensFunction(). Since solve() only reads the spectral Green's function, one
76+
* moved in this way needs no further preparation.
77+
*
78+
* \note In 2D, this is an alias of the Green's function R2C's spectral data.
79+
* Callers may write through it, but must not swap or otherwise re-seat it,
80+
* because a later setGreensFunction() writes into the aliased array.
81+
*
82+
* \return The spectral Green's function.
83+
*/
84+
[[nodiscard]] cMF& greensFunctionFFT () noexcept { return m_G_fft; }
85+
86+
/**
87+
* \brief Access the spectral Green's function held by this solver.
88+
*
89+
* \return The spectral Green's function.
90+
*/
91+
[[nodiscard]] cMF const& greensFunctionFFT () const noexcept { return m_G_fft; }
92+
7093
private:
7194
static IntVect make_padded_length (Box const& domain, Info const& info);
7295
static Box make_grown_domain (Box const& domain, IntVect const& padded_len,

0 commit comments

Comments
 (0)