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.3.tar.gz (7.8 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.3-cp310-cp310-manylinux_2_24_x86_64.whl (28.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64

mfem-4.3.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

mfem-4.3.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (39.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

mfem-4.3.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

mfem-4.3.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.6 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: mfem-4.3.0.3.tar.gz
  • Upload date:
  • Size: 7.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15

File hashes

Hashes for mfem-4.3.0.3.tar.gz
Algorithm Hash digest
SHA256 59f206010fa628362416e8776eba82af7e531f27b32a75d6eecb260549969bbf
MD5 18e1ebfa2c2222befd1e9735c664c75b
BLAKE2b-256 9e0b7b2d76e33fd1f9a848e519c7e1e841c07060719cd8e323626f3adc702437

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.3-cp310-cp310-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 28.2 MB
  • Tags: CPython 3.10, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for mfem-4.3.0.3-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 83b3ebaa23c948001639f86925b674821de697326ed600ec36528fdb95393f26
MD5 e157c1ecd7cc07c5c6083d642c6b1a31
BLAKE2b-256 b69bca0b530a44daf469da176259aa7d15ca2a53f2b0c4e87d81fa99374dcb53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af9f523d081f001de805d75e23560066ff720b3277246c66aa85d6e5a185f7f7
MD5 beabb8de8cd20200cdb5ce3896ae8c00
BLAKE2b-256 0a6b82cbcd71272cfe5bbc8e5283bbddb37aad2c07fb927cd5a09c324d8237f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mfem-4.3.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 39.2 MB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for mfem-4.3.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 657b0b68e2d3fe143df0751a9708dbec8d4df025a0a363f66e2807d5c5a696ee
MD5 199d3ae884244900e219f9ebfec6f11d
BLAKE2b-256 da22c4d81a331063b4d5017174e8dcbead1e238b4786b99496a6ca19cec98d1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d807b74b75e8fa3ece0d7d29bcf1273b7602f8efb76c9d9594a69554dc37ad1
MD5 0b837c95dd4d188afb43fd0aa1fe2157
BLAKE2b-256 b0669652ca8c765567e0b159194113c63711469089dd5163da429b4b034d3f4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.3-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 313740e3ac846c00230657b8ba1d09cd69ff87410bfc5a2f29ddb5d727502be1
MD5 b65a2aa83272470dde051a453cc3826b
BLAKE2b-256 5e921f21841205d6673456eeb20f11d6669d7e82daf14a9eb7d31bcf041857ca

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