Esempio n. 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)
Esempio n. 2
0
    def SetParameters(self, u):
        u_alpha_gf = mfem.ParGridFunction(self.fespace)
        u_alpha_gf.SetFromTrueDofs(u)
        for i in range(u_alpha_gf.Size()):
            u_alpha_gf[i] = self.kappa + self.alpha * u_alpha_gf[i]

        self.K = mfem.ParBilinearForm(self.fespace)
        u_coeff = mfem.GridFunctionCoefficient(u_alpha_gf)
        self.K.AddDomainIntegrator(mfem.DiffusionIntegrator(u_coeff))
        self.K.Assemble(0)
        self.K.FormSystemMatrix(self.ess_tdof_list, self.Kmat)
        self.T = None
Esempio n. 3
0
    def __init__(self, spaces, ess_bdr, block_offsets, rel_tol, abs_tol, iter,
                 mu):

        # Array<Vector *> -> tuple
        super(RubberOperator,
              self).__init__(spaces[0].TrueVSize() + spaces[1].TrueVSize())
        rhs = (None, None)

        self.spaces = spaces
        self.mu = mfem.ConstantCoefficient(mu)
        self.block_offsets = block_offsets

        Hform = mfem.ParBlockNonlinearForm(spaces)
        Hform.AddDomainIntegrator(
            mfem.IncompressibleNeoHookeanIntegrator(self.mu))
        Hform.SetEssentialBC(ess_bdr, rhs)
        self.Hform = Hform

        a = mfem.ParBilinearForm(self.spaces[1])
        one = mfem.ConstantCoefficient(1.0)
        mass = mfem.OperatorHandle(mfem.Operator.Hypre_ParCSR)
        a.AddDomainIntegrator(mfem.MassIntegrator(one))
        a.Assemble()
        a.Finalize()
        a.ParallelAssemble(mass)
        mass.SetOperatorOwner(False)
        pressure_mass = mass.Ptr()

        self.j_prec = JacobianPreconditioner(spaces, pressure_mass,
                                             block_offsets)

        j_gmres = mfem.GMRESSolver(MPI.COMM_WORLD)
        j_gmres.iterative_mode = False
        j_gmres.SetRelTol(1e-12)
        j_gmres.SetAbsTol(1e-12)
        j_gmres.SetMaxIter(300)
        j_gmres.SetPrintLevel(0)
        j_gmres.SetPreconditioner(self.j_prec)
        self.j_solver = j_gmres

        newton_solver = mfem.NewtonSolver(MPI.COMM_WORLD)
        # Set the newton solve parameters
        newton_solver.iterative_mode = True
        newton_solver.SetSolver(self.j_solver)
        newton_solver.SetOperator(self)
        newton_solver.SetPrintLevel(1)
        newton_solver.SetRelTol(rel_tol)
        newton_solver.SetAbsTol(abs_tol)
        newton_solver.SetMaxIter(iter)
        self.newton_solver = newton_solver
Esempio n. 4
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)
Esempio n. 5
0
    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.HypreParMatrix()
        self.Kmat = mfem.HypreParMatrix()
        self.M_solver = mfem.CGSolver(fespace.GetComm())
        self.M_prec = mfem.HypreSmoother()
        self.T_solver = mfem.CGSolver(fespace.GetComm())
        self.T_prec = mfem.HypreSmoother()
        self.z = mfem.Vector(self.Height())

        self.M = mfem.ParBilinearForm(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(100)
        self.M_solver.SetPrintLevel(0)
        self.M_prec.SetType(mfem.HypreSmoother.Jacobi)
        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)
Esempio n. 6
0
# Inflow boundary condition (zero for the problems considered in this example)
class inflow_coeff(mfem.PyCoefficient):
    def EvalValue(self, x):
        return 0


# 8. Set up and assemble the bilinear and linear forms corresponding to the
#    DG discretization. The DGTraceIntegrator involves integrals over mesh
#    interior faces.

