コード例 #1
0
ファイル: demo_wave_equation.py プロジェクト: tang9492/getfem
  This program is used to check that python-getfem is working. This is
  also a good example of use of GetFEM.

"""
import os

import numpy as np

import getfem as gf

NX = 10
m = gf.Mesh('cartesian', np.arange(0., 1. + 1. / NX, 1. / NX),
            np.arange(0., 1. + 1. / NX, 1. / NX))

## create a mesh_fem of for a field of dimension 1 (i.e. a scalar field)
mf = gf.MeshFem(m, 1)
mf.set_classical_fem(2)

## Integration which will be used
mim = gf.MeshIm(m, 4)

## Detect the border of the mesh
border = m.outer_faces()
m.set_region(1, border)

## Interpolate the initial data
U0 = mf.eval('y*(y-1.)*x*(x-1.)*x*x')
V0 = 0. * U0

md = gf.Model('real')
md.add_fem_variable('u', mf)
コード例 #2
0
rho = 1.000e+00
Lambda = 1.000e+00
Mu = 1.000e+00

print "create a Mesh object"
d = 1.000e+00
x = 1.000e+00
y = 1.000e+00
z = 1.000e+00
m = gf.Mesh('cartesian Q1', np.arange(0., x + d, d), np.arange(0., y + d, d),
            np.arange(0., z + d, d))
m.set('optimize_structure')

print "create a MeshFem object"
mfu = gf.MeshFem(m, 3)  # displacement
print "assign the FEM"
mfu.set_fem(gf.Fem('FEM_QK(3,1)'))

print "build a MeshIm object"

mim = gf.MeshIm(m, gf.Integ('IM_HEXAHEDRON(5)'))

print "detect some boundary of the mesh"
P = m.pts()
ctop = (abs(P[0, :] - 0.) < 1e-6)
cbot = (abs(P[1, :] - 0.) < 1e-6)
pidtop = np.compress(ctop, range(0, m.nbpts()))
pidbot = np.compress(cbot, range(0, m.nbpts()))
ftop = m.faces_from_pid(pidtop)
fbot = m.faces_from_pid(pidbot)
コード例 #3
0
import getfem as gf

with_graphics = True
try:
    import getfem_tvtk
except:
    print(
        "\n** Could NOT import getfem_tvtk -- graphical output disabled **\n")
    import time
    time.sleep(2)
    with_graphics = False

m = gf.Mesh('import', 'gid', '../meshes/tripod.GiD.msh')
print('done!')
mfu = gf.MeshFem(m, 3)  # displacement
mfp = gf.MeshFem(m, 1)  # pressure
mfd = gf.MeshFem(m, 1)  # data
mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))
degree = 2
linear = False
incompressible = False  # ensure that degree > 1 when incompressible is on..

mfu.set_fem(gf.Fem('FEM_PK(3,%d)' % (degree, )))
mfd.set_fem(gf.Fem('FEM_PK(3,0)'))
mfp.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,0)'))

print('nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
      (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof()))

P = m.pts()
コード例 #4
0
ファイル: demo_laplacian.py プロジェクト: gitGNU/gnu_getfem
# Import basic modules
import getfem as gf
import numpy as np

## Parameters
NX = 100  # Mesh parameter.
Dirichlet_with_multipliers = True  # Dirichlet condition with multipliers
# or penalization
dirichlet_coefficient = 1e10  # Penalization coefficient

# Create a simple cartesian mesh
m = gf.Mesh('regular_simplices', np.arange(0, 1 + 1. / NX, 1. / NX),
            np.arange(0, 1 + 1. / NX, 1. / NX))

# Create a MeshFem for u and rhs fields of dimension 1 (i.e. a scalar field)
mfu = gf.MeshFem(m, 1)
mfrhs = gf.MeshFem(m, 1)
# assign the P2 fem to all convexes of the both MeshFem
mfu.set_fem(gf.Fem('FEM_PK(2,2)'))
mfrhs.set_fem(gf.Fem('FEM_PK(2,2)'))

#  Integration method used
mim = gf.MeshIm(m, gf.Integ('IM_TRIANGLE(4)'))

# Boundary selection
flst = m.outer_faces()
fnor = m.normal_of_faces(flst)
tleft = abs(fnor[1, :] + 1) < 1e-14
ttop = abs(fnor[0, :] - 1) < 1e-14
fleft = np.compress(tleft, flst, axis=1)
ftop = np.compress(ttop, flst, axis=1)
コード例 #5
0
# Mesh
m = gf.Mesh('cartesian', np.arange(0, 1 + 1. / NX, 1. / NX))

# Selection of the contact and Dirichlet boundaries
GAMMAC = 1
GAMMAD = 2
border = m.outer_faces()
normals = m.normal_of_faces(border)
contact_boundary = border[:, np.nonzero(normals[0] < -0.01)[0]]
m.set_region(GAMMAC, contact_boundary)
contact_boundary = border[:, np.nonzero(normals[0] > 0.01)[0]]
m.set_region(GAMMAD, contact_boundary)

# Finite element methods
mfu = gf.MeshFem(m)
mfu.set_classical_fem(
    u_degree)  # Assumed to be a Lagrange FEM in the following

mfd = gf.MeshFem(m, 1)
mfd.set_classical_fem(u_degree)

# Integration method
mim = gf.MeshIm(m, 4)

# GetFEM model
md = gf.Model('real')
md.add_fem_variable('u', mfu)
md.add_fem_data('v', mfu)
md.add_initialized_data('t_N', theta_N)
md.add_initialized_data('g_N', gamma0_N / h)
コード例 #6
0
dimY = 10.01
dimZ = 3.01
stepX = 2.0
stepY = 2.0
stepZ = 1.5
x = np.arange(0, dimX, stepX)
y = np.arange(0, dimY, stepY)
z = np.arange(0, dimZ, stepZ)
m = gf.Mesh('regular simplices', x, y, z)
m.set('optimize_structure')
# Export the mesh to vtk
m.export_to_vtk("BlockMesh.vtk")

# Create MeshFem objects
# (i.e. assign elements onto the mesh for each variable)
mfu = gf.MeshFem(m, 3)  # displacement
mff = gf.MeshFem(m, 1)  # for plot von-mises
# assign the FEM
mfu.set_fem(gf.Fem('FEM_PK(3,1)'))
mff.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,1,0.01)'))
# mfu.export_to_vtk("BlockMeshDispl.vtk")

# ==== Set the integration method ====
mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))

# ==== Summary ====
print(' ==================================== \n Mesh details: ')
print(' Problem dimension:', mfu.qdim(), '\n Number of elements: ', m.nbcvs(),
      '\n Number of nodes: ', m.nbpts())
print(' Number of dof: ', mfu.nbdof(), '\n Element type: ',
      mfu.fem()[0].char())
コード例 #7
0
t_rg = m.outer_faces_with_direction([0,1], np.pi/180)
in_rg = m.outer_faces_in_box([-1e-6,H1+H2-1e-6],[W1+1e-6,H1+H2+1e-6])
out_rg = m.outer_faces_in_box([W1+W2-1e-6,-1e-6],[W1+W2+1e-6,H2+1e-6])
m.set_region(IN_RG, in_rg)
m.set_region(OUT_RG, out_rg)
m.extend_region(INOUT_RG, in_rg)
m.extend_region(INOUT_RG, out_rg)

m.extend_region(WALL_RG, l_rg)
m.extend_region(WALL_RG, b_rg)
m.extend_region(WALL_RG, r_rg)
m.extend_region(WALL_RG, t_rg)
m.region_subtract(WALL_RG, INOUT_RG)

#MeshFem
mfv_ = gf.MeshFem(m, 2)
mfv_.set_classical_fem(2)
kept_dofs = np.setdiff1d(np.arange(mfv_.nb_basic_dof()),
                         mfv_.basic_dof_on_region(WALL_RG))
mfv = gf.MeshFem("partial", mfv_, kept_dofs)

mfp_ = gf.MeshFem(m, 1)
mfp_.set_classical_fem(1)
kept_dofs = np.setdiff1d(np.arange(mfp_.nb_basic_dof()),
                         mfp_.basic_dof_on_region(OUT_RG))
mfp = gf.MeshFem("partial", mfp_, kept_dofs)

mim = gf.MeshIm(m, 5) # 9 gauss points per quad

md = gf.Model("real")
md.add_fem_variable("v", mfv)
コード例 #8
0
def import_fem(sico):
    """ Build a mesh object using getfem.
    
    We use getfem++ to build the finite element model and
    to fill in the operators required by siconos:
    - the mass matrix (Mass)
    - the stiffness matrix (Stiff)
    - the matrix that links global coordinates and local coord. at contact points (H)
    
    """
    ############################
    # The geometry and the mesh
    ############################
    dimX = 10.01
    dimY = 10.01
    dimZ = 3.01
    stepX = 1.0
    stepY = 1.0
    stepZ = 1.0
    x = np.arange(0, dimX, stepX)
    y = np.arange(0, dimY, stepY)
    z = np.arange(0, dimZ, stepZ)
    m = gf.Mesh('regular simplices', x, y, z)
    m.set('optimize_structure')
    # Export the mesh to vtk
    m.export_to_vtk("BlockMesh.vtk")

    # Create MeshFem objects
    # (i.e. assign elements onto the mesh for each variable)
    mfu = gf.MeshFem(m, 3)  # displacement
    mfd = gf.MeshFem(m, 1)  # data
    mff = gf.MeshFem(m, 1)  # for plot von-mises
    # assign the FEM
    mfu.set_fem(gf.Fem('FEM_PK(3,1)'))
    mfd.set_fem(gf.Fem('FEM_PK(3,0)'))
    mff.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,1,0.01)'))
    # mfu.export_to_vtk("BlockMeshDispl.vtk")

    # Set the integration method
    mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))

    # Summary
    print(' ==================================== \n Mesh details: ')
    print(' Problem dimension:', mfu.qdim(), '\n Number of elements: ',
          m.nbcvs(), '\n Number of nodes: ', m.nbpts())
    print(' Number of dof: ', mfu.nbdof(), '\n Element type: ',
          mfu.fem()[0].char())
    print(' ====================================')

    ###########################
    # Set the parameters
    # for the constitutive law
    ###########################
    E = 1e3  # Young modulus
    Nu = 0.3  # Poisson coef.
    # Lame coeff.
    Lambda = E * Nu / ((1 + Nu) * (1 - 2 * Nu))
    Mu = E / (2 * (1 + Nu))
    # Density
    Rho = 1.0  #7.800
    Gravity = -9.81
    ############################
    # Boundaries detection
    ############################
    allPoints = m.pts()
    # Bottom points and faces
    cbot = (abs(allPoints[2, :]) < 1e-6)
    pidbot = np.compress(cbot, list(range(0, m.nbpts())))
    fbot = m.faces_from_pid(pidbot)
    BOTTOM = 1
    m.set_region(BOTTOM, fbot)
    # Top points and faces
    ctop = (abs(allPoints[2, :]) > dimZ - stepZ)
    pidtop = np.compress(ctop, list(range(0, m.nbpts())))
    ftop = m.faces_from_pid(pidtop)
    TOP = 2
    m.set_region(TOP, ftop)
    # Top-Left points and faces
    cleft = (abs(allPoints[1, :]) < 1e-6)
    clefttop = cleft * ctop
    pidlefttop = np.compress(clefttop, list(range(0, m.nbpts())))
    flefttop = m.faces_from_pid(pidlefttop)
    pidleft = np.compress(cleft, list(range(0, m.nbpts())))
    fleft = m.faces_from_pid(pidleft)
    LEFTTOP = 3
    m.set_region(LEFTTOP, flefttop)
    LEFT = 4
    m.set_region(LEFT, fleft)

    # Create a model
    md = gf.Model('real')
    md.add_fem_variable('u', mfu)
    md.add_initialized_data('lambda', Lambda)
    md.add_initialized_data('mu', Mu)
    md.add_initialized_data('source_term', [0, 0, -100])
    md.add_initialized_data('push', [0, 100, 0])
    md.add_initialized_data('rho', Rho)
    md.add_initialized_data('gravity', Gravity)
    #    Weight = np.zeros(mfu.nbdof())
    ##    Weight = []
    md.add_initialized_data('weight', [0, 0, Rho * Gravity])
    md.add_isotropic_linearized_elasticity_brick(mim, 'u', 'lambda', 'mu')
    #md.add_source_term_brick(mim,'u','source_term',TOP)
    #md.add_source_term_brick(mim,'u','push',LEFT)
    md.add_source_term_brick(mim, 'u', 'weight')
    #md.add_Dirichlet_condition_with_multipliers(mim,'u',mfu,BOTTOM)

    md.assembly()
    sico.Stiff = md.tangent_matrix()
    sico.RHS = md.rhs()
    sico.q0 = md.variable('u')
    md2 = gf.Model('real')
    md2.add_fem_variable('u', mfu)
    md2.add_initialized_data('rho', Rho)
    md2.add_mass_brick(mim, 'u', 'rho')
    md2.assembly()
    sico.Mass = md2.tangent_matrix()
    sico.nbdof = mfu.nbdof()
    sico.mfu = mfu
    sico.mesh = m
    sico.pos = np.zeros(sico.nbdof)

    sico.pos[0:sico.nbdof:3] = m.pts()[0, :]
    sico.pos[1:sico.nbdof:3] = m.pts()[1, :]
    sico.pos[2:sico.nbdof:3] = m.pts()[2, :]
    sico.K0 = np.dot(sico.Stiff.full(), sico.pos)
    sico.bot = pidbot
    # running solve...
    #md.solve()

    # post-processing
    #VM=md.compute_isotropic_linearized_Von_Mises_or_Tresca('u','lambda','mu',mff)
    # extracted solution
    #U = md.variable('u')
    # export U and VM in a pos file
    #sl = gf.Slice(('boundary',),mfu,1)
    #sl.export_to_vtk('toto.vtk', mfu, U, 'Displacement', mff, VM, 'Von Mises Stress')

    # H-Matrix
    fillH(pidbot, sico, mfu.nbdof())

    return md
コード例 #9
0
  mls.add(ls1)
  mls.add(ls2)
  mls.add(ls2)
  mls.add(ls2)
  mls.add(ls3)
mls.adapt()

#print(mls.linked_mesh())

lls = mls.levelsets()

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')
コード例 #10
0
ファイル: demo_mortar.py プロジェクト: tianhaichen/getfem
# creation of a simple cartesian mesh
m = gf.Mesh('cartesian', np.arange(0, 1 + 0.5 / NX, 1. / NX),
            np.arange(0, 1 + 0.5 / NX, 1. / NX))

(pid, idx) = m.pid_from_cvid()

P = m.pts()

is_in_circle = (P[0, :] - xc)**2 + (P[1, :] - yc)**2 <= radius**2

areap = np.zeros(idx.size - 1)
for cv in range(idx.size - 1):
    if all(is_in_circle[pid[idx[cv]:idx[cv + 1]]]):
        areap[cv] = 1

mfu = gf.MeshFem(m, 2)
mfd = gf.MeshFem(m, 1)
mfm = gf.MeshFem(m, 2)
mfdu = gf.MeshFem(m)

mim = gf.MeshIm(m, 5)

mfu.set_fem(gf.Fem('FEM_QK(2,2)'))
mfd.set_fem(gf.Fem('FEM_QK(2,1)'))
mfm.set_fem(gf.Fem('FEM_QK(2,2)'))
mfdu.set_fem(gf.Fem('FEM_QK_DISCONTINUOUS(2,2)'))

mfu.set_dof_partition(areap)

b_in = m.outer_faces(np.nonzero(areap == 1))
b_out = m.outer_faces(np.nonzero(areap == 0))
コード例 #11
0
def import_fem2(sico):
    """ Build a mesh object using getfem.
    
    We use getfem++ to build the finite element model and
    to fill in the operators required by siconos:
    - the mass matrix (Mass)
    - the stiffness matrix (Stiff)
    - the matrix that links global coordinates and local coord. at contact points (H)
    
    """
    ############################
    # The geometry and the mesh
    ############################
    dimX = 10.01
    dimY = 10.01
    dimZ = 10.01
    stepX = 1.0
    stepY = 1.0
    stepZ = 1.0
    x = np.arange(0, dimX, stepX)
    y = np.arange(0, dimY, stepY)
    z = np.arange(0, dimZ, stepZ)
    m = gf.Mesh('regular simplices', x, y, z)
    m.set('optimize_structure')
    # Export the mesh to vtk
    m.export_to_vtk("BlockMesh.vtk")

    # Create MeshFem objects
    # (i.e. assign elements onto the mesh for each variable)
    mfu = gf.MeshFem(m, 3)  # displacement
    mfd = gf.MeshFem(m, 1)  # data
    mff = gf.MeshFem(m, 1)  # for plot von-mises
    # assign the FEM
    mfu.set_fem(gf.Fem('FEM_PK(3,1)'))
    mfd.set_fem(gf.Fem('FEM_PK(3,0)'))
    mff.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,1,0.01)'))
    # mfu.export_to_vtk("BlockMeshDispl.vtk")

    # Set the integration method
    mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))

    # Summary
    print(' ==================================== \n Mesh details: ')
    print(' Problem dimension:', mfu.qdim(), '\n Number of elements: ',
          m.nbcvs(), '\n Number of nodes: ', m.nbpts())
    print(' Number of dof: ', mfu.nbdof(), '\n Element type: ',
          mfu.fem()[0].char())
    print(' ====================================')

    ###########################
    # Set the parameters
    # for the constitutive law
    ###########################
    E = 1e3  # Young modulus
    Nu = 0.3  # Poisson coef.
    # Lame coeff.
    Lambda = E * Nu / ((1 + Nu) * (1 - 2 * Nu))
    Mu = E / (2 * (1 + Nu))
    # Density
    Rho = 7800
    ############################
    # Boundaries detection
    ############################
    allPoints = m.pts()
    # Bottom points and faces
    cbot = (abs(allPoints[2, :]) < 1e-6)
    pidbot = np.compress(cbot, list(range(0, m.nbpts())))
    fbot = m.faces_from_pid(pidbot)
    BOTTOM = 1
    m.set_region(BOTTOM, fbot)
    # Top points and faces
    ctop = (abs(allPoints[2, :]) > dimZ - stepZ)
    pidtop = np.compress(ctop, list(range(0, m.nbpts())))
    ftop = m.faces_from_pid(pidtop)
    TOP = 2
    m.set_region(TOP, ftop)
    # Top-Left points and faces
    cleft = (abs(allPoints[1, :]) < 1e-6)
    clefttop = cleft * ctop
    pidlefttop = np.compress(clefttop, list(range(0, m.nbpts())))
    flefttop = m.faces_from_pid(pidlefttop)
    pidleft = np.compress(cleft, list(range(0, m.nbpts())))
    fleft = m.faces_from_pid(pidleft)
    LEFTTOP = 3
    m.set_region(LEFTTOP, flefttop)
    LEFT = 4
    m.set_region(LEFT, fleft)

    ############################
    # Assembly
    ############################
    nbd = mfd.nbdof()
    # Stiffness matrix
    sico.Stiff = gf.asm_linear_elasticity(mim, mfu, mfd,
                                          np.repeat([Lambda], nbd),
                                          np.repeat([Mu], nbd))
    # Mass matrix
    sico.Mass = Rho * gf.asm_mass_matrix(mim, mfu)
    # Right-hand side
    Ftop = gf.asm_boundary_source(TOP, mim, mfu, mfd,
                                  np.repeat([[0], [0], [-1]], nbd, 1))
    Fleft = gf.asm_boundary_source(LEFT, mim, mfu, mfd,
                                   np.repeat([[0], [10], [0]], nbd, 1))
    sico.RHS = Ftop + Fleft

    sico.nbdof = mfu.nbdof()
    sico.q0 = mfu.basic_dof_from_cvid()

    sico.bot = pidbot

    # H-Matrix
    fillH(pidbot, sico, mfu.nbdof())
    return m
コード例 #12
0
K = 1  # Degree of the finite element method
dirichlet_version = 1  # 0 = simplification, 1 = with multipliers,
# 2 = penalization
r = 1.E8  # Penalization parameter.
NX = 80  # Number of element per direction

if (quadrangles):
    m = gf.Mesh('cartesian', np.arange(0., 1. + 1. / NX, 1. / NX),
                np.arange(0., 1. + 1. / NX, 1. / NX))
else:
    m = gf.Mesh(
        'import', 'structured',
        'GT="GT_PK(2,1)";SIZES=[1,1];NOISED=0;NSUBDIV=[%d,%d];' % (NX, NX))

## Create a mesh_fem for a 2D vector field
mftheta = gf.MeshFem(m, 2)
mfu = gf.MeshFem(m, 1)
mftheta.set_classical_fem(K)
mfu.set_classical_fem(K)
mim = gf.MeshIm(m, 6)
mim_reduced = gf.MeshIm(m, 1)

## Detect the border of the mesh and assign it the boundary number 1
border = m.outer_faces()
m.set_region(1, border)

## Build the model
md = gf.Model('real')
md.add_fem_variable('u', mfu)
md.add_fem_variable('theta', mftheta)
md.add_initialized_data('E', Emodulus)
コード例 #13
0
    ULS2s = np.minimum(ULS2s, (abs(y - yc) + abs(x - xc) - R))

ls2.set_values(ULS2, ULS2s)  # '-y-x+.2') # '(y-.2)^2 - 0.04')

mls = gf.MeshLevelSet(m)
mls.add(ls)
mls.add(ls2)
mls.adapt()
mls.cut_mesh().export_to_pos('ver.pos')

mim_bound = gf.MeshIm('levelset', mls, 'boundary(a+b)',
                      gf.Integ('IM_TRIANGLE(6)'))  #, gf.Integ('IM_QUAD(5)'))
mim = gf.MeshIm('levelset', mls, 'all(a+b)', gf.Integ('IM_TRIANGLE(6)'))
mim.set_integ(4)

mfu0 = gf.MeshFem(m, 2)
mfu0.set_fem(gf.Fem('FEM_QK(2,3)'))

mfdu = gf.MeshFem(m, 1)
mfdu.set_fem(gf.Fem('FEM_QK_DISCONTINUOUS(2,2)'))

mf_mult = gf.MeshFem(m, 2)
mf_mult.set_fem(gf.Fem('FEM_QK(2,1)'))

A = gf.asm('volumic', 'V()+=comp()', mim_bound)

#mls.cut_mesh().export_to_pos('mls.pos','cut mesh')
#mf_ls.export_to_pos('mf_ls.pos',ULS,'ULS')

dof_out = mfu0.dof_from_im(mim)
cv_out = mim.convex_index()
コード例 #14
0
        print 'Experiments for option %d and order %d' % (option, order)

        for i in range(0, len(hrange)):
            NX = round(LX / hrange[i])
            NT = NX
            if (errors1[option, i, 1] < 0.):
                if (call_test_plasticity() != 0):
                    print 'Not converged solution'
                    err_L2 = 400
                    err_H1 = 400
                    exit(1)
                else:
                    # Load the final step
                    filename = resultspath + ('/mf_%d.mf' % (NT))
                    m = gf.Mesh('load', filename)
                    mf_u = gf.MeshFem('load', filename, m)
                    filename = resultspath + ('/U_%d.dat' % (NT))
                    U = np.loadtxt(filename)

                    # Load the reference solution
                    m_ref = gf.Mesh('load', refname_mf)
                    mf_u_ref = gf.MeshFem('load', refname_mf, m_ref)
                    U_ref = np.loadtxt(refname_U)
                    mim_ref = gf.MeshIm(m_ref, 6)

                    # Estimate of the difference in L2 and H1 norms
                    Ui = gf.compute_interpolate_on(mf_u, U, mf_u_ref)
                    norm_L2 = gf.compute_L2_norm(mf_u_ref, U_ref, mim_ref)
                    err_L2 = gf.compute_L2_dist(mf_u_ref, Ui, mim_ref,
                                                mf_u_ref, U_ref)
                    norm_H1 = gf.compute_H1_semi_norm(mf_u_ref, U_ref, mim_ref)
コード例 #15
0
dirichlet_boundary_B = outer_B[:,np.nonzero(normals_B[1] < -0.95)[0]]
mesh_B.set_region(CONTACT_BOUNDARY_B, contact_boundary_B)
mesh_B.set_region(DIRICHLET_BOUNDARY_B, dirichlet_boundary_B)

#pts_B = mesh_B.pts()
#for ip in range(pts_B.shape[1]):
#   x = pts_B[0,ip]
#   y = pts_B[1,ip]
#   pts_B[1,ip] = y + 0.02*x**2
#mesh_B.set_pts(pts_B)

#mesh_R.export_to_vtk('/tmp/mesh_R.vtk')
#mesh_B.export_to_vtk('/tmp/mesh_B.vtk')

# Ring
mfu_R = gf.MeshFem(mesh_R, N)
mfu_R.set_classical_fem(fem_disp_order_R)

pre_mflambda_R = gf.MeshFem(mesh_R, N)
pre_mflambda_R.set_classical_fem(fem_mult_order_R)

mfvm_R = gf.MeshFem(mesh_R)
mfvm_R.set_classical_discontinuous_fem(fem_disp_order_R-1)

mim_R = gf.MeshIm(mesh_R, integration_degree_R)
mim_R_contact = gf.MeshIm(mesh_R, integration_contact_degree_R)

# Block
mfu_B = gf.MeshFem(mesh_B, N)
mfu_B.set_classical_fem(fem_disp_order_B)
コード例 #16
0
    meshs.append(mesh)

print("Time for import mesh", time.process_time() - t)
t = time.process_time()

###############################################################################
# Definition of finite elements methods and integration method
#

mfus = []
mfds = []
mims = []

for elements_degree, mesh in zip(elements_degrees, meshs):

    mfu = gf.MeshFem(mesh, 3)
    mfu.set_classical_fem(elements_degree)
    mfus.append(mfu)

    mfd = gf.MeshFem(mesh, 1)
    mfd.set_classical_fem(elements_degree)
    mfds.append(mfd)

    mim = gf.MeshIm(mesh, elements_degree * 2)
    mims.append(mim)

###############################################################################
# We get the mass and stiffness matrices using asm function.
#

mass_matrixs = []
コード例 #17
0
# (at your option) any later version.
# This program  is  distributed  in  the  hope  that it will be useful,  but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or  FITNESS  FOR  A PARTICULAR PURPOSE.  See the GNU Lesser General Public
# License for more details.
# 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.
#
############################################################################
from numpy import *

import getfem
import getfem_tvtk

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..")
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)
コード例 #18
0
    [0., -1.], 0.01)  # Bottom boundary of the foundation

HOLE_BOUND = 1
CONTACT_BOUND = 2
BOTTOM_BOUND = 3

mesh1.set_region(HOLE_BOUND, fb1)
mesh1.set_region(CONTACT_BOUND, fb2)
mesh1.region_subtract(CONTACT_BOUND, HOLE_BOUND)
mesh2.set_region(BOTTOM_BOUND, fb3)

#
# Definition of finite elements methods and integration method
#

mfu1 = gf.MeshFem(mesh1, 2)
mfu1.set_classical_fem(elements_degree)
mflambda = gf.MeshFem(mesh1, 2)
mflambda.set_classical_fem(elements_degree - 1)
mflambda_C = gf.MeshFem(mesh1, 1)
mflambda_C.set_classical_fem(elements_degree - 1)
mfu2 = gf.MeshFem(mesh2, 2)
mfu2.set_classical_fem(elements_degree)
mfvm1 = gf.MeshFem(mesh1, 1)
mfvm1.set_classical_discontinuous_fem(elements_degree)
mfvm2 = gf.MeshFem(mesh2, 1)
mfvm2.set_classical_discontinuous_fem(elements_degree)
mim1 = gf.MeshIm(mesh1, 4)
mim1c = gf.MeshIm(mesh1, gf.Integ('IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(4),2)'))
mim2 = gf.MeshIm(mesh2, 4)
コード例 #19
0
test_tangent_matrix = False    # Test or not tangent system validity
incompressible = False;        # Incompressibility option
explicit_potential = False;    # Elasticity law with explicit potential

# lawname = 'Ciarlet Geymonat'
# params = [1.,1.,0.25]
lawname = 'SaintVenant Kirchhoff'
params = [1.,1.]
if (incompressible):
    lawname = 'Incompressible Mooney Rivlin'
    params = [1.,1.]

N1 = 2; N2 = 4; h = 20.; DX = 1./N1; DY = (1.*h)/N2;
m = gf.Mesh('cartesian', np.arange(-0.5, 0.5+DX,DX), np.arange(0., h+DY,DY),
            np.arange(-1.5, 1.5+3*DX,3*DX))
mfu  = gf.MeshFem(m, 3)            # mesh-fem supporting a 3D-vector field
mfdu = gf.MeshFem(m,1)
# The mesh_im stores the integration methods for each tetrahedron
mim = gf.MeshIm(m, gf.Integ('IM_GAUSS_PARALLELEPIPED(3,4)'))
# We choose a P2 fem for the main unknown
mfu.set_fem(gf.Fem('FEM_QK(3,2)'))

if (dirichlet_version == 1):
  mfd = mfu;
else:
  mfd = gf.MeshFem(m,1)
  mfd.set_fem(gf.Fem('FEM_QK(3,1)'))

# The P2 fem is not derivable across elements, hence we use a discontinuous
# fem for the derivative of U.
mfdu.set_fem(gf.Fem('FEM_QK_DISCONTINUOUS(3,2)'));
コード例 #20
0
    m_p3.region_merge(RG_CONTACT_p3_in, 500043 + 100 * i)
    m_p3.region_merge(RG_CONTACT_p3_in, 500083 + 100 * i)
    m_p3.region_merge(RG_CONTACT_p3_out, 500013 + 100 * i)
    m_p3.region_merge(RG_CONTACT_p3_out, 500053 + 100 * i)

m_p1.region_merge(RG_CONTACT_p1, RG_CONTACT_p1_in)
m_p1.region_merge(RG_CONTACT_p1, RG_CONTACT_p1_out)
m_p2.region_merge(RG_CONTACT_p2, RG_CONTACT_p2_in)
m_p2.region_merge(RG_CONTACT_p2, RG_CONTACT_p2_out)
m_p3.region_merge(RG_CONTACT_p3, RG_CONTACT_p3_in)
m_p3.region_merge(RG_CONTACT_p3, RG_CONTACT_p3_out)

N = m_1.dim()

# displacement meshfems
mfu_1 = gf.MeshFem(m_1, N)
mfu_2 = gf.MeshFem(m_2, N)
mfu_p1 = gf.MeshFem(m_p1, N)
mfu_p2 = gf.MeshFem(m_p2, N)
mfu_p3 = gf.MeshFem(m_p3, N)
mfu_1.set_classical_fem(disp_fem_order)
mfu_2.set_classical_fem(disp_fem_order)
mfu_p1.set_classical_fem(disp_fem_order)
mfu_p2.set_classical_fem(disp_fem_order)
mfu_p3.set_classical_fem(disp_fem_order)

# rhs meshfems
mfout_1 = gf.MeshFem(m_1, 1)
mfout_2 = gf.MeshFem(m_2, 1)
mfout_p1 = gf.MeshFem(m_p1, 1)
mfout_p2 = gf.MeshFem(m_p2, 1)
コード例 #21
0
  This program is used to check that Python-GetFEM interface, and more
  generally GetFEM are working. It focuses on testing some operations
  of the high generic assembly language.

  $Id$
"""
import numpy as np
import getfem as gf
import os

