예제 #1
0
def degree_elevation(B, knots: list, times=1, direction = 0):
    try:
        from igakit.nurbs import NURBS
        nrb = NURBS(knots, B)
        nrb.elevate(axis=direction, times=times)
        B = nrb.control
        knots = nrb.knots
        return B, knots

    except:
        from geomdl import NURBS
        from geomdl import helpers
        if not isinstance(knots, list):
            knots = [knots]
        degree = np.asarray([len(np.where(knots[x] == 0.)[0]) - 1 for x in range(len(knots))])
        dim = len(degree)
        if dim==1:
            nrb = NURBS.Curve()
            nrb.degree = degree[0]
            nrb.ctrlpts = B[...,:-1]
            nrb.knotvector = knots[0]
            nrb = helpers.degree_elevation(degree[0], )

        else:
            nrb = NURBS.Surface()
            nrb.ctrlpts2d = B
            nrb.knotvector = knots
예제 #2
0
파일: volumify.py 프로젝트: ramosapf/igakit
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
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
 
예제 #6
0
파일: venturi.py 프로젝트: ramosapf/igakit
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()
예제 #7
0
파일: venturi.py 프로젝트: girving/igakit
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()
예제 #8
0
    p = int(sys.argv[2])

U = [0, 0, 1, 1]
V = [0, 0, 0, 1, 1, 1]
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)