mfem


Namemfem JSON
Version 4.6.1.0 PyPI version JSON
download
home_pagehttp://mfem.org
SummaryMFEM + PyMFEM (finite element method library)
upload_time2024-01-10 03:45:30
maintainerS. Shiraiwa
docs_urlNone
authorMFEM developement team
requires_python
licenseBSD-3
keywords scientific computing finite element method
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter)
[![badge](examples/jupyter/ex1.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex1.ipynb)
[![badge](examples/jupyter/ex9.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex9.ipynb)

#  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-310)
pip install mfem --no-binary mfem   # install serial MFEM + wrapper from source

```

## Build with additional features (MPI, GPU, GPU-Hypre, GSLIB, SuiteSparse, libCEED, LAPACK)
The setup script accept various options. TO use it, one can either use --install-option flag
with pip, or download the package manually and run the script. For example, the one below downloads
and build parallel version of MFEM library (linked with Metis and Hypre)
and installs under <prefix>/mfem. See also, docs/install.txt

### Using pip
```
$ pip install mfem --install-option="--with-parallel" 
```

### Build from local source file
```
# Download source and build
$ pip download mfem --no-binary mfem (expand tar.gz file and move to the downloaded directory)
or clone this repository
$ git clone https://github.com/mfem/PyMFEM.git

# Then, build it from local source
$ python -m pip install ./ --install-option="--with-parallel" --install-option="--mfem-branch=master"
or
$ python setup.py install --with-parallel # it download and build metis/hypre/mfem

# Verbose output
$ python setup.py install --verbose # SWIG output and CMAKE_VERBOSE_MAKEFILE is on

# Cleaning
$ python setup.py clean --all # clean external dependencies + wrapper code

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

# Run test
cd test
python test_examples.py -serial

# For other configurations, see docs/install.txt or help
$ python setup.py install --help

```

## Usage
Here is an example to solve div(alpha grad(u)) = f 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 (diffusion coefficient and RHS)
alpha = mfem.ConstantCoefficient(1.0)
rhs = mfem.ConstantCoefficient(1.0)

# Note:
#    Diffusion coefficient can be variable. To use numba-JIT compiled
#    functio. Use the following, where x is numpy-like array.
# @mfem.jit.scalar
# def alpha(x):
#     return x+1.0
#

# define Bilinear and Linear operator
a = mfem.BilinearForm(fespace)
a.AddDomainIntegrator(mfem.DiffusionIntegrator(alpha))
a.Assemble()
b = mfem.LinearForm(fespace)
b.AddDomainIntegrator(mfem.DomainLFIntegrator(rhs))
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()
```
![](https://raw.githubusercontent.com/mfem/PyMFEM/master/docs/example_image.png)


## License
PyMFEM is licensed under BSD-3.
Please refer the developers' web sites for the external libraries
* MFEM: https://mfem.org/
* Hypre: https://computing.llnl.gov/projects/hypre-scalable-linear-solvers-multigrid-methods
* METIS: http://glaros.dtc.umn.edu/gkhome/metis/metis/overview
* libceed: https://github.com/CEED/libCEED
* gslib: https://github.com/Nek5000/gslib

            

Raw data

            {
    "_id": null,
    "home_page": "http://mfem.org",
    "name": "mfem",
    "maintainer": "S. Shiraiwa",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "shiraiwa@princeton.edu",
    "keywords": "scientific computing,finite element method",
    "author": "MFEM developement team",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/c1/b4/f74adf690cb16a5df20a66f8e4156aa345dc2926a23ffda3deed94ac9a30/mfem-4.6.1.0.tar.gz",
    "platform": "Mac OS X",
    "description": "[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter)\n[![badge](examples/jupyter/ex1.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex1.ipynb)\n[![badge](examples/jupyter/ex9.svg)](https://mybinder.org/v2/gh/mfem/PyMFEM/HEAD?labpath=examples%2Fjupyter%2Fex9.ipynb)\n\n#  MFEM + PyMFEM (FEM library)\n\nThis repository provides Python binding for MFEM. MFEM is a high performance parallel finite element method (FEM) library (http://mfem.org/).\n\nInstaller (setup.py) builds both MFEM and binding together.\nBy default, \"pip install mfem\" downloads and builds the serial version of MFEM and PyMFEM.\nAdditionally, the installer supports building MFEM with specific options together with other external libraries, including MPI version.\n\n## Install\n```\npip install mfem                    # binary install is available only on linux platforms (Py36-310)\npip install mfem --no-binary mfem   # install serial MFEM + wrapper from source\n\n```\n\n## Build with additional features (MPI, GPU, GPU-Hypre, GSLIB, SuiteSparse, libCEED, LAPACK)\nThe setup script accept various options. TO use it, one can either use --install-option flag\nwith pip, or download the package manually and run the script. For example, the one below downloads\nand build parallel version of MFEM library (linked with Metis and Hypre)\nand installs under <prefix>/mfem. See also, docs/install.txt\n\n### Using pip\n```\n$ pip install mfem --install-option=\"--with-parallel\" \n```\n\n### Build from local source file\n```\n# Download source and build\n$ pip download mfem --no-binary mfem (expand tar.gz file and move to the downloaded directory)\nor clone this repository\n$ git clone https://github.com/mfem/PyMFEM.git\n\n# Then, build it from local source\n$ python -m pip install ./ --install-option=\"--with-parallel\" --install-option=\"--mfem-branch=master\"\nor\n$ python setup.py install --with-parallel # it download and build metis/hypre/mfem\n\n# Verbose output\n$ python setup.py install --verbose # SWIG output and CMAKE_VERBOSE_MAKEFILE is on\n\n# Cleaning\n$ python setup.py clean --all # clean external dependencies + wrapper code\n\n# Choosing compiler\n$ python setup.py install --with-parallel --CC=icc --CXX=icpc --MPICC=mpiicc --MPICXX=mpiicpc\n\n# Run test\ncd test\npython test_examples.py -serial\n\n# For other configurations, see docs/install.txt or help\n$ python setup.py install --help\n\n```\n\n## Usage\nHere is an example to solve div(alpha grad(u)) = f in a square and to plot the result\nwith matplotlib (modified from ex1.cpp). Use the badge above to open this in Binder.\n```\nimport mfem.ser as mfem\n\n# create sample mesh for square shape\nmesh = mfem.Mesh(10, 10, \"TRIANGLE\")\n\n# create finite element function space\nfec = mfem.H1_FECollection(1, mesh.Dimension())   # H1 order=1\nfespace = mfem.FiniteElementSpace(mesh, fec)\n\n#\ness_tdof_list = mfem.intArray()\ness_bdr = mfem.intArray([1]*mesh.bdr_attributes.Size())\nfespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list)\n\n# constant coefficient (diffusion coefficient and RHS)\nalpha = mfem.ConstantCoefficient(1.0)\nrhs = mfem.ConstantCoefficient(1.0)\n\n# Note:\n#    Diffusion coefficient can be variable. To use numba-JIT compiled\n#    functio. Use the following, where x is numpy-like array.\n# @mfem.jit.scalar\n# def alpha(x):\n#     return x+1.0\n#\n\n# define Bilinear and Linear operator\na = mfem.BilinearForm(fespace)\na.AddDomainIntegrator(mfem.DiffusionIntegrator(alpha))\na.Assemble()\nb = mfem.LinearForm(fespace)\nb.AddDomainIntegrator(mfem.DomainLFIntegrator(rhs))\nb.Assemble()\n\n# create gridfunction, which is where the solution vector is stored\nx = mfem.GridFunction(fespace);\nx.Assign(0.0)\n\n# form linear equation (AX=B)\nA = mfem.OperatorPtr()\nB = mfem.Vector()\nX = mfem.Vector()\na.FormLinearSystem(ess_tdof_list, x, b, A, X, B);\nprint(\"Size of linear system: \" + str(A.Height()))\n\n# solve it using PCG solver and store the solution to x\nAA = mfem.OperatorHandle2SparseMatrix(A)\nM = mfem.GSSmoother(AA)\nmfem.PCG(AA, M, B, X, 1, 200, 1e-12, 0.0)\na.RecoverFEMSolution(X, b, x)\n\n# extract vertices and solution as numpy array\nverts = mesh.GetVertexArray()\nsol = x.GetDataArray()\n\n# plot solution using Matplotlib\n\nimport matplotlib.pyplot as plt\nimport matplotlib.tri as tri\n\ntriang = tri.Triangulation(verts[:,0], verts[:,1])\n\nfig1, ax1 = plt.subplots()\nax1.set_aspect('equal')\ntpc = ax1.tripcolor(triang, sol, shading='gouraud')\nfig1.colorbar(tpc)\nplt.show()\n```\n![](https://raw.githubusercontent.com/mfem/PyMFEM/master/docs/example_image.png)\n\n\n## License\nPyMFEM is licensed under BSD-3.\nPlease refer the developers' web sites for the external libraries\n* MFEM: https://mfem.org/\n* Hypre: https://computing.llnl.gov/projects/hypre-scalable-linear-solvers-multigrid-methods\n* METIS: http://glaros.dtc.umn.edu/gkhome/metis/metis/overview\n* libceed: https://github.com/CEED/libCEED\n* gslib: https://github.com/Nek5000/gslib\n",
    "bugtrack_url": null,
    "license": "BSD-3",
    "summary": "MFEM + PyMFEM (finite element method library)",
    "version": "4.6.1.0",
    "project_urls": {
        "Download": "https://github.com/mfem",
        "Homepage": "http://mfem.org"
    },
    "split_keywords": [
        "scientific computing",
        "finite element method"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a01c3ebdd30aeab181adb69fefd0e0caa04a8796f59ab02e3883f230d7db1551",
                "md5": "1045fbbc3065cca740b42de1caa78bc3",
                "sha256": "3262286f978aafbafd18660d32db00f9d310c67d0cf0fbd6a4deb102bfc959c9"
            },
            "downloads": -1,
            "filename": "mfem-4.6.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "1045fbbc3065cca740b42de1caa78bc3",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": null,
            "size": 62341757,
            "upload_time": "2024-01-10T03:57:40",
            "upload_time_iso_8601": "2024-01-10T03:57:40.146464Z",
            "url": "https://files.pythonhosted.org/packages/a0/1c/3ebdd30aeab181adb69fefd0e0caa04a8796f59ab02e3883f230d7db1551/mfem-4.6.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b05723ec66d6274b121b47fab6bab27c6d5d40b040537cc3beba187e86231404",
                "md5": "038331ca15f478fe5c0af2d6d6b3bafa",
                "sha256": "a9a7e1fb44b8bfce0bff54422ca48e65537c50a7402e0f4ab4efc5606a8be5d2"
            },
            "downloads": -1,
            "filename": "mfem-4.6.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "038331ca15f478fe5c0af2d6d6b3bafa",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": null,
            "size": 61799055,
            "upload_time": "2024-01-10T03:57:43",
            "upload_time_iso_8601": "2024-01-10T03:57:43.388098Z",
            "url": "https://files.pythonhosted.org/packages/b0/57/23ec66d6274b121b47fab6bab27c6d5d40b040537cc3beba187e86231404/mfem-4.6.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "21f1659f0f8836e2bf6503a0952b7c615a6f81660d4b98563dd2196f75dfa1b3",
                "md5": "1c33a386937cd1baa18aae6e32ff92ef",
                "sha256": "51482172f11c33c717f8759295a249fdfa180b0ca88ea6f1b93b771dcb912d70"
            },
            "downloads": -1,
            "filename": "mfem-4.6.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "1c33a386937cd1baa18aae6e32ff92ef",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 62140739,
            "upload_time": "2024-01-10T03:57:35",
            "upload_time_iso_8601": "2024-01-10T03:57:35.060600Z",
            "url": "https://files.pythonhosted.org/packages/21/f1/659f0f8836e2bf6503a0952b7c615a6f81660d4b98563dd2196f75dfa1b3/mfem-4.6.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "639c6e0d4bc36ccc4711df86e8e13e68f002781c234f181211d0605902d98df1",
                "md5": "b8362913bcb06f31efb82e9425882442",
                "sha256": "cc539ee5aca0700d85f0cdff0f05e0b798b224ed3375ce889e074c6eb05f1a7b"
            },
            "downloads": -1,
            "filename": "mfem-4.6.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "b8362913bcb06f31efb82e9425882442",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 62285454,
            "upload_time": "2024-01-10T03:57:50",
            "upload_time_iso_8601": "2024-01-10T03:57:50.916590Z",
            "url": "https://files.pythonhosted.org/packages/63/9c/6e0d4bc36ccc4711df86e8e13e68f002781c234f181211d0605902d98df1/mfem-4.6.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1b4f74adf690cb16a5df20a66f8e4156aa345dc2926a23ffda3deed94ac9a30",
                "md5": "2b89eae32e458e686e0a7b3e1af9812d",
                "sha256": "cf10d8162349dca1ac2f49e0f401a8786ab950a81bbff567ea542252763f11d2"
            },
            "downloads": -1,
            "filename": "mfem-4.6.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2b89eae32e458e686e0a7b3e1af9812d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 406394,
            "upload_time": "2024-01-10T03:45:30",
            "upload_time_iso_8601": "2024-01-10T03:45:30.841188Z",
            "url": "https://files.pythonhosted.org/packages/c1/b4/f74adf690cb16a5df20a66f8e4156aa345dc2926a23ffda3deed94ac9a30/mfem-4.6.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-10 03:45:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "mfem"
}
        
Elapsed time: 0.19805s