invM = mfem.HypreDiagScale(M) invS = mfem.HypreBoomerAMG(S) invM.iterative_mode = False invS.iterative_mode = False darcyPr = mfem.BlockDiagonalPreconditioner(block_trueOffsets) darcyPr.SetDiagonalBlock(0, invM) darcyPr.SetDiagonalBlock(1, invS) maxIter = 500 rtol = 1e-6 atol = 1e-10 import time stime = time.clock() solver = mfem.MINRESSolver(MPI.COMM_WORLD) solver.SetAbsTol(atol) solver.SetRelTol(rtol) solver.SetMaxIter(maxIter) solver.SetOperator(darcyOp) solver.SetPreconditioner(darcyPr) solver.SetPrintLevel(1) trueX.Assign(0.0) solver.Mult(trueRhs, trueX) solve_time = time.clock() - stime if verbose: if solver.GetConverged(): print("MINRES converged in " + str(solver.GetNumIterations()) +
def __init__(self, fespace, ess_bdr, visc, mu, K): mfem.PyTimeDependentOperator.__init__(self, 2 * fespace.TrueVSize(), 0.0) rel_tol = 1e-8 skip_zero_entries = 0 ref_density = 1.0 self.ess_tdof_list = intArray() self.z = mfem.Vector(self.Height() // 2) self.fespace = fespace self.viscosity = visc self.newton_solver = mfem.NewtonSolver(fespace.GetComm()) M = mfem.ParBilinearForm(fespace) S = mfem.ParBilinearForm(fespace) H = mfem.ParNonlinearForm(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) self.Mmat = M.ParallelAssemble() fespace.GetEssentialTrueDofs(ess_bdr, self.ess_tdof_list) self.Mmat.EliminateRowsCols(self.ess_tdof_list) M_solver = mfem.CGSolver(fespace.GetComm()) M_prec = mfem.HypreSmoother() M_solver.iterative_mode = False M_solver.SetRelTol(rel_tol) M_solver.SetAbsTol(0.0) M_solver.SetMaxIter(30) M_solver.SetPrintLevel(0) M_prec.SetType(mfem.HypreSmoother.Jacobi) M_solver.SetPreconditioner(M_prec) M_solver.SetOperator(self.Mmat) self.M_solver = M_solver self.M_prec = M_prec model = mfem.NeoHookeanModel(mu, K) H.AddDomainIntegrator(mfem.HyperelasticNLFIntegrator(model)) H.SetEssentialTrueDofs(self.ess_tdof_list) 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.reduced_oper = ReducedSystemOperator(M, S, H, self.ess_tdof_list) J_hypreSmoother = mfem.HypreSmoother() J_hypreSmoother.SetType(mfem.HypreSmoother.l1Jacobi) J_hypreSmoother.SetPositiveDiagonal(True) J_prec = J_hypreSmoother J_minres = mfem.MINRESSolver(fespace.GetComm()) 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(fespace.GetComm()) newton_solver.iterative_mode = False newton_solver.SetSolver(self.J_solver) newton_solver.SetOperator(self.reduced_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