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  #if USE_FC_FACTORY
111  //! Return the native AMReX x-face EB factory.
112  amrex::EBFArrayBoxFactory const* get_u_const_factory() const noexcept { return m_u_factory_fc.get(); }
113  //! Return the native AMReX y-face EB factory.
114  amrex::EBFArrayBoxFactory const* get_v_const_factory() const noexcept { return m_v_factory_fc.get(); }
115  //! Return the native AMReX z-face EB factory.
116  amrex::EBFArrayBoxFactory const* get_w_const_factory() const noexcept { return m_w_factory_fc.get(); }
117  #else
118  //! Return the ERF auxiliary x-face EB factory.
119  eb_aux_ const* get_u_const_factory() const noexcept { return &m_u_factory; }
120  //! Return the ERF auxiliary y-face EB factory.
121  eb_aux_ const* get_v_const_factory() const noexcept { return &m_v_factory; }
122  //! Return the ERF auxiliary z-face EB factory.
123  eb_aux_ const* get_w_const_factory() const noexcept { return &m_w_factory; }
124  #endif
125 
126  //! Forward declaration for EB surface output.
127  class EBToPVD;
128 
129  private:
130 
131  int m_has_eb;
132  std::string m_type;
133 
134  amrex::EBSupport m_support_level;
135 
137 
138  amrex::FabArray<amrex::EBCellFlagFab>* m_cellflags = nullptr;
139 
140  //! EB level constructed from building GeometryShop
141  amrex::EB2::Level const* m_eb_level;
142 
143  std::unique_ptr<amrex::EBFArrayBoxFactory> m_factory = nullptr;
144 
145  // Original eb_aux_ factories (USE_FC_FACTORY=0)
149 
150  // New native AMReX FC factories (USE_FC_FACTORY=1)
151  std::unique_ptr<amrex::EBFArrayBoxFactory> m_u_factory_fc = nullptr;
152  std::unique_ptr<amrex::EBFArrayBoxFactory> m_v_factory_fc = nullptr;
153  std::unique_ptr<amrex::EBFArrayBoxFactory> m_w_factory_fc = nullptr;
154 
155  /**
156  * \brief Build terrain EB geometry for the supplied Geometry.
157  * \param a_geom Geometry used to define the EB index space.
158  */
159  void make_terrain (amrex::Geometry const& a_geom);
160 
161  /**
162  * \brief Construct EB levels from an AMReX GeometryShop.
163  * \tparam F Implicit-function type stored by the GeometryShop.
164  * \param a_geom Geometry used to build the EB index space.
165  * \param a_gshop GeometryShop describing the implicit EB.
166  */
167  template<class F>
168  void build_level (amrex::Geometry const& a_geom,
169  amrex::EB2::GeometryShop<F> a_gshop)
170  {
171  int const req_lev(0);
172  int const max_lev(2);
173 
174  amrex::EB2::Build(a_gshop, a_geom, req_lev, max_lev);
175  const amrex::EB2::IndexSpace& ebis = amrex::EB2::IndexSpace::top();
176  m_eb_level = &(ebis.getLevel(a_geom));
177  }
178 
179  //! Return mutable EB cell flags from an AMReX factory.
180  inline amrex::FabArray<amrex::EBCellFlagFab>&
181  getNonConstEBCellFlags(const amrex::EBFArrayBoxFactory& ebfact)
182  {
183  const amrex::FabArray<amrex::EBCellFlagFab>& flags_const = ebfact.getMultiEBCellFlagFab();
184  return const_cast<amrex::FabArray<amrex::EBCellFlagFab>&>(flags_const);
185  }
186 
187  //! Return mutable volume fractions from an AMReX factory.
188  inline amrex::MultiFab&
189  getNonConstVolFrac(const amrex::EBFArrayBoxFactory& ebfact)
190  {
191  const amrex::MultiFab& vfrac_const = ebfact.getVolFrac();
192  return const_cast<amrex::MultiFab&>(vfrac_const);
193  }
194 
195  //! Return mutable cell centroids from an AMReX factory.
196  inline amrex::MultiCutFab&
197  getNonConstCentroid(const amrex::EBFArrayBoxFactory& ebfact)
198  {
199  const amrex::MultiCutFab& vcent_const = ebfact.getCentroid();
200  return const_cast<amrex::MultiCutFab&>(vcent_const);
201  }
202 
203  //! Return mutable area-fraction arrays from an AMReX factory.
204  inline amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM>
205  getNonConstAreaFrac(const amrex::EBFArrayBoxFactory& ebfact)
206  {
207  auto afrac_const = ebfact.getAreaFrac();
208  amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM> afrac;
209  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
210  afrac[dir] = const_cast<amrex::MultiCutFab*>(afrac_const[dir]);
211  }
212  return afrac;
213  }
214 
215  //! Return mutable face-centroid arrays from an AMReX factory.
216  inline amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM>
217  getNonConstFaceCent(const amrex::EBFArrayBoxFactory& ebfact)
218  {
219  auto fcent_const = ebfact.getFaceCent();
220  amrex::Array<amrex::MultiCutFab*, AMREX_SPACEDIM> fcent;
221  for (int dir = 0; dir < AMREX_SPACEDIM; ++dir) {
222  fcent[dir] = const_cast<amrex::MultiCutFab*>(fcent_const[dir]);
223  }
224  return fcent;
225  }
226 
227 };
228 #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:181
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:123
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:168
amrex::Array< amrex::MultiCutFab *, AMREX_SPACEDIM > getNonConstAreaFrac(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable area-fraction arrays from an AMReX factory.
Definition: ERF_EB.H:205
amrex::EB2::Level const * m_eb_level
EB level constructed from building GeometryShop.
Definition: ERF_EB.H:141
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:138
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:189
eb_aux_ m_w_factory
Definition: ERF_EB.H:148
std::unique_ptr< amrex::EBFArrayBoxFactory > m_factory
Definition: ERF_EB.H:143
amrex::EBSupport m_support_level
Definition: ERF_EB.H:134
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:217
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:105
amrex::MultiCutFab & getNonConstCentroid(const amrex::EBFArrayBoxFactory &ebfact)
Return mutable cell centroids from an AMReX factory.
Definition: ERF_EB.H:197
eb_aux_ m_u_factory
Definition: ERF_EB.H:146
~eb_()
Destroy the EB factory manager.
Definition: ERF_EB.cpp:25
std::unique_ptr< amrex::EBFArrayBoxFactory > m_w_factory_fc
Definition: ERF_EB.H:153
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:121
eb_aux_ m_v_factory
Definition: ERF_EB.H:147
std::unique_ptr< amrex::EBFArrayBoxFactory > m_v_factory_fc
Definition: ERF_EB.H:152
int m_has_eb
Definition: ERF_EB.H:127
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:136
std::unique_ptr< amrex::EBFArrayBoxFactory > m_u_factory_fc
Definition: ERF_EB.H:151
eb_aux_ const * get_u_const_factory() const noexcept
Return the ERF auxiliary x-face EB factory.
Definition: ERF_EB.H:119
std::string m_type
Definition: ERF_EB.H:132
void set_connection_flags(amrex::EBFArrayBoxFactory *factory)
Disconnect covered neighbors in an EB factory's cell flags.
Definition: ERF_EB.cpp:124
Stores face-centered EB geometry reconstructed from a cell-centered factory.
Definition: ERF_EBAux.H:22