void MantidWSIndexDialog::initButtons() { m_buttonBox = new QHBoxLayout; m_okButton = new QPushButton("Ok"); m_cancelButton = new QPushButton("Cancel"); m_plotAllButton = new QPushButton("Plot All"); m_buttonBox->addWidget(m_okButton); m_buttonBox->addWidget(m_cancelButton); m_buttonBox->addWidget(m_plotAllButton); m_outer->addItem(m_buttonBox); connect(m_okButton, SIGNAL(clicked()), this, SLOT(plot())); connect(m_cancelButton, SIGNAL(clicked()), this, SLOT(close())); connect(m_plotAllButton, SIGNAL(clicked()), this, SLOT(plotAll())); }
PetscErrorCode go(int nGrids, int &status) { CH_TIME("go"); PetscErrorCode ierr; Real errNorm[20][2]; Real convergeRate[20-1][2]; bool sameGrids; const Real log2r = 1.0/log(2.0); const Real targetConvergeRate = 2*0.9; Vector<RefCountedPtr<LevelData<FArrayBox> > > phi; Vector<RefCountedPtr<LevelData<FArrayBox> > > rhs; Vector<LevelData<FArrayBox> *> phi2; Vector<LevelData<FArrayBox> *> rhs2; Vector<RefCountedPtr<LevelData<FArrayBox> > > exact; Vector<int> refratios; Vector<ProblemDomain> domains; Vector<DisjointBoxLayout> grids; Vector<IntVectSet> tagVects(nGrids-1); Real cdx,dx; PetscCompGridPois petscop(0.,-1.,s_order); RefCountedPtr<ConstDiriBC> bcfunc = RefCountedPtr<ConstDiriBC>(new ConstDiriBC(2,petscop.getGhostVect())); BCHolder bc(bcfunc); PetscFunctionBeginUser; petscop.setCornerStencil(s_corner_stencil); petscop.setMatlab(s_matlab); for (int nLev=1,iMaxLev=0; nLev<=nGrids; nLev++,iMaxLev++) { ierr = setupGrids( refratios, domains, grids, nLev, cdx, exact, phi, iMaxLev==0 ? 0.: errNorm[iMaxLev-1][0], tagVects, sameGrids ); CHKERRQ(ierr); if (sameGrids){ nGrids = iMaxLev; break;} // allocate vectors, set RHS and exact phi.resize(nLev); rhs.resize(nLev); exact.resize(nLev); phi2.resize(nLev); rhs2.resize(nLev); dx = cdx; for (int ilev=0;ilev<nLev;ilev++) { phi[ilev] = RefCountedPtr<LevelData<FArrayBox> >(new LevelData<FArrayBox>(grids[ilev],COMP_POIS_DOF,petscop.getGhostVect())); rhs[ilev] = RefCountedPtr<LevelData<FArrayBox> >(new LevelData<FArrayBox>(grids[ilev],COMP_POIS_DOF,IntVect::Zero)); exact[ilev] = RefCountedPtr<LevelData<FArrayBox> >(new LevelData<FArrayBox>(grids[ilev],COMP_POIS_DOF,IntVect::Unit)); rhs2[ilev] = &(*rhs[ilev]); phi2[ilev] = &(*phi[ilev]); const DisjointBoxLayout &dbl = grids[ilev]; for (DataIterator dit(dbl) ; dit.ok(); ++dit) { FArrayBox& rhsFAB = (*rhs[ilev])[dit]; Box region = dbl[dit]; for (BoxIterator bit(region); bit.ok(); ++bit) { IntVect iv = bit(); RealVect loc(iv); loc *= dx; loc += 0.5*dx*RealVect::Unit; for (int i=0;i<COMP_POIS_DOF;i++) rhsFAB(iv,i) = rhsFunc(loc); } FArrayBox& exactfab = (*exact[ilev])[dit]; FArrayBox& phifab = (*phi[ilev])[dit]; Box eregion = exactfab.box(); for (BoxIterator bit(eregion); bit.ok(); ++bit) { IntVect iv = bit(); RealVect loc(iv); loc *= dx; loc += 0.5*dx*RealVect::Unit; for (int i=0;i<COMP_POIS_DOF;i++) exactfab(iv,i) = exactSolution(loc); } phifab *= .0; } if (ilev!=nLev-1) dx /= refratios[ilev]; } // form matrix petscop.define(domains[0],grids,refratios,bc,cdx*RealVect::Unit); petscop.setVerbose(1); ierr = petscop.createMatrix(); CHKERRQ(ierr); // solve Vec x, b; /* approx solution, RHS */ { CH_TIME("PETSC-solve"); Mat A; /* linear system matrix */ KSP ksp; /* linear solver context */ A = petscop.getMatrix(); ierr = MatGetVecs(A,&x,&b); CHKERRQ(ierr); ierr = petscop.putChomboInPetsc(rhs2,b); CHKERRQ(ierr); ierr = KSPCreate(PETSC_COMM_WORLD, &ksp); CHKERRQ(ierr); #if PETSC_VERSION_GE(3,5,0) ierr = KSPSetOperators(ksp, A, A); CHKERRQ(ierr); #else ierr = KSPSetOperators(ksp, A, A, DIFFERENT_NONZERO_PATTERN); CHKERRQ(ierr); #endif ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr); ierr = KSPSolve(ksp, b, x); CHKERRQ(ierr); ierr = KSPDestroy(&ksp); CHKERRQ(ierr); } if (s_plot) { ierr = plotAll(phi2,rhs2,exact,errNorm[iMaxLev],"testPetscCompGrid.", cdx,grids,refratios,domains,petscop,x,nLev); CHKERRQ(ierr); } ierr = VecDestroy(&x); CHKERRQ(ierr); ierr = VecDestroy(&b); CHKERRQ(ierr); } // #ifdef CH_USE_FAS // do AMRFAS if (s_amrfas) { int status; AMRFAS<LevelData<FArrayBox> > amrFASSolver; FASPoissonOpFactory opFactory(2); // solving poisson problem here opFactory.define( bc, 0., -1. ); amrFASSolver.m_pre = 4; amrFASSolver.m_post = 4; amrFASSolver.m_verbosity = 5; s_fas_verbosity = 1; // this is in AMRFASI.H amrFASSolver.setAvoidNorms(false); amrFASSolver.setInternalCoarseningRate(2); amrFASSolver.setNumVcycles(1); amrFASSolver.setCycleType(FAS_FULL); amrFASSolver.m_max_iter = 100; amrFASSolver.m_atol = 1.0e-9; amrFASSolver.m_rtol = 1.0e-9; amrFASSolver.m_stagnate = 1.e-2; amrFASSolver.setSmootherType(FAS_RICH); amrFASSolver.setSmoothingDampingFactor(CH_SPACEDIM==3 ? .7 : .8); amrFASSolver.setFMGProlOrderP(2); amrFASSolver.setProlOrderP(1); amrFASSolver.define( domains[0], cdx*RealVect::Unit, grids, refratios, opFactory ); for (int ilev=0;ilev<nGrids;ilev++) { const DisjointBoxLayout &dbl = grids[ilev]; for (DataIterator dit(dbl) ; dit.ok(); ++dit) { FArrayBox& fab = (*phi[ilev])[dit]; fab.setVal(0.0,dbl[dit],0,fab.nComp()); } } amrFASSolver.solve( phi, rhs, &status ); PetscCompGridPois petscop(0.,-1.,2); petscop.define(domains[0],grids,refratios,bc,cdx*RealVect::Unit); Real errNorms[2]; ierr = plotAll( phi2,rhs2,exact,errNorms,"testPetscCompGridAMRFAS.", cdx,grids,refratios,domains,petscop,PETSC_NULL,nGrids); CHKERRQ(ierr); } #endif // do AMRMultigrid if (s_amrmg) { AMRMultiGrid<LevelData<FArrayBox> > amrMG; AMRPoissonOpFactory opFactory; BiCGStabSolver<LevelData<FArrayBox> > biCGStab; PetscCompGridPois petscop(0.,-1.,2); petscop.define(domains[0],grids,refratios,bc,cdx*RealVect::Unit); // solving poisson problem here opFactory.define( domains[0], grids, refratios, cdx, bc, 0., -1. ); amrMG.define( domains[0], opFactory, &biCGStab, nGrids); amrMG.setSolverParameters(4,4,100,1,100,1.0e-9,1.0e-9,1.0e-9); amrMG.m_verbosity = 3; amrMG.solve( phi2, rhs2, nGrids-1, 0, true, true ); Real errNorms[2]; ierr = plotAll( phi2,rhs2,exact,errNorms,"testPetscCompGridGMG.", cdx,grids,refratios,domains,petscop,PETSC_NULL,nGrids); CHKERRQ(ierr); } pout() << "\nConvergence Rates : Inf norm 1 norm\n"; pout() << "----------------------------------------\n" << std::setprecision(3); if (s_plot) { for (int i=0; i<nGrids-1; i++) { pout() << " "; for (int j=0;j<2;j++) { const Real ratio = errNorm[i][j]/errNorm[i+1][j]; convergeRate[i][j] = log(ratio)*log2r; if (j==1)convergeRate[i][j] *= 2; // this is not quite right if (convergeRate[i][j] < targetConvergeRate && i>0 ) // first test misses because of griding { status += 1; } pout() << " " << convergeRate[i][j]; } pout() << endl; } if (status==0) { pout() << "All tests passed!\n"; } else { pout() << status << " tests failed!\n"; } } PetscFunctionReturn(0); }