Home News Downloads Documentation
Home Downloads Introduction Getting Started Examples
Contact Publications

Python examples are also available in the Tutorials section of the DAE Tools website (OpenCS tutorials).

ODE examples (C++, Python)

# Files Description
1. C++ model:
ode_example_1.cpp
roberts.h
Python model:
tutorial_opencs_ode_1.py
tutorial_opencs_aux.py
Original model results:
tutorial_opencs_ode_1.csv
Reimplementation of CVodes cvsRoberts_dns example.
The Roberts chemical kinetics problem with 3 rate equations:
$$ \frac{dy_1}{dt} = -0.04 y_1 + 1 \cdot 10^4 y_2 y_3 $$ $$ \frac{dy_2}{dt} = 0.04 y_1 - 1 \cdot 10^4 y_2 y_3 - 3 \cdot 10^7 {y_2}^2 $$ $$ \frac{dy_3}{dt} = 3 \cdot 10^7 {y_2}^2 $$
The problem is solved on the time interval from 0.0 <= t <= 4.e10, with initial conditions:
$$ y1 = 1.0 $$ $$ y2 = y3 = 0 $$
The problem is stiff.

Run instructions:
ode_example_1 or python tutorial_opencs_ode_1.py The program will generate OpenCS model into the ode_example_1-sequential directory and perform a single CPU simulation.
2. C++ model:
ode_example_2.cpp
advection_diffusion_2d.h
Python model:
tutorial_opencs_ode_2.py
tutorial_opencs_aux.py
Original model results:
tutorial_opencs_ode_2.csv
Reimplementation of CVodes cvsAdvDiff_bnd example.
The problem is simple advection-diffusion in 2-D:
$$ \frac{du}{dt} = \frac{\partial^2 u}{\partial x^2} + 0.5 \frac{\partial u}{\partial x} + \frac{\partial^2 u}{\partial y^2} $$
on the rectangle 0 <= x <= 2, 0 <= y <= 1, and the time interval 0 <= t <= 1. Homogeneous Dirichlet boundary conditions are imposed, with the initial conditions:
$$ u(x,y,t=0) = x(2-x) y(1-y) e^{5xy} $$
The PDE is discretized on a uniform Nx+2 by Ny+2 grid with central differencing. The boundary points are eliminated leaving an ODE system of size Nx x Ny.

Run instructions:
ode_example_2 Nx Ny or python tutorial_opencs_ode_2.py Nx Ny where Nx and Ny are number of points in x and y domains, respectively. If omitted, the default grid size Nx=10 and Ny=5 will be used.
The program will generate OpenCS model into the ode_example_2-sequential directory and perform a single CPU simulation.
3. C++ model:
ode_example_3.cpp
diurnal_kinetics_2d.h
Python model:
tutorial_opencs_ode_3.py
tutorial_opencs_aux.py
Original model results:
tutorial_opencs_ode_3.csv
Reimplementation of CVodes cvsDiurnal_kry example.
2-species diurnal kinetics advection-diffusion PDE system in 2D:
$$ \frac{dc_i}{dt} = K_h \frac{\partial^2 c_i}{\partial x^2} + V \frac{\partial c_i}{\partial x} + \frac{\partial}{\partial y} \left(K_v(y) \frac{\partial c_i}{\partial y} \right) + R_i(c_1,c_2,t), i = 1,2 $$
where
$$ R_1(c_1,c_2,t) = -q_1 c_1 c_3 - q_2 c_1 c_2 + 2 q_3(t) c_3 + q_4(t) c_2 $$ $$ R_2(c_1,c_2,t) = q_1 c_1 c_3 - q_2 c_1 c_2 - q_4(t) c_2 $$ $$ K_v(y) = K_{v0} e^{y/5} $$
Kh, V, Kv0, q1, q2, and c3 are constants, and q3(t) and q4(t) vary diurnally. The problem is posed on the square: 0 <= x <= 20 (km) and 30 <= y <= 50 (km), with homogeneous Neumann boundary conditions, and integrated for time t in 0 <= t <= 86400 sec (1 day). The PDE system is discretised using the central differences on a uniform 10 x 10 mesh.

