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.TrueAddMult(k, y) self.S.TrueAddMult(self.w, y) y.SetSubVector(self.ess_tdof_list, 0.0)
def __sub__(self, other): from mfem.par import HypreParVector as Vector from mfem.par import add_vector add_vector if self[0] is not None and other[0] is not None: r = Vector(self[0]) add_vector(self[0], -1, other[0], r) elif self[0] is not None: r = Vector(self[0]) elif other[0] is not None: r = Vector(other[0]) r *= -1. else: r = None if self[1] is not None and other[1] is not None: i = Vector(self[1]) add_vector(self[1], -1, other[1], i) elif self[1] is not None: i = Vector(self[1]) elif other[1] is not None: i = Vector(other[1]) i *= -1. else: i = None return CHypreVec(r, i, horizontal=self._horizontal)
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) #print("v = ") #v.Print() #print("x = ") #x.Print() # 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 linear equation for kv, # represented by the backward_euler_oper ndt = -1 * dt self.VX = mfem.Add(1.0, self.Mmat, ndt, self.Smat) self.VX_solver.SetOperator(self.VX) #add_vector(x, dt, dv_dt, self.w) self.Kmat.Mult(x, self.z) #self.S.TrueAddMult(v, self.z) self.Smat.Mult(v, self.tmpVec) add_vector(self.z, 1.0, self.tmpVec, self.z) self.z.Neg() self.z += self.Bx self.z += self.Bv self.VX_solver.Mult(self.z, dv_dt) add_vector(v, dt, dv_dt, dx_dt)
def GetGradient(self, k): localJ = mfem.add_sparse(1.0, self.M.SpMat(), self.dt, self.S.SpMat()); add_vector(self.v, self.dt, k, self.w) add_vector(self.x, self.dt, self.w, self.z) localJ.Add(self.dt * self.dt, self.H.GetLocalGradient(self.z)) Jacobian = self.M.ParallelAssemble(localJ) return Jacobian
def GetGradient(self, k): localJ = mfem.Add(1.0, self.M.SpMat(), self.dt, self.S.SpMat()) add_vector(self.v, self.dt, k, self.w) add_vector(self.x, self.dt, self.w, self.z) localJ.Add(self.dt * self.dt, self.H.GetLocalGradient(self.z)) Jacobian = self.M.ParallelAssemble(localJ) Jacobian.EliminateRowsCols(self.ess_tdof_list) 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.reduced_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 __add__(self, other): Vector = mfem.par.HypreParVector if self[0] is not None and other[0] is not None: r = Vector(self[0]) add_vector(self[0], others[0], r) elif self[0] is not None: r = Vector(self[0]) elif other[0] is not None: r = Vector(other[0]) else: r = None if self[1] is not None and other[1] is not None: i = Vector(self[1]) add_vector(self[1], others[1], i) elif self[1] is not None: i = Vector(self[1]) elif other[1] is not None: i = Vector(other[1]) else: i = None return CHypreVec(r, i, horizontal=self._horizontal)
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.TrueAddMult(k, y) self.S.TrueAddMult(self.w, y)