Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

badge badge

MFEM + PyMFEM (FEM library)

This repository provides Python binding for MFEM. MFEM is a high performance parallel finite element method (FEM) library (http://mfem.org/).

Installer (setup.py) builds both MFEM and binding together. Binary package install is supported for Linux (x86) and MacOSX (Apple Silicon) By default, "pip install mfem" downloads and builds the serial version of MFEM and PyMFEM. Additionally, the installer supports building MFEM with specific options together with other external libraries, including MPI version.

Install

Using pip (Serial MFEM)

pip install mfem

Using pip (MPICH parallel MFEM with GSLIB/HYPRE/METIS)

For Linux x86_64 releases with matching parallel wheels (Python 3.11–3.14):

pip install "mfem[mpich]"
pip install --upgrade "mfem[mpich]"

Build with additional features (MPI, GPU, GPU-Hypre, GSLIB, SuiteSparse, libCEED, LAPACK)

The setup script accept various options. Download the package manually and run the script. Examples below downloads and build parallel version of MFEM library (linked with Metis and Hypre) and installs under /mfem. See INSTALL for various other options

Download source and build

$ git clone https://github.com/mfem/PyMFEM.git
$ cd PyMFEM

# Build it from local source with MPI
$ pip install ./ -C"with-parallel=Yes" --verbose

Cleaning

$ rm -rf build    # clean build directory
$ rm -rf external # clean external dependencies + wrapper code
$ git clean -f    # clean files under mfem/_ser and mfem/_par

Run test

cd test
python run_examples.py -serial

Usage

This example (modified from ex1.cpp) solves the Poisson equation, $$\nabla \cdot (\alpha \nabla u) = f$$ in a square and plots the result using matplotlib. Use the badge above to open this in Colab.

import mfem.ser as mfem

# Create a square mesh
mesh = mfem.Mesh(10, 10, "TRIANGLE")

# Define the finite element function space
fec = mfem.H1_FECollection(1, mesh.Dimension())   # H1 order=1
fespace = mfem.FiniteElementSpace(mesh, fec)

# Define the essential dofs
ess_tdof_list = mfem.intArray()
ess_bdr = mfem.intArray([1]*mesh.bdr_attributes.Size())
fespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list)

# Define constants for alpha (diffusion coefficient) and f (RHS)
alpha = mfem.ConstantCoefficient(1.0)
rhs = mfem.ConstantCoefficient(1.0)

"""
Note
-----
In order to represent a variable diffusion coefficient, you
must use a numba-JIT compiled function. For example:

>>> @mfem.jit.scalar
>>> def alpha(x):
>>>     return x+1.0
"""

# Define the bilinear and linear operators
a = mfem.BilinearForm(fespace)
a.AddDomainIntegrator(mfem.DiffusionIntegrator(alpha))
a.Assemble()
b = mfem.LinearForm(fespace)
b.AddDomainIntegrator(mfem.DomainLFIntegrator(rhs))
b.Assemble()

# Initialize a gridfunction to store the solution vector
x = mfem.GridFunction(fespace)
x.Assign(0.0)

# Form the linear system of equations (AX=B)
A = mfem.OperatorPtr()
B = mfem.Vector()
X = mfem.Vector()
a.FormLinearSystem(ess_tdof_list, x, b, A, X, B)
print("Size of linear system: " + str(A.Height()))

# Solve the linear system using PCG and store the solution in x
AA = mfem.OperatorHandle2SparseMatrix(A)
M = mfem.GSSmoother(AA)
mfem.PCG(AA, M, B, X, 1, 200, 1e-12, 0.0)
a.RecoverFEMSolution(X, b, x)

# Extract vertices and solution as numpy arrays
verts = mesh.GetVertexArray()
sol = x.GetDataArray()

# Plot the solution using matplotlib
import matplotlib.pyplot as plt
import matplotlib.tri as tri

triang = tri.Triangulation(verts[:,0], verts[:,1])

fig, ax = plt.subplots()
ax.set_aspect('equal')
tpc = ax.tripcolor(triang, sol, shading='gouraud')
fig.colorbar(tpc)
plt.show()

License

PyMFEM is licensed under the BSD 3-Clause license. All new contributions must be made under this license. See LICENSE for details.

Binary distributions include the licenses and notices for bundled libraries: MFEM and, for parallel distributions, HYPRE, METIS, and GSLIB. These libraries retain their respective licenses.

For more information about external libraries, see:

Metadata

Release files for mfem 4.10.0.2rc6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for mfem 4.10.0.2rc6
File Actions
mfem-4.10.0.2rc6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for mfem-4.10.0.2rc6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.2rc6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for mfem-4.10.0.2rc6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.2rc6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for mfem-4.10.0.2rc6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.2rc6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for mfem-4.10.0.2rc6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Total release size: 313.2 MB

Release files / mfem-4.10.0.2rc6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.2rc6-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 78.4 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d5293119771c694e99736a43d4122408eb92a48ecc4d4668ff4c5d733538735e
BLAKE2b-256 checksum
How to use checksums
f44a27f499336ddde4bc80515863bbfe295455cdba0c4574076e2e2c5b6c4c62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem-4.10.0.2rc6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.2rc6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 78.6 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
addd315d21fdf55220836a692b882ef762fe2a551288f53181f774392a7f102c
BLAKE2b-256 checksum
How to use checksums
ee8024e6fd42604f1911589765dc9b7dbc431e53fdf158cf9b73557ed1023a39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem-4.10.0.2rc6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.2rc6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 78.4 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
872957fcbac1047b0a5100f31592a536c539eba761512be55428fb028ec35aeb
BLAKE2b-256 checksum
How to use checksums
dcb991ad496b172d509b1b264d42d181be330ad4fde209479372155aab5ecca1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem-4.10.0.2rc6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.2rc6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 77.8 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ce5ae7227d2424ba442bc36c019b3dc5d44b0a568a7dbc9b9ab79eaa931c85c0
BLAKE2b-256 checksum
How to use checksums
24b56d46310de11b4fe04b1482cd0022240f66a9452fcad4d51d4b49d7132852
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for mfem 4.10.0.2rc6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page