def __init__(self, control=None, fields=None, weights=None): if control is not None: shape = control.shape degree = shape[:-1] knots = [] for p in degree: u = [-1.0] * p + [1.0] * p knots.append(u) NURBS.__init__(self, knots, control)
def __init__(self, control=None, fields=None, weights=None): if control is not None: shape = control.shape degree = shape[:-1] knots = [] for p in degree: u = [-1.] * p + [1.] * p knots.append(u) NURBS.__init__(self, knots, control)
def test_srf_ki(PLOT=0): p = 2 q = 1 U = np.asarray([0,0,0, 1,1,1], dtype=float) V = np.asarray([0,0, 1,1], dtype=float) n = len(U)-1-(p+1) m = len(V)-1-(q+1) Pw = np.zeros((n+1,m+1,4)) Pw[0,0,:] = [0.0, 0.5, 0.0, 1.0] Pw[1,0,:] = [0.5, 0.5, 0.0, 1.0] Pw[2,0,:] = [0.5, 0.0, 0.0, 1.0] Pw[0,1,:] = [0.0, 1.0, 0.0, 1.0] Pw[1,1,:] = [1.0, 1.0, 0.0, 1.0] Pw[2,1,:] = [1.0, 0.0, 0.0, 1.0] Pw[1,:,:] *= np.sqrt(2)/2 nurbs = NURBS([U,V],Pw) X = np.asarray([]) Y = np.asarray([]) nrb = nurbs.copy().refine(0,X).refine(1,Y) (Ubar, Vbar), Qw = nrb.knots, nrb.control assert np.allclose(U, Ubar) assert np.allclose(V, Vbar) assert np.allclose(Pw, Qw) X = np.asarray([.25, 0.5])#;X = np.asarray([]) Y = np.asarray([0.5, .75])#;Y = np.asarray([]) nrb = nurbs.refine(0,X).refine(1,Y) (Ubar, Vbar), Qw = nrb.knots, nrb.control u = np.linspace(Ubar[0], Ubar[-1], 31) v = np.linspace(Vbar[0], Vbar[-1], 10) Cw = bsp.Evaluate2(p,Ubar,q,Vbar,Qw,u,v) Q = Qw[:,:,:2] / Qw[:,:,3,None] C = Cw[:,:,:2] / Cw[:,:,3,None] if not PLOT: return plt.figure() plt.title("Surface - Knot Insertion") x = Q[:,:,0] y = Q[:,:,1] plt.plot(x,y,'sr') x = C[:,:,0] y = C[:,:,1] plt.plot(x,y,'.b') t = np.linspace(0,np.pi/2,100) a = np.cos(t) b = np.sin(t) plt.plot(1.0*a,1.0*b,'-k') plt.plot(0.5*a,0.5*b,'-k') plt.axis("equal")
def VolumifyInterior(nrb): """ Creates volumes from closed surfaces. Given a tube-like, closed surface, return a nurbs volume of the interior. Actually returns 5 volumes, one of the core and 4 which connect the core to the outer hull. Assumes that the circumferential direction is 1st direction ..note: Lisandro, for now I am just making this work for the pipe example, but several things will need to be made more general. """ assert nrb.dim == 2 """ Step 1: extract 4 C0 surfaces from the single input surface. I propose that we simple insert knots to extract at [0.25,0.5,0.75]*U[-1]. Note that in this case, these knots are already inserted and so I skip this part. """ """ Step 2: locate the control point id's which corresponds to the C0 lines we just inserted. Create a trilinear solid which will form the core of the returned volume. Degree elevate to make equal to the 1st dim of the input surface. """ fct = 0.75 c0 = 0; c1 = 2; c2 = 4; c3 = 6; c4 = 8 C = np.zeros((2,2,nrb.shape[1],4)) C[0,0,:,:] = fct*nrb.control[c0,:,:] + (1.0-fct)*nrb.control[c2,:,:] C[1,1,:,:] = (1.0-fct)*nrb.control[c0,:,:] + fct*nrb.control[c2,:,:] C[1,0,:,:] = fct*nrb.control[c1,:,:] + (1.0-fct)*nrb.control[c3,:,:] C[0,1,:,:] = (1.0-fct)*nrb.control[c1,:,:] + fct*nrb.control[c3,:,:] core = NURBS(C,[[0,0,1,1],[0,0,1,1],nrb.knots[1]]) t=max(0,nrb.degree[0]-core.degree[0]) core.elevate(t,t,0) """ Step 3: create 4 volumes around the core. """ D1 = np.zeros((3,2,nrb.shape[1],4)) D1[:,0,:,:] = core.control[:,0,:,:] D1[:,1,:,:] = nrb.control[c0:c1+1,:,:] v1 = NURBS(D1,[[0,0,0,1,1,1],[0,0,1,1],nrb.knots[1]]) D2 = np.zeros((3,2,nrb.shape[1],4)) D2[:,0,:,:] = core.control[2,:,:,:] D2[:,1,:,:] = nrb.control[c1:c2+1,:,:] v2 = NURBS(D2,[[0,0,0,1,1,1],[0,0,1,1],nrb.knots[1]]) D3 = np.zeros((3,2,nrb.shape[1],4)) D3[:,0,:,:] = core.control[:,2,:,:] D3[:,1,:,:] = CntRev(nrb.control[c2:c3+1,:,:],0) v3 = NURBS(D3,[[0,0,0,1,1,1],[0,0,1,1],nrb.knots[1]]) D4 = np.zeros((3,2,nrb.shape[1],4)) D4[:,0,:,:] = core.control[0,:,:,:] D4[:,1,:,:] = CntRev(nrb.control[c3:c4+1,:,:],0) v4 = NURBS(D4,[[0,0,0,1,1,1],[0,0,1,1],nrb.knots[1]]) return core,v1,v2,v3,v4
def sweep(section, trajectory): """ Construct the translational sweep of a section curve/surface along a trajectory curve. S(u,v) = C(u) + T(v) V(u,v,w) = S(u,v) + T(w) Parameters ---------- section : NURBS Section curve/surface trajectory : NURBS Trajectory curve """ assert 1 <= section.dim <= 2 assert trajectory.dim == 1 Cs, ws = section.points, section.weights Ct, wt = trajectory.points, trajectory.weights C = Cs[..., np.newaxis, :] + Ct w = ws[..., np.newaxis] * wt UVW = section.knots + trajectory.knots return NURBS(UVW, (C, w))
def extrude(nrb, displ, axis=None): """ Construct a NURBS surface/volume by extruding a NURBS curve/surface. Parameters ---------- nrb : NURBS displ : array_like or float axis : array_like or int, optional Example ------- >>> crv = circle() >>> srf = extrude(crv, displ=1, axis=2) >>> srf = bilinear() >>> vol = extrude(srf, displ=1, axis=2) """ assert nrb.dim <= 2 T = transform().translate(displ, axis) Cw = np.empty(nrb.shape + (2, 4)) Cw[..., 0, :] = nrb.control Cw[..., 1, :] = T(nrb.control) UVW = nrb.knots + ([0, 0, 1, 1], ) return NURBS(UVW, Cw)
def trilinear(points=None): """ p[0,1,1] p[1,1,1] o------------o /| /| / | / | w o------------o | ^ v | p[0,0,1] | p[1,0,1] | / | | | | |/ | o-------- | -o +----> u | / p[0,1,0] | / p[1,1,0] |/ |/ o------------o p[0,0,0] p[1,0,0] """ if points is None: s = slice(-0.5, +0.5, 2j) x, y, z = np.ogrid[s, s, s] points = np.zeros((2, 2, 2, 3), dtype='d') points[..., 0] = x points[..., 1] = y points[..., 2] = z else: points = np.array(points, dtype='d') assert points.shape[:-1] == (2, 2, 2) knots = [0, 0, 1, 1] return NURBS([knots] * 3, points)
def __init__( self, patch, backend="matplotlib" ): # backend can be 'mayavi' or 'matplotlib' or "null" or "none" self.backend = backend plt.use(self.backend) if patch.WorkingSpaceDimension() == 2: U = patch.FESpace().KnotU V = patch.FESpace().KnotV C = patch.GridFunction(CONTROL_POINT).ControlGrid.ControlValues self.nurbs = NURBS([V, U], C) elif patch.WorkingSpaceDimension() == 3: U = patch.FESpace().KnotU V = patch.FESpace().KnotV W = patch.FESpace().KnotW C = patch.GridFunction(CONTROL_POINT).ControlGrid.ControlValues self.nurbs = NURBS([W, V, U], C)
def line(p0=(0, 0), p1=(1, 0)): """ p0 p1 o-----------o +--> u """ p0 = np.asarray(p0, dtype='d') p1 = np.asarray(p1, dtype='d') points = np.zeros((2, 3), dtype='d') points[0, :p0.size] = p0 points[1, :p1.size] = p1 knots = [0, 0, 1, 1] return NURBS([knots], points)
def make_srf(): C = np.zeros((3, 5, 5)) C[:, :, 0] = [ [0.0, 3.0, 5.0, 8.0, 10.0], [0.0, 0.0, 0.0, 0.0, 0.0], [2.0, 2.0, 7.0, 7.0, 8.0], ] C[:, :, 1] = [ [0.0, 3.0, 5.0, 8.0, 10.0], [3.0, 3.0, 3.0, 3.0, 3.0], [0.0, 0.0, 5.0, 5.0, 7.0], ] C[:, :, 2] = [ [0.0, 3.0, 5.0, 8.0, 10.0], [5.0, 5.0, 5.0, 5.0, 5.0], [0.0, 0.0, 5.0, 5.0, 7.0], ] C[:, :, 3] = [ [0.0, 3.0, 5.0, 8.0, 10.0], [8.0, 8.0, 8.0, 8.0, 8.0], [5.0, 5.0, 8.0, 8.0, 10.0], ] C[:, :, 4] = [ [0.0, 3.0, 5.0, 8.0, 10.0], [10.0, 10.0, 10.0, 10.0, 10.0], [5.0, 5.0, 8.0, 8.0, 10.0], ] C = C.transpose() U = [ 0, 0, 0, 1 / 3., 2 / 3., 1, 1, 1, ] V = [ 0, 0, 0, 1 / 3., 2 / 3., 1, 1, 1, ] nrb = NURBS([U, V], C) return nrb
def coons(curves, tol=1.e-10): """ C[1,1] o--------------o | v | | ^ | C[0,0] | | | C[0,1] | | | | +------> u | o--------------o C[1,0] """ (C00, C01), (C10, C11) = curves assert C00.dim == C01.dim == 1 assert C10.dim == C11.dim == 1 # (C00, C01) = compat(C00, C01) (C10, C11) = compat(C10, C11) # p, U = C10.degree[0], C10.knots[0] u0, u1 = U[p], U[-p - 1] P = np.zeros((2, 2, 3), dtype='d') P[0, 0] = C10(u0) P[1, 0] = C10(u1) P[0, 1] = C11(u0) P[1, 1] = C11(u1) # q, V = C00.degree[0], C00.knots[0] v0, v1 = V[q], V[-q - 1] Q = np.zeros((2, 2, 3), dtype='d') Q[0, 0] = C00(v0) Q[0, 1] = C00(v1) Q[1, 0] = C01(v0) Q[1, 1] = C01(v1) # # print "P[0,0] ", P[0,0] , " Q[0,0] ", Q[0,0] # print "P[1,0] ", P[1,0] , " Q[1,0] ", Q[1,0] # print "P[0,1] ", P[0,1] , " Q[0,1] ", Q[0,1] # print "P[1,1] ", P[1,1] , " Q[1,1] ", Q[1,1] assert np.allclose(P, Q, rtol=0, atol=tol) # R0 = ruled(C00, C01).transpose() R1 = ruled(C10, C11) B = bilinear(P) R0, R1, B = compat(R0, R1, B) control = R0.control + R1.control - B.control knots = B.knots return NURBS(knots, control)
def test_refinement_iga(): from igakit.nurbs import NURBS points = np.array([ [0, 0, 0], # , 0], [1, 1, 0], # 0], [2, 0, 0], # 0], # [1,0,0] ]) knot = np.array([0, 0, 0, 1, 1, 1]) # D1 resolution = 500 reso = np.linspace(0, 1, resolution) weight = np.ones((points.shape[0], 1)) crv = NURBS([knot], points) crv.refine(0, [0.5, 0.6]) fig1, ax1 = plt.subplots() ax1.plot(crv(reso)[..., 0], crv(reso)[..., 1], 'b') ax1.plot(crv.control[..., 0], crv.control[..., 1], color='red', marker='s', linestyle='None') ax1.set_ylim(0, 1) fig1.show()
def linear(points=None): """ p[0] p[1] o------------o +----> u """ if points is None: points = np.zeros((2, 2), dtype='d') points[0, 0] = -0.5 points[1, 0] = +0.5 else: points = np.asarray(points, dtype='d') assert points.shape[:-1] == (2, ) knots = [0, 0, 1, 1] return NURBS([knots], points)
def test_srf_de(PLOT=0): p = 2 q = 1 U = np.asarray([0,0,0, 1,1,1], dtype=float) V = np.asarray([0,0, 1,1], dtype=float) n = len(U)-1-(p+1) m = len(V)-1-(q+1) Pw = np.zeros((n+1,m+1,4)) Pw[0,0,:] = [0.0, 0.5, 0.0, 1.0] Pw[1,0,:] = [0.5, 0.5, 0.0, 1.0] Pw[2,0,:] = [0.5, 0.0, 0.0, 1.0] Pw[0,1,:] = [0.0, 1.0, 0.0, 1.0] Pw[1,1,:] = [1.0, 1.0, 0.0, 1.0] Pw[2,1,:] = [1.0, 0.0, 0.0, 1.0] Pw[1,:,:] *= np.sqrt(2)/2 nurbs = NURBS([U,V],Pw) nrb = nurbs.copy().elevate(0,0).elevate(1,0) (Uh, Vh), Qw = nrb.knots, nrb.control nrb = nurbs.copy().elevate(0,1).elevate(1,0) (Uh, Vh), Qw = nrb.knots, nrb.control nrb = nurbs.copy().elevate(0,0).elevate(1,1) (Uh, Vh), Qw = nrb.knots, nrb.control r, s = 1, 2 nrb = nurbs.copy().elevate(0,r).elevate(1,s) (Uh, Vh), Qw = nrb.knots, nrb.control ph = p+r; qh = q+s; u = np.linspace(Uh[0], Uh[-1], 31) v = np.linspace(Vh[0], Vh[-1], 10) Cw = bsp.Evaluate2(ph,Uh,qh,Vh,Qw,u,v) Q = Qw[:,:,:2] / Qw[:,:,3, None] C = Cw[:,:,:2] / Cw[:,:,3, None] if not PLOT: return plt.figure() plt.title("Surface - Degree Elevation") x = Q[:,:,0] y = Q[:,:,1] plt.plot(x,y,'sr') x = C[:,:,0] y = C[:,:,1] plt.plot(x,y,'.b') t = np.linspace(0,np.pi/2,100) a = np.cos(t) b = np.sin(t) plt.plot(1.0*a,1.0*b,'-k') plt.plot(0.5*a,0.5*b,'-k') plt.axis("equal")
def make_vol(): C = np.zeros((3,2,3,4), dtype='d') C[0,0,:,0:2] = [0.0, 0.5] C[1,0,:,0:2] = [0.5, 0.5] C[2,0,:,0:2] = [0.5, 0.0] C[0,1,:,0:2] = [0.0, 1.0] C[1,1,:,0:2] = [1.0, 1.0] C[2,1,:,0:2] = [1.0, 0.0] C[:,:,0,2] = 0.0 C[:,:,1,2] = 0.5 C[:,:,2,2] = 1.0 C[:,:,:,3] = 1.0 C[1,:,:,:] *= np.sqrt(2)/2 U = [0,0,0, 1,1,1] V = [0,0, 1,1] W = [0,0, 0.5, 1,1] vol = NURBS([U,V,W], C) return vol
def ruled(nrb1, nrb2): """ Construct a ruled surface/volume between two NURBS curves/surfaces. Parameters ---------- nrb1, nrb2 : NURBS """ assert nrb1.dim == nrb2.dim assert nrb1.dim <= 2 assert nrb2.dim <= 2 nrb1, nrb2 = compat(nrb1, nrb2) Cw = np.zeros(nrb1.shape + (2, 4), dtype='d') Cw[..., 0, :] = nrb1.control Cw[..., 1, :] = nrb2.control UVW = nrb1.knots + ([0, 0, 1, 1], ) return NURBS(UVW, Cw)
def make_crv(): C = [[ 6.0, 0.0, 6.0], [-5.5, 0.5, 5.5], [-5.0, 1.0,-5.0], [ 4.5, 1.5,-4.5], [ 4.0, 2.0, 4.0], [-3.5, 2.5, 3.5], [-3.0, 3.0,-3.0], [ 2.5, 3.5,-2.5], [ 2.0, 4.0, 2.0], [-1.5, 4.5, 1.5], [-1.0, 5.0,-1.0], [ 0.5, 5.5,-0.5], [ 0.0, 6.0, 0.0],] U = [0, 0, 0, 0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1, 1, 1, 1,] crv = NURBS([U], C) return crv
def bilinear(points=None): """ p[0,1] p[1,1] o------------o | v | | ^ | | | | | +----> u | o------------o p[0,0] p[1,0] """ if points is None: s = slice(-0.5, +0.5, 2j) x, y = np.ogrid[s, s] points = np.zeros((2, 2, 2), dtype='d') points[..., 0] = x points[..., 1] = y else: points = np.array(points, dtype='d') assert points.shape[:-1] == (2, 2) knots = [0, 0, 1, 1] return NURBS([knots] * 2, points)
def test_k_refinement(): try: from igakit.nurbs import NURBS active = True except: raise ImportError points = np.array([ [0, 0], # , 0], [1, 1], # 0], [2, 0], # 0], # [1,0,0] ]) knot = np.array([0, 0, 0, 1, 1, 1]) # D1 resolution = 500 reso = np.linspace(0, 1, resolution) crv = NURBS([knot], points) basis_fun, _ = gn.NURB_engine.basis_function_array_nurbs( crv.knots[0], crv.degree[0], resolution, crv.weights) _0 = crv.control fig = make_plot(crv.control, basis_fun, reso, crv(reso)) print(crv.knots) crv.insert(axis=0, value=0.3).insert(axis=0, value=0.5) basis_fun1, _ = gn.NURB_engine.basis_function_array_nurbs( crv.knots[0], crv.degree[0], resolution, crv.weights) _1 = crv.control fig1 = make_plot(crv.control, basis_fun1, reso, crv(reso)) print(crv.knots) crv.elevate(axis=0, times=1) basis_fun2, _ = gn.NURB_engine.basis_function_array_nurbs( crv.knots[0], crv.degree[0], resolution, crv.weights) _2 = crv.control fig2 = make_plot(crv.control, basis_fun2, reso, crv(reso)) print(crv.knots) save = False if save or save_all: fig.savefig(fig_folder + "k_refine_ori.pdf", **kwargs_savefig) fig1.savefig(fig_folder + "k_refine_1.pdf", **kwargs_savefig) fig2.savefig(fig_folder + "k_refine_2.pdf", **kwargs_savefig)
def test_refinement_order(): try: from igakit.nurbs import NURBS active = True except: _0 = np.asarray([[0., 0., 0., 1.], [1., 1., 0., 1.], [2., 0., 0., 1.]]) _1 = np.asarray([[ 0., 0., 0., 1., ], [ 0.66666667, 0.66666667, 0., 1., ], [ 1.33333333, 0.66666667, 0., 1., ], [ 2., 0., 0., 1., ]]) _2 = np.asarray([[0., 0., 0., 1.], [ 0.5, 0.5, 0., 1., ], [ 1., 0.66666667, 0., 1., ], [ 1.5, 0.5, 0., 1., ], [ 2., 0., 0., 1., ]]) active = False points = np.array([ [0, 0], # , 0], [1, 1], # 0], [2, 0], # 0], # [1,0,0] ]) knot = np.array([0, 0, 0, 1, 1, 1]) # D1 resolution = 500 reso = np.linspace(0, 1, resolution) if active: crv = NURBS([knot], points) basis_fun, _ = gn.NURB_engine.basis_function_array_nurbs( crv.knots[0], crv.degree[0], resolution, crv.weights) _0 = crv.control fig = make_plot(crv.control, basis_fun, reso, crv(reso)) crv.elevate(axis=0, times=1) basis_fun1, _ = gn.NURB_engine.basis_function_array_nurbs( crv.knots[0], crv.degree[0], resolution, crv.weights) _1 = crv.control fig1 = make_plot(crv.control, basis_fun1, reso, crv(reso)) crv.elevate(axis=0, times=1) basis_fun2, _ = gn.NURB_engine.basis_function_array_nurbs( crv.knots[0], crv.degree[0], resolution, crv.weights) _2 = crv.control fig2 = make_plot(crv.control, basis_fun1, reso, crv(reso)) else: x, y, z = gn.engine.NURB_construction([knot], _0, resolution, None) basis_fun, _ = gn.NURB_engine.basis_function_array_nurbs( knot, 2, resolution, None) fig = make_plot(_0, basis_fun, reso, np.asarray([x, y]).T) knot1 = np.asarray([0, 0, 0, 0, 1, 1, 1, 1]) x1, y1, z1 = gn.engine.NURB_construction([knot1], _1, resolution, None) basis_fun1, _ = gn.NURB_engine.basis_function_array_nurbs( knot1, 3, resolution, None) fig1 = make_plot(_1, basis_fun1, reso, np.asarray([x1, y1]).T) knot2 = np.asarray([0, 0, 0, 0, 0, 1, 1, 1, 1, 1]) x2, y2, z2 = gn.engine.NURB_construction([knot2], _2, resolution, None) basis_fun2, _ = gn.NURB_engine.basis_function_array_nurbs( knot2, 4, resolution, None) fig2 = make_plot(_2, basis_fun2, reso, np.asarray([x2, y2]).T) save = False if save or save_all: fig.savefig(fig_folder + "p_refine_2.pdf", **kwargs_savefig) fig1.savefig(fig_folder + "p_refine_3.pdf", **kwargs_savefig) fig2.savefig(fig_folder + "p_refine_4.pdf", **kwargs_savefig)
def create_model(self, engine=None): if engine is None: engine = self.engine if engine == "c++": try: import gempyExplicit except Exception: traceback.print_exc() if self.dim == 1: self.model = gempyExplicit.NURBS_Curve(self.degree[0], self.knots[0], self.cpoints, self.weight, self.resolution, engine="auto") return self.dim elif self.dim == 2: self.model, self.triangles = gempyExplicit.NURBS_Surface( self.degree[0], self.degree[1], self.knots[0], self.knots[1], self.cpoints, self.weight, self.resolution, self.resolution, engine="auto") return self.dim elif self.dim == 3: self.model, self.triangles, self.surf_triangles = gempyExplicit.NURBS_Volume( self.degree[0], self.degree[1], self.degree[2], self.knots[0], self.knots[1], self.knots[2], self.cpoints, self.weight, self.resolution, self.resolution, self.resolution, engine="auto") return self.dim else: print(self.dim) return TypeError elif engine == "python": try: from pygeoiga.engine import NURB_construction except: traceback.print_exc() self.model = NURB_construction(list(self.knots), self.cpoints, self.resolution, self.weight) return self.dim elif engine == "igakit": try: from igakit.nurbs import NURBS except Exception: traceback.print_exc() self._NURB = NURBS(knots=list(self.knots), control=self.B) #, weights=self.weight) else: print(self.engine, "Not available") return TypeError
# Open knot vectors for a one-Bezier-element bi-unit square. uKnots = [-1.0, -1.0, -1.0, 1.0, 1.0, 1.0] vKnots = [-1.0, -1.0, -1.0, 1.0, 1.0, 1.0] # Array of control points, for a bi-unit square with the interior # parameterization distorted. cpArray = array([[[-1.0, -1.0], [0.0, -1.0], [1.0, -1.0]], [[-1.0, 0.0], [0.7, 0.3], [1.0, 0.0]], [[-1.0, 1.0], [0.0, 1.0], [1.0, 1.0]]]) # NOTE: Polynomial degree is determined based on the number of knots and # control points. In this case, the NURBS is quadratic. # Create initial mesh ikNURBS = NURBS_ik([uKnots, vKnots], cpArray) # Refinement numNewKnots = 1 for i in range(0, REF_LEVEL): numNewKnots *= 2 h = 2.0 / float(numNewKnots) numNewKnots -= 1 knotList = [] for i in range(0, numNewKnots): knotList += [ float(i + 1) * h - 1.0, ] newKnots = array(knotList) ikNURBS.refine(0, newKnots) ikNURBS.refine(1, newKnots)
U[degree + 1:-degree - 2] = vec_add U = np.sort(U) U[-degree - 1:] = 1 U[:degree + 1] = 0 return U #%% U = make_knot_vector(degree=2, len_cp=tot_U) V = make_knot_vector(degree=2, len_cp=tot_V) #%%%% #to igakit from igakit.plot import plt as plt_surf surface = NURBS([U, V], control_points) plt_surf.figure() plt_surf.cpoint(surface) plt_surf.cwire(surface) plt_surf.curve(surface) plt.show() # %% anti-refinement new_surf = surface.clone() deviation = 10000000 for i in U: new_surf = new_surf.remove(0, i, deviation=deviation) for j in V: new_surf = new_surf.remove(1, i, deviation=deviation) plt_surf.figure()
from tIGAr import * from tIGAr.NURBS import * from igakit.nurbs import NURBS as NURBS_ik from igakit.io import PetIGA #from igakit.plot import plt import matplotlib.pyplot as plt import math vKnots = [0.0,0.0,0.0,1.0,1.0,1.0] uKnots = [0.0,0.0,1.0,1.0] cpArray = array([[[1.0,0.0],[1.0,1.0],[0.0,1.0]], [[2.0,0.0],[2.0,2.0],[0.0,2.0]]]) w = array([[[1.0],[sqrt(2)/2],[1.0]],[[1.0],[sqrt(2)/2],[1.0]]]) ikNURBS = NURBS_ik([uKnots,vKnots],cpArray) ikNURBS.elevate(0,1) print(ikNURBS.degree) print(ikNURBS.knots) numNewKnots = 1 for i in range(0,6): numNewKnots *= 2 h = 1.0/float(numNewKnots) numNewKnots -= 1 knotList = [] for i in range(0,numNewKnots): knotList += [float(i+1)*h,] newKnots = array(knotList) ikNURBS.refine(0,newKnots) ikNURBS.refine(1,newKnots)
t2 = transform().move(0, 2) t3 = transform() t3.scale([np.sqrt(2), 1, np.sqrt(2)]) t3.rotate(-np.pi/4, 1).move(-Rb, 2) t4 = transform() t4.rotate(-np.pi/2, 1).move([Rb, 0, -Rb]) bentpipe[:,0,:] = t0(circle) bentpipe[:,1,:] = t1(circle) bentpipe[:,2,:] = t2(circle) bentpipe[:,3,:] = t3(circle) bentpipe[:,4,:] = t4(circle) Pw = bentpipe U = [0,0,0, 1,1, 2,2, 3,3, 4,4,4] W = [0,0,0, 1,1, 2,2,2] nrb = NURBS(Pw, [U,W]) import sys try: backend = sys.argv[1] plt.use(backend) except IndexError: pass plt.figure() plt.plot(nrb) n1,n2,n3,n4,n5 = VolumifyInterior(nrb) plt.figure() for i in range(1,6):
# geo = patch(n=[nx,ny],p=[px,py]) geo_s = square(p=[2,2]) nrb = geo_s[0] U,V = nrb.knots #C = nrb.points C = np.zeros_like(nrb.points) s = 1./np.sqrt(2) weights = np.ones((3,3)) weights[1,0] = s weights[0,1] = s weights[2,1] = s weights[1,2] = s srf = NURBS([U,V], C, weights=weights) geo = cad_geometry() geo.append(srf) geo._internal_faces = geo_s._internal_faces geo._external_faces = geo_s._external_faces geo._connectivity = geo_s._connectivity # srf = geo[0] dim = srf.dim n = [nx,ny] list_t = [] for axis in range(0,dim): ub = srf.knots[axis][0] ue = srf.knots[axis][-1] list_t.append(np.linspace(ub,ue,n[axis]+2)[1:-1])
""" Step 1: Create a quadratic curve between each line. The extra control point is determined as the point where the lines intersect. This way the construction is C1. """ P = np.zeros((3, 2)) C = [] C.append(L[0]) for i in range(len(L) - 1): mid = seg_intersect(L[i].points[0, 0:2], L[i].points[1, 0:2], L[i + 1].points[0, 0:2], L[i + 1].points[1, 0:2]) plt.plot(mid[0], mid[1], 'yo', markersize=ms) P[0, :] = L[i].points[1, 0:2] P[1, :] = mid[0:2] P[2, :] = L[i + 1].points[0, 0:2] C.append(NURBS(P, [[0, 0, 0, 1, 1, 1]])) C.append(L[i + 1]) """ Step 2-4: Degree elevate to make all curves p=2. Also compute each curve's length and the total combined length. """ plt.subplot(313) L = [] for c in C: c.elevate(2 - c.degree[0]) L.append(curve_length(c)) L = np.asarray(L) Lt = L.sum() L /= Lt """ Step 5-6: Combine all curves into 1. This we do by juxtaposing each
P[6, 1, :] = [5.24524, 50.0859] P[7, 1, :] = [42.1936, 50.0884] P[8, 1, :] = [95.7095, 50.0937] P[9, 1, :] = [128.203, 50.0974] P[10, 1, :] = [183.546, 47.168] P[11, 1, :] = [335.568, 38.9067] P[12, 1, :] = [782.636, 12.9908] P[13, 1, :] = [1120.1, -10.3521] # Adjust control points such that the length scale is 1 delx = P[:, :, 0].max() - P[:, :, 0].min() minx = P[:, :, 0].min() P -= minx P /= delx tube = NURBS(P, [U, V]) tube.elevate(0, 1) # Determine which knots to insert res = 32 insert_U = InsertUniformly(U, 4 * res) insert_V = InsertUniformly(V, res) tube.refine(insert_U, insert_V) plt.use('mayavi') plt.figure() plt.plot(tube) plt.show()
data = {} cwdir = os.getcwd() geom = PetIGA().read('mesh.dat') inc = 1 if (nPrjtnScalars + nPrjtnVectors > 0): for filename1, filename2 in zip(glob.glob('outU*.dat'), glob.glob('outE*.dat')): if int(filename1.split(".")[0][4:]) >= bound: filename2 = "outE" + filename1.split(".")[0][4:] + ".dat" outname = "out" + filename1.split(".")[0][4:] + ".vtk" sol2 = PetIGA().read_vec(filename1, geom) sol1 = PetIGA().read_vec(filename2, geom) if (sol1.ndim == dim): sol1 = np.expand_dims(sol1, axis=dim) if (sol2.ndim == dim): sol2 = np.expand_dims(sol2, axis=dim) sol = np.concatenate((sol1, sol2), axis=dim) nrb = NURBS(geom.knots, (geom.points, geom.weights), sol) VTK().write(outname, nrb, scalars=scalars, vectors=vectors) else: for filename in glob.glob('outU*.dat'): if int(filename.split(".")[0][4:]) >= bound: outname = "out" + filename.split(".")[0][4:] + ".vtk" sol = PetIGA().read_vec(filename, geom) nrb = NURBS(geom.knots, (geom.points, geom.weights), sol) VTK().write(outname, nrb, scalars=scalars, vectors=vectors)
def join(nrb1, nrb2, axis): """ Join two curves/surfaces/volumes along a specified parametric axis. Parameters ---------- nrb1, nrb2 : NURBS axis : int Examples -------- >>> C1 = circle(radius=0.5) >>> C2 = circle(radius=1.0) >>> annulus = ruled(C1, C2) >>> pipe = extrude(annulus, displ=2, axis=2) >>> elbow = revolve(annulus, point=(1.5,0,0), ... axis=(0,-1,0), angle=Pi/2) >>> bentpipe = join(pipe.reverse(2), elbow, axis=2) """ dim = nrb1.dim assert dim == nrb2.dim assert 0 <= axis < dim axes = list(range(dim)) del axes[axis] nrb1, nrb2 = compat(nrb1, nrb2, axes=axes) nrb1 = nrb1.clamp(axis, side=1) nrb2 = nrb2.clamp(axis, side=0) p1 = nrb1.degree[axis] p2 = nrb2.degree[axis] U1 = nrb1.knots[axis] U2 = nrb2.knots[axis] u = U1[-p1-1] a = U2[p2] b = U2[-p2-1] nrb2.remap(axis, a+u, b+u) p = max(p1, p2) nrb1.elevate(axis, p-p1) nrb2.elevate(axis, p-p2) A1 = nrb1.array A2 = nrb2.array I1 = [slice(None)] * (dim+1) I2 = [slice(None)] * (dim+1) I1[axis] = slice(0,-1) I2[axis] = slice(1,None) Al = A1[I1] Ar = A2[I2] I1[axis] = -1 I2[axis] = +0 Ac = (A1[I1]+A2[I2])/2.0 Ic = [slice(None)] * (dim+1) Ic[axis] = np.newaxis Ac = Ac[Ic] A = np.concatenate([Al, Ac, Ar], axis) U1 = nrb1.knots[axis] U2 = nrb2.knots[axis] Ul = U1[:-p-1] Ur = U2[p+1:] Uc = [u]*p U = np.concatenate([Ul, Uc, Ur]) knots = list(nrb1.knots) knots[axis] = U nrb = NURBS.__new__(type(nrb1)) nrb._array = np.ascontiguousarray(A) nrb._knots = tuple(knots) nrb.remove(axis, u, p-1) return nrb
P[6,1,:] = [5.24524, 50.0859] P[7,1,:] = [42.1936, 50.0884] P[8,1,:] = [95.7095, 50.0937] P[9,1,:] = [128.203, 50.0974] P[10,1,:] = [183.546, 47.168] P[11,1,:] = [335.568, 38.9067] P[12,1,:] = [782.636, 12.9908] P[13,1,:] = [1120.1, -10.3521] # Adjust control points such that the length scale is 1 delx=P[:,:,0].max()-P[:,:,0].min() minx=P[:,:,0].min() P -= minx P /= delx tube = NURBS(P,[U,V]) tube.elevate(0,1) # Determine which knots to insert res = 32 insert_U=InsertUniformly(U,4*res) insert_V=InsertUniformly(V,res) tube.refine(insert_U,insert_V) plt.use('mayavi') plt.figure() plt.plot(tube) plt.show()
circleFileName='circle40.mat'; splineFileName='tubeFullWithBaseFor1R4Helix40.mat' outputFileName='tubeFullWithBaseFor1R4HelixH200.dat' C2Continuity=False; #Read from mat file mat = scipy.io.loadmat(splineFileName) order = np.array(mat['order']) order = order.tolist()[0][0]; knots = np.array(mat['knots']) knots = knots.tolist()[0]; C = np.transpose(np.array(mat['controlPoints'])) U=knots; Curve = NURBS([U],C) S = revolve(Curve, circleFileName, (0,0), 1) print S.knots[0]; print S.knots[1]; #refine along X #to_insertX = np.setdiff1d(linspace(0.25,0.5,11)[1:-1],S.knots[0]); #S.refine(0,to_insertX) #refine along Y #to_insertY = np.setdiff1d(linspace(0,1.0,21)[1:-1],S.knots[1]); #S.elevate(0,1); #S.elevate(1,1); #S.refine(1,kX); #S.refine(1,kX);
#%% cpoints, knot1, knot2 = make_srf() #%% from igakit.nurbs import NURBS from igakit.plot import plt import matplotlib matplotlib.use('Qt5Agg') C1 = [[-1.5, 0], [-1, 0.5], [-1, 1]] U = [0, 0, 0, 1, 1, 1] crv = NURBS([U], C1) plt.figure() plt.cpoint(crv) plt.cwire(crv) plt.plot(crv) plt.show() #%% C1 = [[-1, 1], [-1.2, 2], [-1, 3]] U1 = [0, 0, 0, 1, 1, 1] crv1 = NURBS([U1], C1) plt.figure()
help='project while enforcing end conditions') opts,args = parser.parse_args() nelem = opts.nelem p = opts.p l2 = opts.L2 h1 = opts.H1 dbc = opts.dbc k = opts.k # setup function space xmax = 1.0 xmin = -1.0 U = iga.iga.KnotVector(nelem,p,k,-1,1,0) C = np.zeros((U.size-p-1,2)) crv = NURBS([U],C) # plot exact solution fh = 4.0 fig = plt.figure(figsize=(2.0*fh*1.62,fh)) u = np.linspace(-1.0,1.0,1000,endpoint=True) x=[] dx=[] for i in range(len(u)): x.append(f(u[i])) dx.append(df(u[i])) plt.subplot(121) plt.plot(u,x,'r-',label='exact') plt.subplot(122) plt.plot(u,dx,'r-',label='exact')