$ show mfem/PyMFEM
PyMFEM provides Python bindings for the MFEM finite element library, enabling finite element simulations (PDE solvers) from Python. The architecture consists of SWIG-generated wrapper modules for serial (`mfem.ser`) and parallel MPI (`mfem.par`) execution, built on top of the C++ MFEM library. Key entry points include the core modules (`mfem.ser`, `mfem.par`), a suite of 30+ example scripts covering Laplace, elasticity, Maxwell, Navier-Stokes, and more, and miniapps for specialized applications (DPG, multidomain, field interpolation). The system supports JIT-compiled coefficients via Numba, complex-valued solvers via CHypre, and GPU backends (CUDA, libCEED). While primarily a software library, it has a strong research character due to its advanced numerical methods (DPG, fractional PDEs, topology optimization) and extensive example set that serves as both documentation and validation.
The LLM identified 4 files worth highlighting for reuse:
Provides SWIG typemaps (OSTREAM_TYPEMAP, ISTREAM_TYPEMAP) that allow passing filenames, stdout/stderr, or Python StringIO objects to C++ methods expecting std::ostream/std::istream. This pattern is reusable across any SWIG project needing flexible I/O, and demonstrates non-obvious skill in SWIG typemap design.
Wraps Hypre's parallel linear algebra for complex-valued systems (CHypreVec, CHypreMat, ComplexHypreParMatrix). Provides conversion to/from scipy sparse matrices and implements complex arithmetic on top of Hypre's real data structures. This is a self-contained module that could be extracted for any project needing complex parallel sparse linear algebra.
Implements vertex-patch based additive Schwarz preconditioners (PatchAssembly, SchwarzSmoother, ComplexSchwarzSmoother) for symmetric and complex systems. Uses UMFPACK for local solves. This is a standalone C++ component that can be reused in any MFEM-based solver requiring robust domain decomposition preconditioning.
Contains utility functions for generating Numba-JIT compiled coefficient code from Python functions. Handles dependency injection, scalar/vector/matrix variants, and fallback to pure Python. This pattern is reusable for any project needing on-the-fly compilation of user-defined mathematical functions with Numba.