Пример #1
0
 def build_from_mesh(self, m, **args):
     dim = m.dim()
     if (dim == 2):
         self.sl = getfem.Slice(('none', ), m, self.nrefine)
     elif (dim == 3):
         self.sl = getfem.Slice(('boundary', ), m, self.nrefine)
     else:
         raise Exception('%d-D Meshes are not supported' % (dim, ))
     self.build_from_slice(self.sl, **args)
Пример #2
0
print "U0.shape: ", U0.shape

Nt = gf.Spmat('copy', N)
Nt.transpose()
KK = Nt * K * N
FF = Nt * F  # FF = Nt*(F-K*U0)

# solve ...
P = gf.Precond('ildlt', KK)
UU = gf.linsolve_cg(KK, FF, P)
print "UU.shape:", UU.shape
U = N * UU + U0
print "U.shape:", U.shape

# post-processing
sl = gf.Slice(('boundary', ), mfu, degree)

# compute the Von Mises Stress
DU = gf.compute_gradient(mfu, U, mfe)
VM = np.zeros((DU.shape[2], ), 'd')
Sigma = DU

for i in range(DU.shape[2]):
    d = np.array(DU[:, :, i])
    E = (d + d.T) * 0.5
    Sigma[:, :, i] = E
    VM[i] = np.sum(E**2) - (1. / 3.) * np.sum(np.diagonal(E))**2

print 'Von Mises range: ', VM.min(), VM.max()

# export results to VTK (you can use http://mayavi.sourceforge.net/ to view these results )
Пример #3
0
    ])
])

m0.add_convex(gf.GeoTrans('GT_PRISM_INCOMPLETE_P2'),
              [[1, .5, 0, .5, 0, 0, 1, 0, 0, 1, .5, 0, .5, 0, 0],
               [0, 1, 2, 0, 1, 0, 0, 2, 0, 0, 1, 2, 0, 1, 0],
               [2, 2, 2, 2, 2, 2, 3.5, 3.5, 3.5, 4, 4, 4, 4, 4, 4]])

m1 = gf.Mesh('cartesian', [0, 1, 2, 3], [0, 1, 2], [-3, -2])

mf0 = gf.MeshFem(m0)
mf0.set_classical_fem(1)
mf1 = gf.MeshFem(m1)
mf1.set_classical_fem(1)

sl = gf.Slice(('boundary', ), m0, 6)
U = np.random.standard_normal(mf0.nbdof())

# VTK:
m0.export_to_vtk('check_export0.vtk', 'quality')
m1.export_to_vtk('check_export1.vtk', 'quality')
mf0.export_to_vtk('check_export2.vtk', 'ascii')
mf1.export_to_vtk('check_export3.vtk', 'ascii')

# DX:
try:
    m0.export_to_dx('check_export0.dx')
except RuntimeError as detail:
    print(detail)

m1.export_to_dx('check_export0.dx', 'ascii', 'edges')
Пример #4
0
# You  should  have received a copy of the GNU Lesser General Public License
# along  with  this program;  if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
#
############################################################################
import getfem
from numpy import *

mfu = getfem.MeshFem('load', 'tank_3D.mfu')
m = mfu.linked_mesh()
mfp = getfem.MeshFem('load', 'tank_3D.mfp', m)
U = fromfile('tank_3D.U', 'd')
P = fromfile('tank_3D.P', 'd')

sl = getfem.Slice(
    ('boundary', ('intersection', ('planar', +1, [0, 0, 0], [0, 1, 0]),
                  ('planar', +1, [0, 0, 0], [1, 0, 0]))), m, 3)

print "importing tvtk.."
import getfem_tvtk
print "import done"

fig = getfem_tvtk.Figure(gui='tvtk')

fig.show(sl, data=(mfp, P), vdata=(mfu, U), edges=False)

fig.show(sl, data=(mfp, P), edges=False)

old = fig.scalar_range()

