void ARingTower::text_out(buffer &o) const { o << "Tower[ZZ/" << characteristic() << "["; for (size_t i = 0; i < n_vars() - 1; i++) o << varNames()[i] << ","; if (n_vars() > 0) o << varNames()[n_vars() - 1]; o << "]]"; extensions_text_out(o); }
void ARingTower::elem_text_out(buffer &o, int level, const poly f, bool p_one, bool p_plus, bool p_parens) const { // o << to_string(level, f); if (f == 0) { o << "0"; return; } int nterms = n_nonzero_terms(level, f); bool needs_parens = p_parens && (nterms >= 2); if (needs_parens) { if (p_plus) o << '+'; o << '('; p_plus = false; } bool one = is_one(level, f); if (one) { if (p_plus) o << "+"; if (p_one) o << "1"; return; } const std::string &this_varname = varNames()[level]; if (level == 0) { bool firstterm = true; for (int i = f->deg; i >= 0; i--) if (f->coeffs[i] != 0) { if (!firstterm || p_plus) o << "+"; firstterm = false; if (i == 0 || f->coeffs[i] != 1) mBaseRing.elem_text_out(o, f->coeffs[i], p_one, p_plus, p_parens); if (i > 0) o << this_varname; if (i > 1) o << i; } if (needs_parens) o << ")"; } else { bool firstterm = true; for (int i = f->deg; i >= 0; i--) if (f->polys[i] != 0) { bool this_p_parens = p_parens || (i > 0); if (i == 0 || !is_one(level - 1, f->polys[i])) elem_text_out(o, level - 1, f->polys[i], p_one, p_plus || !firstterm, this_p_parens); else if (p_plus || !firstterm) o << "+"; if (i > 0) o << this_varname; if (i > 1) o << i; firstterm = false; } if (needs_parens) o << ")"; } }
PetscErrorCode plotAll( Vector<LevelData<FArrayBox> *> &a_phi, Vector<LevelData<FArrayBox> *> &a_rhs, Vector<RefCountedPtr<LevelData<FArrayBox> > > &a_exact, Real a_errNorm[2], string a_fname, Real a_cdx, Vector<DisjointBoxLayout> &a_grids, Vector<int> &a_refratios, Vector<ProblemDomain> &a_domains, PetscCompGridPois &a_petscop, Vec a_x, int a_sub_id = -1 ) { CH_TIME("plotAll"); int nLev = a_phi.size(); PetscErrorCode ierr; Vector<LevelData<FArrayBox>* > plotData(nLev, NULL); if ( a_x ) { ierr = a_petscop.putPetscInChombo(a_x,a_phi); CHKERRQ(ierr); } for (int ilev=0;ilev<nLev;ilev++) { plotData[ilev] = new LevelData<FArrayBox>(a_grids[ilev],4*COMP_POIS_DOF,IntVect::Unit); } a_errNorm[0] = a_errNorm[1] = 0; Real dx = a_cdx; for (int ilev=0;ilev<nLev;ilev++,dx/=s_refRatio) { Interval phiInterval(0,COMP_POIS_DOF-1); a_phi[ilev]->copyTo(phiInterval, *plotData[ilev], phiInterval); Interval rhsInterval(COMP_POIS_DOF,2*COMP_POIS_DOF-1); a_rhs[ilev]->copyTo(phiInterval, *plotData[ilev], rhsInterval); Interval exInterval(2*COMP_POIS_DOF,3*COMP_POIS_DOF-1); a_exact[ilev]->copyTo(phiInterval, *plotData[ilev], exInterval); // use phi for error const DisjointBoxLayout& dbl = a_grids[ilev]; for (DataIterator dit(dbl); dit.ok(); ++dit) { FArrayBox& exactfab = (*a_exact[ilev])[dit]; FArrayBox& phiFAB = (*a_phi[ilev])[dit]; Box region = exactfab.box(); for (BoxIterator bit(region); bit.ok(); ++bit) { IntVect iv = bit(); for (int i=0;i<COMP_POIS_DOF;i++) phiFAB(iv,i) = phiFAB(iv,i) - exactfab(iv,i); } } // zero error on covered if (ilev!=nLev-1) { const DisjointBoxLayout& dbl = a_grids[ilev]; // zero out fine cover DisjointBoxLayout dblCoarsenedFine; Copier copier; coarsen(dblCoarsenedFine, a_grids[ilev+1], a_refratios[ilev]); // coarsens entire grid copier.define(dblCoarsenedFine, dbl, IntVect::Zero); LevelDataOps<FArrayBox> ops; ops.copyToZero(*a_phi[ilev],copier); } // copy in Interval errInterval(3*COMP_POIS_DOF,4*COMP_POIS_DOF-1); a_phi[ilev]->copyTo(phiInterval, *plotData[ilev], errInterval); // get error norms for (DataIterator dit(dbl); dit.ok(); ++dit) { Box region = dbl[dit]; FArrayBox& phifab = (*a_phi[ilev])[dit]; Real mnorm = phifab.norm(region,0); if (mnorm>a_errNorm[0]) a_errNorm[0] = mnorm; mnorm = phifab.norm(region,1)*D_TERM(dx,*dx,*dx); a_errNorm[1] += mnorm; } } { double error; #ifdef CH_MPI MPI_Allreduce( &a_errNorm[0], &error, 1, MPI_DOUBLE, MPI_MAX, PETSC_COMM_WORLD ); a_errNorm[0] = error; #endif #ifdef CH_MPI MPI_Allreduce( &a_errNorm[1], &error, 1, MPI_DOUBLE, MPI_SUM, PETSC_COMM_WORLD ); a_errNorm[1] = error; #endif } pout() << "\t\t plot |error|_inf=" << a_errNorm[0] << endl; // plot if (true){ CH_TIME("plot"); char suffix[30]; if (a_sub_id>=0) sprintf(suffix, "%dd.%d.hdf5",SpaceDim,a_sub_id); else sprintf(suffix, "%dd.hdf5",SpaceDim); a_fname += suffix; Vector<string> varNames(4*COMP_POIS_DOF); int kk=0; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk] = "phi "; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk] = "rhs "; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk] = "exa "; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk] = "err "; kk=0; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk][3] = '1' + i; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk][3] = '1' + i; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk][3] = '1' + i; for (int i=0; i<COMP_POIS_DOF; ++i,kk++) varNames[kk][3] = '1' + i; Real bogusVal = 1.0; WriteAMRHierarchyHDF5(a_fname, a_grids, plotData, varNames, a_domains[0].domainBox(), a_cdx, bogusVal, bogusVal, a_refratios, nLev); } for (int ilev=0;ilev<nLev;ilev++) { delete plotData[ilev]; } PetscFunctionReturn(0); }