{"id":19024008,"url":"https://github.com/mfem/pymfem","last_synced_at":"2025-05-15T09:08:41.359Z","repository":{"id":37978737,"uuid":"83574932","full_name":"mfem/PyMFEM","owner":"mfem","description":"Python wrapper for MFEM","archived":false,"fork":false,"pushed_at":"2025-05-13T04:17:27.000Z","size":27083,"stargazers_count":246,"open_issues_count":34,"forks_count":64,"subscribers_count":87,"default_branch":"master","last_synced_at":"2025-05-13T04:27:44.745Z","etag":null,"topics":["fem","finite-elements","gpu-computing","hpc","parallel-computing","python","scientific-computing","swig"],"latest_commit_sha":null,"homepage":"http://mfem.org","language":"SWIG","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfem.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-01T16:16:48.000Z","updated_at":"2025-05-07T10:09:34.000Z","dependencies_parsed_at":"2022-07-09T11:00:26.562Z","dependency_job_id":"71960e7a-be86-48f4-b4b7-c67bba1453c2","html_url":"https://github.com/mfem/PyMFEM","commit_stats":null,"previous_names":[],"tags_count":107,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfem%2FPyMFEM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfem%2FPyMFEM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfem%2FPyMFEM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfem%2FPyMFEM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfem","download_url":"https://codeload.github.com/mfem/PyMFEM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310520,"owners_count":22049470,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fem","finite-elements","gpu-computing","hpc","parallel-computing","python","scientific-computing","swig"],"created_at":"2024-11-08T20:34:24.148Z","updated_at":"2025-05-15T09:08:36.350Z","avatar_url":"https://github.com/mfem.png","language":"SWIG","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![badge](examples/jupyter/.assets/ex1.svg)](https://colab.research.google.com/github/mfem/pymfem/blob/master/examples/jupyter/ex1.ipynb)\n[![badge](examples/jupyter/.assets/ex9.svg)](https://colab.research.google.com/github/mfem/pymfem/blob/master/examples/jupyter/ex9.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```shell\npip install mfem                    # binary install is available only on linux platforms (Py36-310)\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 \u003cprefix\u003e/mfem. See also, docs/install.txt\n\n\n### Build from local source file\n```shell\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\nThis example (modified from `ex1.cpp`) solves the Poisson equation,\n$$\\nabla \\cdot (\\alpha \\nabla u) = f$$\nin a square and plots the result using matplotlib.\nUse the badge above to open this in Colab.\n\n```python\nimport mfem.ser as mfem\n\n# Create a square mesh\nmesh = mfem.Mesh(10, 10, \"TRIANGLE\")\n\n# Define the finite element function space\nfec = mfem.H1_FECollection(1, mesh.Dimension())   # H1 order=1\nfespace = mfem.FiniteElementSpace(mesh, fec)\n\n# Define the essential dofs\ness_tdof_list = mfem.intArray()\ness_bdr = mfem.intArray([1]*mesh.bdr_attributes.Size())\nfespace.GetEssentialTrueDofs(ess_bdr, ess_tdof_list)\n\n# Define constants for alpha (diffusion coefficient) and f (RHS)\nalpha = mfem.ConstantCoefficient(1.0)\nrhs = mfem.ConstantCoefficient(1.0)\n\n\"\"\"\nNote\n-----\nIn order to represent a variable diffusion coefficient, you\nmust use a numba-JIT compiled function. For example:\n\n\u003e\u003e\u003e @mfem.jit.scalar\n\u003e\u003e\u003e def alpha(x):\n\u003e\u003e\u003e     return x+1.0\n\"\"\"\n\n# Define the bilinear and linear operators\na = mfem.BilinearForm(fespace)\na.AddDomainIntegrator(mfem.DiffusionIntegrator(alpha))\na.Assemble()\nb = mfem.LinearForm(fespace)\nb.AddDomainIntegrator(mfem.DomainLFIntegrator(rhs))\nb.Assemble()\n\n# Initialize a gridfunction to store the solution vector\nx = mfem.GridFunction(fespace)\nx.Assign(0.0)\n\n# Form the linear system of equations (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 the linear system using PCG and store the solution in 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 arrays\nverts = mesh.GetVertexArray()\nsol = x.GetDataArray()\n\n# Plot the solution using matplotlib\nimport matplotlib.pyplot as plt\nimport matplotlib.tri as tri\n\ntriang = tri.Triangulation(verts[:,0], verts[:,1])\n\nfig, ax = plt.subplots()\nax.set_aspect('equal')\ntpc = ax.tripcolor(triang, sol, shading='gouraud')\nfig.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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfem%2Fpymfem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfem%2Fpymfem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfem%2Fpymfem/lists"}