def AddPlot(self, plot_cmd):
     if plot_cmd == "cplot":
         plt.cplot(self.nurbs)
     elif plot_cmd == "kplot":
         plt.kplot(self.nurbs)
     elif plot_cmd == "plot":
         plt.plot(self.nurbs)
     elif plot_cmd == "curve":
         plt.curve(self.nurbs)
     elif plot_cmd == "surface":
         plt.surface(self.nurbs)
     elif plot_cmd == "cpoint":
         plt.cpoint(self.nurbs)
     elif plot_cmd == "cwire":
         plt.cwire(self.nurbs)
     elif plot_cmd == "kpoint":
         plt.kpoint(self.nurbs)
     elif plot_cmd == "kwire":
         plt.kwire(self.nurbs)
Exemplo n.º 2
0
    U[:degree + 1] = 0
    return U


#%%
U = make_knot_vector(degree=2, len_cp=tot_U)
V = make_knot_vector(degree=2, len_cp=tot_V)

#%%%%
#to igakit
from igakit.plot import plt as plt_surf
surface = NURBS([U, V], control_points)

plt_surf.figure()
plt_surf.cpoint(surface)
plt_surf.cwire(surface)
plt_surf.curve(surface)
plt.show()

# %% anti-refinement
new_surf = surface.clone()
deviation = 10000000
for i in U:
    new_surf = new_surf.remove(0, i, deviation=deviation)
for j in V:
    new_surf = new_surf.remove(1, i, deviation=deviation)
plt_surf.figure()
plt_surf.cpoint(new_surf)
plt.show()
print(surface.shape, new_surf.shape)
#%%
Exemplo n.º 3
0
    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)

plt.figure()
plt.surface(vol)

plt.figure()
plt.cplot(vol)
plt.kplot(vol)
plt.plot(vol)
Exemplo n.º 4
0
elbow    = revolve(annulus, point=(Rb,0,0),
                   axis=(0,-1,0), angle=Pi/2)
bentpipe = join(pipe.reverse(2), elbow, axis=2)

# ---

nrb = bentpipe

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.cpoint(nrb)
plt.cwire(nrb, mode='tube')
plt.kpoint(nrb)
plt.kwire(nrb, mode='tube')
plt.plot(nrb, opacity=0.1)

plt.figure()
plt.kplot(nrb, color=(0,0,1))
plt.plot(nrb)

plt.show()
Exemplo n.º 5
0
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:
    from igakit.io import PetIGA, VTK
    nrb = PetIGA().read("ClassicalShell.dat")
    sol = PetIGA().read_vec("ClassicalShell.out", nrb)
    U = sol[..., :3]
    X = nrb.points
    W = nrb.weights
    nrb = NURBS(nrb.knots, (X, W), U)
    VTK().write(
        "ClassicalShell.vtk",
        nrb,
Exemplo n.º 6
0
         1, 1, 1, 1,]
    crv = NURBS([U], C)
    return crv

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

crv = make_crv()

plt.figure()
plt.cpoint(crv)
plt.cwire(crv)

plt.figure()
plt.kpoint(crv)
plt.kwire(crv)

plt.figure()
plt.curve(crv)

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

plt.show()
Exemplo n.º 7
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)
Exemplo n.º 8
0
#nrb1 = nrb.clone().elevate(0,1,1)
#nrb2 = nrb.clone().refine([],[0.5],[0.25, 0.5, 0.75])

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

plt.figure()
plt.cpoint(nrb)
plt.cwire(nrb)

plt.figure()
plt.kpoint(nrb)
plt.kwire(nrb)

plt.figure()
plt.curve(nrb)
plt.figure()
plt.surface(nrb)

plt.figure()
plt.cplot(nrb)
plt.kplot(nrb)
plt.plot(nrb)
Exemplo n.º 9
0
    V = [0, 0, 0, 1/3., 2/3., 1, 1, 1,]
    srf = NURBS([U,V], C)
    return srf

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

srf = make_srf()

plt.figure()
plt.cpoint(srf)
plt.cwire(srf)

plt.figure()
plt.kpoint(srf)
plt.kwire(srf)

plt.figure()
plt.curve(srf)
plt.figure()
plt.surface(srf)

plt.figure()
plt.cplot(srf)
plt.kplot(srf)
plt.plot(srf)
Exemplo n.º 10
0
    srf = NURBS([U, V], C)
    return srf


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

srf = make_srf()

plt.figure()
plt.cpoint(srf)
plt.cwire(srf)

plt.figure()
plt.kpoint(srf)
plt.kwire(srf)

plt.figure()
plt.curve(srf)
plt.figure()
plt.surface(srf)

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