NX = 4

m1 = gf.Mesh('cartesian', np.arange(0, 1 + 1. / NX,
                                    1. / NX))  # Structured 1D mesh
mfu1 = gf.MeshFem(m1, 1)
mfu1.set_fem(gf.Fem('FEM_PK(1,1)'))
mim1 = gf.MeshIm(m1, gf.Integ('IM_GAUSS1D(4)'))
U1 = mfu1.eval('x')

m2 = gf.Mesh('triangles grid', np.arange(0, 1 + 1. / NX, 1. / NX),
             np.arange(0, 1 + 1. / NX, 1. / NX))  # Structured 2D mesh
mfu2 = gf.MeshFem(m2, 1)
mfu2.set_fem(gf.Fem('FEM_PK(2,1)'))
mim2 = gf.MeshIm(m2, gf.Integ('IM_TRIANGLE(4)'))
U2 = mfu2.eval('x+y')

md = gf.Model('real')

md.add_fem_variable('u1', mfu1)
md.set_variable('u1', U1)
コード例 #22
0
NX = 20  # Mesh parameter.
N = 2
Dirichlet_with_multipliers = True  # Dirichlet condition with multipliers
# or penalization
dirichlet_coefficient = 1e10  # Penalization coefficient
using_HHO = True  # Use HHO method or standard Lagrange FEM

