示例#1
0
 def updStiffMatMS(self, elmLst, elmCompStiffMat):
     self.K = mfem.ParBilinearForm(self.fespace)
     lambVec = mfem.Vector(self.fespace.GetMesh().attributes.Max())
     lambVec.Assign(self.lmbda)
     lambVec[0] = lambVec[1]
     lambda_func = mfem.PWConstCoefficient(lambVec)
     muVec = mfem.Vector(self.fespace.GetMesh().attributes.Max())
     muVec.Assign(self.mu)
     muVec[0] = muVec[1]
     mu_func = mfem.PWConstCoefficient(muVec)
     self.K.AddDomainIntegrator(
         mfem.ElasticityIntegrator(lambda_func, mu_func))
     self.K.Assemble(0, elmLst, elmCompStiffMat, False, True)
     self.Kmat = mfem.HypreParMatrix()
     empty_tdof_list = intArray()
     self.K.FormLinearSystem(empty_tdof_list, self.x_gfBdr, self.bx,
                             self.Kmat, self.vx.GetBlock(1), self.Bx, 1)
示例#2
0
    print("Number of unknowns: " + str(size))
    print("Assembling")

# 8. Set up the parallel bilinear forms a(.,.) and m(.,.) on the finite
#    element space corresponding to the linear elasticity integrator with
#    piece-wise constants coefficient lambda and mu, a simple mass matrix
#    needed on the right hand side of the generalized eigenvalue problem
#    below. The boundary conditions are implemented by marking only boundary
#    attribute 1 as essential. We use special values on the diagonal to
#    shift the Dirichlet eigenvalues out of the computational range. After
#    serial/parallel assembly we extract the corresponding parallel matrices
#    A and M.
lamb = mfem.Vector(pmesh.attributes.Max())
lamb.Assign(1.0)
lamb[0] = lamb[1] * 50
lambda_func = mfem.PWConstCoefficient(lamb)
mu = mfem.Vector(pmesh.attributes.Max())
mu.Assign(1.0)
mu[0] = mu[1] * 50
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)
示例#3
0
#  9. Set up the parallel linear form b(.) which corresponds to the
#     right-hand side of the FEM linear system. In this case, b_i equals the
#     boundary integral of f*phi_i where f represents a "pull down" force on
#     the Neumann part of the boundary and phi_i are the basis functions in
#     the finite element fespace. The force is defined by the object f, which
#     is a vector of Coefficient objects. The fact that f is non-zero on
#     boundary attribute 2 is indicated by the use of piece-wise constants
#     coefficient for its last component.
f = mfem.VectorArrayCoefficient(dim)
for i in range(dim - 1):
    f.Set(i, mfem.ConstantCoefficient(0.0))

pull_force = mfem.Vector([0] * pmesh.bdr_attributes.Max())
pull_force[1] = -1.0e-2
f.Set(dim - 1, mfem.PWConstCoefficient(pull_force))

b = mfem.ParLinearForm(fespace)
b.AddBoundaryIntegrator(mfem.VectorBoundaryLFIntegrator(f))
print('r.h.s. ...')
b.Assemble()

# 10. Define the solution vector x as a parallel finite element grid
#     function corresponding to fespace. Initialize x with initial guess of
#     zero, which satisfies the boundary conditions.
x = mfem.GridFunction(fespace)
x.Assign(0.0)

# 11. Set up the parallel bilinear form a(.,.) on the finite element space
#     corresponding to the linear elasticity integrator with piece-wise
#     constants coefficient lambda and mu.
示例#4
0
#     boundary attribute 2 is indicated by the use of piece-wise constants
#     coefficient for its last component.
print dim

f = mfem.VectorArrayCoefficient(dim)
c1 = mfem.ConstantCoefficient(0.0); 
c2 = mfem.ConstantCoefficient(0.0); 
c3 = mfem.ConstantCoefficient(0.0); 
#for i in range(dim-1): 
f.Set(0, c1)
f.Set(1, c2)
print [0]*pmesh.bdr_attributes.Max()
pull_force = mfem.Vector([0]*pmesh.bdr_attributes.Max())
pull_force[1] = -1.0e-2;
pull_force.Print()
c3 = mfem.PWConstCoefficient(pull_force)
f.Set(dim-1, c3)


b = mfem.ParLinearForm(fespace)
'''
b.AddBoundaryIntegrator(mfem.VectorBoundaryLFIntegrator(f))
print('r.h.s. ...')
b.Assemble()

# 10. Define the solution vector x as a parallel finite element grid
#     function corresponding to fespace. Initialize x with initial guess of
#     zero, which satisfies the boundary conditions.
x = mfem.GridFunction(fespace)
x.Assign(0.0)  
print('here')
示例#5
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)