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)
Ejemplo n.º 2
0
from igakit.cad import *

c1 = line().reverse()
c2 = circle(center=(0, 1), angle=Pi)
S = ruled(c1, c2)

# ---

from igakit.plot import plt
import sys
try:
    backend = sys.argv[1]
    plt.use(backend)
except IndexError:
    pass
#plt.use('mayavi')
#plt.use('matplotlib')

plt.figure()
plt.curve(c1, color=(1, 0, 0))
plt.curve(c2, color=(1, 0, 0))
plt.cplot(S)
plt.plot(S)

plt.show()
Ejemplo n.º 3
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

import sys
try:
    backend = sys.argv[1]
    plt.use(backend)
except IndexError:
    pass

vol = make_vol()

plt.figure()
plt.cpoint(vol)
plt.cwire(vol)

plt.figure()
plt.kpoint(vol)
plt.kwire(vol)

plt.figure()
plt.curve(vol)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 6
0
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()