# Create a simple cartesian mesh
I = np.arange(0, 1 + 1. / NX, 1. / NX)
if (N == 2):
    m = gf.Mesh('regular_simplices', I, I)
elif (N == 3):
    m = gf.Mesh('regular_simplices', I, I, I)

# Meshfems
mfu = gf.MeshFem(m, 1)
mfgu = gf.MeshFem(m, N)
mfur = gf.MeshFem(m, 1)
mfrhs = gf.MeshFem(m, 1)

if (using_HHO):
    mfu.set_fem(
        gf.Fem('FEM_HHO(FEM_SIMPLEX_IPK(%d,2),FEM_SIMPLEX_CIPK(%d,2))' %
               (N, N - 1)))
    mfur.set_fem(gf.Fem('FEM_PK(%d,3)' % N))
else:
    mfu.set_fem(gf.Fem('FEM_PK(%d,2)' % N))
    mfur.set_fem(gf.Fem('FEM_PK(%d,2)' % N))

mfgu.set_fem(gf.Fem('FEM_PK(%d,2)' % N))
mfrhs.set_fem(gf.Fem('FEM_PK(%d,2)' % N))
コード例 #23
0
m.export_to_vtk("mesh.vtk")

# Levelset definition:
R1 = 2.5
R2 = 16
ytip = R1
xtip = np.sqrt(R2 * R2 - R1 * R1)
ls1 = gf.LevelSet(m, 2, "y-%g*tanh(x/7.)" % R1, "x*x+y*y-%g" % (R2 * R2))
ls2 = gf.LevelSet(m, 2, "y+%g*tanh(x/7.)" % R1, "x*x+y*y-%g" % (R2 * R2))
mls = gf.MeshLevelSet(m)
mls.add(ls1)
mls.add(ls2)
mls.adapt()

