本文整理汇总了C++中MultiGrid::oneCycle方法的典型用法代码示例。如果您正苦于以下问题:C++ MultiGrid::oneCycle方法的具体用法?C++ MultiGrid::oneCycle怎么用?C++ MultiGrid::oneCycle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MultiGrid
的用法示例。
在下文中一共展示了MultiGrid::oneCycle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
#ifdef CH_MPI
MPI_Init (&argc, &argv);
#endif
// test parameters
const int nGrids = 3;
const int nCells0 = 32;
// xLo has to be zero in order for DiriBc to work.
const RealVect xLo = RealVect::Zero;
const Real xHi = 1.0;
const Box box0(IntVect::Zero, (nCells0-1)*IntVect::Unit);
const int nGhosts = 1;
const int resNT = 2; // norm Type
const int errNT = 0;
// A test is considered as a failure
// if its convergence rate is smaller than below.
const Real targetConvergeRate = 1.75;
// solver parameters
// To converge within 10 V-Cycles in 1D,
// nRelax=3 is the minimum number of relaxations.
const int nRelax = 3; // m_pre=m_post
// cycle Type, 1 : V-Cycle; -1 : FMG-Cycle
const int cycleType[2] =
{
1, -1
};
const std::string cycleStr[2] =
{
" V" , " FMG"
};
// test results holder
const int nCycles[2] =
{
9, 5
};
const int maxCycles = 10; // > max(nCycles)
// Real resNorm[nGrids][nCycles+1], errNorm[nGrids][nCycles+1];
Real resNorm[nGrids][maxCycles], errNorm[nGrids][maxCycles];
Real convergeRate[nGrids-1][2];
const Real log2r = 1.0/log(2.0);
// status records the number of errors detected.
int status = 0;
for (int j=0; j<2; j++)
{
pout() << "\n**************************************************\n"
<< "\nTesting MultiGrid::oneCycle(correction, residual)\n"
<< " cycle type = " << cycleStr[j]
<< "; m_pre = m_post = " << nRelax << "\n";
for (int iGrid=0; iGrid<nGrids; iGrid++)
{
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
//.........这里部分代码省略.........