ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_EB.H
Go to the documentation of this file.
1 /**
2  * \file ERF_EB.H
3  * \brief Declares the embedded-boundary factory manager used by ERF levels.
4  */
5 #ifndef ERF_EB_H_
6 #define ERF_EB_H_
7 
8 #include <AMReX_Geometry.H>
9 #include <AMReX_DistributionMapping.H>
10 #include <AMReX_BoxArray.H>
11 
12 #include <AMReX_EB2.H>
13 #include <AMReX_EBFabFactory.H>
14 
15 #include <ERF_EBAux.H>
16 
17 /**
18  * \brief Owns and exposes cell-centered and face-centered EB factories.
19  *
20  * The class builds AMReX EB factories for cell-centered state data and, depending
21  * on USE_FC_FACTORY, either native AMReX or ERF auxiliary factories for staggered
22  * velocity components.
23  */
24 class eb_ {
25 
26  public:
27 
28  //! Destroy the EB factory manager.
29  ~eb_ ();
30 
31  /**
32  * \brief Construct an EB description from terrain data.
33  * \param a_geom Geometry used to place the terrain EB.
34  * \param terrain_fab Terrain height data.
35  * \param a_dz_stretched Device vector containing stretched vertical spacing.
36  * \param is_anelastic Whether the owning level is using anelastic dynamics.
37  */
38  eb_ (amrex::Geometry const& a_geom,
39  amrex::FArrayBox const& terrain_fab,
40  amrex::Gpu::DeviceVector<amrex::Real>& a_dz_stretched,
41  bool is_anelastic);
42  //! Construct an empty EB factory manager.
43  eb_ ();
44 
45  /**
46  * \brief Define the EB level metadata used by this factory manager.
47  * \param level AMR level index.
48  * \param a_geom Geometry for the level.
49  * \param a_eb_level AMReX EB level owned by the global EB index space.
50  * \param is_anelastic Whether the owning level is using anelastic dynamics.
51  */
52  void define (int level,
53  amrex::Geometry const& a_geom,
54  amrex::EB2::Level const* a_eb_level,
55  bool is_anelastic);
56 
57  /**
58  * \brief Build cell-centered and staggered EB factories for the level.
59  * \param level AMR level index.
60  * \param a_geom Geometry for the level.
61  * \param ba BoxArray over which factories are defined.
62  * \param dm DistributionMapping for the BoxArray.
63  * \param a_eb_level AMReX EB level used to populate factory data.
64  */
65  void make_all_factories ( int level,
66  amrex::Geometry const& a_geom,
67  amrex::BoxArray const& ba,
68  amrex::DistributionMapping const& dm,
69  amrex::EB2::Level const& a_eb_level);
70 
71  /**
72  * \brief Build only the cell-centered EB factory for the level.
73  * \param level AMR level index.
74  * \param a_geom Geometry for the level.
75  * \param ba BoxArray over which the factory is defined.
76  * \param dm DistributionMapping for the BoxArray.
77  * \param a_eb_level AMReX EB level used to populate factory data.
78  */
79  void make_cc_factory ( int level,
80  amrex::Geometry const& a_geom,
81  amrex::BoxArray const& ba,
82  amrex::DistributionMapping const& dm,
83  amrex::EB2::Level const& a_eb_level);
84 
85  //! Number of ghost cells needed for basic EB flags.
86  int nghost_basic () const { return 5; } // nghost_eb_basic ()
87  //! Number of ghost cells needed for EB volume data.
88  int nghost_volume () const { return 5; } // nghost_eb_volume ()
89  //! Number of ghost cells needed for full EB geometric data.
90  int nghost_full () const { return 4; } // nghost_eb_full ()
91 
92  // Toggle between eb_aux_ and native AMReX FC factories
93  #ifndef USE_FC_FACTORY
94  /**
95  * \def USE_FC_FACTORY
96  * \brief Select native AMReX face-centered factories instead of ERF auxiliary factories.
97  */
98  #define USE_FC_FACTORY 0 // Default to 0: use eb_aux_ (original)
99  #endif
100 
101  //! Return the cell-centered EB factory.
102  const std::unique_ptr<amrex::EBFArrayBoxFactory>& get_const_factory () const noexcept { return m_factory; }
103 
104  /**
105  * \brief Disconnect covered neighbors in an EB factory's cell flags.
106  * \param factory Factory whose non-const flag data are updated.
107  */
108  void set_connection_flags (amrex::EBFArrayBoxFactory* factory);
109 
110  /**
111  * \brief Enforce FC-CC consistency by marking FC faces as covered when both CC neighbors are covered.
112  * \param fc_factory Face-centered factory to modify (non-const)
113  * \param cc_factory Cell-centered factory to read neighbor states (const)
114  * \param idim Direction of face centering (0=x, 1=y, 2=z)
115  */
116  void mask_fc_from_cc (amrex::EBFArrayBoxFactory* fc_factory,
117  const amrex::EBFArrayBoxFactory* cc_factory,
118  int idim);
119 
120  #if USE_FC_FACTORY
121  //! Return the native AMReX x-face EB factory.
122  amrex::EBFArrayBoxFactory const* get_u_const_factory() const noexcept { return m_u_factory_fc.get(); }
123  //! Return the native AMReX y-face EB factory.
124  amrex::EBFArrayBoxFactory const* get_v_const_factory() const noexcept { return m_v_factory_fc.get(); }
125  //! Return the native AMReX z-face EB factory.
126  amrex::EBFArrayBoxFactory const* get_w_const_factory() const noexcept { return m_w_factory_fc.get(); }
127  #else
128  //! Return the ERF auxiliary x-face EB factory.
129  eb_aux_ const* get_u_const_factory() const noexcept { return &m_u_factory; }
130  //! Return the ERF auxiliary y-face EB factory.
131  eb_aux_ const* get_v_const_factory() const noexcept { return &m_v_factory; }
132  //! Return the ERF auxiliary z-face EB factory.
133  eb_aux_ const* get_w_const_factory() const noexcept { return &m_w_factory; }
134  #endif
135 
136  //! Forward declaration for EB surface output.
137  class EBToPVD;
138 
139  private:
140 
141  int m_has_eb;
142  std::string m_type;
143 
144  amrex::EBSupport m_support_level;
145 
147 
148  amrex::FabArray<amrex::EBCellFlagFab>* m_cellflags = nullptr;
149 
150  //! EB level constructed from building GeometryShop
151  amrex::EB2::Level const* m_eb_level;
152 
153  std::unique_ptr<amrex::EBFArrayBoxFactory> m_factory = nullptr;
154 
155  // Original eb_aux_ factories (USE_FC_FACTORY=0)
159 
160  // New native AMReX FC factories (USE_FC_FACTORY=1)
161  std::unique_ptr<amrex::EBFArrayBoxFactory> m_u_factory_fc = nullptr;
162  std::unique_ptr<amrex::EBFArrayBoxFactory> m_v_factory_fc = nullptr;
163  std::unique_ptr<amrex::EBFArrayBoxFactory> m_w_factory_fc = nullptr;
164 
165  /**
166  * \brief Build terrain EB geometry for the supplied Geometry.
167  * \param a_geom Geometry used to define the EB index space.
168  */
169  void make_terrain (amrex::Geometry const& a_geom);
170 
171  /**
172  * \brief Construct EB levels from an AMReX GeometryShop.
173  * \tparam F Implicit-function type stored by the GeometryShop.
174  * \param a_geom Geometry used to build the EB index space.
175  * \param a_gshop GeometryShop describing the implicit EB.
176  */
177  template<class F>
178  void build_level (amrex::Geometry const& a_geom,
179  amrex::EB2::GeometryShop<F> a_gshop)
180  {
181  int const req_lev(0);
182  int const max_lev(2);
183 
184  amrex::EB2::Build(a_gshop, a_geom, req_lev, max_lev);
185  const amrex::EB2::IndexSpace& ebis = amrex::EB2::IndexSpace::top();
186  m_eb_level = &(ebis.getLevel(a_geom));
187  }
188 
189  //! Return mutable EB cell flags from an AMReX factory.
190  inline amrex::FabArray<amrex::EBCellFlagFab>&
191  getNonConstEBCellFlags(const amrex::EBFArrayBoxFactory& ebfact)
192  {
193  const amrex::FabArray<amrex::EBCellFlagFab>& flags_const = ebfact.getMultiEBCellFlagFab();
194  return const_cast<amrex::FabArray<amrex::EBCellFlagFab>&>(flags_const);
195  }
196 
197  //! Return mutable volume fractions from an AMReX factory.
198  inline amrex::MultiFab&
199  getNonConstVolFrac(const amrex::EBFArrayBoxFactory& ebfact)
200  {
201  const amrex::MultiFab& vfrac_const = ebfact.getVolFrac();
202  return const_cast<amrex::MultiFab&>(vfrac_const);
203  }
204 
205  //! Return mutable cell centroids from an AMReX factory.
206  inline amrex::MultiCutFab&
207  getNonConstCentroid(const amrex::EBFArrayBoxFactory& ebfact)
208  {
209  const amrex::MultiCutFab& vcent_const = ebfact.getCentroid();
210  return const_cast<amrex::MultiCutFab&>(vcent_const);
211  }
212 
213  //! Return mutable area-fraction arrays from an AMReX factory.
214  inline amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM>
215  getNonConstAreaFrac(const amrex::EBFArrayBoxFactory& ebfact)
216  {
217  auto afrac_const = ebfact.getAreaFrac();
218  amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM> afrac;
219  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
220  afrac[dir] = const_cast<amrex::MultiCutFab*>(afrac_const[dir]);
221  }
222  return afrac;
223  }
224 
225  //! Return mutable face-centroid arrays from an AMReX factory.
226  inline amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM>
227  getNonConstFaceCent(const amrex::EBFArrayBoxFactory& ebfact)
228  {
229  auto fcent_const = ebfact.getFaceCent();
230  amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM> fcent;
231  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
232  fcent[dir] = const_cast<amrex::MultiCutFab*>(fcent_const[dir]);
233  }
234  return fcent;
235  }
236 
237 };
238 #endif
Declares auxiliary EB factories for face-centered data.
Owns and exposes cell-centered and face-centered EB factories.
Definition: ERF_EB.H:24
amrex::FabArray< amrex::EBCellFlagFab > & getNonConstEBCellFlags(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable EB cell flags from an AMReX factory.
Definition: ERF_EB.H:191
eb_()
Construct an empty EB factory manager.
Definition: ERF_EB.cpp:30
void define(int level, amrex::Geometry const &a_geom, amrex::EB2::Level const *a_eb_level, bool is_anelastic)
Define the EB level metadata used by this factory manager.
void make_terrain(amrex::Geometry const &a_geom)
Build terrain EB geometry for the supplied Geometry.
eb_aux_ const * get_w_const_factory() const noexcept
Return the ERF auxiliary z-face EB factory.
Definition: ERF_EB.H:133
void build_level(amrex::Geometry const &a_geom, amrex::EB2::GeometryShop< F > a_gshop)
Construct EB levels from an AMReX GeometryShop.
Definition: ERF_EB.H:178
amrex::Array< amrex::MultiCutFab *, AMREX_SPACEDIM > getNonConstAreaFrac(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable area-fraction arrays from an AMReX factory.
Definition: ERF_EB.H:215
void mask_fc_from_cc(amrex::EBFArrayBoxFactory *fc_factory, const amrex::EBFArrayBoxFactory *cc_factory, int idim)
Enforce FC-CC consistency by marking FC faces as covered when both CC neighbors are covered.
Definition: ERF_EB.cpp:171
amrex::EB2::Level const * m_eb_level
EB level constructed from building GeometryShop.
Definition: ERF_EB.H:151
void make_all_factories(int level, amrex::Geometry const &a_geom, amrex::BoxArray const &ba, amrex::DistributionMapping const &dm, amrex::EB2::Level const &a_eb_level)
Build cell-centered and staggered EB factories for the level.
Definition: ERF_EB.cpp:37
amrex::FabArray< amrex::EBCellFlagFab > * m_cellflags
Definition: ERF_EB.H:148
const std::unique_ptr< amrex::EBFArrayBoxFactory > & get_const_factory() const noexcept
Return the cell-centered EB factory.
Definition: ERF_EB.H:102
amrex::MultiFab & getNonConstVolFrac(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable volume fractions from an AMReX factory.
Definition: ERF_EB.H:199
eb_aux_ m_w_factory
Definition: ERF_EB.H:158
std::unique_ptr< amrex::EBFArrayBoxFactory > m_factory
Definition: ERF_EB.H:153
amrex::EBSupport m_support_level
Definition: ERF_EB.H:144
int nghost_volume() const
Number of ghost cells needed for EB volume data.
Definition: ERF_EB.H:88
amrex::Array< amrex::MultiCutFab *, AMREX_SPACEDIM > getNonConstFaceCent(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable face-centroid arrays from an AMReX factory.
Definition: ERF_EB.H:227
void make_cc_factory(int level, amrex::Geometry const &a_geom, amrex::BoxArray const &ba, amrex::DistributionMapping const &dm, amrex::EB2::Level const &a_eb_level)
Build only the cell-centered EB factory for the level.
Definition: ERF_EB.cpp:108
amrex::MultiCutFab & getNonConstCentroid(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable cell centroids from an AMReX factory.
Definition: ERF_EB.H:207
eb_aux_ m_u_factory
Definition: ERF_EB.H:156
~eb_()
Destroy the EB factory manager.
Definition: ERF_EB.cpp:25
std::unique_ptr< amrex::EBFArrayBoxFactory > m_w_factory_fc
Definition: ERF_EB.H:163
eb_(amrex::Geometry const &a_geom, amrex::FArrayBox const &terrain_fab, amrex::Gpu::DeviceVector< amrex::Real > &a_dz_stretched, bool is_anelastic)
Construct an EB description from terrain data.
eb_aux_ const * get_v_const_factory() const noexcept
Return the ERF auxiliary y-face EB factory.
Definition: ERF_EB.H:131
eb_aux_ m_v_factory
Definition: ERF_EB.H:157
std::unique_ptr< amrex::EBFArrayBoxFactory > m_v_factory_fc
Definition: ERF_EB.H:162
int m_has_eb
Definition: ERF_EB.H:137
int nghost_full() const
Number of ghost cells needed for full EB geometric data.
Definition: ERF_EB.H:90
int nghost_basic() const
Number of ghost cells needed for basic EB flags.
Definition: ERF_EB.H:86
int m_write_eb_surface
Definition: ERF_EB.H:146
std::unique_ptr< amrex::EBFArrayBoxFactory > m_u_factory_fc
Definition: ERF_EB.H:161
eb_aux_ const * get_u_const_factory() const noexcept
Return the ERF auxiliary x-face EB factory.
Definition: ERF_EB.H:129
std::string m_type
Definition: ERF_EB.H:142
void set_connection_flags(amrex::EBFArrayBoxFactory *factory)
Disconnect covered neighbors in an EB factory's cell flags.
Definition: ERF_EB.cpp:127
Stores face-centered EB geometry reconstructed from a cell-centered factory.
Definition: ERF_EBAux.H:24