This example demonstrates how to simulate steady Stokes flow past a sphere using the FEniCS plugin in Sim4Life. The setup and results can be loaded directly into Sim4Life using the provided mesh and simulation setup files.
Stokes flow describes the motion of a viscous, incompressible fluid at low Reynolds numbers, where inertial forces are negligible compared to viscous forces. The governing equations are:
where
The FEniCS plugin solves the weak form of the Stokes equations. For test functions
This is implemented in the plugin by adding the following bilinear form in the subdomain settings for
ufl.inner(ufl.grad(u), ufl.grad(u_test)) - ufl.div(u_test) * p + p_test * ufl.div(u)where:
-
uis the velocity trial function ($\mathbf{u}$ ) -
u_testis the velocity test function ($\mathbf{v}$ ) -
pis the pressure trial function ($p$ ) -
p_testis the pressure test function ($q$ )
This directly corresponds to the weak form above, with each term mapping as follows:
-
ufl.inner(ufl.grad(u), ufl.grad(u_test))$\rightarrow$ $\int_\Omega \nabla \mathbf{u} : \nabla \mathbf{v} , dx$ -
- ufl.div(u_test) * p$\rightarrow$ $-\int_\Omega p , \nabla \cdot \mathbf{v} , dx$ -
p_test * ufl.div(u)$\rightarrow$ $\int_\Omega q , \nabla \cdot \mathbf{u} , dx$
The computational domain consists of a sphere embedded in a rectangular box, representing the fluid region around the sphere. The mesh and subdomain assignments are shown below:
- Simulation Type: Stationary (steady-state)
- Solver Type: Linear (Direct LU)
- Field Type: Real
-
Equation:
-
Subdomain Settings:
-
Dirichlet Boundary Conditions:
- Load the mesh and simulation setup files into Sim4Life.
- Review and adjust the parameters as needed.
- Run the simulation to compute the velocity and pressure fields.
- Visualize the results to observe the flow pattern and pressure distribution around the sphere.
The figure below shows the velocity distribution around the sphere, visualized in Sim4Life using a combination of a slice field and vector field viewer. This allows you to see both the magnitude and direction of the flow as it moves past the sphere:










