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

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

$ 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.3.0.6.tar.gz (8.3 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.3.0.6-cp310-cp310-manylinux_2_24_x86_64.whl (35.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

mfem-4.3.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

mfem-4.3.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

mfem-4.3.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.8 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

mfem-4.3.0.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (40.7 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: mfem-4.3.0.6.tar.gz
  • Upload date:
  • Size: 8.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 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.3.0.6.tar.gz
Algorithm Hash digest
SHA256 125fddf4179af2b6e3f3b09ddbeb0c9c8fc66c48a4d29f2ec94083d180ca2222
MD5 beb585eede2d8cadb9a1545475a68ded
BLAKE2b-256 c3759b2d106cc20e73158a9904bcd13fe93264ae28d41bd182664d7d74c74b60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.6-cp310-cp310-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 35.1 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for mfem-4.3.0.6-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 8350891ed9b691d84a84442f95731482e2944bd6f92fbb40760ac7cea3a80e62
MD5 c38250029e7f87b16489ccb232ddad83
BLAKE2b-256 dc18f4a0b23f092f01c855f5de5c593de068d9f86de9dbd19f7b7438170558e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 41.4 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for mfem-4.3.0.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fcd085e10b06bac4985a8eb53e56210a150b1a44b43ce5e34baec23655fefaa1
MD5 a8e11b2f55d28e6504b48ba54a0abefb
BLAKE2b-256 d72df153c4678759f5c1c9a576fea185a93a991bd7145d2ade07208fb31c06c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 41.3 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for mfem-4.3.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0effeb31c0a0f6019a6406fd2b25c50c36bec766a392a6d1d186de46488bdc99
MD5 1e87f2bdbea04f67b61e83a069255cb2
BLAKE2b-256 fbaca6b981b490bb6271fa9f24e5017e0b72b54372331fae698b1f6898472898

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 40.8 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for mfem-4.3.0.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2af7e6155d0ce37a6fcfe33fcfa4c8f8834e941ff6b5cb3455e12c9d84bdde3
MD5 7379fe4322e63f5bd6253dd6e84efe27
BLAKE2b-256 9987b3c894921e299bf5c16e08df8cc51bee245340bc655a52f39fae548a8b0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 40.7 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/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 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.3.0.6-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7666e6b3ef6b06d1149881872362f43b56b20d0c354dd9e67e42f83d0eceea43
MD5 fbec3ef8083912a5057bcfaf702b1ba7
BLAKE2b-256 a640a177b2abb55d0387dcd5fd0c63138274544d626fc703d4b1d5eb853838ac

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