Esempio n. 1
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. 2
0
        # 16. Project the exact solution to the essential DOFs.
        x.ProjectBdrCoefficient(bdr, ess_bdr)

        # 17. Create and solve the parallel linear system.
        ess_tdof_list = mfem.intArray()
        fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list)

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

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

        # 18. Extract the local solution on each processor.
        a.RecoverFEMSolution(X, b, x)

        # 19. Send the solution by socket to a GLVis server
        if visualization:
            sout.send_text("parallel " + str(num_procs) + " " + str(myid))
            sout.precision(8)
            sout.send_solution(pmesh, x)
Esempio n. 3
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()
        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()))

    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)
        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)