本文整理汇总了C++中MultiGrid::init方法的典型用法代码示例。如果您正苦于以下问题:C++ MultiGrid::init方法的具体用法?C++ MultiGrid::init怎么用?C++ MultiGrid::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiGrid
的用法示例。
在下文中一共展示了MultiGrid::init方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
int ref = 1;
for (int i=0; i<iGrid; i++)
ref*=2;
const Real dx = xHi/nCells0/ref;
const Box domain = refine(box0,ref);
const Box ghostBox = grow(domain,nGhosts);
pout() << "\n----------------------------------------------------\n";
pout() << "nCells = " << nCells0*ref << " ; dx = " << dx << " \n";
FArrayBox phi(ghostBox, 1);
FArrayBox correction(ghostBox, 1);
FArrayBox rhs(domain, 1);
FArrayBox error(domain, 1);
FArrayBox phiExact(domain, 1);
FArrayBox residual(domain, 1);
// set initial guess
phi.setVal(0.0);
// set RHS and the exact solution
for (BoxIterator bit(domain); bit.ok(); ++bit)
{
const RealVect offset = bit()-domain.smallEnd();
const RealVect x = xLo + dx*(0.5+offset);
rhs(bit()) = rhsFunc( x );
phiExact(bit()) = exactSolution( x );
}
// Initialize big objects
NewPoissonOpFactory opFactory;
opFactory.define(dx*RealVect(IntVect::Unit), constDiriBC);
MultiGrid<FArrayBox> solver;
BiCGStabSolver<FArrayBox> bottomSolver;
bottomSolver.m_verbosity = 0;
MGLevelOp<FArrayBox>* op = opFactory.MGnewOp(domain,0);
solver.m_numMG = 1;
solver.m_bottom = 1;
solver.m_pre = nRelax;
solver.m_post = nRelax;
solver.m_cycle = cycleType[j];
solver.define(opFactory, &bottomSolver, domain);
// put the data into residual-correction form
op->residual(residual, phi, rhs);
resNorm[iGrid][0] = residual.norm(resNT);
op->axby(error, phi, phiExact, 1, -1);
errNorm[iGrid][0] = error.norm(errNT);
solver.init(correction, residual);
// Solve the problem using MultiGrid::oneCycle
for (int i=0; i<nCycles[j]; i++)
{
correction.setVal(0.0);
solver.oneCycle(correction, residual);
op->incr(phi, correction, 1);
op->residual(residual, phi, rhs);
resNorm[iGrid][i+1] = residual.norm(resNT);
op->axby(error, phi, phiExact, 1, -1);
errNorm[iGrid][i+1] = error.norm(errNT);
}
delete op;
// output a table of results
pout()<< cycleStr[j] << "-Cycle N.O. | residual " << resNT
<< "-norm | Error " << errNT << "-norm \n";
for (int i=0; i<nCycles[j]+1; i++)
{
pout() << " " << i << " | " << resNorm[iGrid][i]
<< " | " << errNorm[iGrid][i] << "\n";
}
} // end grid loop
pout() << "\nConvergence Rate based on the error in the last cycle:\n";
for (int i=0; i<nGrids-1; i++)
{
Real ratio = errNorm[i][nCycles[j]]/errNorm[i+1][nCycles[j]];
convergeRate[i][j] = log(ratio)*log2r;
if (convergeRate[i][j] < targetConvergeRate)
{
status += 1;
}
pout() << " " << convergeRate[i][j] << "\n";
}
}// end cycle type
if (status==0)
{
pout() << "All tests passed!\n";
}
else
{
pout() << status << " tests failed!\n";
}
#ifdef CH_MPI
MPI_Finalize ();
#endif
return status;
}