Run instructions:
ode_example_3 Nx Ny or python tutorial_opencs_ode_3.py Nx Ny where Nx and Ny are number of points in x and y domains, respectively. If omitted, the default grid size Nx=80 and Ny=80 will be used.
The program will generate OpenCS model into the ode_example_3-sequential directory and perform a single CPU simulation.
In addition, the OpenCS model for MPI simulation on 8 nodes will be generated in the ode_example_3-Npe=8-2D_Npde directory. Parallel simulation can be started from the examples directory on GNU/Linux and macOS: mpirun -np 8 ../bin/csSimulator ode_example_3-Npe=8-2D_Npde and on Windows: mpiexec -n 8 ../bin/csSimulator ode_example_3-Npe=8-2D_Npde
3b. C++ model:
ode_example_3_groups.cpp
diurnal_kinetics_groups_2d.h
Python model:
tutorial_opencs_ode_3_groups.py
tutorial_opencs_aux.py
Identical to ode_example_3 (reimplementation of CVodes cvsDiurnal_kry example).
This example uses groups.
3c. C++ model:
ode_example_3_kernels.cpp
diurnal_kinetics_kernels_2d.h
diurnal_kinetics_udf.h
Python model:
tutorial_opencs_ode_3_kernels.py
tutorial_opencs_aux.py
Simulation options:
ode_example_3_kernels-simulation_options.json
Identical to ode_example_3 (reimplementation of CVodes cvsDiurnal_kry example).
This example uses kernels.

DAE examples (C++, Python)

# Files Description
1. C++ model:
dae_example_1.cpp
chemical_kinetics.h
Python model:
tutorial_opencs_dae_1.py
tutorial_opencs_aux.py
Original model results:
tutorial_opencs_dae_1.csv
Reimplementation of IDAS idasAkzoNob_dns example.
The chemical kinetics problem with 6 non-linear diff. equations. The system is stiff.

Run instructions:
dae_example_1 or python tutorial_opencs_dae_1.py
The program will generate OpenCS model into the dae_example_1-sequential directory and perform a single CPU simulation.
2. C++ model:
dae_example_2.cpp
heat_conduction_2d.h
Python model:
tutorial_opencs_dae_2.py
tutorial_opencs_aux.py
Original model results:
tutorial_opencs_dae_2.csv
Reimplementation of DAE Tools tutorial1.py example.
A simple heat conduction problem: conduction through a very thin, rectangular copper plate. Two-dimensional Cartesian grid (x,y) of 20 x 20 elements.

Run instructions:
dae_example_2 Nx Ny or python tutorial_opencs_dae_2.py Nx Ny where Nx and Ny are number of points in x and y domains, respectively. If omitted, the default grid size Nx=20 and Ny=20 will be used.
The program will generate OpenCS model into the dae_example_2-sequential directory and perform a single CPU simulation.
3. C++ model:
dae_example_3.cpp
brusselator_2d.h
Python model:
tutorial_opencs_dae_3.py
tutorial_opencs_aux.py
Original model results:
tutorial_opencs_dae_3.csv
Reimplementation of IDAS idasBruss_kry_bbd_p example.
The PDE system is a two-species time-dependent PDE known as Brusselator PDE and models a chemically reacting system:
$$ \frac{du}{dt} = \varepsilon_1 \left( \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} \right) + u^2 v - (B+1)u + A $$ $$ \frac{dv}{dt} = \varepsilon_2 \left( \frac{\partial^2 v}{\partial x^2} + \frac{\partial^2 v}{\partial y^2} \right) - u^2 v + Bu $$
BCs: Homogenous Neumann.
ICs:
$$ u(x,y,t0) = u0(x,y) = 1 - 0.5 cos \left( \frac{\pi y}{L} \right) $$ $$ v(x,y,t0) = v0(x,y) = 3.5 - 2.5 cos \left( \frac{\pi x}{L} \right) $$
The PDEs are discretised by central differencing on a Nx x Ny grid.