velocity = velocity_coeff(dim)
inflow = inflow_coeff()
u0 = u0_coeff()

m = mfem.ParBilinearForm(fes)
m.AddDomainIntegrator(mfem.MassIntegrator())
k = mfem.ParBilinearForm(fes)
k.AddDomainIntegrator(mfem.ConvectionIntegrator(velocity, -1.0))
k.AddInteriorFaceIntegrator(
    mfem.TransposeIntegrator(mfem.DGTraceIntegrator(velocity, 1.0, -0.5)))
k.AddBdrFaceIntegrator(
    mfem.TransposeIntegrator(mfem.DGTraceIntegrator(velocity, 1.0, -0.5)))

b = mfem.ParLinearForm(fes)
b.AddBdrFaceIntegrator(
    mfem.BoundaryFlowIntegrator(inflow, velocity, -1.0, -0.5))

m.Assemble()
m.Finalize()
skip_zeros = 0
Esempio n. 7
0
# 5. Define a parallel mesh by partitioning the serial mesh.  Once the
#    parallel mesh is defined, the serial mesh can be deleted.
pmesh = mfem.ParMesh(MPI.COMM_WORLD, mesh)
del mesh
ess_bdr = mfem.intArray(pmesh.bdr_attributes.Max())
ess_bdr.Assign(1)

# 6. Define a finite element space on the mesh. The polynomial order is one
#   (linear) by default, but this can be changed on the command line.
fec = mfem.H1_FECollection(order, dim)
fespace = mfem.ParFiniteElementSpace(pmesh, fec)

# 7. As in Example 1p, we set up bilinear and linear forms corresponding to
#    the Laplace problem -\Delta u = 1. We don't assemble the discrete
#    problem yet, this will be done in the inner loop.
a = mfem.ParBilinearForm(fespace)
b = mfem.ParLinearForm(fespace)

one = mfem.ConstantCoefficient(1.0)
bdr = BdrCoefficient()
rhs = RhsCoefficient()

integ = mfem.DiffusionIntegrator(one)
a.AddDomainIntegrator(integ)
b.AddDomainIntegrator(mfem.DomainLFIntegrator(rhs))

# 8. The solution vector x and the associated finite element grid function
#    will be maintained over the AMR iterations.
x = mfem.ParGridFunction(fespace)

# 9. Connect to GLVis.
Esempio n. 8
0
ess_bdr.Assign(1)
ess_dof = mfem.intArray()
x0_space.GetEssentialVDofs(ess_bdr, ess_dof)

B0 = mfem.ParMixedBilinearForm(x0_space, test_space)
B0.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
B0.Assemble()
B0.EliminateEssentialBCFromTrialDofs(ess_dof, x0, F)
B0.Finalize()

Bhat = mfem.ParMixedBilinearForm(xhat_space, test_space)
Bhat.AddTraceFaceIntegrator(mfem.TraceJumpIntegrator())
Bhat.Assemble()
Bhat.Finalize()

Sinv = mfem.ParBilinearForm(test_space)
Sum = mfem.SumIntegrator()
Sum.AddIntegrator(mfem.DiffusionIntegrator(one))
Sum.AddIntegrator(mfem.MassIntegrator(one))
Sinv.AddDomainIntegrator(mfem.InverseIntegrator(Sum))
Sinv.Assemble()
Sinv.Finalize()

S0 = mfem.ParBilinearForm(x0_space)
S0.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
S0.Assemble()
S0.EliminateEssentialBC(ess_bdr)
S0.Finalize()

matB0 = B0.ParallelAssemble()
del B0
Esempio n. 9
0
trueRhs = mfem.BlockVector(block_trueOffsets)

