stokes_solver

Stokes solver

https://github.com/skjelanger/stokes_solver

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.8%) to scientific vocabulary
Last synced: 7 months ago · JSON representation ·

Repository

Stokes solver

Basic Info
  • Host: GitHub
  • Owner: skjelanger
  • Language: Python
  • Default Branch: main
  • Size: 254 KB
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 1
Created 10 months ago · Last pushed 8 months ago
Metadata Files
Readme Citation

README.md

FEM Stokes Flow Solver with Periodic Boundaries and Adaptive Meshing

This project simulates 2D incompressible Stokes flow through a square domain with a circular obstacle. The solver is based on P2-P1 mixed finite elements, periodic boundary conditions, and is designed to assess permeability under varying geometries.

Mesh generation and classification are handled via Gmsh and Meshio, while linear systems are solved with Pypardiso for efficiency.


Features

  • Quadratic P2 elements for velocity and linear P1 elements for pressure
  • Support for periodic boundary conditions (top-bottom and left-right)
  • Adaptive meshing around obstacles and domain walls
  • Batch simulation support with logging and result saving
  • Permeability calculation via Darcy's law
  • Mesh and result visualization (pressure, velocity fields, vector plots)

Dependencies

Install the following Python packages (e.g., via pip or conda):

  • gmsh
  • meshio
  • numpy
  • scipy
  • matplotlib
  • pypardiso (or switch to another solver manually if needed)

Running the Stokes Solver

To execute a simulation:

  1. Download stokes_solver.py and mesher.py.
  2. Install the required dependencies listed above.
  3. Run the main solver script:

bash python stokes_solver.py bash

This will:

  1. Generate a mesh using Gmsh.
  2. Assemble and solve the Stokes system using P2-P1 mixed finite elements.
  3. Apply periodic or inflow/outflow boundary conditions (as configured).
  4. Plot and save the velocity magnitude, velocity vectors, and pressure fields.
  5. Compute the permeability.
  6. Save the entire simulation state (solution + mesh + metadata) as a compressed file under simulations/.

Output

  • Figures are saved to the plots/ folder as .png files.
  • Full simulation results are saved as .pkl.gz files under simulations/.

You can modify mesh parameters and boundary settings directly in the main section at the bottom of stokes_solver.py.

Notes

Periodic boundary conditions are applied at the matrix level via slave-master DOF enforcement.

Meshing can be adapted by adjusting create_mesh() in mesher.py.

Pressure is anchored to one node to ensure solvability.

Acknowledgements

Created during the PCS911 course at Western Norway University of Applied Sciences

Owner

  • Name: Skjelanger
  • Login: skjelanger
  • Kind: user
  • Location: Bergen

Master degree in Theoretical Physics.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
title: "Finite Element Solver in Python for 2D Stokes flow"
version: "1.0.0"
authors:
  - family-names: "Skjelanger"
    given-names: "Kristoffer"
date-released: 2025-05-29
repository-code: "https://github.com/skjelanger/stokes_solver"
license: "MIT"
keywords:
  - stokes flow
  - CFD
  - numerical methods
  - finite element

GitHub Events

Total
  • Release event: 1
  • Push event: 4
  • Create event: 1
Last Year
  • Release event: 1
  • Push event: 4
  • Create event: 1

Dependencies

requirements.txt pypi
  • gmsh *
  • matplotlib *
  • meshio *
  • numpy *
  • scipy *