def GetGradient(self, k): Jacobian = Add(1.0, self.M.SpMat(), self.dt, self.S.SpMat()) self.Jacobian = Jacobian add_vector(self.v, self.dt, k, self.w) add_vector(self.x, self.dt, self.w, self.z) grad_H = self.H.GetGradientMatrix(self.z) Jacobian.Add(self.dt**2, grad_H) return Jacobian
def ImplicitSolve(self, dt, vx, dvx_dt): sc = self.Height() / 2 v = mfem.Vector(vx, 0, sc) x = mfem.Vector(vx, sc, sc) dv_dt = mfem.Vector(dvx_dt, 0, sc) dx_dt = mfem.Vector(dvx_dt, sc, sc) # By eliminating kx from the coupled system: # kv = -M^{-1}*[H(x + dt*kx) + S*(v + dt*kv)] # kx = v + dt*kv # we reduce it to a nonlinear equation for kv, represented by the # backward_euler_oper. This equation is solved with the newton_solver # object (using J_solver and J_prec internally). self.backward_euler_oper.SetParameters(dt, v, x) zero = mfem.Vector() # empty vector is interpreted as # zero r.h.s. by NewtonSolver self.newton_solver.Mult(zero, dv_dt) add_vector(v, dt, dv_dt, dx_dt)
def Mult(self, k, y): add_vector(self.v, self.dt, k, self.w) add_vector(self.x, self.dt, self.w, self.z) self.H.Mult(self.z, y) self.M.AddMult(k, y) self.S.AddMult(self.w, y)