コード例 #1
0
 def __init__(self, point_coords, element_nodes, spring_constant=1.):
     self.pts = array(point_coords, copy=1)
     self.elnodes = array(element_nodes, copy=1)
     self.npts = len(self.pts)
     self.nels = len(self.elnodes)
     self.mesh = gf.Mesh('empty', 2)
     for i in range(self.npts):
         self.mesh.add_point(self.pts[i, :])
     for i in range(self.nels):
         self.mesh.add_convex(gf.GeoTrans('GT_PK(1,1)'),
                              transpose(self.pts[self.elnodes[i, :]]))
     self.fem = gf.MeshFem(self.mesh)
     self.ptdm = zeros(
         (self.npts, 2), dtype=int
     )  # point-to-dof-map i.e. rhs=self.model.rhs() then rhs[ptdm[p,i]] applies to point p and coordinate axis i
     self.fem.set_qdim(2)
     self.fem.set_classical_fem(1)
     # classic means Lagrange polynomial
     self.mim = gf.MeshIm(self.mesh, gf.Integ('IM_GAUSS1D(2)'))
     self.model = gf.Model('real')  # 2D model variable U is of real value
     self.EA = spring_constant  # stiffness k = E*A
     self.model.add_initialized_data(
         'lambda', self.EA)  # define Lame coefficients lambda and mu
     self.model.add_initialized_data('mu', 0)
     # define Lame coefficients lambda and mu
     self.model.add_fem_variable('U', self.fem)
     self.model.add_isotropic_linearized_elasticity_brick(
         self.mim, 'U', 'lambda', 'mu')
     self.nreg = 0  # how many regions are defined on the mesh
     self.fixreg = 0  # how many regions have been created for the purpose of fixing nodes
     self.loadreg = 0  # how many regions have been created for the purpose of loading nodes
     self.s_pts = zeros((self.npts, 2))  # shifted points
     self.lengths = zeros(self.nels)  # element lengths
     self.s_lengths = zeros(
         self.nels)  # element lengths in deformed geometry
     self.elong = zeros(self.nels)  # element elongation factor
     self.p_elong = zeros(self.nels)  # element percentage of elongation
     self.delta_l = zeros(self.nels)  # element length differences
     self.thescore = 0
コード例 #2
0
import getfem as gf
import numpy as np

# creation of a simple cartesian mesh
m = gf.Mesh('cartesian', np.arange(0,1.1,0.1), np.arange(0,1.1,0.1))

# create a MeshFem of for a field of dimension 1 (i.e. a scalar field)
mf = gf.MeshFem(m, 1)
# assign the Q2 fem to all convexes of the MeshFem
mf.set_fem(gf.Fem('FEM_QK(2,2)'))

# view the expression of its basis functions on the reference convex
print gf.Fem('FEM_QK(2,2)').poly_str()

# an exact integration will be used
mim = gf.MeshIm(m, gf.Integ('IM_EXACT_PARALLELEPIPED(2)'))

# detect the border of the mesh
border = m.outer_faces()
# mark it as boundary #42
m.set_region(42, border)

# empty real model
md = gf.Model('real')

# declare that "u" is an unknown of the system
# on the finite element method `mf`
md.add_fem_variable('u', mf)

# add generic elliptic brick on "u"
md.add_Laplacian_brick(mim, 'u');
コード例 #3
0
# create a Mesh object (importing)
m = gf.Mesh('import', 'gid', file_msh)
m.set('optimize structure')

# create a MeshFem object
mfu = gf.MeshFem(m, 3)  # displacement
mfd = gf.MeshFem(m, 1)  # data
mfe = gf.MeshFem(m, 1)  # for plot von-mises
# assign the FEM
mfu.set_fem(gf.Fem('FEM_PK(3,%d)' % (degree, )))
mfd.set_fem(gf.Fem('FEM_PK(3,0)'))
mfe.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,%d,0.01)' % (degree, )))

# build a MeshIm object
mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))

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

# detect some boundary of the mesh
P = m.pts()
ctop = (abs(P[1, :] - 13) < 1e-6)
cbot = (abs(P[1, :] + 10) < 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)
# create boundary region
NEUMANN_BOUNDARY = 1
DIRICHLET_BOUNDARY = 2
コード例 #4
0
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')

# Main unknown
md.add_fem_variable('u', mfu)

