ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_TerrainPoisson.H
Go to the documentation of this file.
1 /**
2  * \file ERF_TerrainPoisson.H
3  */
4 #ifndef ERF_TERRAIN_POISSON_H_
5 #define ERF_TERRAIN_POISSON_H_
6 
7 #include <AMReX_Geometry.H>
8 #include <AMReX_MultiFab.H>
9 #include <AMReX_BCRec.H>
10 
11 #ifdef ERF_USE_FFT
12 
14 #include <AMReX_FFT_Poisson.H>
15 
16 /**
17  * Matrix-vector interface for the terrain Poisson operator used by GMRES.
18  */
19 class TerrainPoisson
20 {
21 public:
22 
23  using RT = amrex::Real;
24 
25  /**
26  * Construct a terrain Poisson operator and its FFT preconditioner metadata.
27  *
28  * @param geom Geometry for the subdomain being solved
29  * @param ba BoxArray for operator and vector allocation
30  * @param dm DistributionMapping for operator and vector allocation
31  * @param domain_bcs_type Domain boundary-condition names
32  * @param stretched_dz_lev_d Device stretched-dz spacing for the level
33  * @param ax Terrain metric coefficient on x-faces
34  * @param ay Terrain metric coefficient on y-faces
35  * @param az Terrain metric coefficient on z-faces
36  * @param dJ Cell-centered Jacobian determinant
37  * @param z_phys_nd Node-centered physical height field
38  * @param use_real_bcs Whether real lateral boundary conditions are active
39  */
40  TerrainPoisson (amrex::Geometry const& geom, amrex::BoxArray const& ba,
41  amrex::DistributionMapping const& dm,
42  amrex::Array<std::string,2*AMREX_SPACEDIM>& domain_bcs_type,
43  amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_lev_d,
44  const amrex::MultiFab& ax, const amrex::MultiFab& ay,
45  const amrex::MultiFab& az, const amrex::MultiFab& dJ,
46  amrex::MultiFab const* z_phys_nd,
47  bool use_real_bcs);
48 
49  /**
50  * Apply the terrain Poisson operator.
51  *
52  * @param lhs Destination for the operator result
53  * @param rhs Input vector with ghost cells available for boundary fills
54  */
55  void apply(amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
56 
57  /**
58  * Fill ghost cells according to the configured Poisson boundary conditions.
59  *
60  * @param phi Field whose ghost cells are updated
61  */
62  void apply_bcs(amrex::MultiFab& phi);
63 
64  /**
65  * Enable or disable the FFT preconditioner.
66  *
67  * @param precond_flag True to use the FFT preconditioner
68  */
69  void usePrecond(bool precond_flag);
70 
71  /**
72  * Compute face-centered terrain Poisson fluxes from a solution field.
73  *
74  * @param phi Solution field used to compute gradients
75  * @param fluxes Face-centered fluxes to fill
76  */
77  void getFluxes(amrex::MultiFab& phi, amrex::Array<amrex::MultiFab,AMREX_SPACEDIM>& fluxes);
78 
79  /**
80  * Copy one vector into another.
81  *
82  * @param lhs Destination vector
83  * @param rhs Source vector
84  */
85  void assign(amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
86 
87  /**
88  * Scale a vector in place.
89  *
90  * @param lhs Vector to scale
91  * @param fac Multiplicative scale factor
92  */
93  void scale(amrex::MultiFab& lhs, amrex::Real fac);
94 
95  /**
96  * Compute the vector dot product.
97  *
98  * @param v1 First input vector
99  * @param v2 Second input vector
100  * @return Dot product of v1 and v2
101  */
102  amrex::Real dotProduct(amrex::MultiFab const& v1, amrex::MultiFab const& v2);
103 
104  /**
105  * Add a scaled vector into another vector.
106  *
107  * @param lhs Destination vector to increment
108  * @param rhs Source vector
109  * @param a Scale factor applied to rhs
110  */
111  void increment(amrex::MultiFab& lhs, amrex::MultiFab const& rhs, amrex::Real a);
112 
113  /**
114  * Compute a linear combination of two source vectors.
115  *
116  * @param lhs Destination vector
117  * @param a Scale factor applied to rhs_a
118  * @param rhs_a First source vector
119  * @param b Scale factor applied to rhs_b
120  * @param rhs_b Second source vector
121  */
122  void linComb(amrex::MultiFab& lhs, amrex::Real a, amrex::MultiFab const& rhs_a,
123  amrex::Real b, amrex::MultiFab const& rhs_b);
124 
125  /**
126  * Allocate a vector with the right-hand-side ghost-cell layout.
127  *
128  * @return Newly allocated right-hand-side vector
129  */
130  amrex::MultiFab makeVecRHS();
131 
132  /**
133  * Allocate a vector with the solution ghost-cell layout.
134  *
135  * @return Newly allocated solution vector
136  */
137  amrex::MultiFab makeVecLHS();
138 
139  /**
140  * Compute the L2 norm of a vector.
141  *
142  * @param v Input vector
143  * @return L2 norm of v
144  */
145  amrex::Real norm2(amrex::MultiFab const& v);
146 
147  /**
148  * Apply the configured preconditioner.
149  *
150  * @param lhs Destination for the preconditioned result
151  * @param rhs Input vector to precondition
152  */
153  void precond(amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
154 
155  /**
156  * Set a vector to zero.
157  *
158  * @param v Vector to zero
159  */
160  void setToZero(amrex::MultiFab& v);
161 
162 private:
163  bool m_use_precond = false;
164  amrex::Geometry m_geom;
165  amrex::BoxArray m_grids;
166  amrex::DistributionMapping m_dmap;
167  amrex::Array<std::string,2*AMREX_SPACEDIM> m_domain_bcs_type;
168  amrex::Gpu::DeviceVector<amrex::Real> m_stretched_dz_d;
169  const amrex::MultiFab& m_ax;
170  const amrex::MultiFab& m_ay;
171  const amrex::MultiFab& m_az;
172  const amrex::MultiFab& m_dJ;
173  const amrex::MultiFab* m_zphys;
174 
175  std::unique_ptr<amrex::FFT::PoissonHybrid<amrex::MultiFab>> m_2D_fft_precond;
176  amrex::Array<std::pair<amrex::FFT::Boundary,amrex::FFT::Boundary>,AMREX_SPACEDIM> bc_fft;
177 };
178 
179 #endif
180 #endif
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< 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)
Definition: ERF_ResolvedWallFlux.H:112