From 9e8aca63877e32463a912cd6b3fafb660e898f15 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 26 Apr 2019 20:59:35 -0700 Subject: Use factory method for the solver --- .../SpectralAlgorithms/SpectralBaseAlgorithm.H | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H (limited to 'Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H') diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H new file mode 100644 index 000000000..18d26e0c8 --- /dev/null +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H @@ -0,0 +1,44 @@ +#ifndef WARPX_SPECTRAL_BASE_ALGORITHM_H_ +#define WARPX_SPECTRAL_BASE_ALGORITHM_H_ + +#include +#include + +/* \brief Class that updates the field in spectral space + * and stores the coefficients of the corresponding update equation. + * TODO: Mention base class + */ +class SpectralBaseAlgorithm +{ + public: + // Member function that updates the fields in spectral space ; + // meant to be overridden in subclasses + virtual void pushSpectralFields(SpectralFieldData& f) const = 0; + + protected: // Meant to be used in the subclasses + + using SpectralCoefficients = amrex::FabArray< amrex::BaseFab >; + + // Constructor + SpectralBaseAlgorithm(const SpectralKSpace& spectral_kspace, + const amrex::DistributionMapping& dm, + const int norder_x, const int norder_y, + const int norder_z, const bool nodal) + // Compute and assign the modified k vectors + : modified_kx_vec(spectral_kspace.getModifiedKComponent(dm,0,norder_x,nodal)), +#if (AMREX_SPACEDIM==3) + modified_ky_vec(spectral_kspace.getModifiedKComponent(dm,1,norder_y,nodal)), + modified_kz_vec(spectral_kspace.getModifiedKComponent(dm,2,norder_z,nodal)) +#else + modified_kz_vec(spectral_kspace.getModifiedKComponent(dm,1,norder_z,nodal)) +#endif + {}; + + // Modified finite-order vectors + KVectorComponent modified_kx_vec, modified_kz_vec; +#if (AMREX_SPACEDIM==3) + KVectorComponent modified_ky_vec; +#endif +}; + +#endif // WARPX_SPECTRAL_BASE_ALGORITHM_H_ -- cgit v1.2.3 From e4985aa4188ce6f9605171db2a1c621ecc730e26 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 1 May 2019 08:20:32 -0700 Subject: Add comments --- .../SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H | 5 ++++- Source/FieldSolver/SpectralSolver/SpectralSolver.cpp | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H') diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H index 18d26e0c8..5c662e533 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H @@ -6,7 +6,10 @@ /* \brief Class that updates the field in spectral space * and stores the coefficients of the corresponding update equation. - * TODO: Mention base class + * + * `SpectralBaseAlgorithm` is only a base class and cannot be used directly. + * Instead use its subclasses, which implement the specific field update + * equations for a given spectral algorithm. */ class SpectralBaseAlgorithm { diff --git a/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp b/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp index 5da39a7c7..c21c3cfb1 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp +++ b/Source/FieldSolver/SpectralSolver/SpectralSolver.cpp @@ -2,7 +2,11 @@ #include #include -/* \brief TODO Description +/* \brief Initialize the spectral Maxwell solver + * + * This function selects the spectral algorithm to be used, allocates the + * corresponding coefficients for the discretized field update equation, + * and prepares the structures that store the fields in spectral space. */ SpectralSolver::SpectralSolver( const amrex::BoxArray& realspace_ba, -- cgit v1.2.3 From f07d411bc3b6110a48e70a6b69907d5f7100759d Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 1 May 2019 12:07:11 -0700 Subject: Add virtual destructor --- .../SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H') diff --git a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H index 5c662e533..602eb2473 100644 --- a/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H +++ b/Source/FieldSolver/SpectralSolver/SpectralAlgorithms/SpectralBaseAlgorithm.H @@ -17,6 +17,10 @@ class SpectralBaseAlgorithm // Member function that updates the fields in spectral space ; // meant to be overridden in subclasses virtual void pushSpectralFields(SpectralFieldData& f) const = 0; + // The destructor should also be a virtual function, so that + // a pointer to subclass of `SpectraBaseAlgorithm` actually + // calls the subclass's destructor. + virtual ~SpectralBaseAlgorithm() {}; protected: // Meant to be used in the subclasses -- cgit v1.2.3