SfePy Documentation
repository·master·Indexed 21 days ago
https://github.com/sfepy/sfepySfePy is a Python-based finite element software for solving coupled partial differential equations in 1D, 2D, and 3D. It provides a balance between rapid prototyping and flexibility for custom application development, featuring support for discretization, boundary conditions, and both finite element (FEM) and isogeometric analysis (IGA) specific classes.
What's inside SfePy
- SfePy (Simple finite elements in Python) is a software package for solving systems of coupled partial differential equations (PDEs) using the finite element method (FEM) in 1D, 2D, and 3D. It can be used as a standalone black-box PDE solver or as a Python package to build custom applications. SfePy is built primarily on NumPy and SciPy.
Overview of SfePy
masterSfePy (Simple finite elements in Python) is a software package designed for solving systems of coupled partial differential equations (PDEs) using the finite element method (FEM) in 1D, 2D, and 3D.
It serves two primary purposes:
- Black-box PDE solver: A standalone tool for solving mathematical models.
- Python package: A library that can be imported and used to build custom scientific applications.
Key technical characteristics:
- Implementation: Primarily written in Python, with performance-critical routines implemented in C and wrapped via Cython.
- Dependencies: Relies on
NumPyandSciPyfor scientific computations. - License: Free software released under the New BSD License.
- Platform Support: Multi-platform (Linux, Mac OS X, and Windows).
Explore advanced SfePy example applications
masterFor complex, real-world physics simulations, SfePy hosts a collection of advanced example applications. These cover topics such as:
- Peristaltic flows and piezoelectric porous media
- Deformation of foam-reinforced shell beams
- Two-scale and multiscale numerical simulations (e.g., fluid-saturated porous structures, Biot-Darcy-Brinkman models)
- Vibro-acoustic transmission
- Viscous flow in deformable double porous media
- Biological models (e.g., Fish heart model)
- Phononic materials
Note: Older examples (pre-2020) may not reflect the current state of the SfePy API or best practices. It is recommended to prioritize newer examples for current development.
Use the sfepy.homogenization.coefficients module
masterThesfepy.homogenization.coefficientsmodule provides tools for calculating homogenization coefficients. This module is part of the homogenization suite in SfePy, used to derive effective properties of periodic media from microscale simulations.The SfePy workflow overview
masterThe typical process for solving a problem using SfePy follows these four stages:
- Meshing: Create a geometric model and discretize it into a mesh (e.g., using
Gmsh). - Problem Description: Draft a Python problem definition file that specifies the mesh, material properties, boundary conditions, and equations.
- Running SfePy: Execute the problem description file using the
sfepy-runcommand to solve the equations. - Post-processing: Visualize the results (e.g., displacements, stresses) using tools like
sfepy-viewor external VTK viewers.
- Meshing: Create a geometric model and discretize it into a mesh (e.g., using
Understand the SfePy package structure
masterSfePy is organized into several functional packages. Understanding this hierarchy helps in locating specific discretization schemes, solvers, or mathematical terms:
sfepy.applications: High-level application interfaces (e.g.,pde_solver_app,evp_solver_app).sfepy.base: Core utilities including configuration, logging, I/O, and timing.sfepy.discrete: Implementation of PDE discretization schemes. This is a major component containing:sfepy.discrete.common: Low-level code and parent classes for FEM and IGA.sfepy.discrete.fem: Finite Element Method implementations.sfepy.discrete.iga: Isogeometric Analysis implementations.sfepy.discrete.dg: Discontinuous Galerkin implementations.
sfepy.homogenization: Tools for homogenization calculations.sfepy.linalg: Linear algebra utilities (sparse, eigen, geometry).sfepy.mechanics: Mechanics-specific tools (tensors, elastic constants, contact).sfepy.mesh: Mesh generation and manipulation tools.sfepy.parallel: Parallel evaluation and plotting utilities.sfepy.postprocess: Tools for visualizing results (VTK, DOF plots, etc.).sfepy.solvers: Various numerical solvers (Newton-Raphson, Eigenvalue, Time-stepping, etc.).sfepy.terms: The mathematical terms used in equations (e.g., diffusion, elastic, mass, surface terms).
Define fields and variables for PDEs
masterIn SfePy, Fields define the discrete approximation spaces (e.g., linear finite elements) on a region. Variables are then mapped to these fields.
To solve a PDE in weak form, you must define both an unknown field (the state variable) and a test field (the virtual variable). The test variable must explicitly link to its corresponding unknown variable using the
'dual'parameter.Example mapping:
- Unknown variable
't'is associated with field'temperature'. - Test variable
's'is associated with field'temperature'and its dual is't'.
fields = { 'temperature': ('real', 1, 'Omega', 1) } variables = { 't': ('unknown field', 'temperature', 0), 's': ('test field', 'temperature', 't'), }- Unknown variable
Understand SfePy solver types and interfaces
masterSfePy provides a uniform interface for various types of solvers. All PDEs described in a problem description file are solved using a time-stepping solver. For stationary problems, the default single-step solver
'ts.stationary'is used automatically.Available solver categories include:
- Time-stepping solvers: For transient problems. See
sfepy.solvers.ts_solversfor options. Includes time step controllers found insfepy.solvers.ts_controllers. - Nonlinear Solvers: Used for almost every problem (including linear ones) to unify treatment and simplify Dirichlet boundary conditions. They call a linear solver in each iteration. See
sfepy.solvers.nls,sfepy.solvers.oseen, orsfepy.solvers.semismooth_newton. - Linear Solvers: For solving the linear systems within iterations. See
sfepy.solvers.ls. - Virtual Linear Solvers: Use these if you are unsure which external linear solvers are available; they automatically select the first available solver from a pre-defined list. See
sfepy.solvers.auto_fallback. - Eigenvalue Problem Solvers: For eigenvalue problems. See
sfepy.solvers.eigen. - Quadratic Eigenvalue Problem Solvers: For quadratic eigenvalue problems. See
sfepy.solvers.qeigen. - Optimization Solvers: For optimization problems. See
sfepy.solvers.optimize.
- Time-stepping solvers: For transient problems. See
Understand SfePy symmetric tensor ordering
masterSfePy does not use Voigt notation for 3D symmetric tensors. Instead, it uses the ordering from Crisfield, where components are ordered as[11, 22, 33, 12, 13, 23]. Note that the12and23components are swapped compared to standard Voigt notation. This applies to stress vectors, strain vectors, and $6\times6$ stiffness matrices.How the Finite Element Method (FEM) solves PDEs
masterSfePy uses the Finite Element Method (FEM) to solve Partial Differential Equations (PDEs) by converting their strong form into a weak form.
Instead of solving the PDE directly at every point in the domain, FEM solves an integral equation (the weak form) using test functions ($s$). This approach allows for the inclusion of boundary conditions through two different mechanisms:
- Essential Boundary Conditions (Dirichlet): These are constraints on the unknown function itself (e.g., $T(x) = u(x)$). They are not part of the integral equation but are applied to the solution space. The test functions must be zero on these boundaries.
- Natural Boundary Conditions (Neumann): These represent known fluxes or derivatives at the boundary (e.g., $ abla T ext{n} = g(x)$). These are incorporated directly into the integral terms of the weak form.
To solve a problem in SfePy, you essentially translate the mathematical weak form into a computational model.
Workflow for EBC evaluation in the Newton solver
masterWhen using SfePy to solve problems with EBCs, the internal evaluation of the residual and tangent matrix follows a specific lifecycle to maintain the reduction:
- Reconstruction: The full DOF vector $u$ is reconstructed from the current reduced vector $u_r$.
- Local Evaluation: Local element contributions are calculated using the reconstructed $u$.
- Reduced Assembly: Local contributions are assembled into the reduced residual $f_r$ or tangent matrix $K_r$. Crucially, any values corresponding to fixed DOF positions are thrown away during this step.
- Linear Solve: The reduced system $K_r \Delta u_r = r_r$ is solved for the increment $\Delta u_r$.
- Update: The reduced solution is updated: $u_r \leftarrow u_r - \Delta u_r$.
- Final Reconstruction: Once the Newton loop terminates, the final full vector $u$ is reconstructed from the final $u_r$.
Understand the SfePy Problem Description File
masterA problem description file (or input file) is a regular Python module that defines a PDE problem. Because it is a standard Python file, it can be imported normally and does not require a special parser.
To define a problem, you use specific Python variables (typically of type
dict) with reserved names. These keywords allow you to define:- Equations
- Variables
- Finite element approximations
- Solvers
- Solution domain and subdomains