Chombo + EB  3.0
MultilevelLinearOp.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 // BVS, June 18, 2003
12 
13 // We can assume that template class T has null construction.
14 
15 #ifndef _MULTILEVELLINEAROP_H_
16 #define _MULTILEVELLINEAROP_H_
17 
18 #include <cmath>
19 
20 #include "RefCountedPtr.H"
21 #include "Vector.H"
22 #include "RealVect.H"
23 #include "LevelData.H"
24 #include "LinearSolver.H"
25 #include "AMRMultiGrid.H"
26 #include "BiCGStabSolver.H"
27 
28 #include "NamespaceHeader.H"
29 
30 ///
31 /**
32  Operator class for Linear solver for solving L(phi) = rhs for the case
33  where <T> is a multilevel (AMR) data structure; as such, T is actually
34  a Vector<T>. The MultilevelLinearOp is also
35  defined with a Vector<AMRLevelOp> which applies the operator in an AMR
36  way. For now, this is hardwired for T = LevelData<FArrayBox>, but we can
37  hopefully get back redo this once I get the kinks worked out...
38  */
39 template <class T>
40 class MultilevelLinearOp : public LinearOp< Vector<LevelData<T>* > >
41 {
42 
43 public:
44  /// default constructor (sets defaults for preconditioner)
46 
47  /// define function -- opFactory should be able to define all required levels
48  /**
49  */
50  void define(const Vector<DisjointBoxLayout>& a_vectGrids,
51  const Vector<int>& a_refRatios,
52  const Vector<ProblemDomain>& a_domains,
53  const Vector<RealVect>& a_vectDx,
55  int a_lBase);
56 
57 
58  ///
59  virtual ~MultilevelLinearOp();
60 
61  /// compute residual using AMRLevelOps AMRResidual functionality
62  /**
63  a_lhs = L(a_phi) - a_rhs.
64  If a_homogeneous is true, evaluate the operator using
65  homogeneous boundary conditions.
66  */
67  virtual void residual( Vector<LevelData<T>* >& a_lhs,
68  const Vector<LevelData<T>* >& a_phi,
69  const Vector<LevelData<T>* >& a_rhs,
70  bool a_homogeneous = false);
71 
72  /// Apply preconditioner
73  /**
74  Given the current state of the residual the correction,
75  apply your preconditioner to a_cor.
76  */
77  virtual void preCond(Vector<LevelData<T>* >& a_cor,
78  const Vector<LevelData<T>* >& a_residual);
79 
80  ///
81  /**
82  In the context of solving L(phi) = rhs, set a_lhs = L(a_phi).
83  If a_homogeneous is true,
84  evaluate the operator using homogeneous boundary conditions.
85  */
86  virtual void applyOp(Vector<LevelData<T>* >& a_lhs,
87  const Vector<LevelData<T>* >& a_phi,
88  bool a_homogeneous = false);
89 
90  ///
91  /**
92  Create data holder a_lhs that mirrors a_rhs. You do not need
93  to copy the data of a_rhs, just make a holder the same size.
94  */
95  virtual void create(Vector<LevelData<T>* >& a_lhs,
96  const Vector<LevelData<T>* >& a_rhs);
97 
98  ///
99  /**
100  Clean up data holder before it goes out of scope. This is necessary
101  because create calls new.
102  */
103  virtual void clear(Vector<LevelData<T>* >& a_lhs);
104 
105 
106  ///
107  /**
108  Set a_lhs equal to a_rhs.
109  */
110  virtual void assign(Vector<LevelData<T>* >& a_lhs,
111  const Vector<LevelData<T>* >& a_rhs);
112 
113  ///
114  /**
115  Compute and return the dot product of a_1 and a_2. In most
116  contexts, this means return the sum over all data points of a_1*a_2.
117  */
118  virtual Real dotProduct(const Vector<LevelData<T>* >& a_1,
119  const Vector<LevelData<T>* >& a_2);
120 
121  ///
122  /**
123  Increment by scaled amount (a_lhs += a_scale*a_x).
124  */
125  virtual void incr (Vector<LevelData<T>* >& a_lhs,
126  const Vector<LevelData<T>* >& a_x,
127  Real a_scale);
128 
129  ///
130  /**
131  Set input to a scaled sum (a_lhs = a_a*a_x + a_b*a_y).
132  */
133  virtual void axby(Vector<LevelData<T>* >& a_lhs,
134  const Vector<LevelData<T>* >& a_x,
135  const Vector<LevelData<T>* >& a_y,
136  Real a_a,
137  Real a_b);
138 
139  ///
140  /**
141  Multiply the input by a given scale (a_lhs *= a_scale).
142  */
143  virtual void scale(Vector<LevelData<T>* >& a_lhs,
144  const Real& a_scale);
145 
146  ///
147  /**
148  Return the norm of a_rhs.
149  a_ord == 0 max norm, a_ord == 1 sum(abs(a_rhs)), else, L(a_ord) norm.
150  */
151  virtual Real norm(const Vector<LevelData<T>* >& a_rhs,
152  int a_ord);
153 
154  ///
155  /**
156  Set a_lhs to zero.
157  */
158  virtual void setToZero(Vector<LevelData<T>* >& a_lhs);
159 
160 
161  virtual void write(const Vector<LevelData<T>* >* a_data,
162  const char* a_filename);
163 
164  /// if true, preCond(...) function uses multigrid v-cycle(s)
166 
167  /// number of mg v-cycles for each preCond call (if using mg preconditioner)
169 
170  /// number of smoothings in the multigrid preconditioner
172 
173  /// max depth for multigrid preconditioner (if using mg preconditioner)
175 
176  ///
178 
179  ///
181 
182  ///
184 
185  // cell spacing
187 
188  /// vector of level operators
190 
191  ///
192  int m_lBase;
193 
194  /// Solver which is used by the preCond function
195  /**
196  if m_use_multigrid_preconditioner is true, this solver is
197  used to apply a AMR multigrid v-cycle as the preconditioner
198  */
200 
201  /// bottom solver for m_preCondSolver
203 
204  /// has the preconditioner solver been initialized?
206 };
207 
208 #include "NamespaceFooter.H"
209 
210 #include "MultilevelLinearOpI.H"
211 #endif /*_MULTILEVELLINEAROP_H_*/
LinearSolver< LevelData< T > > * m_precondBottomSolverPtr
bottom solver for m_preCondSolver
Definition: MultilevelLinearOp.H:202
virtual void incr(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_x, Real a_scale)
Definition: MultilevelLinearOpI.H:533
Vector< int > m_refRatios
Definition: MultilevelLinearOp.H:180
Definition: LinearSolver.H:28
virtual Real norm(const Vector< LevelData< T > * > &a_rhs, int a_ord)
Definition: MultilevelLinearOpI.H:596
A reference-counting handle class.
Definition: RefCountedPtr.H:66
AMRMultiGrid< LevelData< T > > m_preCondSolver
Solver which is used by the preCond function.
Definition: MultilevelLinearOp.H:199
virtual void write(const Vector< LevelData< T > * > *a_data, const char *a_filename)
Definition: MultilevelLinearOpI.H:679
bool m_isPrecondSolverInitialized
has the preconditioner solver been initialized?
Definition: MultilevelLinearOp.H:205
Vector< ProblemDomain > m_domains
Definition: MultilevelLinearOp.H:183
Definition: AMRMultiGrid.H:306
virtual void axby(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_x, const Vector< LevelData< T > * > &a_y, Real a_a, Real a_b)
Definition: MultilevelLinearOpI.H:552
virtual ~MultilevelLinearOp()
Definition: MultilevelLinearOpI.H:121
virtual void setToZero(Vector< LevelData< T > * > &a_lhs)
Definition: MultilevelLinearOpI.H:664
MultilevelLinearOp()
default constructor (sets defaults for preconditioner)
Definition: MultilevelLinearOpI.H:21
virtual void scale(Vector< LevelData< T > * > &a_lhs, const Real &a_scale)
Definition: MultilevelLinearOpI.H:576
int m_num_mg_smooth
number of smoothings in the multigrid preconditioner
Definition: MultilevelLinearOp.H:171
Definition: BoxLayoutData.H:136
int m_lBase
Definition: MultilevelLinearOp.H:192
int m_preCondSolverDepth
max depth for multigrid preconditioner (if using mg preconditioner)
Definition: MultilevelLinearOp.H:174
double Real
Definition: REAL.H:33
Vector< RefCountedPtr< AMRLevelOp< LevelData< T > > > > m_vectOperators
vector of level operators
Definition: MultilevelLinearOp.H:189
int m_num_mg_iterations
number of mg v-cycles for each preCond call (if using mg preconditioner)
Definition: MultilevelLinearOp.H:168
virtual void clear(Vector< LevelData< T > * > &a_lhs)
Definition: MultilevelLinearOpI.H:409
virtual void assign(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs)
Definition: MultilevelLinearOpI.H:430
virtual void applyOp(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_phi, bool a_homogeneous=false)
Definition: MultilevelLinearOpI.H:325
virtual void residual(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_phi, const Vector< LevelData< T > * > &a_rhs, bool a_homogeneous=false)
compute residual using AMRLevelOps AMRResidual functionality
Definition: MultilevelLinearOpI.H:140
Definition: LinearSolver.H:158
virtual void preCond(Vector< LevelData< T > * > &a_cor, const Vector< LevelData< T > * > &a_residual)
Apply preconditioner.
Definition: MultilevelLinearOpI.H:222
void define(const Vector< DisjointBoxLayout > &a_vectGrids, const Vector< int > &a_refRatios, const Vector< ProblemDomain > &a_domains, const Vector< RealVect > &a_vectDx, RefCountedPtr< AMRLevelOpFactory< LevelData< T > > > &a_opFactory, int a_lBase)
define function – opFactory should be able to define all required levels
Definition: MultilevelLinearOpI.H:35
Definition: MultilevelLinearOp.H:40
virtual Real dotProduct(const Vector< LevelData< T > * > &a_1, const Vector< LevelData< T > * > &a_2)
Definition: MultilevelLinearOpI.H:453
Definition: AMRMultiGrid.H:231
virtual void create(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs)
Definition: MultilevelLinearOpI.H:385
bool m_use_multigrid_preconditioner
if true, preCond(...) function uses multigrid v-cycle(s)
Definition: MultilevelLinearOp.H:165
Vector< DisjointBoxLayout > m_vectGrids
Definition: MultilevelLinearOp.H:177
Vector< RealVect > m_vectDx
Definition: MultilevelLinearOp.H:186