Run instructions:
dae_example_3 Nx Ny or python tutorial_opencs_dae_3.py Nx Ny where Nx and Ny are number of points in x and y domains, respectively. If omitted, the default grid size Nx=82 and Ny=82 will be used.
The program will generate OpenCS model into the dae_example_3-sequential directory and perform a single CPU simulation.
In addition, the OpenCS model for MPI simulation on 8 nodes will be generated in the dae_example_3-Npe=8-2D_Npde directory. Parallel simulation can be started from the examples directory on GNU/Linux and macOS: mpirun -np 8 ../bin/csSimulator dae_example_3-Npe=8-2D_Npde and on Windows: mpiexec -n 8 ../bin/csSimulator dae_example_3-Npe=8-2D_Npde
3b. C++ model:
dae_example_3_groups.cpp
brusselator_groups_2d.h
Python model:
tutorial_opencs_dae_3_groups.py
tutorial_opencs_aux.py
Simulation options:
dae_example_3_groups-simulation_options.json
Identical to dae_example_3 (reimplementation of IDAS idasBruss_kry_bbd_p example).
This example uses groups.
3c. C++ model:
dae_example_3_kernels.cpp
brusselator_kernels_2d.h
Python model:
tutorial_opencs_dae_3_kernels.py
tutorial_opencs_aux.py
Simulation options:
dae_example_3_kernels-simulation_options.json
Identical to dae_example_3 (reimplementation of IDAS idasBruss_kry_bbd_p example).
This example uses kernels.
3d. C++ model:
dae_example_3_vector_kernels.cpp
brusselator_vector_kernels_2d.h
Python model:
tutorial_opencs_dae_3_vector_kernels.py
tutorial_opencs_aux.py
Simulation options:
dae_example_3_kernels-simulation_options.json
Identical to dae_example_3 (reimplementation of IDAS idasBruss_kry_bbd_p example).
This example uses auto- and explicitly vectorised kernels. See brusselator_vector_kernels_2d.h for more details.
3e. C++ model:
dae_example_3_single_source.cpp
brusselator_single_source_2d.h
Python model:
tutorial_opencs_dae_3_single_source.py
tutorial_opencs_aux.py
Simulation options:
dae_example_3_kernels-simulation_options.json
Identical to dae_example_3 (reimplementation of IDAS idasBruss_kry_bbd_p example).
This example uses Kokkos and SYCL programming models. See brusselator_single_source_2d.h for more details.
3f. C++ model:
dae_example_3_fpga.cpp
brusselator_2d.h
Python model:
tutorial_opencs_dae_3_fpga.py
Identical to dae_example_3 (reimplementation of IDAS idasBruss_kry_bbd_p example).
Simulated using the FPGA CSMachine (emulator version, at the moment).
3g. C++ model:
dae_example_3_kernels_fpga.cpp
brusselator_fpga_2d.h
Python model:
tutorial_opencs_dae_3_kernels_fpga.py
Identical to dae_example_3 (reimplementation of IDAS idasBruss_kry_bbd_p example).
Simulated using the Kernels FPGA evaluator (emulator version, at the moment).
4. C++ model:
dae_example_4_cv.cpp
burgers_equations_cv_2d.h
Python plots:
dae_example_4_cv_plots_plots.py
Simulation options:
dae_example_4_cv-simulation_options.json
The model describes a viscous fluid flow defined by the Burgers equations (transient convection-diffusion equations):
$$\frac{du}{dt} + \frac{\partial(uu)}{\partial x} + \frac{\partial(uv)}{\partial y} - \nu \left( \frac{\partial^2 u}{\partial x^2} + \frac{\partial^2 u}{\partial y^2} \right) = S_u(x,y)$$ $$\frac{dv}{dt} + \frac{\partial(vu)}{\partial x} + \frac{\partial(vv)}{\partial y} - \nu \left( \frac{\partial^2 v}{\partial x^2} + \frac{\partial^2 v}{\partial y^2} \right) = S_v(x,y)$$
presented in Appendix C of: K. Salari, P. Knupp. Code Verification by the Method of Manufactured Solutions. SAND2000 – 1444 (2000), https://doi.org/10.2172/759450. It represents a re-implementation of DAE Tools code verifications tutorial CV-4. This problem uses a formal code verification technique: the Method of Manufactured Solutions for checking the correctness of the numerical software. The procedure is the following: (1) a function representing the solution is selected (the manufactured solution), (2) the new source term for the original problem is computed, and (3) the original problem is solved with the new source term. The computed numerical solution should be equal to the manufactured one. The manufactured solutions are given by:
$$u_m(x,y) = u_0 \left( sin (x^2 + y^2 + w_0 t ) + \varepsilon \right) $$ $$v_m(x,y) = v_0 \left( cos (x^2 + y^2 + w_0 t ) + \varepsilon \right) $$
The terms in the new sources Su and Sv are computed by differentiation of the manufactured solution equations for um and vm.
$$ S_u(x,y) = \frac{du_m}{dt} + \frac{\partial (u_m u_m)}{\partial x} + \frac{\partial (u_m v_m)}{\partial y} - \nu \left( \frac{\partial ^2u_m}{\partial x^2} + \frac{\partial ^2u_m}{\partial y^2} \right) $$ $$ S_v(x,y) = \frac{dv_m}{dt} + \frac{\partial (v_m u_m)}{\partial x} + \frac{\partial (v_m v_m)}{\partial y} - \nu \left( \frac{\partial ^2v_m}{\partial x^2} + \frac{\partial ^2v_m}{\partial y^2} \right) $$
The Dirichlet boundary conditions are applied at boundaries:
$$ u(x, y) = um(x, y) $$ $$ v(x, y) = vm(x, y) $$
for x = {0, Nx-1} and y = {0, Ny-1}. The equations are distributed on a non-uniform structured rectangular 2D grid (-0.1, 0.7)x(0.2, 0.8) with 10x8, 20x16, 40x32 and 80x64 grid points to avoid symmetry for a more thorough check of the computed solution.

