コード例 #1
0
DIRICHLET_BOUNDARY_NUM1 = 1
DIRICHLET_BOUNDARY_NUM2 = 2
NEUMANN_BOUNDARY_NUM = 3
m.set_region(DIRICHLET_BOUNDARY_NUM1, fleft)
m.set_region(DIRICHLET_BOUNDARY_NUM2, ftop)
m.set_region(NEUMANN_BOUNDARY_NUM, fneum)

# Interpolate the exact solution (Assuming mfu is a Lagrange fem)
Ue = mfu.eval('y*(y-1)*x*(x-1)+x*x*x*x*x')

# Interpolate the source term
F1 = mfrhs.eval('-(2*(x*x+y*y)-2*x-2*y+20*x*x*x)')
F2 = mfrhs.eval('[y*(y-1)*(2*x-1) + 5*x*x*x*x, x*(x-1)*(2*y-1)]')

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

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

# Laplacian term on u
md.add_Laplacian_brick(mim, 'u')

# Volumic source term
md.add_initialized_fem_data('VolumicData', mfrhs, F1)
md.add_source_term_brick(mim, 'u', 'VolumicData')

# Neumann condition.
md.add_initialized_fem_data('NeumannData', mfrhs, F2)
md.add_normal_source_term_brick(mim, 'u', 'NeumannData',
                                NEUMANN_BOUNDARY_NUM)
mfmult = gf.MeshFem(mesh, 1)
mfmult.set_classical_fem(mult_fem_order)

mfout1 = gf.MeshFem(mesh)
mfout1.set_classical_discontinuous_fem(disp_fem_order-1)
mfout2 = gf.MeshFem(mesh)
mfout2.set_classical_discontinuous_fem(disp_fem_order)

mim = gf.MeshIm(mesh, integration_degree)

mimd1 = gf.MeshImData(mim)
mimd4 = gf.MeshImData(mim, -1, 4)

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

md.add_fem_variable("u", mfu)

# Vertical displacement
md.add_initialized_data("disp", [0.])

md.add_initialized_data("K", E/(3.*(1.-2.*nu))) # Bulk modulus
md.add_initialized_data("mu", E/(2*(1+nu)))     # Shear modulus
md.add_macro("F", "Id(2)+Grad_u")
md.add_macro("F3d", "Id(3)+[0,0,0;0,0,0;0,0,1/X(2)]*u(2)+[1,0;0,1;0,0]*Grad_u*[1,0,0;0,1,0]")
md.add_macro("J", "Det(F)*(1+u(2)/X(2))")
md.add_macro("tauH", "K*log(J)")
md.add_im_data("gamma0", mimd1)                        # accumulated plastic strain at previous time step
md.add_im_data("invCp0vec", mimd4)                     # Components 11, 22, 33 and 12 of the plastic part of
md.set_variable("invCp0vec",                           # the inverse right Cauchy Green tensor at the previous
コード例 #3
0
pidtop = np.compress(ctop,list(range(0,m.nbpts())))
ftop = m.faces_from_pid(pidtop)
TOP = 2
m.set_region(TOP,ftop)
# Left points and faces
cleft = (abs(allPoints[1,:]) < 1e-6)
pidleft = np.compress(cleft,list(range(0,m.nbpts())))
fleft= m.faces_from_pid(pidleft)
LEFT = 3
m.set_region(LEFT,fleft)

# ==== Create getfem models ====
# We use two identical models, one to get the stiffness matrix and the rhs
# and the other to get the mass matrix.
#
md = gf.Model('real')
# The dof (displacements on nodes)
md.add_fem_variable('u',mfu)
# Add model constants
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)
md.add_initialized_data('weight',[0,0,Rho*Gravity])
# Build model (linear elasticity)
md.add_isotropic_linearized_elasticity_brick(mim,'u','lambda','mu')
md.add_source_term_brick(mim,'u','weight')

# Assembly
コード例 #4
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
コード例 #5
0
cross_jump_test_b = JUMP_VPRODUCT_VAR_.format(var='Test_b')
curl_int_b = CURL_INT_VAR_.format(var='b')
curl_b = CURL_VAR_.format(var='b')
mean_curl_b = MEAN_VAR_.format(M=curl_b, N=curl_int_b)
curl_int_test_b = CURL_INT_VAR_.format(var='Test_b')
curl_test_b = CURL_VAR_.format(var='Test_b')
mean_curl_test_b = MEAN_VAR_.format(M=curl_test_b, N=curl_int_test_b)
curl_testb_curl_b_exp = '({L}).({M})'.format(L=CURL_VAR_.format(var='Test_b'),
                                             M=CURL_VAR_.format(var='b'))
cross_jump_a = JUMP_VPRODUCT_VAR_.format(var='a')
cross_jump_test_a = JUMP_VPRODUCT_VAR_.format(var='Test_a')
jump_a = JUMP_VVAR_N_.format(v='a')
jump_test_a = JUMP_VVAR_N_.format(v='Test_a')

#magentec potential model
mdmag = gf.Model('real')

######################################################################################################################
#Interpolate and export exact fields
intonme = mfb
CurlBexact = mdmag.interpolation(CurlBexact_exp, intonme)
intonme.export_to_vtk('curl_exact3d.vtk', 'ascii', CurlBexact)
print('exact curl B norm l2', gf.compute_L2_norm(intonme, CurlBexact, mim))
Bexact = mdmag.interpolation(Bexact_exp, intonme)
intonme.export_to_vtk('field_exact3d.vtk', 'ascii', Bexact)
print('exact B norm l2', gf.compute_L2_norm(intonme, Bexact, mim))
#Interpolate and export exact fields END
######################################################################################################################

WITH_B_CROSS_N = True