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.

Install

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

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

The setup script accept various options. TO use it, please download the package and run the script manually. 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

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

Choosing compiler

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

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

$ python setup.py install --help

Install from github master

git clone https://github.com/mfem/PyMFEM.git
cd PyMFEM
python setup.py install --mfem-branch=master  # build both MFEM and PyMFEM
  
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.0.tar.gz (8.7 MB 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.0-cp310-cp310-manylinux_2_24_x86_64.whl (36.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

mfem-4.4.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (43.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

mfem-4.4.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (43.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

mfem-4.4.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (43.3 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

mfem-4.4.0.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (43.3 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: mfem-4.4.0.0.tar.gz
  • Upload date:
  • Size: 8.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for mfem-4.4.0.0.tar.gz
Algorithm Hash digest
SHA256 212e33f3f936d6e048e6a4ac2b83e849f84fa6f7e810c31200ac302e64eb1a62
MD5 5d9b672e706bbfb7292f4633a95248f1
BLAKE2b-256 72795d857b7351a51405704eed932356b499674eceea7f82cd314277bbf18a14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.4.0.0-cp310-cp310-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 36.7 MB
  • Tags: CPython 3.10, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for mfem-4.4.0.0-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 bb5c44c44752f71ee30fdd4f59820f33fdfb771de07c2b7165c23c4aea9932a9
MD5 3f0fda7938138b16fe483e2ba87c270e
BLAKE2b-256 2521748fe7fdee17068c7a74320f51215bea868451d95740500683e364e09c13

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.4.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 43.9 MB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for mfem-4.4.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 12e67d784134fb26a184c3fafba3df221f8cb642236304eeb0c584b9966e3974
MD5 3d32f96121d4252be5fdbf3b6423b51f
BLAKE2b-256 36f2bf63a4881b9a28d29b050d5d126b0e56cc010c19f0fda12dc03b346a1303

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.4.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 43.8 MB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.13

File hashes

Hashes for mfem-4.4.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef08346ed75f7f30c2c4e93ced8e142dfaf6b3c97ff6907e35055e354a6758d6
MD5 8d1db281ded8e5ab13e0f5a4dc4034df
BLAKE2b-256 4947330cc421f0482a5fac6b77973f6616fb370ae572883abfebe362e3656bff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.4.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 43.3 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.13

File hashes

Hashes for mfem-4.4.0.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cd733b336bac88712baf018226764bc3710b173f5cfbd17a7a22c69cf25048ba
MD5 e0aa1224c23c02f212776216bcae616e
BLAKE2b-256 c179893a2be772e4974670f4f458e614517af07652196d429445d80172c346bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.4.0.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 43.3 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.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for mfem-4.4.0.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b150c533d4f59755abe89a32ccb7c80a5b1f18dd2fd9eccf8b133b9018144233
MD5 2ca7528aa6894ba59d890c725444e182
BLAKE2b-256 a3d9c70d58df8f0fdef20cad6d376c1b7ac0cd5b27212f9e1d6b4d0e1957137c

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