Run instructions:
dae_example_4_cv
  1. Run dae_example_4_cv
    It will produce dae_example_4_cv-sequential directory with 10x8, 20x16, 40x32, 80x64 subdirectories with results for the corresponding meshes.
  2. Run python dae_example_4_cv_plots.py opencs | comparison.
    • Using the opencs option, the script will load results from dae_example_4_cv-sequential and plot the normalised global errors and the order of accuracy plots for OpenCS results.
    • Using comparison option, the script will first run daetools simulations for the 10x8, 20x16, 40x32 and 80x64 meshes, load OpenCS data from the dae_example_4_cv-sequential directory, print the comparison and plot the DAE Tools normalised global errors and the order of accuracy plots.
5. Python model:
tutorial_opencs_dae_5_cv.py
The model describes a viscous fluid flow defined by the 1D Burgers equations (transient convection-diffusion equations) presented in
(1) G. Tryggvason. Method of Manufactured Solutions, Lecture 33: Predictivity-I, 2011. http://www3.nd.edu/~gtryggva/CFD-Course/2011-Lecture-33.pdf,
(2) K. Salari and P. Knupp. Code Verification by the Method of Manufactured Solutions. SAND2000 – 1444 (2000), https://doi.org/10.2172/759450, and
(3) P.J. Roache. Fundamentals of Verification and Validation. Hermosa, 2009, http://www.isbnsearch.org/isbn/0913478121.
It represents a re-implementation of DAE Tools code verifications tutorial CV-2. This problem uses a formal code verification technique: the Method of Manufactured Solutions for checking the correctness of the numerical software. The manufactured solution is:
$$ q = A + sin(x + Ct) $$
for x = {0, Nx-1}. The Dirichlet boundary conditions are applied at boundaries:
$$ f(x=0) = q(x=0) = A + sin(0 + Ct) $$ $$ f(x=2pi) = q(x=2pi) = A + sin(2pi + Ct) $$
The equations are distributed on a uniform structured 1D grid (0, 2*numpy.pi) with 60, 90, 120 and 150 grid points.
Run instructions:
python dae_example_5_cv.py Note: The function csSimulate cannot be called multiple times from python (multiple MPI init and finalize are not allowed). Therefore, the simulations are performed using the csSimulator binary (it has to be in the PATH for this to work).
6. Python model:
tutorial_opencs_dae_6_cv.py
The model describes a viscous fluid flow defined by the 1D Burgers equations (transient convection-diffusion equations) identical to the tutorial_opencs_dae_5_cv example. The only difference is that Neumann boundary conditions are applied at boundaries.
Run instructions:
python dae_example_6_cv.py Note: The function csSimulate cannot be called multiple times from python (multiple MPI init and finalize are not allowed). Therefore, the simulations are performed using the csSimulator binary (it has to be in the PATH for this to work).
7. Python model:
tutorial_opencs_dae_7_cv.py
This problem and its solution in COMSOL Multiphysics software is described in the COMSOL blog: Verify Simulations with the Method of Manufactured Solutions (2015), https://www.comsol.com/blogs/verify-simulations-with-the-method-of-manufactured-solutions. Here, a 1D transient heat conduction problem in a bar of length L is solved using the Centered Finite Difference method:
dT/dt - k/(rho*cp) * d2T/dx2 = 0, x in [0,L]
Dirichlet boundary conditions are applied at both bar ends (500 K). Initial conditions are 500 K. The manufactured solution is given by function u(x):
u(x) = 500 + (x/L) * (x/L - 1) * (t/tau)

