11 #ifndef _MULTILEVELLINEAROPI_H_ 12 #define _MULTILEVELLINEAROPI_H_ 16 #include "NamespaceHeader.H" 24 m_use_multigrid_preconditioner =
true;
25 m_num_mg_iterations = 1;
28 m_preCondSolverDepth = -1;
29 m_precondBottomSolverPtr = NULL;
42 CH_TIME(
"MultilevelLinearOp::define");
44 int numLevels = a_vectGrids.
size();
56 m_vectGrids = a_vectGrids;
57 m_refRatios = a_refRatios;
58 m_domains = a_domains;
60 m_vectOperators.
resize(numLevels);
63 int coarsestLevel =
Max(0, m_lBase-1);
64 for (
int level=coarsestLevel; level<numLevels; level++)
67 m_vectOperators[level] = op;
71 if (m_use_multigrid_preconditioner)
76 m_precondBottomSolverPtr = newPtr;
77 int bottomSolverVerbosity = 1;
81 if (m_preCondSolverDepth >= 0)
83 m_preCondSolver.m_maxDepth = m_preCondSolverDepth;
85 m_preCondSolver.define(m_domains[0],
87 m_precondBottomSolverPtr,
92 Real solverEps = 1.0e-7;
93 int maxIterations = 1;
95 Real normThresh = 1.0e-30;
98 m_preCondSolver.setSolverParameters(m_num_mg_smooth,
108 m_preCondSolver.m_verbosity = 1;
112 m_isPrecondSolverInitialized =
false;
123 CH_TIME(
"MultilevelLinearOp::~MultilevelLinearOp");
125 if (m_precondBottomSolverPtr != NULL)
127 delete m_precondBottomSolverPtr;
128 m_precondBottomSolverPtr = NULL;
145 CH_TIME(
"MultilevelLinearOp::residual");
150 int numLevels = a_lhs.size();
153 CH_assert (m_vectOperators.size() >= numLevels);
155 int maxLevel = numLevels -1;
156 for (
int level = m_lBase; level < numLevels; level++)
166 if (level < maxLevel)
169 m_vectOperators[level]->AMRResidual(thisResid,
175 (m_vectOperators[level+1].operator->()));
180 m_vectOperators[level]->AMRResidualNF(thisResid,
191 if (level < maxLevel)
194 m_vectOperators[level]->AMRResidualNC(thisResid,
199 (m_vectOperators[level+1].operator->()));
204 m_vectOperators[level]->residual(thisResid,
226 CH_TIME(
"MultilevelLinearOp::preCond");
229 int numLevels = a_cor.size();
230 CH_assert (a_residual.size() == numLevels);
231 CH_assert (m_vectOperators.size() <= numLevels);
234 if (m_use_multigrid_preconditioner)
236 CH_TIME(
"MultilevelLinearOp::preCond::Multigrid");
240 create(localCorr, a_cor);
241 create(localResid, a_residual);
249 CH_TIME(
"MultilevelLinearOp::preCond::Multigrid::NewStorage");
252 for (
int lev=0; lev<numLevels; lev++)
254 tempCorr[lev] = localCorr[lev];
255 tempResid[lev] =
const_cast<LevelData<T>*
>(localResid[lev]);
259 int finestLevel = numLevels -1;
261 CH_TIME(
"MultilevelLinearOp::preCond::Multigrid::Initialize");
263 if (!m_isPrecondSolverInitialized)
266 m_preCondSolver.init(tempCorr, tempResid, finestLevel,
269 m_preCondSolver.setBottomSolver(finestLevel, m_lBase);
270 m_isPrecondSolverInitialized =
true;
274 for (
int iter = 0; iter<m_num_mg_iterations; iter++)
276 CH_TIME(
"MultilevelLinearOp::preCond::Multigrid::Iterate");
285 bool homogeneous =
true;
286 residual(localResid, a_cor, a_residual, homogeneous);
287 setToZero(localCorr);
289 m_preCondSolver.AMRVCycle(tempCorr, tempResid,
290 finestLevel, finestLevel,
294 incr(a_cor, localCorr, 1.0);
298 CH_TIME(
"MultilevelLinearOp::preCond::Multigrid::Clear");
306 CH_TIME(
"MultilevelLinearOp::preCond::LevelBased");
309 for (
int level = m_lBase; level < numLevels; level++)
311 m_vectOperators[level]->preCond(*a_cor[level], *a_residual[level]);
329 CH_TIME(
"MultilevelLinearOp::applyOp");
331 int numLevels = a_phi.size();
332 int maxLevel = numLevels-1;
334 for (
int level = m_lBase; level<numLevels; level++)
338 if (level < maxLevel)
340 m_vectOperators[level]->AMROperatorNC(*a_lhs[level],
344 m_vectOperators[level+1].operator->());
349 m_vectOperators[level]->applyOp(*a_lhs[level],
357 if (level < maxLevel)
359 m_vectOperators[level]->AMROperator(*a_lhs[level],
364 m_vectOperators[level+1].operator->());
368 m_vectOperators[level]->AMROperatorNF(*a_lhs[level],
388 CH_TIME(
"MultilevelLinearOp::create");
390 a_lhs.resize(a_rhs.size());
392 int coarsestLevel =
Max(0, m_lBase-1);
393 for (
int level =coarsestLevel; level < a_rhs.size(); level++)
396 m_vectOperators[level]->create(*a_lhs[level],
411 CH_TIME(
"MultilevelLinearOp::clear");
413 for (
int level =0; level < a_lhs.size(); level++)
415 if (a_lhs[level] != NULL)
433 CH_TIME(
"MultilevelLinearOp::assign");
435 CH_assert (a_lhs.size() == a_rhs.size());
437 for (
int level = m_lBase; level < a_lhs.size(); level++)
439 if (!(a_lhs[level] ==NULL) && !(a_rhs[level] == NULL))
441 m_vectOperators[level]->assign(*a_lhs[level], *a_rhs[level]);
456 CH_TIME(
"MultilevelLinearOp::dotProduct");
473 for (
int level =m_lBase; level<temp1.
size()-1; level++)
478 CH_assert(temp1[level]->getBoxes() == temp2[level]->getBoxes());
481 int nRefFine = m_refRatios[level];
487 for (levelDit.
begin(); levelDit.
ok(); ++levelDit)
489 const Box& thisBox = levelGrids[levelDit];
490 for (finerLit.
begin(); finerLit.
ok(); ++finerLit)
492 Box testBox = finerGrids[finerLit];
497 temp1Level[levelDit].setVal(0.0, testBox,
498 0, temp1Level.
nComp());
500 temp2Level[levelDit].setVal(0.0, testBox,
501 0, temp2Level.
nComp());
509 for (
int level =m_lBase; level<temp1.
size(); level++)
511 Real levelProd = m_vectOperators[level]->dotProduct(*temp1[level],
516 Real scale = D_TERM(dxLev[0], *dxLev[1], *dxLev[2]);
537 CH_TIME(
"MultilevelLinearOp::incr");
540 for (
int level=m_lBase; level<a_lhs.size(); level++)
542 m_vectOperators[level]->incr(*a_lhs[level], *a_x[level], a_scale);
558 CH_TIME(
"MultilevelLinearOp::axby");
561 for (
int level=m_lBase; level<a_lhs.size(); ++level)
563 m_vectOperators[level]->axby(*a_lhs[level],
579 CH_TIME(
"MultilevelLinearOp::scale");
582 for (
int level =m_lBase; level<a_lhs.size(); level++)
584 m_vectOperators[level]->scale(*a_lhs[level], a_scale);
599 CH_TIME(
"MultilevelLinearOp::norm");
602 int maxLevel = a_rhs.size()-1;
604 for (
int level = m_lBase; level<a_rhs.size(); level++)
608 if (level < maxLevel)
611 int refRatio = m_refRatios[level];
612 normLevel = m_vectOperators[level]->AMRNorm(*a_rhs[level],
622 normLevel = m_vectOperators[level]->AMRNorm(*a_rhs[level],
632 MayDay::Error(
"MultilevelLinearOp::norm -- undefined for order > 2");
637 normLevel = normLevel*normLevel;
642 thisNorm += normLevel;
644 else if (normLevel > thisNorm)
646 thisNorm = normLevel;
652 thisNorm = sqrt(thisNorm);
666 CH_TIME(
"MultilevelLinearOp::setToZero");
670 int coarsestLevel =
Max(0, m_lBase-1);
671 for (
int level = coarsestLevel; level< a_lhs.size(); level++)
673 m_vectOperators[level]->setToZero(*a_lhs[level]);
680 const char* a_filename)
685 MayDay::Warning(
"MultilevelLinearOp<T>::write unimplemented since CH_USE_HDF5 undefined");
689 #include "NamespaceFooter.H" Box & coarsen(int refinement_ratio)
coarsening
virtual void incr(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_x, Real a_scale)
Definition: MultilevelLinearOpI.H:533
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
virtual void write(const Vector< LevelData< T > * > *a_data, const char *a_filename)
Definition: MultilevelLinearOpI.H:679
#define CH_assert(cond)
Definition: CHArray.H:37
int m_verbosity
Definition: BiCGStabSolver.H:78
void begin()
initialize this iterator to the first Box in its Layout
Definition: LayoutIterator.H:115
virtual bool ok() const
return true if this iterator is still in its Layout
Definition: LayoutIterator.H:110
IndexTM< T, N > scale(const IndexTM< T, N > &a_p, T a_s)
Definition: IndexTMI.H:384
Definition: DataIterator.H:140
An Iterator based on a BoxLayout object.
Definition: LayoutIterator.H:38
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
void resize(unsigned int isize)
Definition: Vector.H:323
virtual ~MultilevelLinearOp()
Definition: MultilevelLinearOpI.H:121
virtual void setToZero(Vector< LevelData< T > * > &a_lhs)
Definition: MultilevelLinearOpI.H:664
#define CH_TIME(name)
Definition: CH_Timer.H:59
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
Definition: BoxLayoutData.H:136
double Real
Definition: REAL.H:33
A BoxLayout that has a concept of disjointedness.
Definition: DisjointBoxLayout.H:31
virtual void clear(Vector< LevelData< T > * > &a_lhs)
Definition: MultilevelLinearOpI.H:409
size_t size() const
Definition: Vector.H:177
static void Error(const char *const a_msg=m_nullString, int m_exitCode=CH_DEFAULT_ERROR_CODE)
Print out message to cerr and exit with the specified exit code.
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
static void Warning(const char *const a_msg=m_nullString)
Print out message to cerr and continue.
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
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
A Real vector in SpaceDim-dimensional space.
Definition: RealVect.H:41
virtual void preCond(Vector< LevelData< T > * > &a_cor, const Vector< LevelData< T > * > &a_residual)
Apply preconditioner.
Definition: MultilevelLinearOpI.H:222
int nComp() const
Definition: BoxLayoutData.H:258
T Max(const T &a_a, const T &a_b)
Definition: Misc.H:39
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
virtual Real dotProduct(const Vector< LevelData< T > * > &a_1, const Vector< LevelData< T > * > &a_2)
Definition: MultilevelLinearOpI.H:453
void writeVectorLevelName(const Vector< LevelData< FArrayBox > *> *a_dataPtr, const Vector< int > *a_refRatios, const char *a_filename)
LayoutIterator layoutIterator() const
Iterator that processes through ALL the boxes in a BoxLayout.
Definition: AMRMultiGrid.H:231
DataIterator dataIterator() const
Parallel iterator.
bool isEmpty() const
{ Comparison Functions}
Definition: Box.H:1863
virtual void create(Vector< LevelData< T > * > &a_lhs, const Vector< LevelData< T > * > &a_rhs)
Definition: MultilevelLinearOpI.H:385
Definition: BiCGStabSolver.H:26