当前位置: 首页>>代码示例>>C++>>正文


C++ MultiGrid::init方法代码示例

本文整理汇总了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;
}
开发者ID:rsnemmen,项目名称:Chombo,代码行数:101,代码来源:testNewPoissonOp.cpp


注:本文中的MultiGrid::init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。