Skip to main content

MFEM + PyMFEM (finite element method library)

Project description

Binder badge badge

MFEM + PyMFEM (FEM library)

This package provides MFEM and its Python wrapper (PyMFEM). MFEM is a high performance parallel finite element method (FEM) 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.3.0.1.tar.gz (6.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.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (46.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

mfem-4.3.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (46.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

mfem-4.3.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (46.1 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

mfem-4.3.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (46.1 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.17+ x86-64

File details

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

File metadata

  • Download URL: mfem-4.3.0.1.tar.gz
  • Upload date:
  • Size: 6.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.6.14

File hashes

Hashes for mfem-4.3.0.1.tar.gz
Algorithm Hash digest
SHA256 1e9b298fba9ef1cb0359d47f3c0d1df0f2a7e4267389aaca8b3700cc7ebf84fc
MD5 f423318e11317039f60464561a753467
BLAKE2b-256 0bdddb88cd730b7e56c341f4b9d6473728666b768334dd24f073cce84ec3b540

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a6a38829cebec8b5f2010638171e3e7826cb128ffea5acaf86deb8530c671b9
MD5 44cac70182c31a9c57f6ad5afe6d0bc5
BLAKE2b-256 b8518b878f7a34b566f7ab4f72c06a99a67bded6f17db736fbc15f3f38ce935d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc1e24e8fa3b174f7e9010d118e59ffd07203554020955115ac250b0d5b6d26d
MD5 9731b83c10358dea94c20cfe9bc04665
BLAKE2b-256 9d12e20ad3a73835c16fd2a55db5bf608c75f45ac5720ada81c289ab97f3883b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71d5d3654b4cf269c796c7003a865ec48de6cb7fdad48092dd14e2f4bd96d255
MD5 2a59348e379e252c67b37137226ad2ad
BLAKE2b-256 5f8e87eb809a68bb619af9aa0bf6016a2642ebc9e312c72bd11d620c83202074

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mfem-4.3.0.1-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 87212af97ddc58b3b6562c1ba851fe3085dd60efeaa17d933a389e20c78059d0
MD5 6c13c88eb7561b166f30fc2ead6ee56c
BLAKE2b-256 7fc08e6d8b62ecff6b366b3ca8f206a0a29b0f1cdfeccb636ef51a0a955a6bee

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