# Laplacian term on u
md.add_Laplacian_brick(mim, 'u')
コード例 #5
0
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

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
コード例 #6
0
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)
print "create boundary region"
NEUMANN_BOUNDARY = 1
DIRICHLET_BOUNDARY = 2
m.set_region(NEUMANN_BOUNDARY, ftop)
m.set_region(DIRICHLET_BOUNDARY, fbot)
コード例 #7
0
    gf.MeshFem("product", mf_part_unity,
               gf.MeshFem("global function", m, ls, ck, 1))
    for ls in [ls1, ls2]
]
mf_sing[0].set_enriched_dofs(np.union1d(ctip_dofs[0], ctip_dofs[1]))
mf_sing[1].set_enriched_dofs(np.union1d(ctip_dofs[2], ctip_dofs[3]))
mf_u = gf.MeshFem("sum", mf_sing[0], mf_sing[1], mfls)
mf_u.set_qdim(2)

mf_theta = gf.MeshFem("sum", mf_sing[0], mf_sing[1], mfls)

# MeshIm definition (MeshImLevelSet):
if (quad):
    mim = gf.MeshIm(
        "levelset", mls, "all",
        gf.Integ("IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),5)"),
        gf.Integ("IM_STRUCTURED_COMPOSITE(IM_GAUSS_PARALLELEPIPED(2,6),9)"),
        gf.Integ("IM_GAUSS_PARALLELEPIPED(2,4)"))
else:
    mim = gf.MeshIm(
        "levelset", mls, "all",
        gf.Integ("IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),3)"),
        gf.Integ("IM_STRUCTURED_COMPOSITE(IM_GAUSS_PARALLELEPIPED(2,6),9)"),
        gf.Integ("IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),5)"))

mim_bound = [
    gf.MeshIm("levelset", mls, boundary,
              gf.Integ("IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),3)"))
    for boundary in ["boundary(a)", "boundary(b)"]
]
コード例 #8
0
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)
md.add_fem_data("v0", mfv)
md.add_fem_variable("p", mfp)
md.add_fem_data("p_in", mfp_)
md.add_initialized_data("f", [0,0])
md.add_initialized_data("dt", [dt])
md.add_initialized_data("nu", [nu])

md.add_Dirichlet_condition_with_multipliers(mim, "p", mfp, IN_RG, "p_in")
md.add_nonlinear_term\
(mim, "1/dt*(v-v0).Test_v + (Grad_v0*v0).Test_v + nu*Grad_v:Grad_Test_v - f.Test_v")
md.add_nonlinear_term\
(mim, "Grad_p.Grad_Test_p + 1/dt*Trace(Grad_v)*Test_p")
コード例 #9
0
ファイル: demo_mortar.py プロジェクト: tianhaichen/getfem
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))
b_border = m.outer_faces()
b_out = np.array(
    tuple(
        set(tuple(r) for r in b_out.transpose()) -
        set(tuple(r) for r in b_border.transpose()))).transpose()
コード例 #10
0
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)
md.add_initialized_data('nu', nu)
md.add_initialized_data('epsilon', epsilon)
md.add_initialized_data('kappa', kappa)
コード例 #11
0
    n = [-np.sin(theta), np.cos(theta)]

    R = 0.19  #rand() * 0.09 + 0.02
    ULS2 = np.minimum(ULS2, ((x - xc) * n[0] + (y - yc) * n[1]))
    #ULS2s = np.minimum(ULS2s, ((x - xc)**2 + (y - yc)**2) - R**2)
    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')
コード例 #12
0
                    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)
                    norm_H1 = np.sqrt(pow(norm_L2, 2) + pow(norm_H1, 2))
                    err_H1 = gf.compute_H1_semi_dist(mf_u_ref, Ui, mim_ref,
                                                     mf_u_ref, U_ref)

                print 'Error in L2 norm: %g' % err_L2
                print 'Error in H1 semi-norm: %g' % err_H1
                errors1[option, i, 0] = err_L2 / norm_L2
                errors1[option, i,
コード例 #13
0
            np.square(DOFpts[1, :] + 0.375) <= 0.1**2)[0]
        mf_sing_u2 = gf.MeshFem('global function', m, ls2,
                                [ck0, ck1, ck2, ck3], 1)
        mf_xfem_sing2 = gf.MeshFem('product', mf_part_unity, mf_sing_u2)
        mf_xfem_sing2.set_enriched_dofs(np.union1d(Idofs_up, Idofs_down))
    if variant == 2:
        mf_u = gf.MeshFem('sum', mf_xfem_sing, mfls_u)
    else:
        mf_u = gf.MeshFem('sum', mf_xfem_sing, mf_xfem_sing2, mfls_u)

