示例#1
0
文件: ruled.py 项目: ramosapf/igakit
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()
示例#2
0
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)

plt.figure()
plt.surface(vol)

plt.figure()
plt.cplot(vol)
plt.kplot(vol)
plt.plot(vol)

plt.show()
示例#3
0
def elastic_test(props):
  type = props.type()
  mode = props.mode()
  petsc_reinitialize()
  if mode=='tao':
    petsc_add_options([sys.argv[0]]+'''
      -tao_monitor -tao_converged_reason -tao_type nls
      -tao_nls_ksp_type petsc -ksp_type minres
      -tao_max_it 200 -ksp_max_it 500'''.split())
  petsc_add_options([sys.argv[0]]+props.petsc().split())
  comm = petsc_comm_world()
  d = props.dim()
  material = props.youngs_modulus(),props.poissons_ratio()
  rho_g = props.density()*props.gravity()*-axis_vector(d-1,d=d)

  # Diagnostic options
  petsc_add_options('ignored -tao_monitor -tao_converged_reason'.split())

  if type=='iga':
    assert props.model()=='neo-hookean'
    iga = NeoHookeanElasticIGA[d](comm,material,rho_g)
    geom,boundary = iga_geometry(props,iga)
    iga.set_from_options()
    iga.set_up()

    # Boundary conditions
    x = iga.read_vec(boundary.name)
    dummy = 17 # Overwritten by set_fix_table
    for axis in xrange(d):
      for side in 0,1:
        for i in xrange(d):
          if axis==0 and side==0:
            iga.set_boundary_value(axis,side,i,0)
    iga.set_fix_table(x)

    if mode=='snes':
      snes = iga.create_snes()
      snes.set_from_options()
    elif mode=='tao':
      tao = iga.create_tao()
      tao.set_from_options()

  elif type=='fe':
    dm = dm_geometry(props,comm)
    degree = props.degree()
    degree = 1
    petsc_add_options(['ignored','-petscspace_order',str(degree)])
    if 0: # Would be needed for neumann
      petsc_add_options(['ignored','-bd_petscspace_order',str(degree)])
    snes = SNES(comm)
    snes.set_dm(dm)
    fe = FE(comm,d,d),
    print('fe dofs = %s'%fe[0].dofs)
    fe_bd = fe_aux = ()
    dm.create_default_section(('x',),fe,'wall',(0,))
    start = identity_analytic(d)
    model = {'neo-hookean':NeoHookeanElasticModel,'laplace':LaplaceElasticModel}[props.model()]
    model = model[d](fe,fe_aux,fe_bd,start,material,rho_g)
    dm.set_model(model,mode=='tao') # Use a real objective for tao but not for snes
    A = dm.create_matrix()
    snes.set_jacobian(A,A)
    snes.set_from_options()
    if mode=='tao':
      tao = TaoSolver(comm)
      tao.set_snes(snes)
      tao.set_from_options()
    x = dm.create_global_vector()
    dm.project((start,),INSERT_VALUES,x)
  else:
    raise RuntimeError("unknown discretization type '%s'"%type)

  def check(*args):
    if props.check() and (mode=='snes' or type=='fe'):
      snes.consistency_test(x,1e-6,1e-3,2e-10,10)
  check()

  # Solve
  if mode=='snes':
    snes.add_monitor(check)
    snes.solve(None,x)
  elif mode=='tao':
    tao.set_initial_vector(x)
    tao.add_monitor(check)
    tao.solve()

  # View
  if props.view():
    if type=='iga':
      geom_file = named_tmpfile(prefix='geom',suffix='.nurbs')
      x_file = named_tmpfile(prefix='x',suffix='.vec')
      iga.write(geom_file.name)
      iga.write_vec(x_file.name,x)

      from igakit.io import PetIGA
      geom = PetIGA().read(geom_file.name)
      x = PetIGA().read_vec(x_file.name,nurbs=geom)
      geom.control[...,:d] = x
      from igakit.plot import plt
      plt.figure()
      plt.cwire(geom)
      plt.kwire(geom)
      plt.surface(geom)
      plt.show()
    elif type=='fe':
      name = props.output()
      if not name:
        f = named_tmpfile(prefix='elastic',suffix='.vtk')
        name = f.name
      assert name.endswith('.vtk')
      dm.write_vtk(name,x)
      cmd = ['hollow-view',name]
      print(' '.join(cmd))
      subprocess.check_call(cmd)
    else:
      raise RuntimeError("weird type '%s'"%type)
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()
 def Render(self):
     plt.show()