WarpX
SpectralSolver.H
Go to the documentation of this file.
1 /* Copyright 2019-2020 Maxence Thevenet, Remi Lehe, Edoardo Zoni
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_SPECTRAL_SOLVER_H_
8 #define WARPX_SPECTRAL_SOLVER_H_
9 
10 #include "SpectralSolver_fwd.H"
11 
13 #include "SpectralFieldData.H"
14 
15 #include <ablastr/utils/Enums.H>
16 
17 #include <AMReX_Array.H>
18 #include <AMReX_REAL.H>
19 #include <AMReX_RealVect.H>
20 
21 #include <AMReX_BaseFwd.H>
22 
23 #include <array>
24 #include <memory>
25 
26 #ifdef WARPX_USE_FFT
35 {
36  public:
37 
74  SpectralSolver (int lev,
75  const amrex::BoxArray& realspace_ba,
77  int norder_x,
78  int norder_y,
79  int norder_z,
81  const amrex::Vector<amrex::Real>& v_galilean,
82  const amrex::Vector<amrex::Real>& v_comoving,
84  amrex::Real dt,
85  bool pml,
86  bool periodic_single_box,
87  bool update_with_rho,
88  bool fft_do_time_averaging,
89  int psatd_solution_type,
90  int J_in_time,
91  int rho_in_time,
92  bool dive_cleaning,
93  bool divb_cleaning);
94 
104  void ForwardTransform (int lev,
105  const amrex::MultiFab& mf,
106  int field_index,
107  int i_comp = 0);
108 
113  void BackwardTransform( int lev,
114  amrex::MultiFab& mf,
115  int field_index,
116  const amrex::IntVect& fill_guards,
117  int i_comp=0 );
118 
122  void pushSpectralFields();
123 
128  void ComputeSpectralDivE ( int lev,
129  const std::array<std::unique_ptr<amrex::MultiFab>,3>& Efield,
130  amrex::MultiFab& divE ) {
131  algorithm->ComputeSpectralDivE( lev, field_data, Efield, divE );
132  }
133 
141  {
142  algorithm->CurrentCorrection(field_data);
143  }
144 
152  {
153  algorithm->VayDeposition(field_data);
154  }
155 
163  void CopySpectralDataComp (const int src_comp, const int dest_comp)
164  {
165  // The last two arguments represent the number of components and
166  // the number of ghost cells to perform this operation
167  Copy(field_data.fields, field_data.fields, src_comp, dest_comp, 1, 0);
168  }
169 
175  void ZeroOutDataComp (const int icomp)
176  {
177  // The last argument represents the number of components to perform this operation
178  field_data.fields.setVal(0., icomp, 1);
179  }
180 
188  void ScaleDataComp (const int icomp, const amrex::Real scale_factor)
189  {
190  // The last argument represents the number of components to perform this operation
191  field_data.fields.mult(scale_factor, icomp, 1);
192  }
193 
195 
196  protected:
197 
199 
200  private:
201 
202  void ReadParameters ();
203 
204  // Store field in spectral space and perform the Fourier transforms
206 
207  // Defines field update equation in spectral space and the associated coefficients.
208  // SpectralBaseAlgorithm is a base class; this pointer is meant to point
209  // to an instance of a sub-class defining a specific algorithm
210  std::unique_ptr<SpectralBaseAlgorithm> algorithm;
211 };
212 #endif // WARPX_USE_FFT
213 #endif // WARPX_SPECTRAL_SOLVER_H_
Class that stores the fields in spectral space, and performs the Fourier transforms between real spac...
Definition: SpectralFieldData.H:143
SpectralField fields
Definition: SpectralFieldData.H:169
Definition: SpectralFieldData.H:34
Top-level class for the electromagnetic spectral solver.
Definition: SpectralSolver.H:35
void ReadParameters()
void ForwardTransform(int lev, const amrex::MultiFab &mf, int field_index, int i_comp=0)
Transform the component i_comp of the MultiFab mf to Fourier space, and store the result internally (...
Definition: SpectralSolver.cpp:123
SpectralFieldIndex m_spectral_index
Definition: SpectralSolver.H:194
void VayDeposition()
Public interface to call the virtual function VayDeposition, declared in the base class SpectralBaseA...
Definition: SpectralSolver.H:151
void ZeroOutDataComp(const int icomp)
Set to zero the data on component icomp of field_data.fields.
Definition: SpectralSolver.H:175
void ScaleDataComp(const int icomp, const amrex::Real scale_factor)
Scale the data on component icomp of field_data.fields by a given scale factor.
Definition: SpectralSolver.H:188
SpectralSolver(int lev, const amrex::BoxArray &realspace_ba, const amrex::DistributionMapping &dm, int norder_x, int norder_y, int norder_z, ablastr::utils::enums::GridType grid_type, const amrex::Vector< amrex::Real > &v_galilean, const amrex::Vector< amrex::Real > &v_comoving, amrex::RealVect dx, amrex::Real dt, bool pml, bool periodic_single_box, bool update_with_rho, bool fft_do_time_averaging, int psatd_solution_type, int J_in_time, int rho_in_time, bool dive_cleaning, bool divb_cleaning)
Constructor of the class SpectralSolver.
Definition: SpectralSolver.cpp:26
void pushSpectralFields()
Update the fields in spectral space, over one timestep.
Definition: SpectralSolver.cpp:144
void CurrentCorrection()
Public interface to call the virtual function CurrentCorrection, defined in the base class SpectralBa...
Definition: SpectralSolver.H:140
void ComputeSpectralDivE(int lev, const std::array< std::unique_ptr< amrex::MultiFab >, 3 > &Efield, amrex::MultiFab &divE)
Public interface to call the member function ComputeSpectralDivE of the base class SpectralBaseAlgori...
Definition: SpectralSolver.H:128
SpectralFieldData field_data
Definition: SpectralSolver.H:205
amrex::IntVect m_fill_guards
Definition: SpectralSolver.H:198
void CopySpectralDataComp(const int src_comp, const int dest_comp)
Copy spectral data from component src_comp to component dest_comp of field_data.fields.
Definition: SpectralSolver.H:163
void BackwardTransform(int lev, amrex::MultiFab &mf, int field_index, const amrex::IntVect &fill_guards, int i_comp=0)
Transform spectral field specified by field_index back to real space, and store it in the component i...
Definition: SpectralSolver.cpp:133
std::unique_ptr< SpectralBaseAlgorithm > algorithm
Definition: SpectralSolver.H:210
void setVal(value_type val)
void mult(value_type val, int comp, int num_comp, int nghost=0)
GridType
Definition: Enums.H:17
void Copy(FabArray< DFAB > &dst, FabArray< SFAB > const &src, int srccomp, int dstcomp, int numcomp, int nghost)
float dt
Definition: stencil.py:442
tuple dx
lab frame
Definition: stencil.py:429