コード例 #1
0
            if (j + i < Ndof):
                M[j, j] += M[j, j + i]
                M[j, j + i] = 0.
            if (j - i >= 0):
                M[j, j] += M[j, j - i]
                M[j, j - i] = 0.
K = gf.asm_generic(mim, 2, 'Grad_u*Grad_Test_u', -1, md)

# Dirichlet condition on the top
for i in range(0, u_degree + 1):
    K[Ndof - 1, Ndof - 1 - i] = 0.
for i in range(0, u_degree + 1):
    M[Ndof - 1, Ndof - 1 - i] = 0.
M[Ndof - 1, Ndof - 1] = 1.
K[Ndof - 1, Ndof - 1] = 1.
M2 = gf.Spmat('copy', M)

if (mass_matrix_type == 1):  # Redistributed mass matrix
    M[1, 1] += M[0, 0]
    M[0, 0] = 0.
    for i in range(1, u_degree + 1):
        M[i, i] += M[i, 0]
        M[0, i] = M[i, 0] = 0.
    M2 = gf.Spmat('copy', M)
    M2[0, 0] = 1.
elif (mass_matrix_type == 2):  # Singular dynamic mass matrix
    assert (u_degree == 1), 'Sorry, implemented for linear element only'
    M[1, 1] = 7. * h / 12.
    for i in range(0, u_degree + 1):
        M[0, i] = M[i, 0] = 0.
    M2 = gf.Spmat('copy', M)
コード例 #2
0
print "np.repeat([Mu], nbd).shape:", np.repeat([Mu], nbd).shape

# handle Dirichlet condition
(H, R) = gf.asm_dirichlet(DIRICHLET_BOUNDARY, mim, mfu, mfd,
                          mfd.eval('numpy.identity(3)'), mfd.eval('[0,0,0]'))
print "H.info: ", H.info  # Spmat instance
print "R.shape: ", R.shape
print "mfd.eval('numpy.identity(3)').shape: ", mfd.eval(
    'numpy.identity(3)').shape
print "mfd.eval('[0,0,0]').shape: ", mfd.eval('[0,0,0]').shape

(N, U0) = H.dirichlet_nullspace(R)
print "N.info: ", N.info  # Spmat instance
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
コード例 #3
0
elif condition_type == 1:
    # Small penalty term to avoid rigid motion (should be replaced by an
    # explicit treatment of the rigid motion with a constraint matrix)
    md.add_initialized_data('penalty_param', [penalty_parameter])
    md.add_mass_brick(mim, 'u', 'penalty_param')

# The contact condition

cdof = mfu.dof_on_region(GAMMAC)
nbc = cdof.shape[0] / d

solved = False
if version == 1 or version == 2:  # defining the matrices BN and BT by hand
    contact_dof = cdof[d - 1:nbc * d:d]
    contact_nodes = mfu.basic_dof_nodes(contact_dof)
    BN = gf.Spmat('empty', nbc, nbdofu)
    ngap = np.zeros(nbc)
    for i in range(nbc):
        BN[i, contact_dof[i]] = -1.
        ngap[i] = contact_nodes[d - 1, i]

    if version == 2:
        BT = gf.Spmat('empty', nbc * (d - 1), nbdofu)
        for i in range(nbc):
            for j in range(d - 1):
                BT[j + i * (d - 1), contact_dof[i] - d + j + 1] = 1.0

    md.add_variable('lambda_n', nbc)
    md.add_initialized_data('r', [r])
    if version == 2:
        md.add_variable('lambda_t', nbc * (d - 1))
コード例 #4
0
ファイル: demo_mortar.py プロジェクト: tianhaichen/getfem
fright = m.faces_from_pid(np.nonzero(abs(P[1] - 1.) < 1e-6))

# assign boundary numbers
m.set_region(1, fleft)
m.set_region(2, fright)

MORTAR_BOUNDARY_IN = 40
MORTAR_BOUNDARY_OUT = 41
m.set_region(MORTAR_BOUNDARY_IN, b_in)
m.set_region(MORTAR_BOUNDARY_OUT, b_out)

indm = mfm.basic_dof_on_region(MORTAR_BOUNDARY_OUT)
expr = 'M(#1,#2)+=comp(vBase(#1).vBase(#2))(:,i,:,i)'
M = gf.asm_boundary(MORTAR_BOUNDARY_IN, expr, mim, mfm, mfu)
M = M - gf.asm_boundary(MORTAR_BOUNDARY_OUT, expr, mim, mfm, mfu)
M = gf.Spmat('copy', M, indm, list(range(M.size()[1])))

md = gf.Model('real')
md.add_fem_variable('u', mfu)
md.add_initialized_data('lambda', [1])
md.add_initialized_data('mu', [1])
md.add_isotropic_linearized_elasticity_brick(mim, 'u', 'lambda', 'mu')

md.add_Dirichlet_condition_with_multipliers(mim, 'u', mfu, 1)

F = mfd.eval('[0,y+2]')

md.add_initialized_fem_data('VolumicData', mfd, F)
md.add_source_term_brick(mim, 'u', 'VolumicData')
md.add_variable('mult_spec', indm.size)
md.add_constraint_with_multipliers('u', 'mult_spec', M, np.zeros(indm.size))
コード例 #5
0
                                                        L=cross_jump_b,
                                                        M=cross_jump_test_b)
    CROSS_CROSS_IP = gf.asm('generic', mim, 2, CROSS_CROSS_IP_EXP, INNER_FACES,
                            'b', 1, mfb, 0)
    bi = mdmag.add_explicit_matrix('b', 'b', CROSS_CROSS_IP)
    bi = mdmag.add_explicit_matrix('b', 'b', -J_CROSSTAU_DOT_M_CURLB)
    #bi=mdmag.add_explicit_matrix('b', 'b', -J_CROSSB_DOT_M_CURLTAU)
# Interior penalty terms END
#####################################################################################################

#####################################################################################################
# Lagrange multipliers for div B=0 condition
DIV_B1 = gf.asm('generic', mim, 2, 'Grad_Test_p.Test2_b', -1, 'b', 1, mfb, 0,
                'p', 1, mfdiv_mult, 0)
DIV_B1 = gf.Spmat('copy', DIV_B1,
                  range(mfb.nbdof(),
                        mfb.nbdof() + mfdiv_mult.nbdof()), range(mfb.nbdof()))
magi = mdmag.add_explicit_matrix('p', 'b', DIV_B1)
DIV_B1.transpose()
magi = mdmag.add_explicit_matrix('b', 'p', DIV_B1)
if (DS_GA):  # Interior penalty terms for div B=0 part
    FLUX_IP_EXP = "({alpha})*({J}).({K})".format(alpha=ALPHAF,
                                                 J=jump_b,
                                                 K=jump_test_b)
    FLUX_IP = gf.asm('generic', mim, 2, FLUX_IP_EXP, INNER_FACES, 'b', 1, mfb,
                     0)
    bi = mdmag.add_explicit_matrix('b', 'b', FLUX_IP)
    IP_ADD = gf.asm('generic', mim, 2, jump_b + '.' + mean_test_p, INNER_FACES,
                    'b', 1, mfb, 0, 'p', 1, mfdiv_mult, 0)
    IP_ADD = gf.Spmat('copy', IP_ADD,
                      range(mfb.nbdof(),