SfePy Documentation

repository·master·Indexed 21 days ago

https://github.com/sfepy/sfepy

SfePy 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.

Tokens
35.2K
Snippets
109
Records
157
Agent score
71%

What's inside SfePy

  1. What is SfePy?

    master
    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.
  2. Overview of SfePy

    master

    SfePy (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:

    1. Black-box PDE solver: A standalone tool for solving mathematical models.
    2. 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 NumPy and SciPy for scientific computations.
    • License: Free software released under the New BSD License.
    • Platform Support: Multi-platform (Linux, Mac OS X, and Windows).
  3. Explore advanced SfePy example applications

    master

    For 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.

  4. The SfePy workflow overview

    master

    The typical process for solving a problem using SfePy follows these four stages:

    1. Meshing: Create a geometric model and discretize it into a mesh (e.g., using Gmsh).
    2. Problem Description: Draft a Python problem definition file that specifies the mesh, material properties, boundary conditions, and equations.
    3. Running SfePy: Execute the problem description file using the sfepy-run command to solve the equations.
    4. Post-processing: Visualize the results (e.g., displacements, stresses) using tools like sfepy-view or external VTK viewers.
  5. Understand the SfePy package structure

    master

    SfePy 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).
  6. Define fields and variables for PDEs

    master

    In 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'),
    }
  7. Understand SfePy solver types and interfaces

    master

    SfePy 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_solvers for options. Includes time step controllers found in sfepy.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, or sfepy.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.
  8. Understand SfePy symmetric tensor ordering

    master
    SfePy 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 the 12 and 23 components are swapped compared to standard Voigt notation. This applies to stress vectors, strain vectors, and $6\times6$ stiffness matrices.
  9. How the Finite Element Method (FEM) solves PDEs

    master

    SfePy 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:

    1. 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.
    2. 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.

  10. Workflow for EBC evaluation in the Newton solver

    master

    When using SfePy to solve problems with EBCs, the internal evaluation of the residual and tangent matrix follows a specific lifecycle to maintain the reduction:

    1. Reconstruction: The full DOF vector $u$ is reconstructed from the current reduced vector $u_r$.
    2. Local Evaluation: Local element contributions are calculated using the reconstructed $u$.
    3. 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.
    4. Linear Solve: The reduced system $K_r \Delta u_r = r_r$ is solved for the increment $\Delta u_r$.
    5. Update: The reduced solution is updated: $u_r \leftarrow u_r - \Delta u_r$.
    6. Final Reconstruction: Once the Newton loop terminates, the final full vector $u$ is reconstructed from the final $u_r$.
  11. Understand the SfePy Problem Description File

    master

    A 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