sl = getfem.Slice(
Пример #5
0
file_name = "check_meshfem_ascii.vtu"
mfu.export_to_vtu(file_name, "ascii", U1, "U1")
unstructured_grid = pv.read(file_name)
expected = U1
actual = unstructured_grid.point_arrays["U1"]
np.testing.assert_equal(expected, actual, "export of U1 is not correct.")

file_name = "check_meshfem_binary.vtu"
mfu.export_to_vtu(file_name, U1, "U1")
unstructured_grid = pv.read(file_name)
expected = U1
actual = unstructured_grid.point_arrays["U1"]
np.testing.assert_equal(expected, actual, "export of U1 is not correct.")

sl = gf.Slice(("boundary", ), mesh, 1)
U2 = np.array([3.0, 2.0, 1.0, 0.0])

file_name = "check_slice_ascii.vtk"
sl.export_to_vtk(file_name, "ascii", U2, "U2")
unstructured_grid = pv.read(file_name)
expected = U2
actual = unstructured_grid.point_arrays["U2"]
np.testing.assert_equal(expected, actual, "export of U2 is not correct.")

file_name = "check_slice_binary.vtk"
sl.export_to_vtk(file_name, U2, "U2")
unstructured_grid = pv.read(file_name)
expected = U2
actual = unstructured_grid.point_arrays["U2"]
np.testing.assert_equal(expected, actual, "export of U2 is not correct.")
Пример #6
0
    print("Iteration %d done" % step)

    if (test_tangent_matrix):
       md.test_tangent_matrix(1E-8, 10, 0.0001)

    U = md.variable('u')

    VM0 = md.compute_Von_Mises_or_Tresca('u', lawname, 'params', mfdu)

    # Direct interpolation of the Von Mises stress
    # VM = md.interpolation('(sqrt(3/2)/Det(Id(meshdim)+Grad_u))*Norm((Id(meshdim)+Grad_u)*Saint_Venant_Kirchhoff_PK2(Grad_u,params)*(Id(meshdim)+Grad_u'') - Id(meshdim)*Trace((Id(meshdim)+Grad_u)*Saint_Venant_Kirchhoff_PK2(Grad_u,params)*(Id(meshdim)+Grad_u''))/meshdim)', mfdu);

    VM = md.compute_finite_strain_elasticity_Von_Mises(lawname, 'u', 'params', mfdu)
    print(npla.norm(VM-VM0))
    
    sl=gf.Slice(('boundary',), mfu, 4)
    sl.export_to_vtk('demo_nonlinear_elasticity_iter_%d.vtk' % step, 'ascii',
                     mfdu,  VM, 'Von Mises Stress', mfu, U, 'Displacement')



print('You can vizualize the loading steps by launching for instance')
print('mayavi2 -d demo_nonlinear_elasticity_iter_1.vtk -f WarpVector -m Surface')







Пример #7
0
k = 1
# time loop
while (s.hasNextEvent()):
    s.computeOneStep()
    name = 'bounce' + str(k) + '.vtk'
    dataPlot[k, 0] = s.nextTime()
    dataPlot[k, 1] = block.q()[2]
    dataPlot[k, 2] = block.velocity()[2]

    # Post proc for paraview
    md.to_variables(block.q())
    VM = md.compute_isotropic_linearized_Von_Mises_or_Tresca(
        'u', 'lambda', 'mu', mff)
    #U = fem_model.variable('u')
    sl = gf.Slice(('boundary', ), sico.mfu, 1)
    sl.export_to_vtk(name, sico.mfu, block.q(), 'Displacement', mff, VM,
                     'Von Mises Stress')
    #print s.nextTime()
    k += 1
    s.nextStep()

#subplot(211)
#title('position')
#plot(dataPlot[:,0], dataPlot[:,1])

#grid()
#subplot(212)
#title('velocity')
#plot(dataPlot[:,0], dataPlot[:,2])
#grid()
Пример #8
0
   if f_coeff > 1e-10:
      md.set_variable('wR', md.variable('uR'))
      md.set_variable('wB', md.variable('uB'))

   starttime = time.clock()
   md.solve('noisy', 'max_iter', 40, 'max_res', 1e-8, #)[0]
            'lsearch', 'simplest', 'alpha max ratio', 1.5, 'alpha min', 0.2, 'alpha mult', 0.6)[0]
   print('solution time for iteration %i is %f sec' % (nit, time.clock()-starttime))

   U_R = md.variable('uR')
   VM_R = md.compute_Von_Mises_or_Tresca('uR', lawname, 'params_ring1', mfvm_R)
   mfvm_R.export_to_vtk('lsc_R_%i.vtk' % nit, mfvm_R,  VM_R,
                        'Von Mises Stresses', mfu_R, U_R, 'Displacements')

   lambda_R = md.variable('lambda_ring')
   mf_lambda_R = md.mesh_fem_of_variable('lambda_ring')
   sl = gf.Slice(('boundary',), mf_lambda_R, CONTACT_BOUNDARY_R)
   sl.export_to_vtk('lsc_R_boundary_%i.vtk' % nit,
                    mfu_R, U_R, 'BDisplacements',
                    mf_lambda_R, lambda_R, 'BMultiplier')

   U_B = md.variable('uB')
   VM_B = md.compute_Von_Mises_or_Tresca('uB', lawname, 'params_block', mfvm_B)
   mfvm_B.export_to_vtk('lsc_B_%i.vtk' % nit, mfvm_B,  VM_B,
                        'Von Mises Stresses', mfu_B, U_B, 'Displacements')

   sl = gf.Slice(('boundary',), mfu_B, CONTACT_BOUNDARY_B)
   sl.export_to_vtk('lsc_B_boundary_%i.vtk' % nit,
                    mfu_B, U_B, 'BDisplacements')
Пример #9
0
md.add_fem_variable('theta', mfth)
md.add_initialized_data('E', E)
md.add_initialized_data('nu', Nu)
md.add_initialized_data('epsilon', thickness)
md.add_initialized_data('kappa', 5. / 6.)
md.add_Mindlin_Reissner_plate_brick(mim, mim, 'u3', 'theta', 'E', 'nu',
                                    'epsilon', 'kappa', 2)
md.add_initialized_data('VolumicData', f)
md.add_source_term_brick(mim, 'u3', 'VolumicData')

md.add_Dirichlet_condition_with_multipliers(mim, 'u3', mfu3, CLAMPED_BOUNDARY)
md.add_Dirichlet_condition_with_multipliers(mim, 'theta', mfth,
                                            CLAMPED_BOUNDARY)
md.add_Dirichlet_condition_with_multipliers(mim, 'u3', mfu3,
                                            SIMPLE_SUPPORT_BOUNDARY)

print('running solve...')
md.solve()
print('solve done!')

u3 = md.variable('u3')

sl = gf.Slice(('none', ), mfu3, 4)
sl.export_to_vtk('plate.vtk', mfu3, u3, 'Displacement')
sl.export_to_pos('plate.pos', mfu3, u3, 'Displacement')

print('You can view the solution with (for example):')
print('mayavi2 -d plate.vtk -f WarpScalar -m Surface')
print('or')
print('gmsh plate.pos')
Пример #10
0
cm = mls.cut_mesh()

ctip = mls.crack_tip_convexes()

mf = gf.MeshFem(m)
mf.set_classical_fem(1)

mfls = gf.MeshFem('levelset',mls,mf)

gf.memstats()

nbd = mfls.nbdof()

if True:
  sl = gf.Slice(('none',), mls, 2);
  U = rand(1,nbd);
  sl.export_to_pos('slU.pos',mfls,U,'U')
  mfls.export_to_pos('U.pos',U,'U')
  cm.export_to_pos('cm.pos')
  m.export_to_pos('m.pos')
else:
  sl = gf.Slice(('none',), mls, 1);
  for i in range(nbd):
    U = np.zeros(nbd)
    U[i] = 1
    sl.export_to_pos('slU'+str(i)+'.pos',mfls,U,'U'+str(i))
    mfls.export_to_pos('U'+str(i)+'.pos',U,'U'+str(i))
  cm.export_to_pos('cm.pos')
  m.export_to_pos('m.pos')
Пример #11
0
    print("SOLVING LOAD STEP %i" % nit)
    md.solve("noisy", "max_iter", max_iter, "max_res",
             max_res)  # , "lsearch", "simplest")

    U1 = md.variable("u1")
    if nonlinear_elasticity:
        VM1 = md.compute_Von_Mises_or_Tresca("u1", lawname, "params1", mfvm1)
    else:
        VM1 = md.compute_isotropic_linearized_Von_Mises_or_Tresca(
            "u1", "clambda1", "cmu1", mfvm1)
    mfvm1.export_to_vtk("lsc_1_%i.vtk" % nit, mfvm1, VM1,
                        "Von Mises Stresses 1", mfu1, U1, "Displacements 1")

    lambda1 = md.variable("lambda1")
    mf_lambda1 = md.mesh_fem_of_variable("lambda1")
    sl = gf.Slice(("boundary", ), mf_lambda1, CONTACT_BOUNDARY1)
    sl.export_to_vtk("lsc_1_boundary_%i.vtk" % nit, mfu1, U1,
                     "BDisplacements 1", mf_lambda1, lambda1, "BMultiplier 1")

    if test_case not in [0, 3]:
        U2 = md.variable("u2")
        if nonlinear_elasticity:
            VM2 = md.compute_Von_Mises_or_Tresca("u2", lawname, "params2",
                                                 mfvm2)
        else:
            VM2 = md.compute_isotropic_linearized_Von_Mises_or_Tresca(
                "u2", "clambda2", "cmu2", mfvm2)
        mfvm2.export_to_vtk("lsc_2_%i.vtk" % nit, mfvm2, VM2,
                            "Von Mises Stresses 2", mfu2, U2,
                            "Displacements 2")