REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_FillPatcher.H
Go to the documentation of this file.
1#ifndef REMORA_FILLPATCHER_H_
2#define REMORA_FILLPATCHER_H_
3
4#include <REMORA_Constants.H>
5#include <AMReX_FillPatchUtil.H>
6#include <AMReX_Interp_C.H>
7#include <AMReX_MFInterp_C.H>
8
10{
11public:
12
13 /** \brief Fill valid and ghost data with the "state data" at the given time */
14 REMORAFillPatcher (amrex::BoxArray const& fba, amrex::DistributionMapping const& fdm,
15 amrex::Geometry const& fgeom,
16 amrex::BoxArray const& cba, amrex::DistributionMapping const& cdm,
17 amrex::Geometry const& cgeom,
18 int nghost, int nghost_set, int ncomp, amrex::InterpBase* interp);
19
20 /** \brief Redefine the coarse and fine patch MultiFabs. */
21 void Define (amrex::BoxArray const& fba, amrex::DistributionMapping const& fdm,
22 amrex::Geometry const& fgeom,
23 amrex::BoxArray const& cba, amrex::DistributionMapping const& cdm,
24 amrex::Geometry const& cgeom,
25 int nghost, int nghost_set, int ncomp,
26 amrex::InterpBase* interp);
27
28 /** \brief Generate masking array */
29 void BuildMask (amrex::BoxArray const& fba, int nghost, int nghost_set);
30
31 /** \brief Register the coarse data to be used by the REMORAFillPatcher */
32 void RegisterCoarseData (amrex::Vector<amrex::MultiFab const*> const& crse_data,
33 amrex::Vector<amrex::Real> const& crse_time);
34
35 /** \brief Interpolate to cell faces */
36 void InterpFace (amrex::MultiFab& fine,
37 amrex::MultiFab const& crse,
38 int mask_val);
39
40 /** \brief Interpolate to cell centers */
41 void InterpCell (amrex::MultiFab& fine,
42 amrex::MultiFab const& crse,
43 amrex::Vector<amrex::BCRec> const& bcr,
44 int mask_val);
45
46 int GetSetMaskVal () { return m_set_mask; }
47
48 int GetRelaxMaskVal () { return m_relax_mask; }
49
50 amrex::iMultiFab* GetMask () { return m_cf_mask.get(); }
51
52 /** \brief Fill fine data in the set region */
53 template <typename BC>
54 void FillSet (amrex::MultiFab& mf, amrex::Real time,
55 BC& cbc, amrex::Vector<amrex::BCRec> const& bcs);
56
57 /** \brief Fill fine data in the relax region */
58 template <typename BC>
59 void FillRelax (amrex::MultiFab& mf, amrex::Real time,
60 BC& cbc, amrex::Vector<amrex::BCRec> const& bcs);
61 /** \brief Fill fine data in the relax region */
62 template <typename BC>
63 void Fill (amrex::MultiFab& mf, amrex::Real time,
64 BC& cbc, amrex::Vector<amrex::BCRec> const& bcs, int mask_val);
65
66private:
67
68 amrex::BoxArray m_fba;
69 amrex::BoxArray m_cba;
70 amrex::DistributionMapping m_fdm;
71 amrex::DistributionMapping m_cdm;
72 amrex::Geometry m_fgeom;
73 amrex::Geometry m_cgeom;
77 amrex::InterpBase* m_interp;
78 amrex::IntVect m_ratio;
79 std::unique_ptr<amrex::MultiFab> m_cf_crse_data_old;
80 std::unique_ptr<amrex::MultiFab> m_cf_crse_data_new;
81 std::unique_ptr<amrex::iMultiFab> m_cf_mask;
82 amrex::Vector<amrex::Real> m_crse_times;
83 amrex::Real m_dt_crse;
84 int m_set_mask{2};
86};
87
88/**
89 * @param[out] mf MultiFab to be filled
90 * @param[in] time Time at which to fill data
91 * @param[in] cbc Coarse boundary condition
92 * @param[in] bcs Vector of boundary conditions
93 */
94template <typename BC>
95void
96REMORAFillPatcher::FillSet (amrex::MultiFab& mf, amrex::Real time,
97 BC& cbc, amrex::Vector<amrex::BCRec> const& bcs)
98{
99 Fill(mf,time,cbc,bcs,m_set_mask);
100}
101
102/**
103 * @param[out] mf MultiFab to be filled
104 * @param[in] time Time at which to fill data
105 * @param[in] cbc Coarse boundary condition
106 * @param[in] bcs Vector of boundary conditions
107 */
108template <typename BC>
109void
110REMORAFillPatcher::FillRelax (amrex::MultiFab& mf, amrex::Real time,
111 BC& cbc, amrex::Vector<amrex::BCRec> const& bcs)
112{
113 Fill(mf,time,cbc,bcs,m_relax_mask);
114}
115
116/**
117 * @param[out] mf MultiFab to be filled
118 * @param[in] time Time at which to fill data
119 * @param[in] cbc Coarse boundary condition
120 * @param[in] bcs Vector of boundary conditions
121 * @param[in] mask_val Value to assign mask array
122 */
123template <typename BC>
124void
125REMORAFillPatcher::Fill (amrex::MultiFab& mf, amrex::Real time,
126 BC& cbc, amrex::Vector<amrex::BCRec> const& bcs, int mask_val)
127{
128 constexpr amrex::Real eps = std::numeric_limits<float>::epsilon();
129
130 AMREX_ALWAYS_ASSERT((time >= m_crse_times[0]-eps) && (time <= m_crse_times[1]+eps));
131
132 // Time interpolation factors
133 amrex::Real fac_new = (time - m_crse_times[0]) / m_dt_crse;
134 amrex::Real fac_old = one - fac_new;
135
136 // Boundary condition operator
137 cbc(*(m_cf_crse_data_old), 0, m_ncomp, amrex::IntVect(0), time, 0);
138
139 // Coarse MF to hold time interpolated data
140 amrex::MultiFab crse_data_time_interp(m_cf_crse_data_old->boxArray(),
141 m_cf_crse_data_old->DistributionMap(),
142 m_ncomp, amrex::IntVect{0});
143
144 // Time interpolate the coarse data
145 amrex::MultiFab::LinComb(crse_data_time_interp,
146 fac_old, *(m_cf_crse_data_old), 0,
147 fac_new, *(m_cf_crse_data_new), 0,
148 0, m_ncomp, amrex::IntVect{0});
149
150 // Call correct spatial interpolation type
151 amrex::IndexType m_ixt = mf.boxArray().ixType();
152 int ixt_sum = m_ixt[0]+m_ixt[1]+m_ixt[2];
153 if (ixt_sum == 0) {
154 InterpCell(mf,crse_data_time_interp,bcs,mask_val);
155 } else if (ixt_sum == 1) {
156 InterpFace(mf,crse_data_time_interp,mask_val);
157 } else {
158 amrex::Abort("REMORA_FillPatcher only supports face linear and cell cons linear interp!");
159 }
160}
161#endif
constexpr amrex::Real one
AMREX_ALWAYS_ASSERT(!NSPeriodic||!EWPeriodic)
amrex::InterpBase * m_interp
void FillRelax(amrex::MultiFab &mf, amrex::Real time, BC &cbc, amrex::Vector< amrex::BCRec > const &bcs)
Fill fine data in the relax region.
amrex::DistributionMapping m_fdm
amrex::iMultiFab * GetMask()
void Define(amrex::BoxArray const &fba, amrex::DistributionMapping const &fdm, amrex::Geometry const &fgeom, amrex::BoxArray const &cba, amrex::DistributionMapping const &cdm, amrex::Geometry const &cgeom, int nghost, int nghost_set, int ncomp, amrex::InterpBase *interp)
Redefine the coarse and fine patch MultiFabs.
void RegisterCoarseData(amrex::Vector< amrex::MultiFab const * > const &crse_data, amrex::Vector< amrex::Real > const &crse_time)
Register the coarse data to be used by the REMORAFillPatcher.
amrex::IntVect m_ratio
void InterpCell(amrex::MultiFab &fine, amrex::MultiFab const &crse, amrex::Vector< amrex::BCRec > const &bcr, int mask_val)
Interpolate to cell centers.
amrex::Geometry m_fgeom
amrex::BoxArray m_cba
amrex::BoxArray m_fba
void Fill(amrex::MultiFab &mf, amrex::Real time, BC &cbc, amrex::Vector< amrex::BCRec > const &bcs, int mask_val)
Fill fine data in the relax region.
amrex::Vector< amrex::Real > m_crse_times
void InterpFace(amrex::MultiFab &fine, amrex::MultiFab const &crse, int mask_val)
Interpolate to cell faces.
std::unique_ptr< amrex::MultiFab > m_cf_crse_data_new
void BuildMask(amrex::BoxArray const &fba, int nghost, int nghost_set)
Generate masking array.
amrex::DistributionMapping m_cdm
amrex::Geometry m_cgeom
std::unique_ptr< amrex::iMultiFab > m_cf_mask
std::unique_ptr< amrex::MultiFab > m_cf_crse_data_old
void FillSet(amrex::MultiFab &mf, amrex::Real time, BC &cbc, amrex::Vector< amrex::BCRec > const &bcs)
Fill fine data in the set region.