Skip to main content

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. 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            # binary install is available only on linux platforms (Py38-312)

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 BSD-3 license. All new contributions must be made under this license. See License for details.

Please refer the developers' web sites for the external libraries

Metadata

Release files for mfem 4.10.0.1

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

Source distribution (sdist)

Source distribution for mfem 4.10.0.1
File Size Uploaded Provenance Actions
mfem-4.10.0.1.tar.gz 457.5 kB Without provenance Details for mfem-4.10.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for mfem 4.10.0.1
File Actions
mfem-4.10.0.1-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.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.1-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details for mfem-4.10.0.1-cp314-cp314-macosx_14_0_arm64.whl
mfem-4.10.0.1-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.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.1-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details for mfem-4.10.0.1-cp313-cp313-macosx_14_0_arm64.whl
mfem-4.10.0.1-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.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.1-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details for mfem-4.10.0.1-cp312-cp312-macosx_14_0_arm64.whl
mfem-4.10.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for mfem-4.10.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
mfem-4.10.0.1-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details for mfem-4.10.0.1-cp311-cp311-macosx_14_0_arm64.whl

Total release size: 547.0 MB

Release files / mfem-4.10.0.1.tar.gz

Download URL mfem-4.10.0.1.tar.gz
Size 457.5 kB
Tags Source
SHA-256 checksum
How to use checksums
45ebfc4fd76b906db07c8d99f60482a0b7318cd294eba047c0a852de054ae40f
BLAKE2b-256 checksum
How to use checksums
9a306d5b64b12d514c71b96187c8b30500a0f3f5c5f7aa75879942d0fe481491
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / mfem-4.10.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

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

Release files / mfem-4.10.0.1-cp314-cp314-macosx_14_0_arm64.whl

Download URL mfem-4.10.0.1-cp314-cp314-macosx_14_0_arm64.whl
Size 34.8 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
780986c4ec1bdaa4eecacec4c6b0220e040b6c332c79c2908db2086076bad92b
BLAKE2b-256 checksum
How to use checksums
55d2cb630fe432ee25188461fa254de12aff98b7f5ae5558b96c746130b953ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / mfem-4.10.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 102.1 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
682e977880a5beb34f560862ec3467a9e9d220397fb571d5041c2dbf54de13b4
BLAKE2b-256 checksum
How to use checksums
2d32892eb397730499e9e045183fd76963716ecc74492c9ba62ef55c2f508f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / mfem-4.10.0.1-cp313-cp313-macosx_14_0_arm64.whl

Download URL mfem-4.10.0.1-cp313-cp313-macosx_14_0_arm64.whl
Size 34.8 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
792107ec5a28c525219703cc5d86089a5a30f86b1198eb55269c2ad8d2c90e23
BLAKE2b-256 checksum
How to use checksums
9e96d6103e5ba52ab1154d7530460e1ae36c473a1a6c9b730b89f25b396637f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / mfem-4.10.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 102.0 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e7fe115926d4cf8689d5f86f13cbdf837858aa0d93c6fcb65317ecc70b3f6e45
BLAKE2b-256 checksum
How to use checksums
0ad2fc5fdbb22d14b275ffcd2b8e28d6d8cf5bb1f190b6fcba7dcc8fa24c49fb
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.1-cp312-cp312-macosx_14_0_arm64.whl

Download URL mfem-4.10.0.1-cp312-cp312-macosx_14_0_arm64.whl
Size 34.9 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
f9d43b6562f93b379b4b3c84a876f5aa0b267b18864585d8c7ebe91cfd9e389a
BLAKE2b-256 checksum
How to use checksums
7e7f650a4d6894847b286ff759cd2e8f4c67b7b2b33f967f4ca969848258bdac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / mfem-4.10.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL mfem-4.10.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 101.3 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ee5f17c8b2ff308b1e93130e79fc8138c4f4965c13bdcd1f53f9c10ee422e89c
BLAKE2b-256 checksum
How to use checksums
8437ccf94f210875a094839a8bbbdeb5d266e31580d7ab16e4117f7935263422
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Release files / mfem-4.10.0.1-cp311-cp311-macosx_14_0_arm64.whl

Download URL mfem-4.10.0.1-cp311-cp311-macosx_14_0_arm64.whl
Size 34.6 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
5e4843e570b401e87d70c5241d2df3a422e18d355c3d6f7287f65687fe35422f
BLAKE2b-256 checksum
How to use checksums
5972998e3637167be482826917b4cfc9981a4ff09c462a9dd3064c854b0a9e49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for mfem 4.10.0.1

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

4.10.0.1 This release

9 release files No provenance

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