# Systems of chemical reactions in FEniCS

Here’s a sample from the upcoming FEniCS Tutorial that I’m currently working on with Hans Petter Langtangen. As a simple demonstration of how complex problems can be solved with a minimal amount of code in FEniCS, we simulate a system of chemical reactions taking place in a channel with the flow governed by the incompressible Navier-Stokes equations. The reaction itself is modeled as a first-order reaction using the standard advection-diffusion-reaction equation:

For the velocity field, we use a previously computed solution of the incompressible Navier-Stokes equations which we can read/write using a FEniCS TimeSeries. The variational problem for the equations themselves are easily implemented in FEniCS:

The solution is a quite beautiful wavelike pattern as illustrated in the following clip which plots the concentrations of the three species.

The complete code for the above simulation looks as follows.

Anders Logg is Professor of Computational Mathematics at Chalmers University of Technology. His research interests are adaptive finite element methods, high-level automating software systems for solution of PDE, domain-specific languages and compilers in scientific computing, and applications in biomedicine, general relativity, and architecture. Logg is head of the unit for Computational Mathematics and excellence profile leader within Chalmers Area of Advance the Built Environment. He is director of the Swedish Network for Mathematics in Industry and member of the EMS Applied Mathematics Committee and the Swedish National Committee for Mathematics. He is co-founder and a core developer of the FEniCS Project, a leading open-source software for automated solution of PDE. Logg works part-time as scientific advisor to Fraunhofer-Chalmers Centre and Simula Research Laboratory.

1. Nicholas Danes
May 31, 2016

Hi Dr. Logg,

Will there any future documentation with these sorts of problems (systems of ADR equations) with possible stabilization techniques (e.g. SUPG, FEM-FCT, Upwind DG, and/or SOLD methods)?

My own research uses FEniCS and proper stabilization of these sort of problems has been an issue for myself for the past year (in particular, with positivity perservation of ADR equations). I’ve implemented the FEM-FCT method in my personal code, but it does not play well with the native MPI support nor does it scale with systems of ADR equations. I would like eventually to have complete parallel support in my own research code.

Thanks for all you do for this project!

Best,

Nicholas

• June 2, 2016

There are already a number of demos distributed as part of FEniCS. Perhaps there will be a chapter on stabilized finite element methods in the second volume of the tutorial.

2. Hossein
October 4, 2016

Dear Anders,

When I run the above code I get the following error:

V = FunctionSpace(mesh, element)
TypeError: __init__() takes at least 4 arguments (3 given)

Best,
Hossein

• October 4, 2016

You must be running an old version of FEniCS. Get the latest = v2016.1!

3. Hossein
October 5, 2016

Thanks.

I updated the FEniCS but, again it did not work. I’m using ubuntu 14.04 and version of python is 2.7.6. Are these OK ?

Best,
Hossein

4. Hossein
October 5, 2016

Also version of FEniCS is now 1.6.0

5. Hossein
October 5, 2016

I also tried

element = (P1 * P1) * P1

element = P1 * P1* P1

element = VectorElement(’P’, ’triangle’, 1, dim=3)

but again, I get the same error !

6. October 5, 2016