mf_u.set_qdim(2)

# MeshIm definition (MeshImLevelSet):
mim = gf.MeshIm(
    'levelset', mls, 'all',
    gf.Integ('IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),3)'),
    gf.Integ('IM_STRUCTURED_COMPOSITE(IM_GAUSS_PARALLELEPIPED(2,6),9)'),
    gf.Integ('IM_STRUCTURED_COMPOSITE(IM_TRIANGLE(6),5)'))

# Exact solution for a single crack:
mf_ue = gf.MeshFem('global function', m, ls, [ck0, ck1, ck2, ck3])
A = 2 + 2 * Mu / (Lambda + 2 * Mu)
B = -2 * (Lambda + Mu) / (Lambda + 2 * Mu)
Ue = np.zeros([2, 4])
Ue[0, 0] = 0
Ue[1, 0] = A - B  # sin(theta/2)
Ue[0, 1] = A + B
Ue[1, 1] = 0  # cos(theta/2)
Ue[0, 2] = -B
Ue[1, 2] = 0  # sin(theta/2)*sin(theta)
Ue[0, 3] = 0
コード例 #14
0
if test_case >= 2:
    mesh1.set_region(CONTACT_BOUNDARY1, border)
else:
    normals = mesh1.normal_of_faces(border)
    contact_boundary = border[:, np.nonzero(normals[N - 1] < -0.01)[0]]
    mesh1.set_region(CONTACT_BOUNDARY1, contact_boundary)
    P = mesh1.pts()  # get list of mesh points coordinates
    ctop = (P[N - 1, :] > 39.999)  # find those on top of the object
    pidtop = np.compress(ctop, list(range(0, mesh1.nbpts())))
    ftop = mesh1.faces_from_pid(pidtop)
    mesh1.set_region(DIRICHLET_BOUNDARY1, ftop)

# dol1 = pre_mflambda1.basic_dof_on_region(CONTACT_BOUNDARY1)
# mflambda1 = gf.MeshFem("partial", pre_mflambda1, dol1)

mim1 = gf.MeshIm(mesh1, 4)
mim1_contact = gf.MeshIm(mesh1, 4)

if test_case not in [0, 3]:
    mfu2 = gf.MeshFem(mesh2, N)
    mfu2.set_classical_fem(2)

    pre_mflambda2 = gf.MeshFem(mesh2, N)
    pre_mflambda2.set_classical_fem(1)

    mfvm2 = gf.MeshFem(mesh2)
    mfvm2.set_classical_discontinuous_fem(1)

    CONTACT_BOUNDARY2 = 2
    border = mesh2.outer_faces()
    if test_case != 1:
コード例 #15
0
if (export_mesh):
    mesh.export_to_vtk('mesh.vtk');
    print ('\nYou can view the mesh for instance with');
    print ('mayavi2 -d mesh.vtk -f ExtractEdges -m Surface \n');

#
# Definition of finite elements methods and integration method
#

mfu = gf.MeshFem(mesh, 2)  # Finite element for the elastic displacement
mfu.set_classical_fem(elements_degree)
mft = gf.MeshFem(mesh, 1)  # Finite element for temperature and electrical field
mft.set_classical_fem(elements_degree)
mfvm = gf.MeshFem(mesh, 1) # Finite element for Von Mises stress interpolation
mfvm.set_classical_discontinuous_fem(elements_degree)
mim = gf.MeshIm(mesh, pow(elements_degree,2))   # Integration method


#
# Model definition
#

md=gf.Model('real');
md.add_fem_variable('u', mfu)       # Displacement of the structure
md.add_fem_variable('theta', mft)   # Temperature
md.add_fem_variable('V', mft)       # Electric potential

# Membrane elastic deformation
md.add_initialized_data('cmu', [cmu])
md.add_initialized_data('clambdastar', [clambdastar])
md.add_isotropic_linearized_elasticity_brick(mim, 'u', 'clambdastar', 'cmu')
コード例 #16
0
#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)

pre_mflambda_B = gf.MeshFem(mesh_B, N)
pre_mflambda_B.set_classical_fem(fem_mult_order_B)

