示例#1
0
 def updMassMatMS(self, elmLst, elmCompDiagMassMat, rho=1.0):
     self.M = mfem.ParBilinearForm(self.fespace)
     self.ro = mfem.ConstantCoefficient(rho)
     self.M.AddDomainIntegrator(mfem.VectorMassIntegrator(self.ro))
     print("in updateMass")
     self.M.Assemble(0, elmLst, elmCompDiagMassMat, True, True)
     self.M.EliminateEssentialBC(self.vess_bdr)
     self.M.Finalize(0)
     self.Mmat = self.M.ParallelAssemble()
     self.M_solver.SetOperator(self.Mmat)
示例#2
0
mu_func = mfem.PWConstCoefficient(mu)

ess_bdr = mfem.intArray(pmesh.bdr_attributes.Max())
ess_bdr.Assign(0)
ess_bdr[0] = 1

a = mfem.ParBilinearForm(fespace)
a.AddDomainIntegrator(mfem.ElasticityIntegrator(lambda_func, mu_func))
if (myid == 0):
    print("matrix ... ")
a.Assemble()
a.EliminateEssentialBCDiag(ess_bdr, 1.0)
a.Finalize()

m = mfem.ParBilinearForm(fespace)
m.AddDomainIntegrator(mfem.VectorMassIntegrator())
m.Assemble()

# shift the eigenvalue corresponding to eliminated dofs to a large value
m.EliminateEssentialBCDiag(ess_bdr, 3.0e-300)
m.Finalize()
if (myid == 0):
    print("done. ")

A = a.ParallelAssemble()
M = m.ParallelAssemble()

# 9. Define and configure the LOBPCG eigensolver and the BoomerAMG
#    preconditioner for A to be used within the solver. Set the matrices
#    which define the generalized eigenproblem A x = lambda M x.
amg = mfem.HypreBoomerAMG(A)
示例#3
0
    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
示例#4
0
    def __init__(self,
                 fespace,
                 lmbda=1.,
                 mu=1.,
                 rho=1.,
                 visc=0.0,
                 vess_tdof_list=None,
                 vess_bdr=None,
                 xess_tdof_list=None,
                 xess_bdr=None,
                 v_gfBdr=None,
                 x_gfBdr=None,
                 deform=None,
                 velo=None,
                 vx=None):
        mfem.PyTimeDependentOperator.__init__(self, 2 * fespace.GetTrueVSize(),
                                              0.0)
        self.lmbda = lmbda
        self.mu = mu
        self.viscosity = visc
        self.deform = deform
        self.velo = velo
        self.x_gfBdr = x_gfBdr
        self.v_gfBdr = v_gfBdr
        self.vx = vx
        self.z = mfem.Vector(self.Height() / 2)
        self.z.Assign(0.0)
        self.w = mfem.Vector(self.Height() / 2)
        self.w.Assign(0.0)
        self.tmpVec = mfem.Vector(self.Height() / 2)
        self.tmpVec.Assign(0.0)
        self.fespace = fespace
        self.xess_bdr = xess_bdr
        self.vess_bdr = vess_bdr
        self.xess_tdof_list = xess_tdof_list
        self.vess_tdof_list = vess_tdof_list

        # setting up linear form
        cv = mfem.Vector(3)
        cv.Assign(0.0)
        #self.zero_coef = mfem.ConstantCoefficient(0.0)
        self.zero_coef = mfem.VectorConstantCoefficient(cv)
        self.bx = mfem.LinearForm(self.fespace)
        self.bx.AddDomainIntegrator(
            mfem.VectorBoundaryLFIntegrator(self.zero_coef))
        self.bx.Assemble()
        self.bv = mfem.LinearForm(self.fespace)
        self.bv.AddDomainIntegrator(
            mfem.VectorBoundaryLFIntegrator(self.zero_coef))
        self.bv.Assemble()
        self.Bx = mfem.Vector()
        self.Bv = mfem.Vector()

        # setting up bilinear forms
        self.M = mfem.ParBilinearForm(self.fespace)
        self.K = mfem.ParBilinearForm(self.fespace)
        self.S = mfem.ParBilinearForm(self.fespace)

        self.ro = mfem.ConstantCoefficient(rho)
        self.M.AddDomainIntegrator(mfem.VectorMassIntegrator(self.ro))
        self.M.Assemble(0)
        self.M.EliminateEssentialBC(self.vess_bdr)
        self.M.Finalize(0)
        self.Mmat = self.M.ParallelAssemble()

        self.M_solver = mfem.CGSolver(self.fespace.GetComm())
        self.M_solver.iterative_mode = False
        self.M_solver.SetRelTol(1e-8)
        self.M_solver.SetAbsTol(0.0)
        self.M_solver.SetMaxIter(30)
        self.M_solver.SetPrintLevel(0)
        self.M_prec = mfem.HypreSmoother()
        self.M_prec.SetType(mfem.HypreSmoother.Jacobi)
        self.M_solver.SetPreconditioner(self.M_prec)
        self.M_solver.SetOperator(self.Mmat)

        lambVec = mfem.Vector(self.fespace.GetMesh().attributes.Max())
        print('Number of volume attributes : ' +
              str(self.fespace.GetMesh().attributes.Max()))
        lambVec.Assign(lmbda)
        lambVec[0] = lambVec[1] * 1.0
        lambda_func = mfem.PWConstCoefficient(lambVec)
        muVec = mfem.Vector(self.fespace.GetMesh().attributes.Max())
        muVec.Assign(mu)
        muVec[0] = muVec[1] * 1.0
        mu_func = mfem.PWConstCoefficient(muVec)
        self.K.AddDomainIntegrator(
            mfem.ElasticityIntegrator(lambda_func, mu_func))
        self.K.Assemble(0)
        # to set essential BC to zero value uncomment
        #self.K.EliminateEssentialBC(self.xess_bdr)
        #self.K.Finalize(0)
        #self.Kmat = self.K.ParallelAssemble()
        # to set essential BC to non-zero uncomment
        self.Kmat = mfem.HypreParMatrix()

        visc_coeff = mfem.ConstantCoefficient(visc)
        self.S.AddDomainIntegrator(mfem.VectorDiffusionIntegrator(visc_coeff))
        self.S.Assemble(0)
        #self.S.EliminateEssentialBC(self.vess_bdr)
        #self.S.Finalize(0)
        #self.Smat = self.S.ParallelAssemble()
        self.Smat = mfem.HypreParMatrix()

        # VX solver for implicit time-stepping
        self.VX_solver = mfem.CGSolver(self.fespace.GetComm())
        self.VX_solver.iterative_mode = False
        self.VX_solver.SetRelTol(1e-8)
        self.VX_solver.SetAbsTol(0.0)
        self.VX_solver.SetMaxIter(30)
        self.VX_solver.SetPrintLevel(0)
        self.VX_prec = mfem.HypreSmoother()
        self.VX_prec.SetType(mfem.HypreSmoother.Jacobi)
        self.VX_solver.SetPreconditioner(self.VX_prec)
        # setting up operators
        empty_tdof_list = intArray()
        self.S.FormLinearSystem(empty_tdof_list, self.v_gfBdr, self.bv,
                                self.Smat, self.vx.GetBlock(0), self.Bv, 1)
        self.K.FormLinearSystem(empty_tdof_list, self.x_gfBdr, self.bx,
                                self.Kmat, self.vx.GetBlock(1), self.Bx, 1)