# Basic mesh_fem without enrichment:
mf_pre = gf.MeshFem(m)
if (quad):
    mf_pre.set_fem(gf.Fem("FEM_QK(2,2)"))
else:
    mf_pre.set_fem(gf.Fem("FEM_PK(2,2)"))

# Definition of the enriched finite element method (MeshFemLevelSet):
mfls = gf.MeshFem("levelset", mls, mf_pre)

# Global functions for asymptotic enrichment:
mf_part_unity = gf.MeshFem(m)
mf_part_unity.set_classical_fem(1)
DOFpts = mf_part_unity.basic_dof_nodes()
ctip_dofs = [
    np.nonzero(np.linalg.norm(DOFpts - x, axis=0) < 0.5)[0]
    for x in [[[xtip], [-ytip]], [[-xtip], [ytip]], [[xtip], [ytip]],
コード例 #24
0
fb2 = mesh.outer_faces_with_direction([0., -1.], 0.01)  # Bottom (Neumann)
fb3 = mesh.outer_faces_in_box([-1., 10.], [101., 101.])
fb4 = mesh.outer_faces_in_box([10., -1.], [101., 101.])
LEFT_BOUND = 1
BOTTOM_BOUND = 2
AUX_BOUND1 = 3
AUX_BOUND2 = 4
mesh.set_region(LEFT_BOUND, fb1)
mesh.set_region(BOTTOM_BOUND, fb2)
mesh.set_region(AUX_BOUND1, fb3)
mesh.set_region(AUX_BOUND2, fb4)
mesh.region_subtract(LEFT_BOUND, AUX_BOUND2)
mesh.region_subtract(BOTTOM_BOUND, AUX_BOUND1)

# Create a MeshFem for u and rhs fields of dimension 1 (i.e. a scalar field)
mfu = gf.MeshFem(mesh, 1)
mfP0 = gf.MeshFem(mesh, 1)
# Assign the discontinuous P2 fem to all convexes of the both MeshFem
mfu.set_fem(gf.Fem('FEM_PK(2,2)'))
mfP0.set_fem(gf.Fem('FEM_PK(2,0)'))

# Integration method used
mim = gf.MeshIm(mesh, gf.Integ('IM_TRIANGLE(4)'))

# Inner edges for the computation of the normal derivative jump
in_faces = mesh.inner_faces()
INNER_FACES = 18
mesh.set_region(INNER_FACES, in_faces)

# Model
md = gf.Model('real')
コード例 #25
0
ファイル: demo_phase_field.py プロジェクト: tkoyama010/getfem
N = mesh.dim()

bottom_faces = mesh.outer_faces_in_box([-LX / 2 - 1e-5, -LY / 2 - 1e-5],
                                       [LX / 2 + 1e-5, -LY / 2 + 1e-5])
top_faces = mesh.outer_faces_in_box([-LX / 2 - 1e-5, LY / 2 - 1e-5],
                                    [LX / 2 + 1e-5, LY / 2 + 1e-5])

mesh.set_region(B_BOUNDARY, bottom_faces)
mesh.set_region(T_BOUNDARY, top_faces)
mesh.region_merge(TB_BOUNDARY, T_BOUNDARY)
mesh.region_merge(TB_BOUNDARY, B_BOUNDARY)

mesh.export_to_vtk("%s/mesh.vtk" % resultspath)

# FEM
mfu = gf.MeshFem(mesh, N)
mfu.set_classical_fem(disp_fem_order)

mfdir = mfu

mfphi = gf.MeshFem(mesh, 1)
mfphi.set_classical_fem(phi_fem_order)

mfout = gf.MeshFem(mesh)
mfout.set_classical_discontinuous_fem(2)

# Integration method
mim = gf.MeshIm(mesh, integration_degree)
mimd1 = gf.MeshImData(mim, -1)

# Model
コード例 #26
0
ファイル: tutorial1.py プロジェクト: tianhaichen/getfem
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or  FITNESS  FOR  A PARTICULAR PURPOSE.  See the GNU Lesser General Public
# License and GCC Runtime Library Exception for more details.
# 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 numpy as np

import getfem as gf

NX = 10
m = gf.Mesh('cartesian', np.arange(0,1+1./NX,1./NX), np.arange(0,1+1./NX,1./NX))
mf = gf.MeshFem(m,1) # create a meshfem of for a field of dimension 1
mf.set('fem',gf.Fem('FEM_QK(2,2)'))

print (gf.Fem('FEM_QK(2,2)').poly_str())

# mim=gf.MeshIm(m, gf.Integ('IM_EXACT_PARALLELEPIPED(2)')); // not allowed
mim=gf.MeshIm(m, gf.Integ('IM_GAUSS_PARALLELEPIPED(2, 4)'));


border = m.outer_faces()
m.set_region(42, border)  # create the region B42 (:-


md=gf.Model('real')
md.add_fem_variable('u', mf)
md.add_Laplacian_brick(mim, 'u')
コード例 #27
0
ファイル: check_mixed_mesh.py プロジェクト: ytakzk/getfem
    elif str(gt[0])=='GT_PRISM(3,1)':
        #print 'index of PRISM: ', i
        listPrism.append(i)
    elif str(gt[0])=='GT_QK(3,1)':
        #print 'index of HEXA: ', i
        listHexa.append(i)
    else:
        print('Geometric transformation: ', gt[0])

print('num Tetra: ', len(listTetra))
print('num Hexa: ', len(listHexa))
print('num Hexa: ', len(listHexa))
print('num Hexa: ', len(listHexa))


mfu = gf.MeshFem(m, 3)

mfu.set_fem(gf.Fem('FEM_QK(3,{d})'.format(d=degree)),listHexa)
mfu.set_fem(gf.Fem('FEM_PYRAMID_LAGRANGE({d})'.format(d=degree)),listPyramid)
mfu.set_fem(gf.Fem('FEM_PK_PRISM(3,{d})'.format(d=degree)),listPrism)
mfu.set_fem(gf.Fem('FEM_PK(3,{d})'.format(d=degree)),listTetra)

mim = gf.MeshIm(m, 3)


# Model
md = gf.Model('real')
md.add_fem_variable('u',mfu)
md.add_initialized_data('mu_para', Mu)
md.add_initialized_data('lambda_para', Lambda)
md.add_linear_generic_assembly_brick(mim,"lambda_para*Div_u*Div_Test_u + 2*mu_para*Sym(Grad_u):Grad_Test_u")
コード例 #28
0
ファイル: demo_plate.py プロジェクト: tianhaichen/getfem
  This program is used to check that python-getfem is working. This is
  also a good example of use of GetFEM++.

  $Id$
"""
import numpy as np

import getfem as gf

NX = 10.0
thickness = 0.01
f = -5. * pow(thickness, 3.)

m = gf.Mesh('regular simplices', np.arange(0, 1.01, 1 / NX),
            np.arange(0, 1.01, 1 / NX))
mfu3 = gf.MeshFem(m, 1)
mfth = gf.MeshFem(m, 2)
mfd = gf.MeshFem(m, 1)

mfu3.set_fem(gf.Fem('FEM_PK(2,1)'))
mfth.set_fem(gf.Fem('FEM_PK(2,2)'))
mfd.set_fem(gf.Fem('FEM_PK(2,2)'))

mim = gf.MeshIm(m, gf.Integ('IM_TRIANGLE(5)'))

#get the list of faces whose normal is [-1,0]
flst = m.outer_faces()
fnor = m.normal_of_faces(flst)
fleft = np.compress(abs(fnor[1, :] + 1) < 1e-14, flst, axis=1)
fright = np.compress(abs(fnor[1, :] - 1) < 1e-14, flst, axis=1)
CLAMPED_BOUNDARY = 1
コード例 #29
0
try:
    import getfem_tvtk
except:
    print "\n** Could NOT import getfem_tvtk -- graphical output disabled **\n"
    import time
    time.sleep(2)
    with_graphics = False

L = 100
H = 20

m = gf.Mesh('triangles grid', np.arange(0, L + 0.01, 4),
            np.arange(0, H + 0.01, 2))

mim = gf.MeshIm(m, gf.Integ('IM_TRIANGLE(6)'))
mfu = gf.MeshFem(m, 2)
mfsigma = gf.MeshFem(m, 4)
mfd = gf.MeshFem(m)
mf0 = gf.MeshFem(m)
mfdu = gf.MeshFem(m)

mfu.set_fem(gf.Fem('FEM_PK(2,1)'))
mfsigma.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(2,1)'))
mfd.set_fem(gf.Fem('FEM_PK(2,1)'))
mf0.set_fem(gf.Fem('FEM_PK(2,0)'))
mfdu.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(2,1)'))

Lambda = 121150
Mu = 80769
von_mises_threshold = 4000
コード例 #30
0
        0, .5, 1, 0, .5, 1, 0, .5, 1, 0, .5, 1, 0, .5, 1, 0, .5, 1, 0, .5, 1,
        0, .5, 1, 0, .5, 1
    ]) - 1.5,
    np.array([
        0, 0, 0, .5, .5, .5, 1, 1, 1, 0, 0, 0, .5, .5, .5, 1, 1, 1, 0, 0, 0,
        .5, .5, .5, 1, 1, 1
    ]) - 1,
    np.array([
        0, 0, 0, 0, 0, 0, 0, 0, 0, .5, .5, .5, .5, .5, .5, .5, .5, .5, 1, 1, 1,
        1, 1, 1, 1, 1, 1
    ])
])

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: