chombo-discharge
CD_IrregAmrStencilImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_IrregAmrStencilImplem_H
13 #define CD_IrregAmrStencilImplem_H
14 
15 // Our includes
16 #include <CD_IrregAmrStencil.H>
17 #include <CD_NamespaceHeader.H>
18 
19 template <class IrregSten>
21 {
22  CH_TIME("IrregAmrStencil::IrregAmrStencil");
23  m_isDefined = false;
24 }
25 
26 template <class IrregSten>
27 IrregAmrStencil<IrregSten>::IrregAmrStencil(const Vector<DisjointBoxLayout>& a_grids,
28  const Vector<EBISLayout>& a_ebisl,
29  const Vector<ProblemDomain>& a_domains,
30  const Vector<Real>& a_dx,
31  const int a_finestLevel,
32  const int a_order,
33  const int a_radius,
34  const IrregStencil::StencilType a_type)
35 {
36  CH_TIME("IrregAmrStencil::IrregAmrStencil");
37 
38  this->define(a_grids, a_ebisl, a_domains, a_dx, a_finestLevel, a_order, a_radius, a_type);
39 }
40 
41 template <class IrregSten>
43 {
44  CH_TIME("IrregAmrStencil::~IrregAmrStencil");
45 }
46 
47 template <class IrregSten>
48 const IrregStencil&
50 {
51  return *m_stencils[a_lvl];
52 }
53 
54 template <class IrregSten>
57 {
58  return *m_stencils[a_lvl];
59 }
60 
61 template <class IrregSten>
62 void
63 IrregAmrStencil<IrregSten>::define(const Vector<DisjointBoxLayout>& a_grids,
64  const Vector<EBISLayout>& a_ebisl,
65  const Vector<ProblemDomain>& a_domains,
66  const Vector<Real>& a_dx,
67  const int a_finestLevel,
68  const int a_order,
69  const int a_radius,
70  const IrregStencil::StencilType a_type)
71 {
72  CH_TIME("IrregAmrStencil::define");
73 
74  // Store input arguments.
75  m_grids = a_grids;
76  m_ebisl = a_ebisl;
77  m_domains = a_domains;
78  m_dx = a_dx;
79  m_finestLevel = a_finestLevel;
80  m_order = a_order;
81  m_radius = a_radius;
82  m_stencilType = a_type;
83 
84  // Define stencils on each level
85  m_stencils.resize(1 + m_finestLevel);
86  for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
87  m_stencils[lvl] = RefCountedPtr<IrregStencil>(
88  new IrregSten(m_grids[lvl], m_ebisl[lvl], m_domains[lvl], m_dx[lvl], m_order, m_radius, m_stencilType));
89  }
90 
91  m_isDefined = true;
92 }
93 
94 template <class IrregSten>
95 void
96 IrregAmrStencil<IrregSten>::apply(LevelData<EBCellFAB>& a_dst, const LevelData<EBCellFAB>& a_src, const int a_lvl) const
97 {
98  CH_TIME("IrregAmrStencil::apply(LD<EBCellFABx2, int)");
99 
100  CH_assert(m_isDefined);
101 
102  const DataIterator& dit = m_grids[a_lvl].dataIterator();
103 
104  const int nbox = dit.size();
105 #pragma omp parallel for schedule(runtime)
106  for (int mybox = 0; mybox < nbox; mybox++) {
107  const DataIndex& din = dit[mybox];
108 
109  m_stencils[a_lvl]->apply(a_dst[din], a_src[din], din);
110  }
111 }
112 
113 template <class IrregSten>
114 void
115 IrregAmrStencil<IrregSten>::apply(LevelData<EBCellFAB>& a_data, const int a_lvl) const
116 {
117  CH_TIME("IrregAmrStencil::apply(LD<EBCellFAB, int)");
118 
119  CH_assert(m_isDefined);
120 
121  const DataIterator& dit = m_grids[a_lvl].dataIterator();
122 
123  const int nbox = dit.size();
124 #pragma omp parallel for schedule(runtime)
125  for (int mybox = 0; mybox < nbox; mybox++) {
126  const DataIndex& din = dit[mybox];
127 
128  EBCellFAB& data = a_data[din];
129  EBCellFAB cpy;
130 
131  // Need a clone to avoid race condition.
132  cpy.clone(data);
133  cpy.setVal(0.0);
134  cpy += data;
135 
136  m_stencils[a_lvl]->apply(data, cpy, din);
137  }
138 }
139 
140 template <class IrregSten>
141 void
142 IrregAmrStencil<IrregSten>::apply(LevelData<BaseIVFAB<Real>>& a_dst,
143  const LevelData<EBCellFAB>& a_src,
144  const int a_lvl) const
145 {
146  CH_TIME("IrregAmrStencil::apply(LD<BaseIVFAB>, LD<EBCellFAB>, int)");
147 
148  CH_assert(m_isDefined);
149 
150  const DataIterator& dit = m_grids[a_lvl].dataIterator();
151 
152  const int nbox = dit.size();
153 #pragma omp parallel for schedule(runtime)
154  for (int mybox = 0; mybox < nbox; mybox++) {
155  const DataIndex& din = dit[mybox];
156 
157  m_stencils[a_lvl]->apply(a_dst[din], a_src[din], din);
158  }
159 }
160 
161 template <class IrregSten>
162 void
164 {
165  CH_TIME("IrregAmrStencil::apply");
166 
167  CH_assert(m_isDefined);
168 
169  for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
170  this->apply(*a_data[lvl], lvl);
171  }
172 }
173 
174 template <class IrregSten>
175 void
177 {
178  CH_TIME("IrregAmrStencil::apply");
179 
180  CH_assert(m_isDefined);
181 
182  for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
183  this->apply(*a_dst[lvl], *a_src[lvl], lvl);
184  }
185 }
186 
187 template <class IrregSten>
188 void
190 {
191  CH_TIME("IrregAmrStencil::apply");
192 
193  CH_assert(m_isDefined);
194 
195  for (int lvl = 0; lvl <= m_finestLevel; lvl++) {
196  this->apply(*a_dst[lvl], *a_src[lvl], lvl);
197  }
198 }
199 
200 template <class IrregSten>
201 void
202 IrregAmrStencil<IrregSten>::apply(Vector<EBAMRIVData*>& a_dst, const Vector<EBAMRCellData*>& a_src) const
203 {
204  CH_TIME("IrregAmrStencil::apply");
205 
206  const int dstSize = a_dst.size();
207  const int srcSize = a_src.size();
208 
209  CH_assert(m_isDefined);
210  CH_assert(dstSize == srcSize);
211 
212  for (int i = 0; i < dstSize; i++) {
213  this->apply(*a_dst[i], (const EBAMRCellData&)*a_src[i]);
214  }
215 }
216 
217 template <class IrregSten>
218 void
219 IrregAmrStencil<IrregSten>::apply(Vector<EBAMRCellData*>& a_data) const
220 {
221  CH_TIME("IrregAmrStencil::apply");
222 
223  CH_assert(m_isDefined);
224 
225  const int dstSize = a_data.size();
226 
227  for (int i = 0; i < dstSize; i++) {
228  this->apply(*a_data[i]);
229  }
230 }
231 
232 template <class IrregSten>
233 void
234 IrregAmrStencil<IrregSten>::apply(Vector<EBAMRCellData*>& a_dst, const Vector<EBAMRCellData*>& a_src) const
235 {
236  CH_TIME("IrregAmrStencil::apply");
237 
238  const int dstSize = a_dst.size();
239  const int srcSize = a_src.size();
240 
241  CH_assert(m_isDefined);
242  CH_assert(dstSize == srcSize);
243 
244  for (int i = 0; i < dstSize; i++) {
245  this->apply(*a_dst[i], (const EBAMRCellData&)*a_src[i]);
246  }
247 }
248 
249 #include <CD_NamespaceFooter.H>
250 
251 #endif
Class for holding stencils on irregular over an entire AMR hierarchy.
const IrregStencil & operator[](const int &a_lvl) const
Get the stencils over an AMR level.
Definition: CD_IrregAmrStencilImplem.H:49
virtual void define(const Vector< DisjointBoxLayout > &a_grids, const Vector< EBISLayout > &a_ebisl, const Vector< ProblemDomain > &a_domains, const Vector< Real > &a_dx, const int a_finestLevel, const int a_order, const int a_radius, const IrregStencil::StencilType a_type)
Define function.
Definition: CD_IrregAmrStencilImplem.H:63
IrregAmrStencil()
Empty constructor. You must subsequently call define.
Definition: CD_IrregAmrStencilImplem.H:20
virtual void apply(LevelData< EBCellFAB > &a_dst, const LevelData< EBCellFAB > &a_src, const int a_lvl) const
Apply the stencils to an existing data holder.
Definition: CD_IrregAmrStencilImplem.H:96
virtual ~IrregAmrStencil()
Destructor.
Definition: CD_IrregAmrStencilImplem.H:42
Class for holding stencils on irregular cells over a single AMR level.
Definition: CD_IrregStencil.H:38
StencilType
Enum for identifying stencil – only meant for enhancing code visibility.
Definition: CD_IrregStencil.H:44