Run instructions:
python dae_example_7_cv.py Note: The function csSimulate cannot be called multiple times from python (multiple MPI init and finalize are not allowed). Therefore, the simulations are performed using the csSimulator binary (it has to be in the PATH for this to work).
8. Python model:
tutorial_opencs_dae_8.py
In this example the Cahn-Hilliard equation is solved using the finite difference method. This equation describes the process of phase separation, where two components of a binary mixture separate and form domains pure in each component.
$$ \frac{dc}{dt} = D \nabla^2\mu $$ $$ \mu = c^3 - c - \gamma \; \nabla^2c $$
The mesh is a simple square (0-100)x(0-100). Input parameters are Diffusivity = 1 and gamma = 1. For both c an mu insulated boundary conditions are set (no flux on boundaries). Initial conditions are set to c(0) = 0.0 + c_noise where the noise is specified using the normal distribution with standard deviation of 0.1. The system is integrated for 500 seconds and the outputs are taken every 5 seconds.
Run instructions:
python dae_example_8.py Nx Ny If Nx and Ny are omitted, the default grid 100 x 100 is used.
8b. Python model:
tutorial_opencs_dae_8_kernels.py
Identical to dae_example_8 (Cahn-Hilliard equation example).
This example uses kernels.
Run instructions:
python dae_example_8_kernels.py Nx Ny If Nx and Ny are omitted, the default grid 100 x 100 is used.
8c. Python model:
tutorial_opencs_dae_8_vector_kernels.py
Identical to dae_example_8 (Cahn-Hilliard equation example).
This example uses auto- and explicitly vectorised kernels.
Run instructions:
python dae_example_8_vector_kernels.py Nx Ny If Nx and Ny are omitted, the default grid 100 x 100 is used.
9. Python model:
tutorial_opencs_dae_9.py
Reimplementation of IDAS idasHeat2D_kry example. The DAE system solved is a spatial discretization of the PDE:
$$ du/dt = d^2u/dx^2 + d^2u/dy^2 $$
on the unit square. The boundary condition is u = 0 on all edges. Initial conditions are given by u = 16 x (1 - x) y (1 - y). The PDE is treated with central differences on a uniform M x M grid. The values of u at the interior points satisfy ODEs, and equations u = 0 at the boundaries are appended, to form a DAE system of size N = M^2. The grid size is 10 x 10.
Run instructions:
python dae_example_9.py Nx Ny If Nx and Ny are omitted, the default grid 50 x 50 is used.

Copyright: Dragan D. Nikolić, DAE Tools Project 2009-2023