Skip to main content

MFEM + PyMFEM (finite element method library)

Project description

badge badge

PyMFEM (MFEM Python wrapper)

This package (PyMFEM) is Python wrapper for the MFEM high performance parallel finite element method library.(http://mfem.org/).

Installer downloads a couple of external libraries and build them. By default, "pip install mfem" downloads and builds the serial version of MFEM and PyMFEM. See more detail below for other configurations

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

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.2.0.9.tar.gz (6.1 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.2.0.9-cp39-cp39-manylinux2010_x86_64.whl (35.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

mfem-4.2.0.9-cp38-cp38-manylinux2010_x86_64.whl (35.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

mfem-4.2.0.9-cp37-cp37m-manylinux2010_x86_64.whl (35.1 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

mfem-4.2.0.9-cp36-cp36m-manylinux2010_x86_64.whl (35.0 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

File details

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

File metadata

  • Download URL: mfem-4.2.0.9.tar.gz
  • Upload date:
  • Size: 6.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.13

File hashes

Hashes for mfem-4.2.0.9.tar.gz
Algorithm Hash digest
SHA256 92541933c8b247ffafca399d6b33f3117e37f1d24d0b8df879eea803a0ea3e1c
MD5 b746cb240901d3cc9b1fee1380ae15ab
BLAKE2b-256 6e1011f412d39cc8aec6ee9207978dd10b9edd23c7d6ee99137c2caa54d4f2c8

See more details on using hashes here.

File details

Details for the file mfem-4.2.0.9-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: mfem-4.2.0.9-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 35.2 MB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for mfem-4.2.0.9-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 578e45d7f5137846648f1340def4427ee6f94c5ba501a68c978854697f379825
MD5 048451e5e20f13ff5a759f84a143c172
BLAKE2b-256 16d5938f3cf649159c5b31a4ad0f9cf2c6c98bc7d23b7cccb04c5663d97d608d

See more details on using hashes here.

File details

Details for the file mfem-4.2.0.9-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: mfem-4.2.0.9-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 35.1 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

File hashes

Hashes for mfem-4.2.0.9-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0c95dc641b57bf9ec256252a8a96d2ab4e5cd47c520ab810d432bf310148e557
MD5 ebaecaead82a5eeb1a6fdb7bf66014b4
BLAKE2b-256 53fc840c596e98ad1d795322885e1a3670bce6f19af586dd95d49e84abbe369f

See more details on using hashes here.

File details

Details for the file mfem-4.2.0.9-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: mfem-4.2.0.9-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 35.1 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10

File hashes

Hashes for mfem-4.2.0.9-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4b72a66263eb142a9a86e4dbd1a6ac975d8605e0d54544a041ff7ae431e9405c
MD5 2e73e1b9d2a7a70e93f677e1fb088317
BLAKE2b-256 0f11fd98d250c6c615834b9b57a8972054dba1f0e127b101744adb16a6e99f17

See more details on using hashes here.

File details

Details for the file mfem-4.2.0.9-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: mfem-4.2.0.9-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 35.0 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.6.13

File hashes

Hashes for mfem-4.2.0.9-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a2a27ab6a19af0862f4bdfead8612142a05bdeec8978d8f504c9fb0a09208bda
MD5 ab697b8f0f26419558d0e24910bb8196
BLAKE2b-256 3b6006aedb0427a6a039749f54f6726792c361a9a4c82c7e14a88adb3659072d

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