Esempio n. 1
0
    def __init__(self, spaces, ess_bdr, block_offsets, rel_tol, abs_tol, iter,
                 mu):

        # Array<Vector *> -> tuple
        super(RubberOperator,
              self).__init__(spaces[0].TrueVSize() + spaces[1].TrueVSize())
        rhs = (None, None)

        self.spaces = spaces
        self.mu = mfem.ConstantCoefficient(mu)
        self.block_offsets = block_offsets

        Hform = mfem.ParBlockNonlinearForm(spaces)
        Hform.AddDomainIntegrator(
            mfem.IncompressibleNeoHookeanIntegrator(self.mu))
        Hform.SetEssentialBC(ess_bdr, rhs)
        self.Hform = Hform

        a = mfem.ParBilinearForm(self.spaces[1])
        one = mfem.ConstantCoefficient(1.0)
        mass = mfem.OperatorHandle(mfem.Operator.Hypre_ParCSR)
        a.AddDomainIntegrator(mfem.MassIntegrator(one))
        a.Assemble()
        a.Finalize()
        a.ParallelAssemble(mass)
        mass.SetOperatorOwner(False)
        pressure_mass = mass.Ptr()

        self.j_prec = JacobianPreconditioner(spaces, pressure_mass,
                                             block_offsets)

        j_gmres = mfem.GMRESSolver(MPI.COMM_WORLD)
        j_gmres.iterative_mode = False
        j_gmres.SetRelTol(1e-12)
        j_gmres.SetAbsTol(1e-12)
        j_gmres.SetMaxIter(300)
        j_gmres.SetPrintLevel(0)
        j_gmres.SetPreconditioner(self.j_prec)
        self.j_solver = j_gmres

        newton_solver = mfem.NewtonSolver(MPI.COMM_WORLD)
        # Set the newton solve parameters
        newton_solver.iterative_mode = True
        newton_solver.SetSolver(self.j_solver)
        newton_solver.SetOperator(self)
        newton_solver.SetPrintLevel(1)
        newton_solver.SetRelTol(rel_tol)
        newton_solver.SetAbsTol(abs_tol)
        newton_solver.SetMaxIter(iter)
        self.newton_solver = newton_solver
Esempio n. 2
0
    def __init__(self, fespace, alpha, kappa, u):
        mfem.PyTimeDependentOperator.__init__(self, fespace.GetTrueVSize(),
                                              0.0)
        rel_tol = 1e-8
        self.alpha = alpha
        self.kappa = kappa
        self.T = None
        self.K = None
        self.M = None
        self.fespace = fespace

        self.ess_tdof_list = intArray()
        self.Mmat = mfem.HypreParMatrix()
        self.Kmat = mfem.HypreParMatrix()
        self.M_solver = mfem.CGSolver(fespace.GetComm())
        self.M_prec = mfem.HypreSmoother()
        self.T_solver = mfem.CGSolver(fespace.GetComm())
        self.T_prec = mfem.HypreSmoother()
        self.z = mfem.Vector(self.Height())

        self.M = mfem.ParBilinearForm(fespace)
        self.M.AddDomainIntegrator(mfem.MassIntegrator())
        self.M.Assemble()
        self.M.FormSystemMatrix(self.ess_tdof_list, self.Mmat)

        self.M_solver.iterative_mode = False
        self.M_solver.SetRelTol(rel_tol)
        self.M_solver.SetAbsTol(0.0)
        self.M_solver.SetMaxIter(100)
        self.M_solver.SetPrintLevel(0)
        self.M_prec.SetType(mfem.HypreSmoother.Jacobi)
        self.M_solver.SetPreconditioner(self.M_prec)
        self.M_solver.SetOperator(self.Mmat)

        self.T_solver.iterative_mode = False
        self.T_solver.SetRelTol(rel_tol)
        self.T_solver.SetAbsTol(0.0)
        self.T_solver.SetMaxIter(100)
        self.T_solver.SetPrintLevel(0)
        self.T_solver.SetPreconditioner(self.T_prec)

        self.SetParameters(u)
Esempio n. 3
0
# Inflow boundary condition (zero for the problems considered in this example)
class inflow_coeff(mfem.PyCoefficient):
    def EvalValue(self, x):
        return 0


# 8. Set up and assemble the bilinear and linear forms corresponding to the
#    DG discretization. The DGTraceIntegrator involves integrals over mesh
#    interior faces.

velocity = velocity_coeff(dim)
inflow = inflow_coeff()
u0 = u0_coeff()

m = mfem.ParBilinearForm(fes)
m.AddDomainIntegrator(mfem.MassIntegrator())
k = mfem.ParBilinearForm(fes)
k.AddDomainIntegrator(mfem.ConvectionIntegrator(velocity, -1.0))
k.AddInteriorFaceIntegrator(
    mfem.TransposeIntegrator(mfem.DGTraceIntegrator(velocity, 1.0, -0.5)))
k.AddBdrFaceIntegrator(
    mfem.TransposeIntegrator(mfem.DGTraceIntegrator(velocity, 1.0, -0.5)))

b = mfem.ParLinearForm(fes)
b.AddBdrFaceIntegrator(
    mfem.BoundaryFlowIntegrator(inflow, velocity, -1.0, -0.5))

m.Assemble()
m.Finalize()
skip_zeros = 0
k.Assemble(skip_zeros)
Esempio n. 4
0
B0 = mfem.ParMixedBilinearForm(x0_space, test_space)
B0.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
B0.Assemble()
B0.EliminateEssentialBCFromTrialDofs(ess_dof, x0, F)
B0.Finalize()

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

Sinv = mfem.ParBilinearForm(test_space)
Sum = mfem.SumIntegrator()
Sum.AddIntegrator(mfem.DiffusionIntegrator(one))
Sum.AddIntegrator(mfem.MassIntegrator(one))
Sinv.AddDomainIntegrator(mfem.InverseIntegrator(Sum))
Sinv.Assemble()
Sinv.Finalize()

S0 = mfem.ParBilinearForm(x0_space)
S0.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
S0.Assemble()
S0.EliminateEssentialBC(ess_bdr)
S0.Finalize()

matB0 = B0.ParallelAssemble()
del B0
matBhat = Bhat.ParallelAssemble()
del Bhat
matSinv = Sinv.ParallelAssemble()
Esempio n. 5
0
rhs_coef = analytic_rhs()
sol_coef = analytic_solution()
b.AddDomainIntegrator(mfem.DomainLFIntegrator(rhs_coef))
b.Assemble()

#  6. Define the solution vector x as a finite element grid function
#     corresponding to fespace. Initialize x with initial guess of zero.
x = mfem.ParGridFunction(fespace)
x.Assign(0.0)

#  7. Set up the bilinear form a(.,.) on the finite element space
#     corresponding to the Laplacian operator -Delta, by adding the Diffusion
#     and Mass domain integrators.
a = mfem.ParBilinearForm(fespace)
a.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
a.AddDomainIntegrator(mfem.MassIntegrator(one))

#  8. Assemble the linear system, apply conforming constraints, etc.
a.Assemble()
a.Finalize()
mat = a.ParallelAssemble()
mat.Print("parmatrix")

A = mfem.HypreParMatrix()
B = mfem.Vector()
X = mfem.Vector()
empty_tdof_list = mfem.intArray()

a.FormLinearSystem(empty_tdof_list, x, b, A, X, B)

amg = mfem.HypreBoomerAMG(A)