Example #1
0
invM = mfem.DSmoother(M)
invS = mfem.GSSmoother(S)
invM.iterative_mode = False
invS.iterative_mode = False

darcyPrec = mfem.BlockDiagonalPreconditioner(block_offsets)
darcyPrec.SetDiagonalBlock(0, invM)
darcyPrec.SetDiagonalBlock(1, invS)

maxIter = 500
rtol = 1e-6
atol = 1e-10

stime = clock()
solver = mfem.MINRESSolver()
solver.SetAbsTol(atol)
solver.SetRelTol(rtol)
solver.SetMaxIter(maxIter)
solver.SetOperator(darcyOp)
solver.SetPreconditioner(darcyPrec)
solver.SetPrintLevel(1)
x.Assign(0.0)
solver.Mult(rhs, x)

solve_time = clock() - stime

if solver.GetConverged():
    print("MINRES converged in " + str(solver.GetNumIterations()) +
          " iterations with a residual norm of " + str(solver.GetFinalNorm()))
else:
Example #2
0
    def __init__(self, fespace, ess_bdr, visc, mu, K):
        mfem.PyTimeDependentOperator.__init__(self, 2 * fespace.GetVSize(),
                                              0.0)

        rel_tol = 1e-8
        skip_zero_entries = 0
        ref_density = 1.0
        self.z = mfem.Vector(self.Height() / 2)
        self.fespace = fespace
        self.viscosity = visc

        M = mfem.BilinearForm(fespace)
        S = mfem.BilinearForm(fespace)
        H = mfem.NonlinearForm(fespace)
        self.M = M
        self.H = H
        self.S = S

        rho = mfem.ConstantCoefficient(ref_density)
        M.AddDomainIntegrator(mfem.VectorMassIntegrator(rho))
        M.Assemble(skip_zero_entries)
        M.EliminateEssentialBC(ess_bdr)
        M.Finalize(skip_zero_entries)

        M_solver = mfem.CGSolver()
        M_prec = mfem.DSmoother()
        M_solver.iterative_mode = False
        M_solver.SetRelTol(rel_tol)
        M_solver.SetAbsTol(0.0)
        M_solver.SetMaxIter(30)
        M_solver.SetPrintLevel(0)
        M_solver.SetPreconditioner(M_prec)
        M_solver.SetOperator(M.SpMat())

        self.M_solver = M_solver
        self.M_prec = M_prec

        model = mfem.NeoHookeanModel(mu, K)
        H.AddDomainIntegrator(mfem.HyperelasticNLFIntegrator(model))
        H.SetEssentialBC(ess_bdr)
        self.model = model

        visc_coeff = mfem.ConstantCoefficient(visc)
        S.AddDomainIntegrator(mfem.VectorDiffusionIntegrator(visc_coeff))
        S.Assemble(skip_zero_entries)
        S.EliminateEssentialBC(ess_bdr)
        S.Finalize(skip_zero_entries)

        self.backward_euler_oper = BackwardEulerOperator(M, S, H)

        J_prec = mfem.DSmoother(1)
        J_minres = mfem.MINRESSolver()
        J_minres.SetRelTol(rel_tol)
        J_minres.SetAbsTol(0.0)
        J_minres.SetMaxIter(300)
        J_minres.SetPrintLevel(-1)
        J_minres.SetPreconditioner(J_prec)

        self.J_solver = J_minres
        self.J_prec = J_prec

        newton_solver = mfem.NewtonSolver()
        newton_solver.iterative_mode = False
        newton_solver.SetSolver(self.J_solver)
        newton_solver.SetOperator(self.backward_euler_oper)
        newton_solver.SetPrintLevel(1)
        #print Newton iterations
        newton_solver.SetRelTol(rel_tol)
        newton_solver.SetAbsTol(0.0)
        newton_solver.SetMaxIter(10)
        self.newton_solver = newton_solver