void minimum_area_enclosing_rectangle( const Polygon2d& PP, vec2& S, vec2& T ) { // Note: this implementation has O(n2) complexity :-( // (where n is the number of vertices in the convex hull) // If this appears to be a bottleneck, use a smarter // implementation with better complexity. Polygon2d P ; convex_hull(PP, P) ; int N = P.size() ; // Add the first vertex at the end of P P.push_back(P[0]) ; double min_area = Numeric::big_double ; for(int i=1; i<=N; i++) { vec2 Si = P[i] - P[i-1] ; if( ( Si.length2() ) < 1e-20) { continue ; } vec2 Ti(-Si.y, Si.x) ; normalize(Si) ; normalize(Ti) ; double s0 = Numeric::big_double ; double s1 = -Numeric::big_double ; double t0 = Numeric::big_double ; double t1 = -Numeric::big_double ; for(int j=1; j<N; j++) { vec2 D = P[j] - P[0] ; double s = dot(Si, D) ; s0 = gx_min(s0, s) ; s1 = gx_max(s1, s) ; double t = dot(Ti, D) ; t0 = gx_min(t0, t) ; t1 = gx_max(t1, t) ; } double area = (s1 - s0) * (t1 - t0) ; if(area < min_area) { min_area = area ; if((s1 - s0) < (t1 - t0)) { S = Si ; T = Ti ; } else { S = Ti ; T = Si ; } } } }
__device__ Ti load2ShrdMem(const Ti * in, int dim0, int dim1, int gx, int gy, int inStride1, int inStride0) { if (gx<0 || gx>=dim0 || gy<0 || gy>=dim1) return Ti(0); else return in[gx*inStride0+gy*inStride1]; }
void EdgeSE3Expmap::linearizeOplus() { VertexSE3Expmap * vi = static_cast<VertexSE3Expmap *>(_vertices[0]); SE3Quat Ti(vi->estimate()); VertexSE3Expmap * vj = static_cast<VertexSE3Expmap *>(_vertices[1]); SE3Quat Tj(vj->estimate()); const SE3Quat & Tij = _measurement; SE3Quat invTij = Tij.inverse(); SE3Quat invTj_Tij = Tj.inverse()*Tij; SE3Quat infTi_invTij = Ti.inverse()*invTij; _jacobianOplusXi = invTj_Tij.adj(); _jacobianOplusXj = -infTi_invTij.adj(); }
static kernel::se3 mcmc(const KernelCollection& objectEvidence, const KernelCollection& sceneEvidence, const coord_t objectSize, const int n) { kernel::se3 current, best; weight_t currentWeight = 0; best.setWeight(currentWeight); metropolisHastings(objectEvidence, sceneEvidence, current, currentWeight, 1, true, n); const int nSteps = 10*n; for (int i = 0; i < nSteps; i++) { { // begin and end bandwidths for the local proposal coord_t bLocH = objectSize/10; coord_t eLocH = objectSize/40; coord_t bOriH = .1; coord_t eOriH = .02; unsigned e = nSteps-1; current.setLocH(double(e-i)/e * bLocH + double(i)/e * eLocH); current.setOriH(double(e-i)/e * bOriH + double(i)/e * eOriH); if (current.loc_h_ <= 0) NUKLEI_THROW("Unexpected value for curent.loc_h_"); } metropolisHastings(objectEvidence, sceneEvidence, current, currentWeight, Ti(i, nSteps/5), false, n); if (currentWeight > best.getWeight()) { best = current; best.setWeight(currentWeight); } } return best; }
void thermalBaffle1DFvPatchScalarField<solidType>::updateCoeffs() { if (updated()) { return; } // Since we're inside initEvaluate/evaluate there might be processor // comms underway. Change the tag we use. int oldTag = UPstream::msgType(); UPstream::msgType() = oldTag+1; const mappedPatchBase& mpp = refCast<const mappedPatchBase>(patch().patch()); const label patchi = patch().index(); const label nbrPatchi = mpp.samplePolyPatch().index(); if (baffleActivated_) { const fvPatch& nbrPatch = patch().boundaryMesh()[nbrPatchi]; const compressible::turbulenceModel& turbModel = db().template lookupObject<compressible::turbulenceModel> ( "turbulenceModel" ); // local properties const scalarField kappaw(turbModel.kappaEff(patchi)); const fvPatchScalarField& Tp = patch().template lookupPatchField<volScalarField, scalar>(TName_); const scalarField qDot(kappaw*Tp.snGrad()); tmp<scalarField> Ti = patchInternalField(); scalarField myh(patch().deltaCoeffs()*kappaw); // nbr properties const scalarField nbrKappaw(turbModel.kappaEff(nbrPatchi)); const fvPatchScalarField& nbrTw = turbModel.thermo().T().boundaryField()[nbrPatchi]; scalarField nbrQDot(nbrKappaw*nbrTw.snGrad()); mpp.map().distribute(nbrQDot); const thermalBaffle1DFvPatchScalarField& nbrField = refCast<const thermalBaffle1DFvPatchScalarField> ( nbrPatch.template lookupPatchField<volScalarField, scalar>(TName_) ); scalarField nbrTi(nbrField.patchInternalField()); mpp.map().distribute(nbrTi); scalarField nbrTp = nbrPatch.template lookupPatchField<volScalarField, scalar>(TName_); mpp.map().distribute(nbrTp); scalarField nbrh(nbrPatch.deltaCoeffs()*nbrKappaw); mpp.map().distribute(nbrh); // heat source const scalarField Q(Qs_/thickness_); tmp<scalarField> tKDeltaw(new scalarField(patch().size())); scalarField KDeltaw = tKDeltaw(); // Create fields for solid properties (p paramater not used) forAll(KDeltaw, i) { KDeltaw[i] = solidPtr_().kappa(0.0, (Tp[i] + nbrTw[i])/2.0)/thickness_[i]; } const scalarField q ( (Ti() - nbrTi)/(1.0/KDeltaw + 1.0/nbrh + 1.0/myh) ); forAll(qDot, i) { if (Qs_[i] == 0) { this->refValue()[i] = Ti()[i] - q[i]/myh[i]; this->refGrad()[i] = 0.0; this->valueFraction()[i] = 1.0; } else { if (q[i] > 0) { this->refValue()[i] = nbrTp[i] - Q[i]*thickness_[i]/(2*KDeltaw[i]); this->refGrad()[i] = 0.0; this->valueFraction()[i] = 1.0 / ( 1.0 + patch().deltaCoeffs()[i]*kappaw[i]/KDeltaw[i] ); } else if (q[i] < 0) { this->refValue()[i] = 0.0; this->refGrad()[i] = (-nbrQDot[i] + Q[i]*thickness_[i])/kappaw[i]; this->valueFraction()[i] = 0.0; } else { scalar Qt = Q[i]*thickness_[i]; this->refValue()[i] = 0.0; this->refGrad()[i] = Qt/2/kappaw[i]; this->valueFraction()[i] = 0.0; } } } if (debug) { scalar Q = gSum(patch().magSf()*qDot); Info<< patch().boundaryMesh().mesh().name() << ':' << patch().name() << ':' << this->dimensionedInternalField().name() << " <- " << nbrPatch.name() << ':' << this->dimensionedInternalField().name() << " :" << " heat[W]:" << Q << " walltemperature " << " min:" << gMin(*this) << " max:" << gMax(*this) << " avg:" << gAverage(*this) << endl; } }
void foo (int i, int j) { typedef int I; int (*pf)[2]; int (*pv)[i]; int (*pi)[]; I (*pfI)[2]; I (*pvI)[i]; I (*piI)[]; TEST_COMP_FIX(pf, pf); TEST_COMP_FIX(pf, pv); TEST_COMP_FIX(pf, pi); TEST_COMP_FIX(pf, pfI); TEST_COMP_FIX(pf, pvI); TEST_COMP_FIX(pf, piI); TEST_COMP_FIX(pv, pf); TEST_COMP_VLA(pv, pv); TEST_COMP_VLA(pv, pi); TEST_COMP_FIX(pv, pfI); TEST_COMP_VLA(pv, pvI); TEST_COMP_VLA(pv, piI); TEST_COMP_FIX(pi, pf); TEST_COMP_VLA(pi, pv); TEST_COMP_INC(pi, pi); TEST_COMP_FIX(pi, pfI); TEST_COMP_VLA(pi, pvI); TEST_COMP_INC(pi, piI); TEST_COMP_FIX(pfI, pf); TEST_COMP_FIX(pfI, pv); TEST_COMP_FIX(pfI, pi); TEST_COMP_FIX(pfI, pfI); TEST_COMP_FIX(pfI, pvI); TEST_COMP_FIX(pfI, piI); TEST_COMP_FIX(pvI, pf); TEST_COMP_VLA(pvI, pv); TEST_COMP_VLA(pvI, pi); TEST_COMP_FIX(pvI, pfI); TEST_COMP_VLA(pvI, pvI); TEST_COMP_VLA(pvI, piI); TEST_COMP_FIX(piI, pf); TEST_COMP_VLA(piI, pv); TEST_COMP_INC(piI, pi); TEST_COMP_FIX(piI, pfI); TEST_COMP_VLA(piI, pvI); TEST_COMP_INC(piI, piI); typedef int (*Ti)[i]; typedef int (*Tj)[j]; Ti (*qf)[2]; Ti (*qv)[i]; Ti (*qi)[]; Tj (*rf)[2]; Tj (*rv)[j]; Tj (*ri)[]; TEST_COMP_FIX(qf, qf); TEST_COMP_FIX(qf, qv); TEST_COMP_FIX(qf, qi); TEST_COMP_FIX(qf, rf); TEST_COMP_FIX(qf, rv); TEST_COMP_FIX(qf, ri); TEST_COMP_FIX(qv, qf); TEST_COMP_VLA(qv, qv); TEST_COMP_VLA(qv, qi); TEST_COMP_FIX(qv, rf); TEST_COMP_VLA(qv, rv); TEST_COMP_VLA(qv, ri); TEST_COMP_FIX(qi, qf); TEST_COMP_VLA(qi, qv); TEST_COMP_INC(qi, qi); TEST_COMP_FIX(qi, rf); TEST_COMP_VLA(qi, rv); TEST_COMP_INC(qi, ri); TEST_COMP_FIX(rf, qf); TEST_COMP_FIX(rf, qv); TEST_COMP_FIX(rf, qi); TEST_COMP_FIX(rf, rf); TEST_COMP_FIX(rf, rv); TEST_COMP_FIX(rf, ri); TEST_COMP_FIX(rv, qf); TEST_COMP_VLA(rv, qv); TEST_COMP_VLA(rv, qi); TEST_COMP_FIX(rv, rf); TEST_COMP_VLA(rv, rv); TEST_COMP_VLA(rv, ri); TEST_COMP_FIX(ri, qf); TEST_COMP_VLA(ri, qv); TEST_COMP_INC(ri, qi); TEST_COMP_FIX(ri, rf); TEST_COMP_VLA(ri, rv); TEST_COMP_INC(ri, ri); }
Bool_t TZigZag::PointsNear(Double_t x, Double_t y, Double_t &yi, TArrayD &Tn, TArrayD &Yn) const { // Two-dimensional case. Finds in I,T,X,Y the 4 points of the grid around point (x,y). //Then finds the 2 closest points along the zigzag in In,Tn,Xn,Yn. // If point (x,y) not inside [fXmin,fXmax] and [fYmin,fYmax], make a projection //towards center and stops at point just after entry and gives the 4 points for it. const Double_t un = 1.0; const Double_t aeps = 1.0e-6; TArrayI Ii(4); TArrayD Ti(4); TArrayD Xi(4); TArrayD Yi(4); Bool_t ok; Int_t i; Int_t kx=0; Int_t ky=0; Double_t mx,my,eps; Double_t xc,xl,xr,dx,dxs2; Double_t yc,yl,yr,dy,dys2; Double_t xi,xp,yp; Double_t xle,xre,yle,yre; Tn.Set(2); Yn.Set(2); dx = (fXmax-fXmin)/fNx; dxs2 = dx/2; dy = (fYmax-fYmin)/fNy; dys2 = dy/2; xl = dxs2; xr = dxs2 + (fNx-1)*dx; yl = dys2; yr = dys2 + (fNy-1)*dy; if ((yr-yl) > (xr-xl)) eps = aeps*(yr-yl); else eps = aeps*(xr-xl); xle = xl + eps; xre = xr - eps; yle = yl + eps; yre = yr - eps; if ((x>=xle) && (x<=xre) && (y>=yle) && (y<=yre)) { xi = x; yi = y; kx = Int_t((xi-dxs2)/dx) + 1; ky = Int_t((yi-dys2)/dy) + 1; ok = kTRUE; }//end if ((x>xl) && (x<xr) && (y>yl) && (y<yr)) else { xc = (fXmax-fXmin)/2; yc = (fYmax-fYmin)/2; mx = (y-yc)/(x-xc); my = un/mx; xi = xle; yi = yc + mx*(xi-xc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); if (!ok) { xi = xre; yi = yc + mx*(xi-xc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); if (!ok) { yi = yle; xi = xc + my*(yi-yc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); if (!ok) { yi = yre; xi = xc + my*(yi-yc); ok = IsInside(xi,yi,x,y,xc,yc,xl,xr,yl,yr); }//end if (!ok) }//end if (!ok) }//end if (!ok) if (ok) { kx = Int_t((xi-dxs2)/dx) + 1; ky = Int_t((yi-dys2)/dy) + 1; } else { cout << "TZigZag::PointsNear : ERROR point inside not found" << endl; } }//end else if ((x>xl) && (x<xr) && (y>yl) && (y<yr)) if (ok) { //Point kx,ky xp = dxs2 + (kx-1)*dx; yp = dys2 + (ky-1)*dy; i = NToZZ(kx,ky); Ii[0] = i; Ti[0] = T(i); Xi[0] = xp; Yi[0] = yp; //Point kx+1,ky xp = dxs2 + kx*dx; yp = dys2 + (ky-1)*dy; i = NToZZ(kx+1,ky); Ii[1] = i; Ti[1] = T(i); Xi[1] = xp; Yi[1] = yp; //Point kx,ky+1 xp = dxs2 + (kx-1)*dx; yp = dys2 + ky*dy; i = NToZZ(kx,ky+1); Ii[2] = i; Ti[2] = T(i); Xi[2] = xp; Yi[2] = yp; //Point kx+1,ky+1 xp = dxs2 + kx*dx; yp = dys2 + ky*dy; i = NToZZ(kx+1,ky+1); Ii[3] = i; Ti[3] = T(i); Xi[3] = xp; Yi[3] = yp; //Finding the 2 points along the zigzag Order(4,Ii,Ti,Xi,Yi); Yn[0] = Yi[0]; Tn[0] = Ti[0] + ((Ti[1] - Ti[0])/(Xi[1] -Xi[0]))*(xi - Xi[0]); Yn[1] = Yi[2]; Tn[1] = Ti[2] + ((Ti[3] - Ti[2])/(Xi[3] -Xi[2]))*(xi - Xi[2]); } return ok; }