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-mpich 4.10.0.2rc7

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-mpich 4.10.0.2rc7
File Actions
mfem_mpich-4.10.0.2rc7-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_mpich-4.10.0.2rc7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem_mpich-4.10.0.2rc7-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details for mfem_mpich-4.10.0.2rc7-cp314-cp314-macosx_14_0_arm64.whl
mfem_mpich-4.10.0.2rc7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for mfem_mpich-4.10.0.2rc7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem_mpich-4.10.0.2rc7-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details for mfem_mpich-4.10.0.2rc7-cp313-cp313-macosx_14_0_arm64.whl
mfem_mpich-4.10.0.2rc7-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_mpich-4.10.0.2rc7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem_mpich-4.10.0.2rc7-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details for mfem_mpich-4.10.0.2rc7-cp312-cp312-macosx_14_0_arm64.whl
mfem_mpich-4.10.0.2rc7-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_mpich-4.10.0.2rc7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem_mpich-4.10.0.2rc7-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details for mfem_mpich-4.10.0.2rc7-cp311-cp311-macosx_14_0_arm64.whl

Total release size: 514.3 MB

Release files / mfem_mpich-4.10.0.2rc7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 90.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
7c7fdc2fe08731bbaceec71e834ed6e48cc9eb4134512284bf79161e3cda6ff1
BLAKE2b-256 checksum
How to use checksums
cd9f124d94b85f3c491f23ea7b4cd8a3a0c9e2b47a2cb376b736948985174551
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp314-cp314-macosx_14_0_arm64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp314-cp314-macosx_14_0_arm64.whl
Size 38.3 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
5482853fbbf23e5a76ac928f930bbd62f399f8a73194b9b18f06a0f19bf5c0ff
BLAKE2b-256 checksum
How to use checksums
634f76fb07290262d0ab406c3bbc1db36aa4583b7c62f62133d9b7d39563ea32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 90.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
d05ab1e27bf9e0c139752066984541ff611efd45b56d74591c622aaf46a2b32b
BLAKE2b-256 checksum
How to use checksums
e8d7b3a28c3f69e44f509660b8938000b8f6ba5a29fdd0560fcdb5fe37994927
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp313-cp313-macosx_14_0_arm64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp313-cp313-macosx_14_0_arm64.whl
Size 38.2 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
143ec33cad5825d6d7171c9bd3af329b7c36e2c7540c2459745ac37a79542f43
BLAKE2b-256 checksum
How to use checksums
2a31eb8342c0e4ec854c174b586abb332721a6bb928d38ee77bbd0d1d40a9b1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 90.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
e1daa4e224731b0dadb90c378c3f709197030143b312d34d18de4df0c39c67ba
BLAKE2b-256 checksum
How to use checksums
abd349017436b5c3ea88425ea83926e3ce6a5c62c67648c72e22d88468d11ff3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp312-cp312-macosx_14_0_arm64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp312-cp312-macosx_14_0_arm64.whl
Size 38.3 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
aeb6ca75e2a33adbd0b45fdd87ebaa0dd0b49a50831a0a0b1d7329818ae24c79
BLAKE2b-256 checksum
How to use checksums
4f7530e4fa6933085de768595b4a9a47e105880589884d985dcb1b3a15535672
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 89.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
03c81a442097fd1d9c777ef14ff3f852e386525b06b994623349ba4da4da5681
BLAKE2b-256 checksum
How to use checksums
9c93f6deeb97b93491df91ff45bbecd6ed039d0d0d5d0f90a698f0c75e442349
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / mfem_mpich-4.10.0.2rc7-cp311-cp311-macosx_14_0_arm64.whl

Download URL mfem_mpich-4.10.0.2rc7-cp311-cp311-macosx_14_0_arm64.whl
Size 38.3 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
d1fc7ba2cf30a07f17dbe173e9c06b59bbc78edac3b7c7826c9c00370c27b772
BLAKE2b-256 checksum
How to use checksums
193f1e59a4c0209cab84a76976c586c52390194b4b10a589e63d34187d8732f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for mfem-mpich 4.10.0.2rc7

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