int testEBFluxFAB(const EBISBox& a_ebisBox, const Box& a_box) { Interval comps(0,0); IntVectSet ivs(a_box); EBFluxFAB srcFab( a_ebisBox, a_box, 1); EBFluxFAB dstFab( a_ebisBox, a_box, 1); for (int idir = 0; idir < SpaceDim; idir++) { //set source fab to right ans for (FaceIterator faceit(ivs, a_ebisBox.getEBGraph(), idir, FaceStop::SurroundingWithBoundary); faceit.ok(); ++faceit) { srcFab[idir](faceit(), 0) = rightAns(faceit()); } } //linearize the data to dst int sizeFab = srcFab.size(a_box, comps); unsigned char* buf = new unsigned char[sizeFab]; srcFab.linearOut(buf, a_box, comps); dstFab.linearIn( buf, a_box, comps); delete[] buf; //check the answer int eekflag = 0; for (int idir = 0; idir < SpaceDim; idir++) { Real tolerance = 0.001; for (FaceIterator faceit(ivs, a_ebisBox.getEBGraph(), idir, FaceStop::SurroundingWithBoundary); faceit.ok(); ++faceit) { Real correct = rightAns(faceit()); if (Abs(dstFab[idir](faceit(), 0) - correct) > tolerance) { pout() << "ivfab test failed at face " << faceit().gridIndex(Side::Lo) << faceit().gridIndex(Side::Hi) << endl; eekflag = -4; return eekflag; } } } return 0; }
int testIVFAB(const EBISBox& a_ebisBox, const Box& a_box) { IntVectSet ivs = a_ebisBox.getIrregIVS(a_box); if (ivs.isEmpty()) return 0; Interval comps(0,0); BaseIVFAB<Real> srcFab(ivs, a_ebisBox.getEBGraph(), 1); BaseIVFAB<Real> dstFab(ivs, a_ebisBox.getEBGraph(), 1); //set source fab to right ans for (VoFIterator vofit(ivs, a_ebisBox.getEBGraph()); vofit.ok(); ++vofit) { srcFab(vofit(), 0) = rightAns(vofit()); } //linearize the data to dst int sizeFab = srcFab.size(a_box, comps); unsigned char* buf = new unsigned char[sizeFab]; srcFab.linearOut(buf, a_box, comps); dstFab.linearIn( buf, a_box, comps); delete[] buf; //check the answer int eekflag = 0; Real tolerance = 0.001; for (VoFIterator vofit(ivs, a_ebisBox.getEBGraph()); vofit.ok(); ++vofit) { Real correct = rightAns(vofit()); if (Abs(dstFab(vofit(), 0) - correct) > tolerance) { pout() << "ivfab test failed at vof " << vofit().gridIndex() << endl; eekflag = -1; return eekflag; } } return 0; }
void meanShiftSegmentation(const oclMat &src, Mat &dst, int sp, int sr, int minsize, TermCriteria criteria) { CV_Assert(src.type() == CV_8UC4); const int nrows = src.rows; const int ncols = src.cols; const int hr = sr; const int hsp = sp; // Perform mean shift procedure and obtain region and spatial maps oclMat h_rmap, h_spmap; meanShiftProc(src, h_rmap, h_spmap, sp, sr, criteria); Mat rmap = h_rmap; Mat spmap = h_spmap; Graph<SegmLinkVal> g(nrows * ncols, 4 * (nrows - 1) * (ncols - 1) + (nrows - 1) + (ncols - 1)); // Make region adjacent graph from image Vec4b r1; Vec4b r2[4]; Vec2s sp1; Vec2s sp2[4]; int dr[4]; int dsp[4]; for (int y = 0; y < nrows - 1; ++y) { Vec4b *ry = rmap.ptr<Vec4b>(y); Vec4b *ryp = rmap.ptr<Vec4b>(y + 1); Vec2s *spy = spmap.ptr<Vec2s>(y); Vec2s *spyp = spmap.ptr<Vec2s>(y + 1); for (int x = 0; x < ncols - 1; ++x) { r1 = ry[x]; sp1 = spy[x]; r2[0] = ry[x + 1]; r2[1] = ryp[x]; r2[2] = ryp[x + 1]; r2[3] = ryp[x]; sp2[0] = spy[x + 1]; sp2[1] = spyp[x]; sp2[2] = spyp[x + 1]; sp2[3] = spyp[x]; dr[0] = dist2(r1, r2[0]); dr[1] = dist2(r1, r2[1]); dr[2] = dist2(r1, r2[2]); dsp[0] = dist2(sp1, sp2[0]); dsp[1] = dist2(sp1, sp2[1]); dsp[2] = dist2(sp1, sp2[2]); r1 = ry[x + 1]; sp1 = spy[x + 1]; dr[3] = dist2(r1, r2[3]); dsp[3] = dist2(sp1, sp2[3]); g.addEdge(pix(y, x, ncols), pix(y, x + 1, ncols), SegmLinkVal(dr[0], dsp[0])); g.addEdge(pix(y, x, ncols), pix(y + 1, x, ncols), SegmLinkVal(dr[1], dsp[1])); g.addEdge(pix(y, x, ncols), pix(y + 1, x + 1, ncols), SegmLinkVal(dr[2], dsp[2])); g.addEdge(pix(y, x + 1, ncols), pix(y + 1, x, ncols), SegmLinkVal(dr[3], dsp[3])); } } for (int y = 0; y < nrows - 1; ++y) { r1 = rmap.at<Vec4b>(y, ncols - 1); r2[0] = rmap.at<Vec4b>(y + 1, ncols - 1); sp1 = spmap.at<Vec2s>(y, ncols - 1); sp2[0] = spmap.at<Vec2s>(y + 1, ncols - 1); dr[0] = dist2(r1, r2[0]); dsp[0] = dist2(sp1, sp2[0]); g.addEdge(pix(y, ncols - 1, ncols), pix(y + 1, ncols - 1, ncols), SegmLinkVal(dr[0], dsp[0])); } for (int x = 0; x < ncols - 1; ++x) { r1 = rmap.at<Vec4b>(nrows - 1, x); r2[0] = rmap.at<Vec4b>(nrows - 1, x + 1); sp1 = spmap.at<Vec2s>(nrows - 1, x); sp2[0] = spmap.at<Vec2s>(nrows - 1, x + 1); dr[0] = dist2(r1, r2[0]); dsp[0] = dist2(sp1, sp2[0]); g.addEdge(pix(nrows - 1, x, ncols), pix(nrows - 1, x + 1, ncols), SegmLinkVal(dr[0], dsp[0])); } DjSets comps(g.numv); // Find adjacent components for (int v = 0; v < g.numv; ++v) { for (int e_it = g.start[v]; e_it != -1; e_it = g.edges[e_it].next) { int c1 = comps.find(v); int c2 = comps.find(g.edges[e_it].to); if (c1 != c2 && g.edges[e_it].val.dr < hr && g.edges[e_it].val.dsp < hsp) comps.merge(c1, c2); } } vector<SegmLink> edges; edges.reserve(g.numv); // Prepare edges connecting differnet components for (int v = 0; v < g.numv; ++v) { int c1 = comps.find(v); for (int e_it = g.start[v]; e_it != -1; e_it = g.edges[e_it].next) { int c2 = comps.find(g.edges[e_it].to); if (c1 != c2) edges.push_back(SegmLink(c1, c2, g.edges[e_it].val)); } } // Sort all graph's edges connecting differnet components (in asceding order) std::sort(edges.begin(), edges.end()); // Exclude small components (starting from the nearest couple) for (size_t i = 0; i < edges.size(); ++i) { int c1 = comps.find(edges[i].from); int c2 = comps.find(edges[i].to); if (c1 != c2 && (comps.size[c1] < minsize || comps.size[c2] < minsize)) comps.merge(c1, c2); } // Compute sum of the pixel's colors which are in the same segment Mat h_src = src; vector<Vec4i> sumcols(nrows * ncols, Vec4i(0, 0, 0, 0)); for (int y = 0; y < nrows; ++y) { Vec4b *h_srcy = h_src.ptr<Vec4b>(y); for (int x = 0; x < ncols; ++x) { int parent = comps.find(pix(y, x, ncols)); Vec4b col = h_srcy[x]; Vec4i &sumcol = sumcols[parent]; sumcol[0] += col[0]; sumcol[1] += col[1]; sumcol[2] += col[2]; } } // Create final image, color of each segment is the average color of its pixels dst.create(src.size(), src.type()); for (int y = 0; y < nrows; ++y) { Vec4b *dsty = dst.ptr<Vec4b>(y); for (int x = 0; x < ncols; ++x) { int parent = comps.find(pix(y, x, ncols)); const Vec4i &sumcol = sumcols[parent]; Vec4b &dstcol = dsty[x]; dstcol[0] = static_cast<uchar>(sumcol[0] / comps.size[parent]); dstcol[1] = static_cast<uchar>(sumcol[1] / comps.size[parent]); dstcol[2] = static_cast<uchar>(sumcol[2] / comps.size[parent]); } } }
RankFourTensor TensorMechanicsPlasticTensileMulti::consistentTangentOperator(const RankTwoTensor & trial_stress, const RankTwoTensor & stress, const Real & intnl, const RankFourTensor & E_ijkl, const std::vector<Real> & cumulative_pm) const { if (!_use_custom_cto) return TensorMechanicsPlasticModel::consistentTangentOperator(trial_stress, stress, intnl, E_ijkl, cumulative_pm); mooseAssert(cumulative_pm.size() == 3, "TensorMechanicsPlasticTensileMulti size of cumulative_pm should be 3 but it is " << cumulative_pm.size()); if (cumulative_pm[2] <= 0) // All cumulative_pm are non-positive, so this is admissible return E_ijkl; // Need the eigenvalues at the returned configuration std::vector<Real> eigvals; stress.symmetricEigenvalues(eigvals); // need to rotate to and from principal stress space // using the eigenvectors of the trial configuration // (not the returned configuration). std::vector<Real> trial_eigvals; RankTwoTensor trial_eigvecs; trial_stress.symmetricEigenvaluesEigenvectors(trial_eigvals, trial_eigvecs); // The returnMap will have returned to the Tip, Edge or // Plane. The consistentTangentOperator describes the // change in stress for an arbitrary change in applied // strain. I assume that the change in strain will not // change the type of return (Tip remains Tip, Edge remains // Edge, Plane remains Plane). // I assume isotropic elasticity. // // The consistent tangent operator is a little different // than cases where no rotation to principal stress space // is made during the returnMap. Let S_ij be the stress // in original coordinates, and s_ij be the stress in the // principal stress coordinates, so that // s_ij = diag(eigvals[0], eigvals[1], eigvals[2]) // We want dS_ij under an arbitrary change in strain (ep->ep+dep) // dS = S(ep+dep) - S(ep) // = R(ep+dep) s(ep+dep) R(ep+dep)^T - R(ep) s(ep) R(ep)^T // Here R = the rotation to principal-stress space, ie // R_ij = eigvecs[i][j] = i^th component of j^th eigenvector // Expanding to first order in dep, // dS = R(ep) (s(ep+dep) - s(ep)) R(ep)^T // + dR/dep s(ep) R^T + R(ep) s(ep) dR^T/dep // The first line is all that is usually calculated in the // consistent tangent operator calculation, and is called // cto below. // The second line involves changes in the eigenvectors, and // is called sec below. RankFourTensor cto; Real hard = dtensile_strength(intnl); Real la = E_ijkl(0,0,1,1); Real mu = 0.5*(E_ijkl(0,0,0,0) - la); if (cumulative_pm[1] <= 0) { // only cumulative_pm[2] is positive, so this is return to the Plane Real denom = hard + la + 2*mu; Real al = la*la/denom; Real be = la*(la + 2*mu)/denom; Real ga = hard*(la + 2*mu)/denom; std::vector<Real> comps(9); comps[0] = comps[4] = la + 2*mu - al; comps[1] = comps[3] = la - al; comps[2] = comps[5] = comps[6] = comps[7] = la - be; comps[8] = ga; cto.fillFromInputVector(comps, RankFourTensor::principal); } else if (cumulative_pm[0] <= 0) { // both cumulative_pm[2] and cumulative_pm[1] are positive, so Edge Real denom = 2*hard + 2*la + 2*mu; Real al = hard*2*la/denom; Real be = hard*(2*la + 2*mu)/denom; std::vector<Real> comps(9); comps[0] = la + 2*mu - 2*la*la/denom; comps[1] = comps[2] = al; comps[3] = comps[6] = al; comps[4] = comps[5] = comps[7] = comps[8] = be; cto.fillFromInputVector(comps, RankFourTensor::principal); } else { // all cumulative_pm are positive, so Tip Real denom = 3*hard + 3*la + 2*mu; std::vector<Real> comps(2); comps[0] = hard*(3*la + 2*mu)/denom; comps[1] = 0; cto.fillFromInputVector(comps, RankFourTensor::symmetric_isotropic); } cto.rotate(trial_eigvecs); // drdsig = change in eigenvectors under a small stress change // drdsig(i,j,m,n) = dR(i,j)/dS_mn // The formula below is fairly easily derived: // S R = R s, so taking the variation // dS R + S dR = dR s + R ds, and multiplying by R^T // R^T dS R + R^T S dR = R^T dR s + ds .... (eqn 1) // I demand that RR^T = 1 = R^T R, and also that // (R+dR)(R+dR)^T = 1 = (R+dT)^T (R+dR), which means // that dR = R*c, for some antisymmetric c, so Eqn1 reads // R^T dS R + s c = c s + ds // Grabbing the components of this gives ds/dS (already // in RankTwoTensor), and c, which is: // dR_ik/dS_mn = drdsig(i, k, m, n) = trial_eigvecs(m, b)*trial_eigvecs(n, k)*trial_eigvecs(i, b)/(trial_eigvals[k] - trial_eigvals[b]); // (sum over b!=k). RankFourTensor drdsig; for (unsigned k = 0 ; k < 3 ; ++k) for (unsigned b = 0 ; b < 3 ; ++b) { if (b == k) continue; for (unsigned m = 0 ; m < 3 ; ++m) for (unsigned n = 0 ; n < 3 ; ++n) for (unsigned i = 0 ; i < 3 ; ++i) drdsig(i, k, m, n) += trial_eigvecs(m, b)*trial_eigvecs(n, k)*trial_eigvecs(i, b)/(trial_eigvals[k] - trial_eigvals[b]); } // With diagla = diag(eigvals[0], eigvals[1], digvals[2]) // The following implements // ans(i, j, a, b) += (drdsig(i, k, m, n)*trial_eigvecs(j, l)*diagla(k, l) + trial_eigvecs(i, k)*drdsig(j, l, m, n)*diagla(k, l))*E_ijkl(m, n, a, b); // (sum over k, l, m and n) RankFourTensor ans; for (unsigned i = 0 ; i < 3 ; ++i) for (unsigned j = 0 ; j < 3 ; ++j) for (unsigned a = 0 ; a < 3 ; ++a) for (unsigned k = 0 ; k < 3 ; ++k) for (unsigned m = 0 ; m < 3 ; ++m) ans(i, j, a, a) += (drdsig(i, k, m, m)*trial_eigvecs(j, k) + trial_eigvecs(i, k)*drdsig(j, k, m, m))*eigvals[k]*la; //E_ijkl(m, n, a, b) = la*(m==n)*(a==b); for (unsigned i = 0 ; i < 3 ; ++i) for (unsigned j = 0 ; j < 3 ; ++j) for (unsigned a = 0 ; a < 3 ; ++a) for (unsigned b = 0 ; b < 3 ; ++b) for (unsigned k = 0 ; k < 3 ; ++k) { ans(i, j, a, b) += (drdsig(i, k, a, b)*trial_eigvecs(j, k) + trial_eigvecs(i, k)*drdsig(j, k, a, b))*eigvals[k]*mu; //E_ijkl(m, n, a, b) = mu*(m==a)*(n==b) ans(i, j, a, b) += (drdsig(i, k, b, a)*trial_eigvecs(j, k) + trial_eigvecs(i, k)*drdsig(j, k, b, a))*eigvals[k]*mu; //E_ijkl(m, n, a, b) = mu*(m==b)*(n==a) } return cto + ans; }
void CPDF_RenderStatus::DrawShading(CPDF_ShadingPattern* pPattern, CFX_Matrix* pMatrix, FX_RECT& clip_rect, int alpha, FX_BOOL bAlphaMode) { CPDF_Function** pFuncs = pPattern->m_pFunctions; int nFuncs = pPattern->m_nFuncs; CPDF_Dictionary* pDict = pPattern->m_pShadingObj->GetDict(); CPDF_ColorSpace* pColorSpace = pPattern->m_pCS; if (!pColorSpace) { return; } FX_ARGB background = 0; if (!pPattern->m_bShadingObj && pPattern->m_pShadingObj->GetDict()->KeyExist("Background")) { CPDF_Array* pBackColor = pPattern->m_pShadingObj->GetDict()->GetArray("Background"); if (pBackColor && pBackColor->GetCount() >= (FX_DWORD)pColorSpace->CountComponents()) { CFX_FixedBufGrow<FX_FLOAT, 16> comps(pColorSpace->CountComponents()); for (int i = 0; i < pColorSpace->CountComponents(); i++) { comps[i] = pBackColor->GetNumber(i); } FX_FLOAT R = 0.0f, G = 0.0f, B = 0.0f; pColorSpace->GetRGB(comps, R, G, B); background = ArgbEncode(255, (int32_t)(R * 255), (int32_t)(G * 255), (int32_t)(B * 255)); } } if (pDict->KeyExist("BBox")) { CFX_FloatRect rect = pDict->GetRect("BBox"); rect.Transform(pMatrix); clip_rect.Intersect(rect.GetOutterRect()); } CPDF_DeviceBuffer buffer; buffer.Initialize(m_pContext, m_pDevice, &clip_rect, m_pCurObj, 150); CFX_Matrix FinalMatrix = *pMatrix; FinalMatrix.Concat(*buffer.GetMatrix()); CFX_DIBitmap* pBitmap = buffer.GetBitmap(); if (!pBitmap->GetBuffer()) { return; } pBitmap->Clear(background); int fill_mode = m_Options.m_Flags; switch (pPattern->m_ShadingType) { case kInvalidShading: case kMaxShading: return; case kFunctionBasedShading: DrawFuncShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace, alpha); break; case kAxialShading: DrawAxialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace, alpha); break; case kRadialShading: DrawRadialShading(pBitmap, &FinalMatrix, pDict, pFuncs, nFuncs, pColorSpace, alpha); break; case kFreeFormGouraudTriangleMeshShading: { DrawFreeGouraudShading(pBitmap, &FinalMatrix, ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, pColorSpace, alpha); } break; case kLatticeFormGouraudTriangleMeshShading: { DrawLatticeGouraudShading(pBitmap, &FinalMatrix, ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, pColorSpace, alpha); } break; case kCoonsPatchMeshShading: case kTensorProductPatchMeshShading: { DrawCoonPatchMeshes( pPattern->m_ShadingType == kTensorProductPatchMeshShading, pBitmap, &FinalMatrix, ToStream(pPattern->m_pShadingObj), pFuncs, nFuncs, pColorSpace, fill_mode, alpha); } break; } if (bAlphaMode) { pBitmap->LoadChannel(FXDIB_Red, pBitmap, FXDIB_Alpha); } if (m_Options.m_ColorMode == RENDER_COLOR_GRAY) { pBitmap->ConvertColorScale(m_Options.m_ForeColor, m_Options.m_BackColor); } buffer.OutputToDevice(); }
std::string get_fluid_param_string(std::string FluidName, std::string ParamName) { try{ std::vector<std::string> comps(1,FluidName); shared_ptr<CoolProp::HelmholtzEOSMixtureBackend> HEOS(new CoolProp::HelmholtzEOSMixtureBackend(comps)); CoolProp::CoolPropFluid *fluid = HEOS->get_components()[0]; if (!ParamName.compare("aliases")) { return strjoin(fluid->aliases, ", "); } else if (!ParamName.compare("CAS") || !ParamName.compare("CAS_number")) { return fluid->CAS; } else if (!ParamName.compare("ASHRAE34")) { return fluid->environment.ASHRAE34; } else if (!ParamName.compare("REFPROPName") || !ParamName.compare("REFPROP_name") || !ParamName.compare("REFPROPname")) { return fluid->REFPROPname; } else if (ParamName.find("BibTeX") == 0) // Starts with "BibTeX" { std::vector<std::string> parts = strsplit(ParamName,'-'); // std::string item = parts[1]; if (item == "EOS"){ return fluid->pEOS->BibTeX_EOS; } else if (item == "CP0"){ return fluid->pEOS->BibTeX_CP0; } else if (item == "SURFACE_TENSION"){ return fluid->ancillaries.surface_tension.BibTeX; } else if (item == "MELTING_LINE"){ return fluid->ancillaries.melting_line.BibTeX; } else if (item == "VISCOSITY"){ return fluid->transport.BibTeX_viscosity; } else if (item == "CONDUCTIVITY"){ return fluid->transport.BibTeX_conductivity; } else{ return format("Could not match BibTeX item: %s", item.c_str()); } } else { return format("Input value [%s] is invalid for Fluid [%s]",ParamName.c_str(),FluidName.c_str()); } } catch(std::exception &e) { return(std::string("CoolProp error: ").append(e.what())); } catch(...){ return(std::string("CoolProp error: Indeterminate error")); } }
/*! * \brief Xyce::createNetlist * \param[out] stream QTextStream that associated with spice netlist file * \param[in] simulations The list of simulations that need to included in netlist. * \param[out] vars The list of output variables and node names. * \param[out] outputs The list of spice output raw text files. */ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, QStringList &vars, QStringList &outputs) { QString s; bool hasParSweep = false; if(!prepareSpiceNetlist(stream,true)) return; // Unable to perform spice simulation startNetlist(stream,true); // set variable names for named nodes and wires vars.clear(); for(Node *pn = Sch->DocNodes.first(); pn != 0; pn = Sch->DocNodes.next()) { if(pn->Label != 0) { if (!vars.contains(pn->Label->Name)) { vars.append(pn->Label->Name); } } } for(Wire *pw = Sch->DocWires.first(); pw != 0; pw = Sch->DocWires.next()) { if(pw->Label != 0) { if (!vars.contains(pw->Label->Name)) { vars.append(pw->Label->Name); } } } for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { if (pc->isProbe) { QString var_pr = pc->getProbeVariable(true); if (!vars.contains(var_pr)) { vars.append(var_pr); } } /*if (pc->isEquation) { Equation *eq = (Equation *)pc; QStringList vars_eq; eq->getDepVars(vars_eq); vars.append(vars_eq); }*/ } vars.sort(); qDebug()<<vars; //execute simulations QFileInfo inf(Sch->DocName); QString basenam = inf.baseName(); QString nod,nods; nods.clear(); foreach (nod,vars) { if (!nod.startsWith("I(")) { nods += QString("v(%1) ").arg(nod); } else { nods += nod + " "; } } QString sim = simulations.first(); for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { // Xyce can run if(pc->isSimulation) { // only one simulations per time. QString sim_typ = pc->Model; // Multiple simulations are forbidden. QString s = pc->getSpiceNetlist(true); if ((sim_typ==".AC")&&(sim=="ac")) stream<<s; if ((sim_typ==".TR")&&(sim=="tran")){ stream<<s; Q3PtrList<Component> comps(Sch->DocComps); // find Fourier tran for(Component *pc1 = comps.first(); pc1 != 0; pc1 = comps.next()) { if (pc1->Model==".FOURIER") { if (pc1->Props.at(0)->Value==pc->Name) { QString s1 = pc1->getSpiceNetlist(true); outputs.append("spice4qucs.tran.cir.four"); stream<<s1; } } } } if ((sim_typ==".HB")&&(sim=="hb")) stream<<s; if (sim_typ==".SW") { QString SwpSim = pc->Props.at(0)->Value; if (SwpSim.startsWith("DC")&&(sim=="dc")) stream<<s; else if (SwpSim.startsWith("AC")&&(sim=="ac")) { stream<<s; hasParSweep = true; } else if (SwpSim.startsWith("TR")&&(sim=="tran")) { stream<<s; hasParSweep = true; } if (SwpSim.startsWith("HB")&&(sim=="hb")) { stream<<s; hasParSweep = true; } } if ((sim_typ==".DC")) stream<<s; } } QString filename; if (hasParSweep) filename = QString("%1_%2_swp.txt").arg(basenam).arg(sim); else filename = QString("%1_%2.txt").arg(basenam).arg(sim); QString write_str; if (sim=="hb") { write_str = QString(".PRINT %1 file=%2 %3\n").arg(sim).arg(filename).arg(nods); } else { write_str = QString(".PRINT %1 format=raw file=%2 %3\n").arg(sim).arg(filename).arg(nods); } stream<<write_str; outputs.append(filename); stream<<".END\n"; }
bool isConnected(const Graph & g) { std::vector<int> comps(order(g)); long num = connected_components(g, &comps[0]); return num < 2; }
int main(int argc,char **argv) { #ifdef CH_MPI MPI_Init(&argc, &argv); #endif // registerDebugger(); // begin forever present scoping trick { pout()<<std::endl; Vector<std::string> names0(1, "phi"); Vector<int> refRatio(3,2); Vector<Real> coveredVal(1,3.0); const char* in_file = "sphere.inputs"; // read in an input file or use default file // if (argc > 1) // { // in_file = argv[1]; // } //parse input file ParmParse pp(0,NULL,NULL,in_file); RealVect center; Real radius; RealVect origin; RealVect dx; Box domain; ProblemDomain pDomain(domain); int eekflag = 0; LevelData<EBCellFAB> fine, med, coarse; LevelData<EBCellFAB> fineRHS, medRHS, coarseRHS; LevelData<EBCellFAB> fineResidual, mediumResidual, coarseResidual; Vector<LevelData<EBCellFAB>* > ebvector(3,NULL); Vector<LevelData<EBCellFAB>* > vresidual(3,NULL); Vector<LevelData<EBCellFAB>* > rhsvector(3,NULL); ebvector[0]=&coarse; ebvector[1]=&med; ebvector[2]=&fine; vresidual[0]=&coarseResidual; vresidual[1]=&mediumResidual; vresidual[2]=&fineResidual; rhsvector[0] = &coarseRHS; rhsvector[1] = &medRHS; rhsvector[2] = &fineRHS; readGeometryInfo(domain, dx, origin, center, radius); Box domainFine(domain), domainMedi, domainCoar; ProblemDomain pFine(domain); RealVect dxFine(dx), dxMedi, dxCoar; CH_assert(eekflag == 0); domainMedi = coarsen(domainFine, 2); domainCoar = coarsen(domainMedi, 2); dxMedi = 2.0*dxFine; dxCoar = 2.0*dxMedi; Vector<RealVect> xVec(3, IntVect::Unit); xVec[0]*= dxCoar; xVec[1]*= dxMedi; xVec[2]*= dxFine; Vector<DisjointBoxLayout> grids(3); ProblemDomain baseDomain(domainCoar); ProblemDomain pMed(domainMedi); Vector<ProblemDomain> pd(3); pd[0] = baseDomain; pd[1] = pMed; pd[2] = ProblemDomain(domainFine); RefCountedPtr<BaseBCValue>value(new DirichletBC()); DirichletPoissonDomainBC* domainBC = new DirichletPoissonDomainBC(); domainBC->setFunction(value); RefCountedPtr<BaseDomainBC> bc(domainBC); //make data holders Vector<int> comps(2,1); int steps= 5; int step = 0; while (step < steps) { eekflag = makeGeometry( domain, dx, origin, center, radius); //make grids //IntVectSet tags = mfIndexSpace->interfaceRegion(2); IntVectSet tags(domainCoar); tags.grow(1); makeHierarchy(grids, baseDomain, tags); const CH_XD::EBIndexSpace* ebisPtr = Chombo_EBIS::instance(); Vector<EBISLayout> layouts(3); EBISLayout& fineLayout = layouts[2]; ebisPtr->fillEBISLayout(fineLayout, grids[2], domainFine, 2); EBCellFactory fineFactory(fineLayout); ebvector[2]->define(grids[2], 1, IntVect::Unit, fineFactory); rhsvector[2]->define(grids[2], 1, IntVect::Zero, fineFactory); EBISLayout& medLayout = layouts[1]; ebisPtr->fillEBISLayout(medLayout, grids[1], domainMedi, 2); EBCellFactory medFactory(medLayout); ebvector[1]->define(grids[1], 1, IntVect::Unit, medFactory); rhsvector[1]->define(grids[1], 1, IntVect::Zero, medFactory); EBISLayout& coarseLayout = layouts[0]; ebisPtr->fillEBISLayout(coarseLayout, grids[0], domainCoar, 2); EBCellFactory coarseFactory(coarseLayout); ebvector[0]->define(grids[0], 1, IntVect::Unit, coarseFactory); rhsvector[0]->define(grids[0], 1, IntVect::Zero, coarseFactory); for (int lev=0; lev<3; lev++) { setValue(*rhsvector[lev], RHS(), pd[lev].domainBox(), xVec[lev], origin, true); } Vector<int> refRatio(3,2); int max_iter = 40; pp.get("max_iter", max_iter); Real eps = 1.e-6; pp.get("eps", eps); int relaxType; pp.get("relaxType",relaxType); DirichletPoissonDomainBCFactory* domDirBC = new DirichletPoissonDomainBCFactory(); domDirBC->setFunction(value); RefCountedPtr<BaseDomainBCFactory> domBC( domDirBC ); DirichletPoissonEBBCFactory* ebDirBC = new DirichletPoissonEBBCFactory(); ebDirBC->setFunction(value); RefCountedPtr<BaseEBBCFactory> ebBC( ebDirBC ); Vector<EBLevelGrid> eblgs(3); Vector<RefCountedPtr<EBQuadCFInterp> > quadCFI(3, RefCountedPtr<EBQuadCFInterp>()); for (int i=0; i<3; i++) { eblgs[i] = EBLevelGrid(grids[i], layouts[i], pd[i]); if (i > 0) { quadCFI[i] = RefCountedPtr<EBQuadCFInterp>( new EBQuadCFInterp(grids[i], grids[i-1], layouts[i], layouts[i-1], pd[i-1], refRatio[i-1], 1, *eblgs[i].getCFIVS())); } } EBAMRPoissonOpFactory opFact(eblgs, refRatio, quadCFI, xVec[0], RealVect::Zero, 4, relaxType, domBC, ebBC, 0.0, 1.0, 0.0, IntVect::Unit, IntVect::Zero); for (int i=0; i<3; i++) { LevelData<EBCellFAB> &phi=*ebvector[i], &rhs=*rhsvector[i], &residual=*vresidual[i]; LevelData<EBCellFAB> correction; DisjointBoxLayout dblMGCoar; EBISLayout ebislMGCoar; EBAMRPoissonOp* opPtr = opFact.AMRnewOp(pd[i]); EBAMRPoissonOp& op = *opPtr; RelaxSolver<LevelData<EBCellFAB> > solver; solver.define(&op, false); solver.m_imax = max_iter; solver.m_eps = eps; op.create(residual, rhs); op.create(correction, phi); op.setToZero(residual); op.setToZero(phi); op.residual(residual, phi, rhs); Real r2norm = op.norm(residual, 2); Real r0norm = op.norm(residual, 0); pout()<<indent<<"Residual L2 norm "<<r2norm<<"Residual max norm = " <<r0norm<<std::endl; solver.solve(phi, rhs); op.residual(residual, phi, rhs); r2norm = op.norm(residual, 2); r0norm = op.norm(residual, 0); pout()<<indent2<<"Residual L2 norm "<<r2norm<<" Residual max norm = " <<r0norm<<std::endl; delete opPtr; } #ifdef CH_USE_HDF5 sprintf(iter_str, "residual.%03d.%dd.hdf5",step, SpaceDim); Vector<std::string> names(1); names[0]="residual"; writeEBHDF5(iter_str, grids, vresidual, names, domainCoar, dxCoar[0], 1, step, refRatio, 3, true, coveredVal); sprintf(iter_str, "phi.%03d.%dd.hdf5",step, SpaceDim); names[0]="phi"; writeEBHDF5(iter_str, grids, ebvector ,names, domainCoar, dxCoar[0], 1, step, refRatio, 3, true, coveredVal); #endif step++; center[0]-= dx[0]/3.0; center[1]-= dx[1]/2.0; radius += dx[0]/6.0; Chombo_EBIS::instance()->clear(); pout()<<step<<std::endl; } pout() <<"\n "<<indent2<<pgmname<<" test passed " << endl; } // end scoping trick #ifdef CH_MPI MPI_Finalize(); #endif return 0; }
void CMessage::drawIWindow(CInfoWindow * ret, std::string text, PlayerColor player) { bool blitOr = false; if(dynamic_cast<CSelWindow*>(ret)) //it's selection window, so we'll blit "or" between components blitOr = true; const int sizes[][2] = {{400, 125}, {500, 150}, {600, 200}, {480, 400}}; for(int i = 0; i < ARRAY_COUNT(sizes) && sizes[i][0] < screen->w - 150 && sizes[i][1] < screen->h - 150 && ret->text->slider; i++) { ret->text->resize(Point(sizes[i][0], sizes[i][1])); } if(ret->text->slider) { ret->text->slider->addUsedEvents(CIntObject::WHEEL | CIntObject::KEYBOARD); } else { ret->text->resize(ret->text->label->textSize + Point(10, 10)); } std::pair<int,int> winSize(ret->text->pos.w, ret->text->pos.h); //start with text size ComponentsToBlit comps(ret->components,500, blitOr); if (ret->components.size()) winSize.second += 10 + comps.h; //space to first component int bw = 0; if (ret->buttons.size()) { // Compute total width of buttons bw = 20*(ret->buttons.size()-1); // space between all buttons for(auto & elem : ret->buttons) //and add buttons width bw+=elem->pos.w; winSize.second += 20 + //before button ok->ourImages[0].bitmap->h; //button } // Clip window size vstd::amax(winSize.second, 50); vstd::amax(winSize.first, 80); vstd::amax(winSize.first, comps.w); vstd::amax(winSize.first, bw); vstd::amin(winSize.first, screen->w - 150); ret->bitmap = drawDialogBox (winSize.first + 2*SIDE_MARGIN, winSize.second + 2*SIDE_MARGIN, player); ret->pos.h=ret->bitmap->h; ret->pos.w=ret->bitmap->w; ret->center(); int curh = SIDE_MARGIN; int xOffset = (ret->pos.w - ret->text->pos.w)/2; if(!ret->buttons.size() && !ret->components.size()) //improvement for very small text only popups -> center text vertically { if(ret->bitmap->h > ret->text->pos.h + 2*SIDE_MARGIN) curh = (ret->bitmap->h - ret->text->pos.h)/2; } ret->text->moveBy(Point(xOffset, curh)); curh += ret->text->pos.h; if (ret->components.size()) { curh += BEFORE_COMPONENTS; comps.blitCompsOnSur (blitOr, BETWEEN_COMPS, curh, ret->bitmap); } if(ret->buttons.size()) { // Position the buttons at the bottom of the window bw = (ret->bitmap->w/2) - (bw/2); curh = ret->bitmap->h - SIDE_MARGIN - ret->buttons[0]->pos.h; for(auto & elem : ret->buttons) { elem->moveBy(Point(bw, curh)); bw += elem->pos.w + 20; } } for(size_t i=0; i<ret->components.size(); i++) ret->components[i]->moveBy(Point(ret->pos.x, ret->pos.y)); }