fform = mfem.ParLinearForm()
fform.Update(R_space, rhs.GetBlock(0), 0)
fform.AddDomainIntegrator(mfem.VectorFEDomainLFIntegrator(fcoeff))
fform.AddBoundaryIntegrator(mfem.VectorFEBoundaryFluxLFIntegrator(fnatcoeff))
fform.Assemble()
fform.ParallelAssemble(trueRhs.GetBlock(0))

gform = mfem.ParLinearForm()
gform.Update(W_space, rhs.GetBlock(1), 0)
gform.AddDomainIntegrator(mfem.DomainLFIntegrator(gcoeff))
gform.Assemble()
gform.ParallelAssemble(trueRhs.GetBlock(1))

mVarf = mfem.ParBilinearForm(R_space)
bVarf = mfem.ParMixedBilinearForm(R_space, W_space)

mVarf.AddDomainIntegrator(mfem.VectorFEMassIntegrator(k))
mVarf.Assemble()
mVarf.Finalize()
M = mVarf.ParallelAssemble()

bVarf.AddDomainIntegrator(mfem.VectorFEDivergenceIntegrator())
bVarf.Assemble()
bVarf.Finalize()
B = bVarf.ParallelAssemble()
B *= -1
BT = B.Transpose()

darcyOp = mfem.BlockOperator(block_trueOffsets)
Esempio n. 10
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
Esempio n. 11
0
def run(order = 1, static_cond = False,
        meshfile = def_meshfile, visualization = False,
        use_strumpack = False):

   mesh = mfem.Mesh(meshfile, 1,1)
   dim = mesh.Dimension()

   ref_levels = int(np.floor(np.log(10000./mesh.GetNE())/np.log(2.)/dim))
   for x in range(ref_levels):
      mesh.UniformRefinement();
   mesh.ReorientTetMesh();
   pmesh = mfem.ParMesh(MPI.COMM_WORLD, mesh)
   del mesh

   par_ref_levels = 2
   for l in range(par_ref_levels):
       pmesh.UniformRefinement();

   if order > 0:
       fec = mfem.H1_FECollection(order, dim)
   elif mesh.GetNodes():
       fec = mesh.GetNodes().OwnFEC()
       print( "Using isoparametric FEs: " + str(fec.Name()));
   else:
       order = 1
       fec = mfem.H1_FECollection(order, dim)

   fespace =mfem.ParFiniteElementSpace(pmesh, fec)
   fe_size = fespace.GlobalTrueVSize()

   if (myid == 0):
      print('Number of finite element unknowns: '+  str(fe_size))

   ess_tdof_list = mfem.intArray()
   if pmesh.bdr_attributes.Size()>0:
       ess_bdr = mfem.intArray(pmesh.bdr_attributes.Max())
       ess_bdr.Assign(1)
       fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list)

   #   the basis functions in the finite element fespace.
   b = mfem.ParLinearForm(fespace)
   one = mfem.ConstantCoefficient(1.0)
   b.AddDomainIntegrator(mfem.DomainLFIntegrator(one))
   b.Assemble();

   x = mfem.ParGridFunction(fespace);
   x.Assign(0.0)

   a = mfem.ParBilinearForm(fespace);
   a.AddDomainIntegrator(mfem.DiffusionIntegrator(one))

   if static_cond: a.EnableStaticCondensation()
   a.Assemble();

   A = mfem.HypreParMatrix()
   B = mfem.Vector()
   X = mfem.Vector()
   a.FormLinearSystem(ess_tdof_list, x, b, A, X, B)

   if (myid == 0):
      print("Size of linear system: " + str(x.Size()))
      print("Size of linear system: " + str(A.GetGlobalNumRows()))

   if use_strumpack:
       import mfem.par.strumpack as strmpk
       Arow = strmpk.STRUMPACKRowLocMatrix(A)
       args = ["--sp_hss_min_sep_size", "128", "--sp_enable_hss"]
       strumpack = strmpk.STRUMPACKSolver(args, MPI.COMM_WORLD)
       strumpack.SetPrintFactorStatistics(True)
       strumpack.SetPrintSolveStatistics(False)
       strumpack.SetKrylovSolver(strmpk.KrylovSolver_DIRECT);
       strumpack.SetReorderingStrategy(strmpk.ReorderingStrategy_METIS)
       strumpack.SetMC64Job(strmpk.MC64Job_NONE)
       # strumpack.SetSymmetricPattern(True)
       strumpack.SetOperator(Arow)
       strumpack.SetFromCommandLine()
       strumpack.Mult(B, X);

   else:
       amg = mfem.HypreBoomerAMG(A)
       cg = mfem.CGSolver(MPI.COMM_WORLD)
       cg.SetRelTol(1e-12)
       cg.SetMaxIter(200)
       cg.SetPrintLevel(1)
       cg.SetPreconditioner(amg)
       cg.SetOperator(A)
       cg.Mult(B, X);


   a.RecoverFEMSolution(X, b, x)

   smyid = '{:0>6d}'.format(myid)
   mesh_name  =  "mesh."+smyid
   sol_name   =  "sol."+smyid

   pmesh.Print(mesh_name, 8)
   x.Save(sol_name, 8)