mfvm_B = gf.MeshFem(mesh_B)
mfvm_B.set_classical_discontinuous_fem(fem_disp_order_B-1)

mim_B = gf.MeshIm(mesh_B, integration_degree_B)
mim_B_contact = gf.MeshIm(mesh_B, integration_contact_degree_B)
コード例 #17
0
# 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)'));

# Display some information about the mesh
print('nbcvs=%d, nbpts=%d, nbdof=%d' % (m.nbcvs(), m.nbpts(), mfu.nbdof()))
コード例 #18
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
コード例 #19
0
  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)
md.add_fem_variable('u2', mfu2)
md.set_variable('u2', U2)
コード例 #20
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
コード例 #21
0
ファイル: demo_phase_field.py プロジェクト: tkoyama010/getfem
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
md = gf.Model("real")

md.add_fem_variable("u", mfu)  # displacements
md.add_fem_variable("phi", mfphi)  # phase field

md.add_fem_data("u_stored", mfu)
md.add_fem_data("phi_stored", mfphi)

md.add_im_data("psi0_max", mimd1)

md.add_initialized_data("kappa", E / (3. * (1. - 2. * nu)))
md.add_initialized_data("mu", E / (2 * (1 + nu)))
コード例 #22
0
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 = []
linear_elasticitys = []

for i, (mfu, mfd, mim) in enumerate(zip(mfus, mfds, mims)):

    mass_matrix = gf.asm_mass_matrix(mim, mfu, mfu)
    mass_matrix.scale(rho)
    mass_matrixs.append(mass_matrix)
コード例 #23
0
ファイル: check_mixed_mesh.py プロジェクト: ytakzk/getfem
        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")
md.add_initialized_data('Fdata',[0.0,-1.0, 0.0])
md.add_source_term_brick(mim, 'u', 'Fdata', NEUMANN_BOUNDARY)
md.add_initialized_data('DirichletData', [0, 0, 0])
md.add_Dirichlet_condition_with_simplification('u', DIRICHLET_BOUNDARY,'DirichletData')

md.solve('max_res', 1E-9, 'max_iter', 100, 'noisy', 'lsearch', 'simplest',  'alpha min', 0.8)
U = md.variable('u');
コード例 #24
0
# 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)

#
# Model definition
#

md = gf.Model('real')
md.add_fem_variable('u1', mfu1)  # Displacement of the structure 1
md.add_fem_variable('u2', mfu2)  # Displacement of the structure 2

md.add_initialized_data('cmu', [cmu])
md.add_initialized_data('clambdastar', [clambdastar])
md.add_isotropic_linearized_elasticity_brick(mim1, 'u1', 'clambdastar', 'cmu')
md.add_isotropic_linearized_elasticity_brick(mim2, 'u2', 'clambdastar', 'cmu')
コード例 #25
0
    kept_dofs = np.setdiff1d(np.arange(mfN.nb_basic_dof()),
                             np.union1d(xdofsL, ydofsB))
    mfu = gf.MeshFem('partial', mfN, kept_dofs)
else:
    mfu = mfN

mfp = gf.MeshFem(mesh, 1)
mfp.set_classical_fem(press_fem_order)

mfksi = gf.MeshFem(mesh, 1)
mfksi.set_classical_fem(mult_fem_order)

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

mim = gf.MeshIm(mesh, integration_degree)
mimd1 = gf.MeshImData(mim, -1, [1])
mimd4 = gf.MeshImData(mim, -1, [4])

mimpress = gf.MeshIm(mesh, integration_degree_press)

# Model
md = gf.Model('real')

md.add_fem_variable('u', mfu)  # displacements
md.add_fem_variable('p', mfp)  # pressure
md.add_fem_variable("ksi", mfksi)  # plastic multiplier for the current step

md.add_im_data("gamma0",
               mimd1)  # accumulated plastic strain at previous time step
