15 #ifndef _AMRFASMULTIGRID_H_ 16 #define _AMRFASMULTIGRID_H_ 21 #include "NamespaceHeader.H" 43 int l_max,
int l_base,
bool a_zeroPhi=
true,
44 bool forceHomogeneous =
false);
71 int l,
int l_max,
int l_base);
75 int l,
int l_max,
int l_base);
78 int l_max,
int l_base);
128 CH_TIME(
"AMRFASMultiGrid::define");
140 for (
int i = 0; i < a_maxAMRLevels; i++)
144 if (this->
m_mg[i] != NULL)
146 delete this->
m_mg[i];
147 this->
m_mg[i] = NULL;
156 if (i < a_maxAMRLevels-1)
168 int l_max,
int l_base )
170 CH_TIME(
"AMRFASMultiGrid::init");
178 for (
int i = l_base+1; i <= l_max; i++)
182 m_HOCopier[i].define( a_phi[i-1]->disjointBoxLayout(), this->
m_resC[i]->disjointBoxLayout(),
183 a_phi[i-1]->ghostVect() );
202 CH_TIME(
"AMRFASMultiGrid::clear_private");
204 for (
int i = 0; i < this->
m_op.
size(); i++)
215 int l_max,
int l_base,
bool a_zeroPhi,
216 bool a_forceHomogeneous)
218 CH_TIMERS(
"AMRFASMultiGrid::solveNoInit");
219 CH_TIMER(
"AMRFASMultiGrid::cycle", vtimer);
221 bool outputIntermediates =
false;
229 for (
int ilev = l_base; ilev <=l_max; ++ilev)
231 this->
m_op[ilev]->setToZero(*(a_phi[ilev]));
237 CH_TIME(
"Initial AMR Residual");
256 pout() <<
" AMRFASMultiGrid:: iteration = " << iter <<
", residual norm = " <<
m_rnorm << std::endl;
264 while (goMin || (goIter && goRedu && goHang && goNorm))
272 FMG( a_phi, a_rhs, l_max, l_max, l_base);
277 this->
m_op[l_max]->assignLocal( *(this->
m_residual[l_max]), *(a_rhs[l_max]) );
278 VCycle( a_phi, a_rhs, l_max, l_max, l_base);
286 for (
int ilev = l_base; ilev <= l_max; ilev++)
288 if (outputIntermediates)
290 char strcorname[100];
291 sprintf(strcorname,
"amrFASmg.phi.iter.%03d", iter);
292 string namecor(strcorname);
293 this->
outputAMR(a_phi, namecor, l_max, l_base);
299 if (this->
m_op[0]->orderOfAccuracy()>2)
301 for (
int ilev=l_max; ilev>l_base; ilev--)
303 this->
m_op[ilev]->enforceCFConsistency(*a_phi[ilev-1], *a_phi[ilev]);
315 pout() <<
" AMRFASMultiGrid:: iteration = " << iter <<
", residual norm = " <<
m_rnorm;
331 this->
m_exitStatus = int(!goRedu) + int(!goIter)*2 + int(!goHang)*4 + int(!goNorm)*8;
334 pout() <<
" AMRFASMultiGrid:: iteration = " << iter <<
", residual norm = " <<
m_rnorm << std::endl;
338 if (!goIter && goRedu && goNorm)
340 pout() <<
" AMRFASMultiGrid:: WARNING: Exit because max iteration count exceeded" << std::endl;
342 if (!goHang && goRedu && goNorm)
344 pout() <<
" AMRFASMultiGrid:: WARNING: Exit because of solver hang" << std::endl;
348 pout() <<
" AMRFASMultiGrid:: exitStatus = " << this->
m_exitStatus << std::endl;
363 int i,
int l_max,
int l_base)
366 this->
m_op[l_base]->assignLocal( *(this->
m_residual[l_base]), *(a_rhs[l_base]) );
367 this->
m_mg[l_base]->oneCycle( *(a_phi[l_base]), *(this->
m_residual[l_base]) );
369 for (
int ilev = l_base+1 ; ilev <= l_max ; ilev++ )
372 this->
m_op[ilev]->AMRProlongS_2( *(a_phi[ilev]), *(a_phi[ilev-1]),
376 this->
m_op[ilev]->assignLocal( *(this->
m_residual[ilev]), *(a_rhs[ilev]) );
379 VCycle( a_phi, a_rhs, ilev, l_max, l_base );
393 int ilev,
int l_max,
int l_base )
397 CH_TIME(
"AMRFASMultiGrid::VCycle:coarse_grid_solver");
401 this->
m_op[ilev]->write(a_phi[ilev],
"zh_coarsest_phi_0.hdf5");
402 this->
m_op[ilev]->write(this->
m_residual[ilev],
"zh_coarsest_rhs.hdf5");
408 T* phiCoarsePtr = NULL;
411 phiCoarsePtr = a_phi[l_base-1];
420 this->
m_op[ilev]->write(a_phi[ilev],
"zh_coarsest_phi_1.hdf5");
436 rhs = a_rhs_dummy[ilev];
445 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_0.hdf5");
446 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_0.hdf5");
450 this->
m_op[ilev]->relaxNF( *(a_phi[ilev]), (a_phi[ilev-1]), *rhs, this->
m_pre );
453 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_1.hdf5");
454 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_1.hdf5");
467 l_max, l_base, ilev-1,
474 this->
m_op[ilev]->AMRRestrictS(*(this->
m_resC[ilev]),
482 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_2.hdf5");
483 this->
m_op[ilev-1]->write(this->
m_resC[ilev],
"zb_coarse_phi_1.hdf5");
487 this->
m_resC[ilev]->copyTo(this->
m_resC[ilev]->interval(), *(a_phi[ilev-1]), a_phi[ilev-1]->interval(), this->
m_resCopier[ilev]);
493 this->
m_op[ilev]->AMRRestrictS(*(this->
m_resC[ilev]),
501 this->
m_op[ilev]->write(this->
m_resC[ilev],
"zd_resC.hdf5");
502 this->
m_op[ilev]->write(a_phi[ilev-1],
"ze_coarse_phi_2.hdf5");
503 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_2.hdf5");
512 this->
m_op[ilev-1]->write(this->
m_residual[ilev-1],
"zf_coarse_res_1.hdf5");
519 this->
m_op[ilev-1]->AMROperatorNC( *(this->
m_correction[ilev-1]), undefined, *(a_phi[ilev-1]),
false, this->
m_op[ilev]);
523 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_3.hdf5");
530 this->
m_op[ilev-1]->write(this->
m_residual[ilev-1],
"zf_coarse_res_3.hdf5");
536 this->
m_op[ilev-1]->create( R_u_f, *a_phi[ilev-1]);
537 this->
m_op[ilev-1]->assignLocal( R_u_f, *(a_phi[ilev-1]) );
539 for (
int img = 0; img < this->
m_numMG; img++)
541 VCycle( a_phi, a_rhs_dummy, ilev-1, l_max, l_base );
545 this->
m_op[ilev-1]->write(a_phi[ilev-1],
"zi_coarse_phi_2.hdf5");
549 this->
m_op[ilev-1]->axby( *this->
m_correction[ilev-1], *a_phi[ilev-1], R_u_f, 1.0, -1.0 );
567 this->
m_op[ilev]->AMRProlongS( *(a_phi[ilev]), *(this->
m_correction[ilev-1]),
573 this->
m_op[ilev]->write(a_phi[ilev],
"zl_fine_phi_1.hdf5");
579 this->
m_op[ilev]->relaxNF( *(a_phi[ilev]), (a_phi[ilev-1]), *rhs, this->
m_post );
582 this->
m_op[ilev]->write(a_phi[ilev],
"zl_fine_phi_2.hdf5");
583 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_3.hdf5");
584 this->
m_op[ilev]->write(a_rhs_dummy[ilev],
"za_rhs.hdf5");
591 #include "NamespaceFooter.H" std::ostream & pout()
Use this in place of std::cout for program output.
virtual int refToFiner(const ProblemDomain &a_indexSpace) const =0
#define CH_TIMERS(name)
Definition: CH_Timer.H:133
virtual void solveNoInit(Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l_max, int l_base, bool a_zeroPhi=true, bool forceHomogeneous=false)
Definition: AMRFASMultiGrid.H:213
#define CH_assert(cond)
Definition: CHArray.H:37
A class to facilitate interaction with physical boundary conditions.
Definition: ProblemDomain.H:141
virtual void define(const ProblemDomain &a_coarseDomain, AMRLevelOpFactory< T > &a_factory, LinearSolver< T > *a_bottomSolver, int a_numLevels)
Definition: AMRMultiGrid.H:1293
virtual void VCycle(Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l, int l_max, int l_base)
Definition: AMRFASMultiGrid.H:391
int m_iterMax
Definition: AMRMultiGrid.H:380
LinearSolver< T > * m_bottomSolver
Definition: AMRMultiGrid.H:492
int m_verbosity
Definition: AMRMultiGrid.H:380
OLD_FASMG_type
Definition: AMRFASMultiGrid.H:24
#define CH_START(tpointer)
Definition: CH_Timer.H:145
Vector< T * > m_residual
Definition: AMRMultiGrid.H:485
Definition: AMRFASMultiGrid.H:24
Definition: AMRFASMultiGrid.H:24
int m_pre
Definition: AMRMultiGrid.H:381
Vector< Copier > m_reverseCopier
Definition: AMRMultiGrid.H:488
virtual void define(const ProblemDomain &a_coarseDomain, AMRLevelOpFactory< T > &a_factory, LinearSolver< T > *a_bottomSolver, int a_numLevels)
Definition: AMRFASMultiGrid.H:123
void setCycleType(OLD_FASMG_type a_type)
Definition: AMRFASMultiGrid.H:46
Real m_eps
Definition: AMRMultiGrid.H:378
Definition: AMRMultiGrid.H:308
ProblemDomain m_coarseDomain
Definition: AMRFASMultiGrid.H:90
OLD_FASMG_type m_type
Definition: AMRFASMultiGrid.H:83
Vector< MultiGrid< T > * > m_mg
Definition: AMRMultiGrid.H:483
void computeAMRResidualLevel(Vector< T *> &a_resid, Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l_max, int l_base, int ilev, bool a_homogeneousBC)
Definition: AMRMultiGrid.H:837
Vector< Copier > m_revHOCopier
Definition: AMRFASMultiGrid.H:87
Real m_convergenceMetric
Definition: AMRMultiGrid.H:391
Definition: AMRMultiGrid.H:39
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:63
Real m_initial_rnorm
Definition: AMRFASMultiGrid.H:63
int m_numVcycles
Definition: AMRFASMultiGrid.H:85
void resize(unsigned int isize)
Definition: Vector.H:346
virtual void oneCycle(T &a_e, const T &a_res)
Execute ONE v-cycle of multigrid.
Definition: FASMultiGrid.H:157
int m_numMG
Definition: AMRMultiGrid.H:381
Vector< Copier > m_HOCornerCopier
Definition: AMRFASMultiGrid.H:89
void setAvoidNorms(bool b=true)
Definition: AMRFASMultiGrid.H:50
void clear()
Definition: Vector.H:180
virtual int refToCoarser()=0
#define CH_TIME(name)
Definition: CH_Timer.H:82
Real m_bottomSolverEpsCushion
Definition: AMRMultiGrid.H:397
int m_maxDepth
max no. of coarsenings – -1 (default) means coarsen as far as possible
Definition: AMRMultiGrid.H:385
double Real
Definition: REAL.H:33
Vector< Copier > m_HOCopier
Definition: AMRFASMultiGrid.H:86
int m_iter
Definition: AMRFASMultiGrid.H:60
Definition: FASMultiGrid.H:22
Real m_hang
Definition: AMRMultiGrid.H:378
Real m_rnorm
Definition: AMRFASMultiGrid.H:66
int m_iterMin
Definition: AMRMultiGrid.H:380
size_t size() const
Definition: Vector.H:192
Vector< T * > m_correction
Definition: AMRMultiGrid.H:484
Vector< T * > m_resC
Definition: AMRMultiGrid.H:486
AMRFASMultiGrid()
Definition: AMRFASMultiGrid.H:101
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.
Definition: AMRFASMultiGrid.H:24
void outputAMR(Vector< T *> &a_data, string &a_name, int a_lmax, int a_lbase)
Definition: AMRMultiGrid.H:516
int m_exitStatus
Definition: AMRMultiGrid.H:380
ProblemDomain & refine(int a_refinement_ratio)
Refine this problem domain.
bool m_avoid_norms
Definition: AMRFASMultiGrid.H:84
Definition: LinearSolver.H:156
int m_post
Definition: AMRMultiGrid.H:381
int m_imin
Definition: AMRMultiGrid.H:380
Real computeAMRResidual(Vector< T *> &a_resid, Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l_max, int l_base, bool a_homogeneousBC=false, bool a_computeNorm=true)
Definition: AMRMultiGrid.H:683
#define CH_STOP(tpointer)
Definition: CH_Timer.H:150
virtual void init(const Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l_max, int l_base)
Definition: AMRMultiGrid.H:1212
Vector< Copier > m_resCopier
Definition: AMRMultiGrid.H:487
Definition: AMRFASMultiGrid.H:31
virtual ~AMRFASMultiGrid()
Definition: AMRFASMultiGrid.H:113
Definition: AMRMultiGrid.H:233
virtual void init(const Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l_max, int l_base)
Definition: AMRFASMultiGrid.H:167
NoOpSolver< T > m_nosolve
Definition: AMRMultiGrid.H:490
void setNumVcycles(int n)
Definition: AMRFASMultiGrid.H:54
Real m_normThresh
Definition: AMRMultiGrid.H:378
virtual void FMG(Vector< T *> &a_phi, const Vector< T *> &a_rhs, int l, int l_max, int l_base)
Definition: AMRFASMultiGrid.H:361
void clear_private()
Definition: AMRFASMultiGrid.H:200
Vector< AMRLevelOp< T > * > m_op
Definition: AMRMultiGrid.H:482
void setBottomSolver(int l_max, int l_base)
set up bottom solver for internal MG solver
Definition: AMRMultiGrid.H:1266