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::Geometry const& lev_geom,
41  amrex::BoxArray const& ba,
42  amrex::DistributionMapping const& dm,
43  amrex::Array<std::string,2*AMREX_SPACEDIM>& domain_bcs_type,
44  amrex::Gpu::DeviceVector<amrex::Real>& stretched_dz_lev_d,
45  const amrex::MultiFab& ax, const amrex::MultiFab& ay,
46  const amrex::MultiFab& az, const amrex::MultiFab& dJ,
47  amrex::MultiFab const* z_phys_nd,
48  bool use_real_bcs);
49 
50  /**
51  * Apply the terrain Poisson operator.
52  *
53  * @param lhs Destination for the operator result
54  * @param rhs Input vector with ghost cells available for boundary fills
55  */
56  void apply(amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
57 
58  /**
59  * Fill ghost cells according to the configured Poisson boundary conditions.
60  *
61  * @param phi Field whose ghost cells are updated
62  */
63  void apply_bcs(amrex::MultiFab& phi);
64 
65  /**
66  * Enable or disable the FFT preconditioner.
67  *
68  * @param precond_flag True to use the FFT preconditioner
69  */
70  void usePrecond(bool precond_flag);
71 
72  /**
73  * Compute face-centered terrain Poisson fluxes from a solution field.
74  *
75  * @param phi Solution field used to compute gradients
76  * @param fluxes Face-centered fluxes to fill
77  */
78  void getFluxes(amrex::MultiFab& phi, amrex::Array<amrex::MultiFab,AMREX_SPACEDIM>& fluxes);
79 
80  /**
81  * Copy one vector into another.
82  *
83  * @param lhs Destination vector
84  * @param rhs Source vector
85  */
86  void assign(amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
87 
88  /**
89  * Scale a vector in place.
90  *
91  * @param lhs Vector to scale
92  * @param fac Multiplicative scale factor
93  */
94  void scale(amrex::MultiFab& lhs, amrex::Real fac);
95 
96  /**
97  * Compute the vector dot product.
98  *
99  * @param v1 First input vector
100  * @param v2 Second input vector
101  * @return Dot product of v1 and v2
102  */
103  amrex::Real dotProduct(amrex::MultiFab const& v1, amrex::MultiFab const& v2);
104 
105  /**
106  * Add a scaled vector into another vector.
107  *
108  * @param lhs Destination vector to increment
109  * @param rhs Source vector
110  * @param a Scale factor applied to rhs
111  */
112  void increment(amrex::MultiFab& lhs, amrex::MultiFab const& rhs, amrex::Real a);
113 
114  /**
115  * Compute a linear combination of two source vectors.
116  *
117  * @param lhs Destination vector
118  * @param a Scale factor applied to rhs_a
119  * @param rhs_a First source vector
120  * @param b Scale factor applied to rhs_b
121  * @param rhs_b Second source vector
122  */
123  void linComb(amrex::MultiFab& lhs, amrex::Real a, amrex::MultiFab const& rhs_a,
124  amrex::Real b, amrex::MultiFab const& rhs_b);
125 
126  /**
127  * Allocate a vector with the right-hand-side ghost-cell layout.
128  *
129  * @return Newly allocated right-hand-side vector
130  */
131  amrex::MultiFab makeVecRHS();
132 
133  /**
134  * Allocate a vector with the solution ghost-cell layout.
135  *
136  * @return Newly allocated solution vector
137  */
138  amrex::MultiFab makeVecLHS();
139 
140  /**
141  * Compute the L2 norm of a vector.
142  *
143  * @param v Input vector
144  * @return L2 norm of v
145  */
146  amrex::Real norm2(amrex::MultiFab const& v);
147 
148  /**
149  * Apply the configured preconditioner.
150  *
151  * @param lhs Destination for the preconditioned result
152  * @param rhs Input vector to precondition
153  */
154  void precond(amrex::MultiFab& lhs, amrex::MultiFab const& rhs);
155 
156  /**
157  * Set a vector to zero.
158  *
159  * @param v Vector to zero
160  */
161  void setToZero(amrex::MultiFab& v);
162 
163 private:
164  bool m_use_precond = false;
165  amrex::Geometry m_geom;
166  amrex::BoxArray m_grids;
167  amrex::DistributionMapping m_dmap;
168  amrex::Array<std::string,2*AMREX_SPACEDIM> m_domain_bcs_type;
169  amrex::Gpu::DeviceVector<amrex::Real> m_stretched_dz_d;
170  const amrex::MultiFab& m_ax;
171  const amrex::MultiFab& m_ay;
172  const amrex::MultiFab& m_az;
173  const amrex::MultiFab& m_dJ;
174  const amrex::MultiFab* m_zphys;
175 
176  std::unique_ptr<amrex::FFT::PoissonHybrid<amrex::MultiFab>> m_2D_fft_precond;
177  amrex::Array<std::pair<amrex::FFT::Boundary,amrex::FFT::Boundary>,AMREX_SPACEDIM> bc_fft;
178 };
179 
180 #endif
181 #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