Example #1
0
for lev in range(ser_ref_levels):
    mesh.UniformRefinement()
    if mesh.NURBSext:
        mesh.SetCurvature(max(order, 1))
    bb_min, bb_max = mesh.GetBoundingBox(max(order, 1))

# 6. Define the parallel mesh by a partitioning of the serial mesh. Refine
#    this mesh further in parallel to increase the resolution. Once the
#    parallel mesh is defined, the serial mesh can be deleted.
pmesh = mfem.ParMesh(MPI.COMM_WORLD, mesh)
for k in range(par_ref_levels):
    pmesh.UniformRefinement()

# 7. Define the discontinuous DG finite element space of the given
#    polynomial order on the refined mesh.
fec = mfem.DG_FECollection(order, dim)
fes = mfem.ParFiniteElementSpace(pmesh, fec)

global_vSize = fes.GlobalTrueVSize()
if myid == 0:
    print("Number of unknowns: " + str(global_vSize))


#
#  Define coefficient using VecotrPyCoefficient and PyCoefficient
#  A user needs to define EvalValue method
#
class velocity_coeff(mfem.VectorPyCoefficient):
    def EvalValue(self, x):
        dim = len(x)
Example #2
0
        np.floor(np.log(5000. / mesh.GetNE()) / np.log(2.) / dim))
for x in range(ser_ref_levels):
    mesh.UniformRefinement()

# Since NURBS meshes do not support DG integrators, we convert them to
# regular polynomial mesh of the specified (solution) order.
if (mesh.NURBSext): mesh.SetCurvature(order)
pmesh = mfem.ParMesh(MPI.COMM_WORLD, mesh)
del mesh
for x in range(par_ref_levels):
    pmesh.UniformRefinement()

# 4. Define a DG vector finite element space on the mesh. Here, we use
#    Gauss-Lobatto nodal basis because it gives rise to a sparser matrix
#    compared to the default Gauss-Legendre nodal basis.
fec = mfem.DG_FECollection(order, dim, mfem.BasisType.GaussLobatto)
fespace = mfem.ParFiniteElementSpace(pmesh, fec, dim, mfem.Ordering.byVDIM)

glob_size = fespace.GlobalTrueVSize()
if (myid == 0):
    print('Number of finite element unknowns: ' + str(glob_size))
    print('Assembling:')

# 5. In this example, the Dirichlet boundary conditions are defined by
#    marking boundary attributes 1 and 2 in the marker Array 'dir_bdr'.
#    These b.c. are imposed weakly, by adding the appropriate boundary
#    integrators over the marked 'dir_bdr' to the bilinear and linear forms.
#    With this DG formulation, there are no essential boundary conditions.
ess_tdof_list = mfem.intArray()
dir_bdr = mfem.intArray(pmesh.bdr_attributes.Max())
dir_bdr.Assign(0)