ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_ImmersedPoisson.H
Go to the documentation of this file.
1 /**
2  * \file ERF_ImmersedPoisson.H
3  */
4 #ifndef ERF_IMMERSED_POISSON_H_
5 #define ERF_IMMERSED_POISSON_H_
6 
7 #include <AMReX_Geometry.H>
8 #include <AMReX_MultiFab.H>
9 
10 #ifdef ERF_USE_FFT
11 #include <AMReX_FFT_Poisson.H>
12 
13 /**
14  * Operator of the anelastic projection with the implicit immersed-forcing drag
15  * (erf.if_implicit_projection), for GMRES on a constant-dz mesh:
16  *
17  * L(phi) = div( sigma grad phi ), sigma = 1 / (1 + dt * rate) on each face,
18  *
19  * where rate is the drag rate of the terrain immersed forcing on that face. The constant
20  * coefficient FFT Poisson solve (sigma = 1) is the preconditioner. The ghost cells of phi
21  * follow the FFT boundary conditions of the subdomain, as in TerrainPoisson.
22  */
23 class ImmersedPoisson
24 {
25 public:
26  using RT = amrex::Real;
27 
28  /**
29  * @param geom Geometry of the subdomain being solved
30  * @param lev_geom Geometry of the level, used for the FFT boundary conditions
31  * @param ba BoxArray of the subdomain
32  * @param dm DistributionMapping of the subdomain
33  * @param domain_bcs_type Domain boundary-condition names
34  * @param sigma Face coefficients on the x-, y- and z-faces of the subdomain
35  * @param use_real_bcs Whether real lateral boundary conditions are active
36  */
37  ImmersedPoisson (amrex::Geometry const& geom, amrex::Geometry const& lev_geom,
38  amrex::BoxArray const& ba, amrex::DistributionMapping const& dm,
39  amrex::Array<std::string,2*AMREX_SPACEDIM> const& domain_bcs_type,
40  amrex::Array<amrex::MultiFab const*,AMREX_SPACEDIM> const& sigma,
41  bool use_real_bcs);
42 
43  //! lhs = div(sigma grad rhs)
44  void apply (amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
45 
46  //! Fill the ghost cells of phi from the FFT boundary conditions and the periodicity
47  void apply_bcs (amrex::MultiFab& phi);
48 
49  //! Enable or disable the FFT preconditioner
50  void usePrecond (bool use_precond_in) { m_use_precond = use_precond_in; }
51 
52  //! fluxes = -grad phi on each face (without sigma)
53  void getFluxes (amrex::MultiFab& phi, amrex::Array<amrex::MultiFab,AMREX_SPACEDIM>& fluxes);
54 
55  void assign (amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
56  void scale (amrex::MultiFab& lhs, amrex::Real fac);
57  amrex::Real dotProduct (amrex::MultiFab const& v1, amrex::MultiFab const& v2);
58  void increment (amrex::MultiFab& lhs, amrex::MultiFab const& rhs, amrex::Real a);
59  void linComb (amrex::MultiFab& lhs, amrex::Real a, amrex::MultiFab const& rhs_a,
60  amrex::Real b, amrex::MultiFab const& rhs_b);
61  amrex::MultiFab makeVecRHS ();
62  amrex::MultiFab makeVecLHS ();
63  amrex::Real norm2 (amrex::MultiFab const& v);
64  //! lhs = the constant-coefficient FFT Poisson solve of rhs (or a copy without the preconditioner)
65  void precond (amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
66  void setToZero (amrex::MultiFab& v);
67 
68 private:
69  bool m_use_precond = false;
70  amrex::Geometry m_geom;
71  amrex::BoxArray m_grids;
72  amrex::DistributionMapping m_dmap;
73  amrex::Array<amrex::MultiFab const*,AMREX_SPACEDIM> m_sigma;
74  std::unique_ptr<amrex::FFT::Poisson<amrex::MultiFab>> m_fft_precond;
75  amrex::Array<std::pair<amrex::FFT::Boundary,amrex::FFT::Boundary>,AMREX_SPACEDIM> m_bc_fft;
76 };
77 
78 #endif
79 #endif
amrex::Real sigma
Definition: ERF_InitCustomPert_DataAssimilation_ISV.H:11
amrex::Real Real
Definition: ERF_ShocInterface.H:19
auto apply_bcs
Definition: ERF_TI_utils.H:34
void apply(const amrex::Box &bx, const amrex::Box &domain, const int quantity, const int flux_comp, const amrex::Array4< const amrex::Real > &state, const amrex::Array4< const amrex::Real > &prim, const amrex::Array4< const amrex::Real > &base_state, const amrex::Array4< const amrex::Real > &u, const amrex::Array4< const amrex::Real > &v, const amrex::Array4< const amrex::Real > &w, const amrex::Array4< amrex::Real > &rhs, const amrex::Array4< amrex::Real > &xflux, const amrex::Array4< amrex::Real > &yflux, const amrex::Array4< amrex::Real > &zflux, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dx_inv, const erf_wall_thermodynamics::Boundary &walls, const amrex::Real alpha_T, const amrex::Real alpha_C, const amrex::Real rdOcp, const bool cloudy=false)
Definition: ERF_CloudChamberWallFlux.H:1037
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real phi(amrex::Real d, amrex::Real z0, amrex::Real psi) noexcept
Definition: ERF_ImmersedWallCell.H:142