This repository contains a topology optimization framework for porous electrodes in electrochemical flow cells. The framework solves combined flow and charge transport problems and is implemented in Python using the Firedrake and PETSc libraries for finite element modeling.
- Topology optimization for combined flow and charge transport problems
- Support for both 2D and 3D simulations
- Customizable problem parameters through command-line arguments
- Batch running capabilities for parameter sweeps
- Post-processing and visualization of results
The main components of the framework are (under the src directory):
optimization.py: Main optimization scriptcharge_problem.py: Defines the charge transport problemflow_problem.py: Defines the flow problem (Navier-Stokes or Stokes)batch_run.py: Script for running multiple simulations with different parameterspostprocess.py: Handles post-processing and visualization of (2D) resultshelpers.py: Contains helper functions and constantspreconditioners.py: Defines various preconditioners and solver parameterspde_filter.py: Implements a PDE-based filter for the design variablepenalization.py: Defines penalization schemes for topology optimization
The run_scripts directory contains a few examples on how to use the framework in HPC environments. For local runs, you need to adjust the MPI binaries and arguments in batch_run.py.
This code requires the following software packages:
- Firedrake: Core finite element library used for solving PDEs, with features for automatic differentiation and parallel computing
- pyadjoint: Automatic differentiation tool for adjoint analysis, installs with Firedrake
- PETSc and petsc4py: Python bindings for PETSc (Portable, Extensible Toolkit for Scientific Computation)
- pyMMAopt: Python implementation of the Method of Moving Asymptotes (MMA) for optimization
- ParaView (Python bindings): Visualization tool used for post-processing and generating images of results
- PIL/Pillow: Python Imaging Library for image manipulation in post-processing
- Matplotlib: Python plotting library used for creating loss function graphs
- Gmsh: Meshing tool to generate the finite element mesh files required for the simulations
The code uses MPI for parallel execution.
This code has been used in the following publication. In scientific work, where results to some extent are obtained using RedOx-TO, please cite the following article:
@article{barzegari2025redoxto,
title = {Topology optimization of porous electrodes for electrochemical flow reactors using the finite element method and triply periodic minimal surfaces},
author = {Mojtaba Barzegari and Antoni Forner-Cuenca},
journal = {Chemical Engineering Journal},
volume = {512},
pages = {161815},
year = {2025},
issn = {1385-8947},
doi = {10.1016/j.cej.2025.161815},
}
RedOx-TO is licensed under the terms of the GNU General Public License v3.