Home News Downloads Docs
Home Introduction Getting Started Examples
Contact Publications

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

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

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