def __init__(self, spaces, mass, offsets): self.pressure_mass = mass self.block_offsets = offsets super(JacobianPreconditioner, self).__init__(offsets[2]) self.gamma = 0.00001 # The mass matrix and preconditioner do not change every Newton cycle, so we # only need to define them once self.mass_prec = mfem.GSSmoother(mass) mass_pcg = mfem.CGSolver() mass_pcg.SetRelTol(1e-12) mass_pcg.SetAbsTol(1e-12) mass_pcg.SetMaxIter(200) mass_pcg.SetPrintLevel(0) mass_pcg.SetPreconditioner(self.mass_prec) mass_pcg.SetOperator(self.pressure_mass) mass_pcg.iterative_mode = False self.mass_pcg = mass_pcg # The stiffness matrix does change every Newton cycle, so we will define it # during SetOperator self.stiff_pcg = None self.stiff_prec = None
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.SparseMatrix() self.Kmat = mfem.SparseMatrix() self.M_solver = mfem.CGSolver() self.M_prec = mfem.DSmoother() self.T_solver = mfem.CGSolver() self.T_prec = mfem.DSmoother() self.z = mfem.Vector(self.Height()) self.M = mfem.BilinearForm(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(30) self.M_solver.SetPrintLevel(0) 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)
def __init__(self, M, K, b): mfem.PyTimeDependentOperator.__init__(self, M.Size()) self.K = K self.M = M self.b = b self.z = mfem.Vector(M.Size()) self.zp = np.zeros(M.Size()) self.M_prec = mfem.DSmoother() self.M_solver = mfem.CGSolver() self.M_solver.SetPreconditioner(self.M_prec) self.M_solver.SetOperator(M) self.M_solver.iterative_mode = False self.M_solver.SetRelTol(1e-9) self.M_solver.SetAbsTol(0.0) self.M_solver.SetMaxIter(100) self.M_solver.SetPrintLevel(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
# 9. Set up a block-diagonal preconditioner for the 2x2 normal equation # # [ S0^{-1} 0 ] # [ 0 Shat^{-1} ] Shat = (Bhat^T Sinv Bhat) # # corresponding to the primal (x0) and interfacial (xhat) unknowns. # RAP_R replaces RAP, since RAP has two definition one accept # pointer and the other accept reference. From Python, two # can not be distingished.. Shat = mfem.RAP_R(matBhat, matSinv, matBhat); prec_rtol = 1e-3 prec_maxit = 200 S0inv = mfem.CGSolver() S0inv.SetOperator(matS0) S0inv.SetPrintLevel(-1) S0inv.SetRelTol(prec_rtol) S0inv.SetMaxIter(prec_maxit) Shatinv = mfem.CGSolver() Shatinv.SetOperator(Shat) Shatinv.SetPrintLevel(-1) Shatinv.SetRelTol(prec_rtol) Shatinv.SetMaxIter(prec_maxit) # Disable 'iterative_mode' when using CGSolver (or any IterativeSolver) as # a preconditioner: S0inv.iterative_mode = False Shatinv.iterative_mode = False