Chombo + EB + MF  3.2
VCAMRPoissonOp2.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _VCAMRPOISSONOP2_H_
12 #define _VCAMRPOISSONOP2_H_
13 
14 #include "AMRPoissonOp.H"
16 
17 #include "NamespaceHeader.H"
18 
19 ///
20 /**
21  Operator for solving variable-coefficient
22  (alpha * aCoef(x) * I - beta * Div(bCoef(x) . Grad)) phi = rho
23  over an AMR hierarchy.
24 */
26 {
27 public:
28  /**
29  \name VCAMRPoissonOp2 functions */
30  /*@{*/
31 
32  ///
33  /**
34  */
36  {
38  }
39 
40  ///
41  /**
42  */
43  virtual ~VCAMRPoissonOp2()
44  {
45  }
46 
47  ///
48  virtual void residualI(LevelData<FArrayBox>& a_lhs,
49  const LevelData<FArrayBox>& a_phi,
50  const LevelData<FArrayBox>& a_rhs,
51  bool a_homogeneous = false);
52 
53  ///
54  virtual void preCond(LevelData<FArrayBox>& a_correction,
55  const LevelData<FArrayBox>& a_residual);
56 
57  ///
58  virtual void applyOpI(LevelData<FArrayBox>& a_lhs,
59  const LevelData<FArrayBox>& a_phi,
60  bool a_homogeneous = false);
61 
62  virtual void applyOpNoBoundary(LevelData<FArrayBox>& a_lhs,
63  const LevelData<FArrayBox>& a_phi);
64 
65  /*@}*/
66 
67  /**
68  \name MGLevelOp functions */
69  /*@{*/
70 
71  /**
72  calculate restricted residual
73  a_resCoarse[2h] = I[h->2h] (rhsFine[h] - L[h](phiFine[h])
74  */
75  virtual void restrictResidual(LevelData<FArrayBox>& a_resCoarse,
76  LevelData<FArrayBox>& a_phiFine,
77  const LevelData<FArrayBox>& a_rhsFine);
78 
79  /*@}*/
80 
81  /**
82  \name VCAMRPoissonOp2 functions */
83  /*@{*/
84 
85  /// For tga stuff
86  virtual void setAlphaAndBeta(const Real& a_alpha,
87  const Real& a_beta);
88 
89  /// Also calls reset lambda
90  virtual void setCoefs(const RefCountedPtr<LevelData<FArrayBox> >& a_aCoef,
91  const RefCountedPtr<LevelData<FluxBox> >& a_bCoef,
92  const Real& a_alpha,
93  const Real& a_beta);
94 
95  /// Should be called before the relaxation parameter is needed.
96  virtual void resetLambda();
97 
98  /// Compute lambda once alpha, aCoef, beta, bCoef are defined
99  virtual void computeLambda();
100 
101  virtual void reflux(const LevelData<FArrayBox>& a_phiFine,
102  const LevelData<FArrayBox>& a_phi,
103  LevelData<FArrayBox>& a_residual,
104  AMRLevelOp<LevelData<FArrayBox> >* a_finerOp);
105 
106  /*@}*/
107 
108  //! This is called on multigrid operators when their AMR operators
109  //! are altered.
110  void finerOperatorChanged(const MGLevelOp<LevelData<FArrayBox> >& a_operator,
111  int a_coarseningFactor);
112 
113  //! Returns identity coefficient data.
115  {
116  return *m_aCoef;
117  }
118 
119  /// For TGA
120  virtual void diagonalScale(LevelData<FArrayBox>& a_rhs,
121  bool a_kappaWeighted)
122  {
123  DisjointBoxLayout grids = a_rhs.disjointBoxLayout();
124  for (DataIterator dit = grids.dataIterator(); dit.ok(); ++dit)
125  {
126  a_rhs[dit()].mult((*m_aCoef)[dit()]);
127  }
128  }
129  /// For TGA
131  {
132  DisjointBoxLayout grids = a_rhs.disjointBoxLayout();
133  for (DataIterator dit = grids.dataIterator(); dit.ok(); ++dit)
134  {
135  a_rhs[dit()].divide((*m_aCoef)[dit()]);
136  }
137  }
138 
139 
140  //! Sets up a model that modifies b coefficient data when the operator's
141  //! time is set.
142  //! \param a_bCoefInterpolator A CoefficientInterpolator that will be used
143  //! to compute the b coefficient at specific
144  //! times.
146  {
147  m_bCoefInterpolator = a_bCoefInterpolator;
148  }
149 
150  //! Returns the B coefficient.
152  {
153  return *m_bCoef;
154  }
155 
156  // Allows access to the B coefficient interpolator.
158  {
159  return m_bCoefInterpolator;
160  }
161 
162  //! Sets the time centering of the operator. This interpolates b coefficient
163  //! data at the given time if an interpolator is set.
164  void setTime(Real a_time);
165 
166  /// Identity operator spatially varying coefficient storage (cell-centered) --- if you change this call resetLambda()
168 
169  /// Laplacian operator spatially varying coefficient storage (face-centered) --- if you change this call resetLambda()
171 
172  /// Reciprocal of the diagonal entry of the operator matrix
174 
175  // getFlux function which matches interface to AMRPoissonOp
176  /** assumes we want to use member-data bCoef, then calls
177  second getFlux function */
178  virtual void getFlux(FluxBox& a_flux,
179  const LevelData<FArrayBox>& a_data,
180  const Box& a_grid,
181  const DataIndex& a_dit,
182  Real a_scale)
183  {
184  const FluxBox& bCoef = (*m_bCoef)[a_dit];
185  getFlux(a_flux,a_data,bCoef,a_grid,a_dit,a_scale);
186  }
187 
188 
189  virtual void getFlux(FluxBox& a_flux,
190  const LevelData<FArrayBox>& a_data,
191  const FluxBox& a_bCoef,
192  const Box& a_grid,
193  const DataIndex& a_dit,
194  Real a_scale)
195  {
196  const FArrayBox& data = a_data[a_dit];
197  a_flux.define(a_grid, a_data.nComp());
198  for (int idir=0; idir<SpaceDim; idir++)
199  {
200  getFlux(a_flux[idir], data, a_bCoef, a_flux[idir].box(), idir, 1);
201  a_flux[idir] *= a_scale;
202  }
203 
204  }
205 
206 protected:
209 
210  // Interpolator for b coefficient data.
212 
213  // Current time.
215 
216  // Does the relaxation coefficient need to be reset?
218 
219  virtual void levelGSRB(LevelData<FArrayBox>& a_phi,
220  const LevelData<FArrayBox>& a_rhs);
221 
222  virtual void levelMultiColor(LevelData<FArrayBox>& a_phi,
223  const LevelData<FArrayBox>& a_rhs);
224 
225  virtual void looseGSRB(LevelData<FArrayBox>& a_phi,
226  const LevelData<FArrayBox>& a_rhs);
227 
228  virtual void overlapGSRB(LevelData<FArrayBox>& a_phi,
229  const LevelData<FArrayBox>& a_rhs);
230 
231  virtual void levelGSRBLazy(LevelData<FArrayBox>& a_phi,
232  const LevelData<FArrayBox>& a_rhs);
233 
234  virtual void levelJacobi(LevelData<FArrayBox>& a_phi,
235  const LevelData<FArrayBox>& a_rhs);
236 
237  /// computes flux over face-centered a_facebox.
238  virtual void getFlux(FArrayBox& a_flux,
239  const FArrayBox& a_data,
240  const FluxBox& a_bCoef,
241  const Box& a_facebox,
242  int a_dir,
243  int a_ref = 1) const ;
244 #if 0
245  /// utility function which computes operator after all bc's have been set
246  void computeOperatorNoBCs(LevelData<FArrayBox>& a_lhs,
247  const LevelData<FArrayBox>& a_phi);
248 #endif
249 };
250 
251 ///
252 /**
253  Factory to create VCAMRPoissonOp2s
254 */
255 class VCAMRPoissonOp2Factory: public AMRLevelOpFactory<LevelData<FArrayBox> >
256 {
257 public:
259 
261  {
262  }
263 
264  ///
265  /**
266  a_coarseDomain is the domain at the coarsest level.
267  a_grids is the AMR hierarchy.
268  a_refRatios are the refinement ratios between levels. The ratio lives
269  with the coarser level so a_refRatios[ilev] is the ratio between
270  ilev and ilev+1
271  a_coarseDx is the grid spacing at the coarsest level.
272  a_bc holds the boundary conditions.
273  a_alpha is the identity constant coefficient
274  a_beta is the laplacian constant coefficient.
275  a_aCoef is the identity spatially varying coefficient
276  a_bCoef is the laplacian spatially varying coefficient.
277  */
278  void define(const ProblemDomain& a_coarseDomain,
279  const Vector<DisjointBoxLayout>& a_grids,
280  const Vector<int>& a_refRatios,
281  const Real& a_coarsedx,
282  BCHolder a_bc,
283  const Real& a_alpha,
285  const Real& a_beta,
287 
288  //! Defines a factory for VCAMRPoissonOp2 which allows the operators to
289  //! allocate their own coefficient data. \f$\alpha\f$ and \f$\beta\f$
290  //! coefficients are initialized to 1.
291  //! \param a_coarseDomain The domain at the coarsest level.
292  //! \param a_grids The disjoint box layouts for the various refinement levels.
293  //! \param a_refRatios The refinement ratios between levels.
294  //! \param a_coarsedx The grid spacing at the coarsest level.
295  //! \param a_bc The boundary condition imposed on the solution.
296  //! \param a_ghostVect The ghost stencil to use in the created coefficient data.
297  void define(const ProblemDomain& a_coarseDomain,
298  const Vector<DisjointBoxLayout>& a_grids,
299  const Vector<int>& a_refRatios,
300  const Real& a_coarsedx,
301  BCHolder a_bc,
302  const IntVect& a_ghostVect);
303 
304  ///
305  virtual MGLevelOp<LevelData<FArrayBox> >* MGnewOp(const ProblemDomain& a_FineindexSpace,
306  int a_depth,
307  bool a_homoOnly = true);
308 
309  ///
310  virtual AMRLevelOp<LevelData<FArrayBox> >* AMRnewOp(const ProblemDomain& a_indexSpace);
311 
312  ///
313  virtual int refToFiner(const ProblemDomain& a_domain) const;
314 
316 
317 private:
318  void setDefaultValues();
319 
322 
324  Vector<int> m_refRatios; // refinement to next coarser level
325 
327 
330 
333 
335 
338 };
339 
340 #include "NamespaceFooter.H"
341 #endif
RefCountedPtr< LevelData< FArrayBox > > m_aCoef
Identity operator spatially varying coefficient storage (cell-centered) — if you change this call re...
Definition: VCAMRPoissonOp2.H:167
LevelData< FArrayBox > & identityCoef()
Returns identity coefficient data.
Definition: VCAMRPoissonOp2.H:114
virtual void preCond(LevelData< FArrayBox > &a_correction, const LevelData< FArrayBox > &a_residual)
Vector< CFRegion > m_cfregion
Definition: VCAMRPoissonOp2.H:337
Real m_time
Definition: VCAMRPoissonOp2.H:214
virtual void getFlux(FluxBox &a_flux, const LevelData< FArrayBox > &a_data, const FluxBox &a_bCoef, const Box &a_grid, const DataIndex &a_dit, Real a_scale)
Definition: VCAMRPoissonOp2.H:189
void define(const DisjointBoxLayout &a_grids, const DisjointBoxLayout &a_gridsFiner, const DisjointBoxLayout &a_gridsCoarser, const Real &a_dxLevel, int a_refRatio, int a_refRatioFiner, const ProblemDomain &a_domain, BCHolder a_bc, const Copier &a_exchange, const CFRegion &a_cfregion, const int a_nComp=1)
virtual ~VCAMRPoissonOp2Factory()
Definition: VCAMRPoissonOp2.H:260
A reference-counting handle class.
Definition: RefCountedPtr.H:173
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_aCoef
Definition: VCAMRPoissonOp2.H:331
Definition: BCFunc.H:136
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
RefCountedPtr< CoefficientInterpolator< LevelData< FluxBox >, LevelData< FArrayBox > > > m_bCoefInterpolator
Definition: VCAMRPoissonOp2.H:211
virtual void overlapGSRB(LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs)
void finerOperatorChanged(const MGLevelOp< LevelData< FArrayBox > > &a_operator, int a_coarseningFactor)
virtual void levelJacobi(LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs)
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:117
Definition: DataIterator.H:190
Real m_beta
Definition: VCAMRPoissonOp2.H:329
VCAMRPoissonOp2()
Definition: VCAMRPoissonOp2.H:35
const int SpaceDim
Definition: SPACE.H:38
Definition: AMRMultiGrid.H:39
Vector< Copier > m_exchangeCopiers
Definition: VCAMRPoissonOp2.H:336
Definition: EBInterface.H:45
Definition: AMRPoissonOp.H:35
A FArrayBox-like container for face-centered fluxes.
Definition: FluxBox.H:22
Real m_alpha
Definition: VCAMRPoissonOp2.H:328
LevelData< FArrayBox > m_lambda
Reciprocal of the diagonal entry of the operator matrix.
Definition: VCAMRPoissonOp2.H:173
Definition: CoefficientInterpolator.H:29
virtual ~VCAMRPoissonOp2()
Definition: VCAMRPoissonOp2.H:43
Vector< ProblemDomain > m_domains
Definition: VCAMRPoissonOp2.H:320
double Real
Definition: REAL.H:33
virtual void residualI(LevelData< FArrayBox > &a_lhs, const LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs, bool a_homogeneous=false)
despite what you might think, the "I" here means "Ignore the coarse-fine boundary" ...
Definition: VCAMRPoissonOp2.H:255
Definition: MultiGrid.H:30
Definition: VCAMRPoissonOp2.H:25
Vector< Real > m_dx
Definition: VCAMRPoissonOp2.H:323
virtual void diagonalScale(LevelData< FArrayBox > &a_rhs, bool a_kappaWeighted)
For TGA.
Definition: VCAMRPoissonOp2.H:120
BCHolder m_bc
Definition: VCAMRPoissonOp2.H:326
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:30
bool m_lambdaNeedsResetting
Definition: VCAMRPoissonOp2.H:217
virtual void looseGSRB(LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs)
int m_coefficient_average_type
Definition: VCAMRPoissonOp2.H:315
virtual void applyOpI(LevelData< FArrayBox > &a_lhs, const LevelData< FArrayBox > &a_phi, bool a_homogeneous=false)
despite what you might think, the "I" here means "Ignore the coarse-fine boundary" ...
virtual void divideByIdentityCoef(LevelData< FArrayBox > &a_rhs)
For TGA.
Definition: VCAMRPoissonOp2.H:130
LayoutData< CFIVS > m_hiCFIVS[SpaceDim]
Definition: VCAMRPoissonOp2.H:208
virtual void levelGSRBLazy(LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs)
Vector< RefCountedPtr< LevelData< FArrayBox > > > m_lambda
Definition: VCAMRPoissonOp2.H:334
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:469
virtual void setCoefs(const RefCountedPtr< LevelData< FArrayBox > > &a_aCoef, const RefCountedPtr< LevelData< FluxBox > > &a_bCoef, const Real &a_alpha, const Real &a_beta)
Also calls reset lambda.
virtual void getFlux(FluxBox &a_flux, const LevelData< FArrayBox > &a_data, const Box &a_grid, const DataIndex &a_dit, Real a_scale)
Definition: VCAMRPoissonOp2.H:178
Vector< RefCountedPtr< LevelData< FluxBox > > > m_bCoef
Definition: VCAMRPoissonOp2.H:332
int nComp() const
Definition: BoxLayoutData.H:306
Definition: DataIndex.H:114
const DisjointBoxLayout & disjointBoxLayout() const
Definition: LevelData.H:225
virtual void reflux(const LevelData< FArrayBox > &a_phiFine, const LevelData< FArrayBox > &a_phi, LevelData< FArrayBox > &a_residual, AMRLevelOp< LevelData< FArrayBox > > *a_finerOp)
virtual void levelGSRB(LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs)
RefCountedPtr< LevelData< FluxBox > > m_bCoef
Laplacian operator spatially varying coefficient storage (face-centered) — if you change this call r...
Definition: VCAMRPoissonOp2.H:170
void setBCoefInterpolator(RefCountedPtr< CoefficientInterpolator< LevelData< FluxBox >, LevelData< FArrayBox > > > &a_bCoefInterpolator)
Definition: VCAMRPoissonOp2.H:145
An integer Vector in SpaceDim-dimensional space.
Definition: CHArray.H:42
Definition: FArrayBox.H:45
virtual void setAlphaAndBeta(const Real &a_alpha, const Real &a_beta)
For tga stuff.
LayoutData< CFIVS > m_loCFIVS[SpaceDim]
Definition: VCAMRPoissonOp2.H:207
void setTime(Real a_time)
Vector< int > m_refRatios
Definition: VCAMRPoissonOp2.H:324
void define(const Box &bx, int n=1)
Resize FluxBox similar to BaseFab::resize()
virtual void restrictResidual(LevelData< FArrayBox > &a_resCoarse, LevelData< FArrayBox > &a_phiFine, const LevelData< FArrayBox > &a_rhsFine)
virtual void applyOpNoBoundary(LevelData< FArrayBox > &a_lhs, const LevelData< FArrayBox > &a_phi)
Definition: AMRMultiGrid.H:233
DataIterator dataIterator() const
Parallel iterator.
virtual void levelMultiColor(LevelData< FArrayBox > &a_phi, const LevelData< FArrayBox > &a_rhs)
LevelData< FluxBox > & BCoef()
Returns the B coefficient.
Definition: VCAMRPoissonOp2.H:151
virtual void computeLambda()
Compute lambda once alpha, aCoef, beta, bCoef are defined.
virtual void resetLambda()
Should be called before the relaxation parameter is needed.
Vector< DisjointBoxLayout > m_boxes
Definition: VCAMRPoissonOp2.H:321
RefCountedPtr< CoefficientInterpolator< LevelData< FluxBox >, LevelData< FArrayBox > > > BCoefInterpolator()
Definition: VCAMRPoissonOp2.H:157