void Tri::genFile (Curve *cur, double *x, double *y){ register int i; Geometry *g; Point p1, p2, a; double *z, *w, *eta, xoff, yoff; int fac; fac = cur->face; p1.x = vert[vnum(fac,0)].x; p1.y = vert[vnum(fac,0)].y; p2.x = vert[vnum(fac,1)].x; p2.y = vert[vnum(fac,1)].y; getzw(qa,&z,&w,'a'); eta = dvector (0, qa); if ((g = lookupGeom (cur->info.file.name)) == (Geometry *) NULL) g = loadGeom (cur->info.file.name); /* If the current edge has an offset, apply it now */ xoff = cur->info.file.xoffset; yoff = cur->info.file.yoffset; if (xoff != 0.0 || yoff != 0.0) { dsadd (g->npts, xoff, g->x, 1, g->x, 1); dsadd (g->npts, yoff, g->y, 1, g->y, 1); if (option("verbose") > 1) printf ("shifting current geometry by (%g,%g)\n", xoff, yoff); } /* get the end points which are assumed to lie on the curve */ /* set up search direction in normal to element point -- This assumes that vertices already lie on spline */ a.x = p1.x - (p2.y - p1.y); a.y = p1.y + (p2.x - p1.x); eta[0] = searchGeom (a, p1, g); a.x = p2.x - (p2.y - p1.y); a.y = p2.y + (p2.x - p1.x); eta[qa-1] = searchGeom (a, p2, g); /* Now generate the points where we'll evaluate the geometry */ for (i = 1; i < qa-1; i++) eta [i] = eta[0] + 0.5 * (eta[qa-1] - eta[0]) * (z[i] + 1.); for (i = 0; i < qa; i++) { x[i] = splint (g->npts, eta[i], g->arclen, g->x, g->sx); y[i] = splint (g->npts, eta[i], g->arclen, g->y, g->sy); } g->pos = 0; /* reset the geometry */ if (xoff != 0.) dvsub (g->npts, g->x, 1, &xoff, 0, g->x, 1); if (yoff != 0.) dvsub (g->npts, g->y, 1, &yoff, 0, g->y, 1); free (eta); /* free the workspace */ return; }
void Element::EdgeJbwd(double *d, int edg){ Basis *b = getbasis(); int va = vnum(edg,0); int vb = vnum(edg,1), i; dsmul(qa, vert[va].hj[0], b->vert[0].a, 1, d, 1); daxpy(qa, vert[vb].hj[0], b->vert[1].a, 1, d, 1); for(i = 0; i < edge[edg].l;++i) daxpy(qa, edge[edg].hj[i], b->edge[0][i].a, 1, d, 1); }
int main() { //int num[] = {10,1,2,7,6,1,5}; int num[] = {}; vector<int> vnum(num, num+sizeof(num)/4); vvi res = Solution().combinationSum2(vnum, 8); printVV(res); }
//--------------------------------------------------------- void NDG3D::Hrefine3D(IVec& refineflag) //--------------------------------------------------------- { DVec lVX("lVX"), lVY("lVY"), lVZ("lVZ"); int a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10; // a b c d e f g h i j lVX.load(10, " 0 1 0 0 0.5 0.5 0.0 0.0 0.5 0.0 "); lVY.load(10, " 0 0 1 0 0.0 0.5 0.5 0.0 0.0 0.5 "); lVZ.load(10, " 0 0 0 1 0.0 0.0 0.0 0.5 0.5 0.5 "); assert(4 == Nfaces); IMat lEToV(8,4, "lEToV"), im84(8,4, "im84"), oFnodes(4,6, "oFnodes"); set84(lEToV, 8,4, a, e, g, h, e, b, f, i, g, f, c, j, h, i, j, d, e, g, h, i, h, i, g, j, e, f, g, i, g, i, f, j); set46(oFnodes, 4,6, a, e, b, f, c, g, a, e, b, i, d, h, b, f, c, j, d, i, a, g, c, j, d, h); IMat vnum(gRowData, 4,3, "1 2 3 1 2 4 2 3 4 3 1 4"); int lK = lEToV.num_rows(); IMat lBCType(lK, Nfaces), tm1, tm2; IVec tv(3),tv1,tv2, oFn,vnp,ksids; int kk=0,ff=0,oo=0; for (kk=1; kk<=lK; ++kk) { for (ff=1; ff<=Nfaces; ++ff) { for (oo=1; oo<=Nfaces; ++oo) { oFn = oFnodes.get_row(oo); vnp = vnum.get_row(ff); tm1 = lEToV(kk, vnp); const IVec& knodes = dynamic_cast<const IVec&>(tm1); //tv = intersect(lEToV(k, vnum(p,All)), oFnodes(o,All)); tv = intersect(knodes, oFn); if ( tv.length()==3 ) { lBCType(kk, ff) = oo; } } } } int NV = VX.length()+1; int sp_len = NV + NV*NV; // sparse buffers nnz vals,triplet CSd newVX(sp_len,1, NV, 1, 1); CSd newVY(sp_len,1, NV, 1, 1); CSd newVZ(sp_len,1, NV, 1, 1); Index1D II(1, NV-1); newVX(II,1) = VX; newVY(II,1) = VY; newVZ(II,1) = VZ; IVec ids("ids"); int oldK = K, f1=0; for (int k1=1; k1<=oldK; ++k1) { if (refineflag(k1)) { a = EToV(k1,1); b = EToV(k1,2); c = EToV(k1,3); d = EToV(k1,4); e = NV + std::max(a*NV+b, b*NV + a); f = NV + std::max(b*NV+c, c*NV + b); g = NV + std::max(a*NV+c, c*NV + a); h = NV + std::max(a*NV+d, d*NV + a); i = NV + std::max(b*NV+d, d*NV + b); j = NV + std::max(c*NV+d, d*NV + c); //ks = [k1, K+1:K+7]; IVec ks(1, k1); ks.append(Range(K+1,K+7)); //-------------------------- // EToV(ks,:) = [a e g h; // e b f i; // g f c j; // h i j d; // e g h i; // h i g j; // e f g i; // g i f j]; //-------------------------- set84(im84, 8,4, a, e, g, h, e, b, f, i, g, f, c, j, h, i, j, d, e, g, h, i, h, i, g, j, e, f, g, i, g, i, f, j); //EToV(ks,All) = im84; EToV.merge_rows(ks, im84); for (f1=1; f1<=Nfaces; ++f1) { tv = lBCType(All,f1); ids = find(tv, '!', 0); ksids = ks(ids); tm1 = lBCType(ids,f1); tm2 = BCType(k1, (const IVec&)tm1); // expand BCType to accommodate new range int maxI=ksids.max_val(), maxR=BCType.num_rows(); if (maxI>maxR) {BCType.realloc(maxI, BCType.num_cols());} BCType(ksids,f1) = trans(tm2); } K += 7; newVX.set1(e,1, 0.5*(VX(a)+VX(b))); newVX.set1(f,1, 0.5*(VX(b)+VX(c))); newVX.set1(g,1, 0.5*(VX(c)+VX(a))); newVX.set1(h,1, 0.5*(VX(a)+VX(d))); newVX.set1(i,1, 0.5*(VX(b)+VX(d))); newVX.set1(j,1, 0.5*(VX(c)+VX(d))); newVY.set1(e,1, 0.5*(VY(a)+VY(b))); newVY.set1(f,1, 0.5*(VY(b)+VY(c))); newVY.set1(g,1, 0.5*(VY(c)+VY(a))); newVY.set1(h,1, 0.5*(VY(a)+VY(d))); newVY.set1(i,1, 0.5*(VY(b)+VY(d))); newVY.set1(j,1, 0.5*(VY(c)+VY(d))); newVZ.set1(e,1, 0.5*(VZ(a)+VZ(b))); newVZ.set1(f,1, 0.5*(VZ(b)+VZ(c))); newVZ.set1(g,1, 0.5*(VZ(c)+VZ(a))); newVZ.set1(h,1, 0.5*(VZ(a)+VZ(d))); newVZ.set1(i,1, 0.5*(VZ(b)+VZ(d))); newVZ.set1(j,1, 0.5*(VZ(c)+VZ(d))); } } //------------------------------------- // drop duplicates and sort //------------------------------------- newVX.compress(true); newVY.compress(true); newVZ.compress(true); //ids = sort(unique(EToV(:)), 'ascend'); ids = unique(EToV); int len=ids.max_val(); IVec gnum(len); gnum(ids) = Range(1,ids.length()); VX = full( newVX, ids ); VY = full( newVY, ids ); VZ = full( newVZ, ids ); // EToV = gnum(EToV); EToV.set_map(EToV, gnum); int NV_old = NV-1; // local counters this->Nv = VX.length(); // update member variable umLOG(1, "Hrefine3D [%d] : old Nv = %4d, new Nv = %4d\n", ++refine_count, NV_old, Nv); umLOG(1, " old K = %4d, new K = %4d\n\n", oldK, K); #if (0) tetramesh(EToV, [VX', VY', VZ']) #endif }