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 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)
plt.cpoint(crv_diapir) plt.cwire(crv_diapir) plt.plot(crv_diapir) ax = plt.backend.gca() ax.set_xlim((-3,3)) ax.set_ylim((0,6)) plt.show() #%% c_bot = [[-1.5,0], [0,0], [1.5,0]] U = [0,0,0,1,1,1] cr_bot = NURBS([U], c_bot) #%% diapir = ruled(crv_diapir, cr_bot) plt.figure() #plt.cpoint(diapir) plt.cwire(diapir) plt.plot(diapir, resolution=100) plt.kpoint(diapir) ax = plt.backend.gca() ax.set_xlim((-3,3)) ax.set_ylim((0,6)) plt.show() #%% C_1 = [[-1.5, 0], [-1, 0.5], [-1, 1], [-1.2, 2], [-1, 3],
import sys, numpy as np from igakit.nurbs import NURBS from igakit.cad import circle, line, join, revolve, ruled from igakit.plot import plt from math import pi as Pi from igakit.io import PetIGA from numpy import linspace #Geometry R = 1.0 c1 = circle(0.005 * R, (0, 0, 1)) c2 = circle(R, (0, 0, 1)) #c1 = circle(radius=R) #c2 = circle(radius=20*R) S = ruled(c1, c2).transpose().elevate(0, 1) #refine along X to_insertX = np.setdiff1d(linspace(0, 0.25, 11)[1:-1], S.knots[0]) S.refine(0, to_insertX) #to_insertX = np.setdiff1d(linspace(0.25,1.0,5)[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.refine(1, to_insertY) #S.elevate (1,1); #periodicity S.unclamp(1, continuity=1)
def create_patch(R1, R2, C1, C2, order=2, viewpatch=False): """ Create a single 2d NURBS-patch of the area between two coplanar nested circles using igakit. Parameters ---------- R1 : float Radius of the inner circle. R2 : float Radius of the outer circle. C1 : list of two floats Coordinates of the center of the inner circle given as [x1, y1]. C2 : list of two floats Coordinates of the center of the outer circle given as [x2, y2]. order : int, optional Degree of the NURBS basis functions. The default is 2. viewpatch : bool, optional When set to True, display the NURBS patch. The default is False. Returns ------- None. """ from sfepy.discrete.iga.domain_generators import create_from_igakit import sfepy.discrete.iga.io as io from igakit.cad import circle, ruled from igakit.plot import plt as iplt from numpy import pi # Assert the inner circle is inside the outer one inter_centers = nm.sqrt((C2[0] - C1[0])**2 + (C2[1] - C1[1])**2) assert R2 > R1, "Outer circle should have a larger radius than the inner one" assert inter_centers < R2 - R1, "Circles are not nested" # Geometry Creation centers_direction = [C2[0] - C1[0], C2[1] - C1[1]] if centers_direction[0] == 0 and centers_direction[1] == 0: start_angle = 0.0 else: start_angle = nm.arctan2(centers_direction[1], centers_direction[0]) c1 = circle(radius=R1, center=C1, angle=(start_angle, start_angle + 2 * pi)) c2 = circle(radius=R2, center=C2, angle=(start_angle, start_angle + 2 * pi)) srf = ruled(c1, c2).transpose() # make the radial direction first # Refinement insert_U = insert_uniformly(srf.knots[0], 6) insert_V = insert_uniformly(srf.knots[1], 6) srf.refine(0, insert_U).refine(1, insert_V) # Setting the NURBS-surface degree srf.elevate(0, order - srf.degree[0] if order - srf.degree[0] > 0 else 0) srf.elevate(1, order - srf.degree[1] if order - srf.degree[1] > 0 else 0) # Sfepy .iga file creation nurbs, bmesh, regions = create_from_igakit(srf, verbose=True) # Save .iga file in sfepy/meshes/iga filename_domain = data_dir + '/meshes/iga/concentric_circles.iga' io.write_iga_data(filename_domain, None, nurbs.knots, nurbs.degrees, nurbs.cps, nurbs.weights, nurbs.cs, nurbs.conn, bmesh.cps, bmesh.weights, bmesh.conn, regions) if viewpatch: try: iplt.use('mayavi') iplt.figure() iplt.plot(srf) iplt.show() except ImportError: iplt.use('matplotlib') iplt.figure() iplt.plot(srf) iplt.show()
conf_srf = srf.copy() conf_srf.control[:,:,0] = U[:shift].reshape((conf_srf.shape[0],conf_srf.shape[1]),order='f') conf_srf.control[:,:,1] = U[shift:].reshape((conf_srf.shape[0],conf_srf.shape[1]),order='f') return conf_srf if __name__ == "__main__": # generates two random curves cp = np.outer([0,0.3,0.5,0.6,1.0],[1,1]) cp[:,1] = np.random.rand(5) c1 = NURBS([[0,0,0,0,0.5,1,1,1,1]],cp) cp[:,0] += 0.3 cp[:,1] = 1.+np.random.rand(5) c2 = NURBS([[0,0,0,0,0.5,1,1,1,1]],cp) # create a surface by linearly blending curves, then refine srf = ruled(c1,c2) srf.elevate(1,1) srf.refine(0,np.linspace(0,0.5,6)[1:-1]) srf.refine(0,np.linspace(0.5,1.0,6)[1:-1]) srf.refine(1,np.linspace(0,1,11)[1:-1]) # make the projection err0 = ConformalProjectionError(srf) srf = QuasiConformalProjection(srf) print "Relative error: %.6e" % (ConformalProjectionError(srf)/err0) from igakit.io import VTK VTK().write("conformal.vtk", srf)