Example #1
0
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")
Example #2
0
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()
Example #3
0
    # 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)

    # Output in PetIGA format
    if (mpirank == 0):
        PetIGA().write("out.dat", ikNURBS)
    MPI.barrier(worldcomm)

    ####### Preprocessing #######

    if (mpirank == 0):
        print("Generating extraction...")

    # Read in the generated geometry to create a control mesh.
    splineMesh = NURBSControlMesh("out.dat", useRect=True)
Example #4
0
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()
Example #5
0
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()
Example #6
0
C = np.zeros((2, 3, 4))
val = np.sqrt(2) * 0.5
C[0, 0, :] = [0, -100, 0, 1]
C[1, 0, :] = [100, -100, 0, 1]
C[0, 1, :] = [0, -100, 100, 1]
C[1, 1, :] = [100, -100, 100, 1]
C[0, 2, :] = [0, 0, 100, 1]
C[1, 2, :] = [100, 0, 100, 1]
C[:, 1, :] *= val

geom = NURBS([U, V], C)
geom.elevate(0, max(p - 1, 0)).elevate(1, max(p - 2, 0))

h = 1. / N
insert = np.linspace(h, 1. - h, N - 1)
geom.refine(0, insert).refine(1, insert)

if True:
    from igakit.io import PetIGA
    PetIGA().write("ClassicalShell.dat", geom, nsd=3)

if False:
    from igakit.plot import plt
    plt.figure()
    plt.cpoint(geom)
    plt.cwire(geom)
    plt.kwire(geom)
    plt.surface(geom)
    plt.show()

if False: