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);
65 int l,
int l_max,
int l_base);
69 int l,
int l_max,
int l_base);
72 int l_max,
int l_base);
122 CH_TIME(
"AMRFASMultiGrid::define");
134 for (
int i = 0; i < a_maxAMRLevels; i++)
138 if (this->
m_mg[i] != NULL)
140 delete this->
m_mg[i];
141 this->
m_mg[i] = NULL;
150 if (i < a_maxAMRLevels-1)
162 int l_max,
int l_base )
164 CH_TIME(
"AMRFASMultiGrid::init");
172 for (
int i = l_base+1; i <= l_max; i++)
176 m_HOCopier[i].define( a_phi[i-1]->disjointBoxLayout(), this->
m_resC[i]->disjointBoxLayout(),
177 a_phi[i-1]->ghostVect() );
196 CH_TIME(
"AMRFASMultiGrid::clear_private");
198 for (
int i = 0; i < this->
m_op.
size(); i++)
209 int l_max,
int l_base,
bool a_zeroPhi,
210 bool a_forceHomogeneous)
212 CH_TIMERS(
"AMRFASMultiGrid::solveNoInit");
213 CH_TIMER(
"AMRFASMultiGrid::cycle", vtimer);
215 bool outputIntermediates =
false;
223 for (
int ilev = l_base; ilev <=l_max; ++ilev)
225 this->
m_op[ilev]->setToZero(*(a_phi[ilev]));
228 Real initial_rnorm = 0;
231 CH_TIME(
"Initial AMR Residual");
243 Real rnorm = initial_rnorm;
244 Real norm_last = 2*initial_rnorm;
250 pout() <<
" AMRFASMultiGrid:: iteration = " << iter <<
", residual norm = " << rnorm << std::endl;
254 bool goRedu = rnorm > this->m_eps*initial_rnorm ||
m_avoid_norms;
256 bool goHang = iter < this->
m_imin || rnorm <(1-this->
m_hang)*norm_last;
258 while (goMin || (goIter && goRedu && goHang && goNorm))
266 FMG( a_phi, a_rhs, l_max, l_max, l_base);
271 this->
m_op[l_max]->assignLocal( *(this->
m_residual[l_max]), *(a_rhs[l_max]) );
272 VCycle( a_phi, a_rhs, l_max, l_max, l_base);
280 for (
int ilev = l_base; ilev <= l_max; ilev++)
282 if (outputIntermediates)
284 char strcorname[100];
285 sprintf(strcorname,
"amrFASmg.phi.iter.%03d", iter);
286 string namecor(strcorname);
287 this->
outputAMR(a_phi, namecor, l_max, l_base);
293 if (this->
m_op[0]->orderOfAccuracy()>2)
295 for (
int ilev=l_max; ilev>l_base; ilev--)
297 this->
m_op[ilev]->enforceCFConsistency(*a_phi[ilev-1], *a_phi[ilev]);
309 pout() <<
" AMRFASMultiGrid:: iteration = " << iter <<
", residual norm = " << rnorm;
312 pout() <<
", rate = " << norm_last/rnorm;
318 goRedu = rnorm > this->m_eps*initial_rnorm;
319 goHang = iter < this->
m_imin || rnorm <(1-this->
m_hang)*norm_last;
325 this->
m_exitStatus = int(!goRedu) + int(!goIter)*2 + int(!goHang)*4 + int(!goNorm)*8;
328 pout() <<
" AMRFASMultiGrid:: iteration = " << iter <<
", residual norm = " << rnorm << std::endl;
332 if (!goIter && goRedu && goNorm)
334 pout() <<
" AMRFASMultiGrid:: WARNING: Exit because max iteration count exceeded" << std::endl;
336 if (!goHang && goRedu && goNorm)
338 pout() <<
" AMRFASMultiGrid:: WARNING: Exit because of solver hang" << std::endl;
342 pout() <<
" AMRFASMultiGrid:: exitStatus = " << this->
m_exitStatus << std::endl;
357 int i,
int l_max,
int l_base)
360 this->
m_op[l_base]->assignLocal( *(this->
m_residual[l_base]), *(a_rhs[l_base]) );
361 this->
m_mg[l_base]->oneCycle( *(a_phi[l_base]), *(this->
m_residual[l_base]) );
363 for (
int ilev = l_base+1 ; ilev <= l_max ; ilev++ )
366 this->
m_op[ilev]->AMRProlongS_2( *(a_phi[ilev]), *(a_phi[ilev-1]),
370 this->
m_op[ilev]->assignLocal( *(this->
m_residual[ilev]), *(a_rhs[ilev]) );
373 VCycle( a_phi, a_rhs, ilev, l_max, l_base );
387 int ilev,
int l_max,
int l_base )
391 CH_TIME(
"AMRFASMultiGrid::VCycle:coarse_grid_solver");
395 this->
m_op[ilev]->write(a_phi[ilev],
"zh_coarsest_phi_0.hdf5");
396 this->
m_op[ilev]->write(this->
m_residual[ilev],
"zh_coarsest_rhs.hdf5");
402 T* phiCoarsePtr = NULL;
405 phiCoarsePtr = a_phi[l_base-1];
414 this->
m_op[ilev]->write(a_phi[ilev],
"zh_coarsest_phi_1.hdf5");
430 rhs = a_rhs_dummy[ilev];
439 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_0.hdf5");
440 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_0.hdf5");
444 this->
m_op[ilev]->relaxNF( *(a_phi[ilev]), (a_phi[ilev-1]), *rhs, this->
m_pre );
447 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_1.hdf5");
448 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_1.hdf5");
461 l_max, l_base, ilev-1,
468 this->
m_op[ilev]->AMRRestrictS(*(this->
m_resC[ilev]),
476 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_2.hdf5");
477 this->
m_op[ilev-1]->write(this->
m_resC[ilev],
"zb_coarse_phi_1.hdf5");
481 this->
m_resC[ilev]->copyTo(this->
m_resC[ilev]->interval(), *(a_phi[ilev-1]), a_phi[ilev-1]->interval(), this->
m_resCopier[ilev]);
487 this->
m_op[ilev]->AMRRestrictS(*(this->
m_resC[ilev]),
495 this->
m_op[ilev]->write(this->
m_resC[ilev],
"zd_resC.hdf5");
496 this->
m_op[ilev]->write(a_phi[ilev-1],
"ze_coarse_phi_2.hdf5");
497 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_2.hdf5");
506 this->
m_op[ilev-1]->write(this->
m_residual[ilev-1],
"zf_coarse_res_1.hdf5");
513 this->
m_op[ilev-1]->AMROperatorNC( *(this->
m_correction[ilev-1]), undefined, *(a_phi[ilev-1]),
true, this->
m_op[ilev]);
517 this->
m_op[ilev]->write(a_phi[ilev],
"zb_fine_phi_3.hdf5");
524 this->
m_op[ilev-1]->write(this->
m_residual[ilev-1],
"zf_coarse_res_3.hdf5");
530 this->
m_op[ilev-1]->create( R_u_f, *a_phi[ilev-1]);
531 this->
m_op[ilev-1]->assignLocal( R_u_f, *(a_phi[ilev-1]) );
533 for (
int img = 0; img < this->
m_numMG; img++)
535 VCycle( a_phi, a_rhs_dummy, ilev-1, l_max, l_base );
539 this->
m_op[ilev-1]->write(a_phi[ilev-1],
"zi_coarse_phi_2.hdf5");
543 this->
m_op[ilev-1]->axby( *this->
m_correction[ilev-1], *a_phi[ilev-1], R_u_f, 1.0, -1.0 );
561 this->
m_op[ilev]->AMRProlongS( *(a_phi[ilev]), *(this->
m_correction[ilev-1]),
567 this->
m_op[ilev]->write(a_phi[ilev],
"zl_fine_phi_1.hdf5");
573 this->
m_op[ilev]->relaxNF( *(a_phi[ilev]), (a_phi[ilev-1]), *rhs, this->
m_post );
576 this->
m_op[ilev]->write(a_phi[ilev],
"zl_fine_phi_2.hdf5");
577 this->
m_op[ilev]->write(this->
m_residual[ilev],
"za_fine_res_3.hdf5");
578 this->
m_op[ilev]->write(a_rhs_dummy[ilev],
"za_rhs.hdf5");
585 #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:207
#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:385
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:117
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:84
OLD_FASMG_type m_type
Definition: AMRFASMultiGrid.H:77
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:81
Real m_convergenceMetric
Definition: AMRMultiGrid.H:391
Definition: AMRMultiGrid.H:39
#define CH_TIMER(name, tpointer)
Definition: CH_Timer.H:63
int m_numVcycles
Definition: AMRFASMultiGrid.H:79
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:83
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:80
int m_iter
Definition: AMRFASMultiGrid.H:60
Definition: FASMultiGrid.H:22
Real m_hang
Definition: AMRMultiGrid.H:378
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:95
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:78
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:107
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:161
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:355
void clear_private()
Definition: AMRFASMultiGrid.H:194
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