Esempio n. 12
0
def run(order = 1, static_cond = False,
        meshfile = def_meshfile, visualization = False):

   mesh = mfem.Mesh(meshfile, 1,1)
   dim = mesh.Dimension()

   ref_levels = int(np.floor(np.log(10000./mesh.GetNE())/np.log(2.)/dim))
   for x in range(ref_levels):
      mesh.UniformRefinement();
   mesh.ReorientTetMesh();
   pmesh = mfem.ParMesh(MPI.COMM_WORLD, mesh)
   del mesh

   par_ref_levels = 2
   for l in range(par_ref_levels):
       pmesh.UniformRefinement();

   if order > 0:
       fec = mfem.H1_FECollection(order, dim)
   elif mesh.GetNodes():
       fec = mesh.GetNodes().OwnFEC()
       prinr( "Using isoparametric FEs: " + str(fec.Name()));
   else:
       order = 1
       fec = mfem.H1_FECollection(order, dim)

   fespace =mfem.ParFiniteElementSpace(pmesh, fec)
   fe_size = fespace.GlobalTrueVSize()

   if (myid == 0):
      print('Number of finite element unknowns: '+  str(fe_size))

   ess_tdof_list = mfem.intArray()
   if pmesh.bdr_attributes.Size()>0:
       ess_bdr = mfem.intArray(pmesh.bdr_attributes.Max())
       ess_bdr.Assign(1)
       fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list)

   #   the basis functions in the finite element fespace.
   b = mfem.ParLinearForm(fespace)
   one = mfem.ConstantCoefficient(1.0)
   b.AddDomainIntegrator(mfem.DomainLFIntegrator(one))
   b.Assemble();

   x = mfem.ParGridFunction(fespace);
   x.Assign(0.0)

   a = mfem.ParBilinearForm(fespace);
   a.AddDomainIntegrator(mfem.DiffusionIntegrator(one))

   if static_cond: a.EnableStaticCondensation()
   a.Assemble();

   A = mfem.HypreParMatrix()
   B = mfem.Vector()
   X = mfem.Vector()
   a.FormLinearSystem(ess_tdof_list, x, b, A, X, B)

   if (myid == 0):
      print("Size of linear system: " + str(x.Size()))
      print("Size of linear system: " + str(A.GetGlobalNumRows()))

   amg = mfem.HypreBoomerAMG(A)
   pcg = mfem.HyprePCG(A)
   pcg.SetTol(1e-12)
   pcg.SetMaxIter(200)
   pcg.SetPrintLevel(2)
   pcg.SetPreconditioner(amg)
   pcg.Mult(B, X);


   a.RecoverFEMSolution(X, b, x)

   smyid = '{:0>6d}'.format(myid)
   mesh_name  =  "mesh."+smyid
   sol_name   =  "sol."+smyid

   pmesh.PrintToFile(mesh_name, 8)
   x.SaveToFile(sol_name, 8)
