Skip to main content

MFEM + PyMFEM (finite element method library)

Project description

Binder 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.

Requirement

numpy, swig  + mpi4py (for --with-parallel)

Install

pip install mfem                    # binary install is available only on linux platforms (Py36-310) 
pip install mfem --no-binary mfem   # install serial MFEM + wrapper from source

Using additional features (MPI, GPU, GPU-Hypre, GSLIB, SuiteSparse)

The setup script accept various options. TO use it, one can either use --install-option flag with pip, or download the package manually and run the script. For example, this below download and build parallel version of MFEM library (linked with Metis and Hypre) and install under /mfem. See also, docs/install.txt

### Using pip
$ pip install mfem --install-option="--with-parallel" [--verbose]

### Runnig setup.py
$ pip download mfem --no-binary mfem (expand tar.gz file and move to the downloaded directory)
$ python setup.py install --with-parallel # it download and build metis/hypre/mfem

### Verbose output
$ python setup.py install --vv # SWIG output and CMAKE_VERBOSE_MAKEFILE is on

### Cleaning
$ python setup.py clean --all # clean external dependencies + wrapper code

Build with MFEM master in Github

$ pip install mfem --install-option="--with-parallel" --install-option="mfem-branch=master"[--verbose]
(or)
$ python setup.py install  --with-parallel --mfem-branch='master'

Choosing compiler

$ python setup.py install --with-parallel --CC=icc --CXX=icpc --MPICC=mpiicc --MPICXX=mpiicpc

### Other options

For other configurations, see docs/install.txt or help

$ python setup.py install --help

Install from github source

# Clone this repo
git clone https://github.com/mfem/PyMFEM.git

# Build & Install
pip install ./PyMFEM --verbosel # build both MFEM and PyMFEM
  *or*
cd PyMFEM
python setup.py install # build both MFEM and PyMFEM

# Run test
cd test
python test_examples.py -serial

Usage

Here is an example to solve div(grad(f)) = 1 in a square and to plot the result with matplotlib (modified from ex1.cpp). Use the badge above to open this in Binder.

import mfem.ser as mfem

# create sample mesh for square shape
mesh = mfem.Mesh(10, 10, "TRIANGLE")

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

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

# constant coefficient 
one = mfem.ConstantCoefficient(1.0)

# define Bilinear and Linear operator
a = mfem.BilinearForm(fespace)
a.AddDomainIntegrator(mfem.DiffusionIntegrator(one))
a.Assemble()
b = mfem.LinearForm(fespace)
b.AddDomainIntegrator(mfem.DomainLFIntegrator(one))
b.Assemble()

# create gridfunction, which is where the solution vector is stored
x = mfem.GridFunction(fespace);
x.Assign(0.0)

# form linear equation (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 it using PCG solver and store the solution to 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 array
verts = mesh.GetVertexArray()
sol = x.GetDataArray()

# plot solution using Matplotlib

import matplotlib.pyplot as plt
import matplotlib.tri as tri

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

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

License

PyMFEM is licensed under BSD-3. Please refer the developers' web sites for the external libraries

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mfem-4.4.0.3.tar.gz (402.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mfem-4.4.0.3-cp310-cp310-manylinux_2_24_x86_64.whl (33.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

mfem-4.4.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (46.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

mfem-4.4.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (46.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

mfem-4.4.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

mfem-4.4.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (45.6 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

Details for the file mfem-4.4.0.3.tar.gz.

File metadata

  • Download URL: mfem-4.4.0.3.tar.gz
  • Upload date:
  • Size: 402.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for mfem-4.4.0.3.tar.gz
Algorithm Hash digest
SHA256 9dd568f1878e9672d53f3cfb2f43167d7b425760d08172b9243cd944ad7f7506
MD5 cfd88bdd260b6dd4bc411557f5771a7f
BLAKE2b-256 b17bcfa08ba692818cd36f700223c70248b5f95882d3a6704e725cd37f994ef2

See more details on using hashes here.

File details

Details for the file mfem-4.4.0.3-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for mfem-4.4.0.3-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 8f96ca1c6b7c1a372d5a5ca3bcefd0fda4c2a1e570a7c7133b74cd76f74d8248
MD5 7dfb1cc830b97e0a6ad72b3967c43707
BLAKE2b-256 ea1bc8e3cfa65efb59fca03eceeb27104b104095f30dfb5e82ebd2539b3cf94f

See more details on using hashes here.

File details

Details for the file mfem-4.4.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mfem-4.4.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4873a73168229f0956ded9e3b04e5ab14cb547c08feae0a7a20f71b5fd411644
MD5 e62677b3691a7a64454807c61fd02d72
BLAKE2b-256 50e94f1ab022962e91187f8038536c8df4c166df218c201702d29c4f8eca43c6

See more details on using hashes here.

File details

Details for the file mfem-4.4.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mfem-4.4.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b749cc4b28ec8cc5b954ee8308a0e53f492fde3cc410f066862ce9d370230d4
MD5 3288512fc24311759d6df0e2101e59fe
BLAKE2b-256 8bdd2d272b61cb07dc6da993b74af909921a1a4caa6b97f9fe31e46c6c989e20

See more details on using hashes here.

File details

Details for the file mfem-4.4.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mfem-4.4.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b9f2b595e8a9da2196d44c2038b1d0aa677689f2ba8be5a0d041c094d837895
MD5 255630bd11922b8bc0c9e40da6e91d1e
BLAKE2b-256 bd7050dd0f783ae0323da7d9acf9d7cf9db9e1deaa24ad1f42ddf47bbf0e74d3

See more details on using hashes here.

File details

Details for the file mfem-4.4.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: mfem-4.4.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 45.6 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.0 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.15

File hashes

Hashes for mfem-4.4.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d02c53e093dab4b1d35c08ede23f5c83a0c82abee42e85f3a714d3bacb33d665
MD5 b97dab1f203cd16550e1059baede3647
BLAKE2b-256 a45d9356bf97bca0e9051adcf3c23ba2df17a48363e2a2417b2de8ce45beffcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page