md.add_im_data('invCp0',
コード例 #26
0
mfmult_1 = gf.MeshFem(m_1, N)
#mfmult_2 = gf.MeshFem(m_2, N)
mfmult_p1 = gf.MeshFem(m_p1, N)
mfmult_p2 = gf.MeshFem(m_p2, N)
mfmult_p3 = gf.MeshFem(m_p3, N)
mfmult_1.set_classical_discontinuous_fem(mult_fem_order)
#mfmult_2.set_classical_discontinuous_fem(mult_fem_order)
mfmult_p1.set_classical_discontinuous_fem(mult_fem_order)
mfmult_p2.set_classical_discontinuous_fem(mult_fem_order)
mfmult_p3.set_classical_discontinuous_fem(mult_fem_order)
#mfmult_p1.set_classical_fem(mult_fem_order)
#mfmult_p2.set_classical_fem(mult_fem_order)
#mfmult_p3.set_classical_fem(mult_fem_order)

# Integration methods
mim_1 = gf.MeshIm(m_1, integration_degree)
mim_2 = gf.MeshIm(m_2, integration_degree)
mim_p1 = gf.MeshIm(m_p1, integration_degree)
mim_p2 = gf.MeshIm(m_p2, integration_degree)
mim_p3 = gf.MeshIm(m_p3, integration_degree)
mim_contact_1 = gf.MeshIm(m_1, integration_contact_degree)
mim_contact_2 = gf.MeshIm(m_2, integration_contact_degree)
mim_contact_p1 = gf.MeshIm(m_p1, integration_contact_degree)
mim_contact_p2 = gf.MeshIm(m_p2, integration_contact_degree)
mim_contact_p3 = gf.MeshIm(m_p3, integration_contact_degree)

# Model definition
md = gf.Model('real')
md.add_fem_variable('u_1', mfu_1)
md.add_fem_variable('u_2', mfu_2)
md.add_fem_variable('u_p1', mfu_p1)
pidright = np.compress((abs(pts[0, :] - 1.0) < 1e-7), list(range(0,
                                                                 m.nbpts())))
fidright = m.faces_from_pid(pidright)
normals = m.normal_of_faces(fidright)
fidright = fidright[:, abs(normals[0, :] - 1.0) < 1e-3]
GAMMAN = 3
m.set_region(GAMMAN, fidright)

#% Definition of the finite element methods
ls = gf.LevelSet(m, ls_degree)
mls = gf.MeshLevelSet(m)
mls.add(ls)
mf_ls = ls.mf()
if N == 2:
    mimls = gf.MeshIm(m, gf.Integ('IM_TRIANGLE(4)'))
else:
    mimls = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))

mf_basic = gf.MeshFem(m, N)
mf_basic.set_fem(gf.Fem(f'FEM_PK({N},{k})'))

mf_g = gf.MeshFem(m, 1)
mf_g.set_fem(gf.Fem(f'FEM_PK_DISCONTINUOUS({N},{k-1})'))

mf_cont = gf.MeshFem(m, 1)
mf_cont.set_fem(gf.Fem(f'FEM_PK({N},{ls_degree})'))

print(f'There is {mf_basic.nbdof()} elasticity dofs')

Mcont = gf.asm_mass_matrix(mimls, mf_cont)
コード例 #28
0
    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))

print('nbdof : %d' % mfu.nbdof())

#  Integration method used
if (N == 2):
    mim = gf.MeshIm(m, gf.Integ('IM_TRIANGLE(4)'))
else:
    mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))

# 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)
fneum = np.compress(np.logical_not(ttop + tleft), flst, axis=1)

# Mark it as boundary
DIRICHLET_BOUNDARY_NUM1 = 1
DIRICHLET_BOUNDARY_NUM2 = 2
コード例 #29
0
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)

# Initial conditions
U0 = mfu.eval('0.5-0.5*x')  # Initial displacement
Um1 = np.copy(U0)  # U_{-1} for Paoli-Schatzman scheme
Ndof = U0.size
V0 = np.zeros(Ndof)  # Initial velocity
s0 = 0.  # Initial stress
md.set_variable('u', U0)
コード例 #30
0
# coding: utf-8
import getfem as gf
import numpy as np
m = gf.Mesh('cartesian', np.arange(0.0, 10.0, 1.0))
print m
mfu = gf.MeshFem(m,1)
mfu.set_fem(gf.Fem('FEM_PK(1,1)'))
mim = gf.MeshIm(m, gf.Integ('IM_GAUSS1D(1)'))
mfd = gf.MeshFem(m, 1)
mfd.set_fem(gf.Fem('FEM_PK(1,1)'))
nbd = mfd.nbdof()
Lambda = 1.0; Mu = 1.0
K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd))
K.full()
print 'Lambda = ', Lambda
print 'Mu     = ', Mu
print K.full()
print '2*Mu+Lambda = ', 2*Mu+Lambda