Пример #1
0
#  Define coefficient using VecotrPyCoefficient and PyCoefficient
#  A user needs to define EvalValue method
#
u0 = InitialCondition(num_equation)
sol = mfem.GridFunction(vfes, u_block.GetData())
sol.ProjectCoefficient(u0)

mesh.PrintToFile("vortex.mesh", 8)
for k in range(num_equation):
    uk = mfem.GridFunction(fes, u_block.GetBlock(k).GetData())
    sol_name = "vortex-" + str(k) + "-init.gf"
    uk.SaveToFile(sol_name, 8)

#  7. Set up the nonlinear form corresponding to the DG discretization of the
#     flux divergence, and assemble the corresponding mass matrix.
Aflux = mfem.MixedBilinearForm(dfes, fes)
Aflux.AddDomainIntegrator(DomainIntegrator(dim))
Aflux.Assemble()

A = mfem.NonlinearForm(vfes)
rsolver = RiemannSolver()
ii = FaceIntegrator(rsolver, dim)
A.AddInteriorFaceIntegrator(ii)

#  8. Define the time-dependent evolution operator describing the ODE
#     right-hand side, and perform time-integration (looping over the time
#     iterations, ti, with a time-step dt).
euler = FE_Evolution(vfes, A, Aflux.SpMat())

if (visualization):
    sout = mfem.socketstream("localhost", 19916)
Пример #2
0
x = mfem.BlockVector(block_offsets)
rhs = mfem.BlockVector(block_offsets)

fform = mfem.LinearForm()
fform.Update(R_space, rhs.GetBlock(0), 0)
fform.AddDomainIntegrator(mfem.VectorFEDomainLFIntegrator(fcoeff))
fform.AddBoundaryIntegrator(mfem.VectorFEBoundaryFluxLFIntegrator(fnatcoeff))
fform.Assemble()

gform = mfem.LinearForm()
gform.Update(W_space, rhs.GetBlock(1), 0)
gform.AddDomainIntegrator(mfem.DomainLFIntegrator(gcoeff))
gform.Assemble()

mVarf = mfem.BilinearForm(R_space)
bVarf = mfem.MixedBilinearForm(R_space, W_space)

mVarf.AddDomainIntegrator(mfem.VectorFEMassIntegrator(k))
mVarf.Assemble()
mVarf.Finalize()
M = mVarf.SpMat()

bVarf.AddDomainIntegrator(mfem.VectorFEDivergenceIntegrator())
bVarf.Assemble()
bVarf.Finalize()
B = bVarf.SpMat()
B *= -1
BT = mfem.Transpose(B)

darcyOp = mfem.BlockOperator(block_offsets)
darcyOp.SetBlock(0, 0, M)
Пример #3
0
# 6. Set up the linear form F(.) which corresponds to the right-hand side of
#    the FEM linear system, which in this case is (f,phi_i) where f=1.0 and
#    phi_i are the basis functions in the test finite element fespace.
one = mfem.ConstantCoefficient(1.0)
F = mfem.LinearForm(test_space);
F.AddDomainIntegrator(mfem.DomainLFIntegrator(one))
F.Assemble();

# 7. Set up the mixed bilinear form for the primal trial unknowns, B0,
#    the mixed bilinear form for the interfacial unknowns, Bhat,
#    the inverse stiffness matrix on the discontinuous test space, Sinv,
#    and the stiffness matrix on the continuous trial space, S0.
ess_bdr = mfem.intArray(mesh.bdr_attributes.Max())
ess_bdr.Assign(1)

B0 = mfem.MixedBilinearForm(x0_space,test_space);
B0.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
B0.Assemble()
B0.EliminateTrialDofs(ess_bdr, x.GetBlock(x0_var), F)
B0.Finalize()

Bhat = mfem.MixedBilinearForm(xhat_space,test_space)
Bhat.AddTraceFaceIntegrator(mfem.TraceJumpIntegrator())
Bhat.Assemble()
Bhat.Finalize()

Sinv = mfem.BilinearForm(test_space)
Sum = mfem.SumIntegrator()
Sum.AddIntegrator(mfem.DiffusionIntegrator(one))
Sum.AddIntegrator(mfem.MassIntegrator(one))
Sinv.AddDomainIntegrator(mfem.InverseIntegrator(Sum))