Esempio n. 13
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)
Esempio n. 14
0
def run_test():
    print("Test complex_operator module")
    Nvert = 6
    Nelem = 8
    Nbelem = 2

    mesh = mfem.Mesh(2, Nvert, Nelem, 2, 3)
    tri_v = [[1., 0., 0.], [0., 1., 0.], [-1., 0., 0.], [0., -1., 0.],
             [0., 0., 1.], [0., 0., -1.]]
    tri_e = [[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 5], [2, 1, 5],
             [3, 2, 5], [0, 3, 5]]
    tri_l = [[1, 4], [1, 2]]

    for j in range(Nvert):
        mesh.AddVertex(tri_v[j])
    for j in range(Nelem):
        mesh.AddTriangle(tri_e[j], 1)
    for j in range(Nbelem):
        mesh.AddBdrSegment(tri_l[j], 1)

    mesh.FinalizeTriMesh(1, 1, True)
    dim = mesh.Dimension()
    order = 1
    fec = mfem.H1_FECollection(order, dim)

    if use_parallel:
        mesh = mfem.ParMesh(MPI.COMM_WORLD, mesh)
        fes = mfem.ParFiniteElementSpace(mesh, fec)
        a1 = mfem.ParBilinearForm(fes)
        a2 = mfem.ParBilinearForm(fes)
    else:
        fes = mfem.FiniteElementSpace(mesh, fec)
        a1 = mfem.BilinearForm(fes)
        a2 = mfem.BilinearForm(fes)
    one = mfem.ConstantCoefficient(1.0)
    a1.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
    a1.Assemble()
    a1.Finalize()

    a2.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
    a2.Assemble()
    a2.Finalize()

    if use_parallel:
        M1 = a1.ParallelAssemble()
        M2 = a2.ParallelAssemble()
        M1.Print('M1')
        width = fes.GetTrueVSize()
        #X = mfem.HypreParVector(fes)
        #Y = mfem.HypreParVector(fes)
        #X.SetSize(fes.TrueVSize())
        #Y.SetSize(fes.TrueVSize())
        #from mfem.common.parcsr_extra import ToScipyCoo
        #MM1 = ToScipyCoo(M1)
        #print(MM1.toarray())
        #print(MM1.dot(np.ones(6)))
    else:
        M1 = a1.SpMat()
        M2 = a2.SpMat()
        M1.Print('M1')
        width = fes.GetVSize()

        #X = mfem.Vector()
        #Y = mfem.Vector()
        #X.SetSize(M1.Width())
        #Y.SetSize(M1.Height())
        #from mfem.common.sparse_utils import sparsemat_to_scipycsr
        #MM1 = sparsemat_to_scipycsr(M1, np.float)
        #print(MM1.toarray())
        #print(MM1.dot(np.ones(6)))
    #X.Assign(0.0)
    #X[0] = 1.0
    #M1.Mult(X, Y)
    #print(Y.GetDataArray())

    Mc = mfem.ComplexOperator(M1, M2, hermitan=True)
    offsets = mfem.intArray([0, width, width])
    offsets.PartialSum()

    x = mfem.BlockVector(offsets)
    y = mfem.BlockVector(offsets)

    x.GetBlock(0).Assign(0)
    if myid == 0:
        x.GetBlock(0)[0] = 1.0
    x.GetBlock(1).Assign(0)
    if myid == 0:
        x.GetBlock(1)[0] = 1.0

    Mc.Mult(x, y)
    print("x", x.GetDataArray())
    print("y", y.GetDataArray())

    if myid == 0:
        x.GetBlock(1)[0] = -1.0

    x.Print()
    Mc.Mult(x, y)
    print("x", x.GetDataArray())
    print("y", y.GetDataArray())