8.7. OpenCS Examples

OpenCS Example DAE 1

The chemical kinetics problem with 6 non-linear differential equations.

OpenCS Example DAE 2

A simple heat conduction problem (re-implementation of the model in Tutorial 1).

OpenCS Example DAE 3

Auto-catalytic chemical reaction with oscillations (the Brusselator PDE).

OpenCS Example DAE 3 Groups

Identical to dae_example_3. This example uses groups.

OpenCS Example DAE 3 Kernels

Identical to dae_example_3. This example uses kernels.

OpenCS Example DAE 3 Vector Kernels

Identical to dae_example_3. This example uses vector kernels.

OpenCS Example DAE 3 Fpga

Identical to dae_example_3. This example is evaluated using FPGA evaluator.

OpenCS Example DAE 3 Kernels FPGA

Identical to dae_example_3. This example is evaluated using kernels FPGA evaluator.

OpenCS Example DAE 3 Single Source

Identical to dae_example_3. This example uses single source programming models SYCL and Kokos.

OpenCS Example DAE 5 CV

1-D transient convection-diffusion (Burger’s) equation (Dirichlet boundary conditions).

OpenCS Example DAE 6 CV

1-D transient convection-diffusion (Burger’s) equation (Neumann boundary conditions).

OpenCS Example DAE 7 CV

1-D transient heat conduction problem in a bar.

OpenCS Example DAE 8

The process of phase separation described by Cahn-Hilliard equation.

OpenCS Example DAE 8 Kernels

Identical to dae_example_8. This example uses kernels.

OpenCS Example DAE 8 Vector Kernels

Identical to dae_example_8. This example uses vector kernels.

OpenCS Example DAE 9

2-D heat transfer equation.

OpenCS Example ODE 1

The Roberts chemical kinetics problem with 3 rate equations.

OpenCS Example ODE 2

A simple advection-diffusion in 2-D.

OpenCS Example ODE 3

2-species diurnal kinetics advection-diffusion PDE system in 2D.

OpenCS Example ODE 3 Groups

Identical to ode_example_3. This example uses groups.

OpenCS Example ODE 3 Kernels

Identical to ode_example_3. This example uses kernels.

8.7.1. OpenCS Example DAE 1

Reimplementation of IDAS idasAkzoNob_dns example. The chemical kinetics problem with 6 non-linear diff. equations:

dy1_dt + 2*r1 - r2 + r3 + r4 = 0
dy2_dt + 0.5*r1 + r4 + 0.5*r5 - Fin = 0
dy3_dt - r1 + r2 - r3 = 0
dy4_dt + r2 - r3 + 2*r4 = 0
dy5_dt - r2 + r3 - r5 = 0
         Ks*y1*y4 - y6 = 0

where:

r1  = k1 * pow(y1,4) * sqrt(y2)
r2  = k2 * y3 * y4
r3  = k2/K * y1 * y5
r4  = k3 * y1 * y4 * y4
r5  = k4 * y6 * y6 * sqrt(y2)
Fin = klA * (pCO2/H - y2)

The system is stiff. The original results are in tutorial_opencs_dae_1.csv file.

Files

Source code

tutorial_opencs_dae_1.py

Auxiliary functions

tutorial_opencs_aux.py

DAE Tools model

tutorial_opencs_daetools_1.py

The original results

tutorial_opencs_dae_1.csv

8.7.2. OpenCS Example DAE 2

Reimplementation of DAE Tools tutorial1.py example. A simple heat conduction problem: conduction through a very thin, rectangular copper plate:

rho * cp * dT(x,y)/dt = k * [d2T(x,y)/dx2 + d2T(x,y)/dy2];  x in (0, Lx), y in (0, Ly)

Two-dimensional Cartesian grid (x,y) of 20 x 20 elements. The original results are in tutorial_opencs_dae_2.csv file.

Files

Source code

tutorial_opencs_dae_2.py

Auxiliary functions

tutorial_opencs_aux.py

The original results

tutorial_opencs_dae_2.csv

8.7.3. OpenCS Example DAE 3

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:

du/dt = eps1(d2u/dx2  + d2u/dy2) + u^2 v - (B+1)u + A
dv/dt = eps2(d2v/dx2  + d2v/dy2) - u^2 v + Bu

Boundary conditions: Homogenous Neumann. Initial Conditions:

u(x,y,t0) = u0(x,y) =  1  - 0.5*cos(pi*y/L)
v(x,y,t0) = v0(x,y) = 3.5 - 2.5*cos(pi*x/L)

The PDEs are discretized by central differencing on a uniform (Nx, Ny) grid. The model is described in:

  • R. Serban and A. C. Hindmarsh. CVODES, the sensitivity-enabled ODE solver in SUNDIALS. In Proceedings of the 5th International Conference on Multibody Systems, Nonlinear Dynamics and Control, Long Beach, CA, 2005. ASME.

  • M. R. Wittman. Testing of PVODE, a Parallel ODE Solver. Technical Report UCRL-ID-125562, LLNL, August 1996.

The original results are in tutorial_opencs_dae_3.csv file.

Files

Source code

tutorial_opencs_dae_3.py

Auxiliary functions

tutorial_opencs_aux.py

The original results

tutorial_opencs_dae_3.csv

8.7.4. OpenCS Example DAE 3 Groups

Reimplementation of tutorial_opencs_dae_3 using groups.

Files

Source code

tutorial_opencs_dae_3_groups.py

8.7.5. OpenCS Example DAE 3 Kernels

Reimplementation of tutorial_opencs_dae_3 using kernels.

Files

Source code

tutorial_opencs_dae_3_kernels.py

8.7.6. OpenCS Example DAE 3 Vector Kernels

Reimplementation of tutorial_opencs_dae_3 using auto- and explicitly-vectorised kernels.

Files

Source code

tutorial_opencs_dae_3_vector_kernels.py

8.7.7. OpenCS Example DAE 3 Fpga

Reimplementation of IDAS idasBruss_kry_bbd_p example. Simulated using the FPGA CSMachine (emulator version, at the moment). To run the example, Intel compiler must be setup by executing setvars.sh script:

source /opt/intel/oneapi/setvars.sh

Files

Source code

tutorial_opencs_dae_3_fpga.py

8.7.8. OpenCS Example DAE 3 Kernels FPGA

Reimplementation of tutorial_opencs_dae_3. Evaluated using FPGA evaluator (emulator version, at the moment). To run the example, Intel compiler must be setup by executing setvars.sh script:

source /opt/intel/oneapi/setvars.sh

Files

Source code

tutorial_opencs_dae_3_kernels_fpga.py

8.7.9. OpenCS Example DAE 3 Single Source

Reimplementation of tutorial_opencs_dae_3 using SYCL and Kokkos programming models.

Files

Source code

tutorial_opencs_dae_3_single_source.py

8.7.10. OpenCS Example DAE 5 CV

Code verification using the Method of Manufactured Solutions. It represents re-implementation of DAE Tools code verifications tutorial CV-2 - the 1-D transient convection-diffusion (Burger’s) equation. This example uses Dirichlet boundary conditions.

References:

  1. G. Tryggvason. Method of Manufactured Solutions, Lecture 33: Predictivity-I, 2011. PDF

  2. K. Salari and P. Knupp. Code Verification by the Method of Manufactured Solutions. SAND2000 – 1444 (2000). doi:10.2172/759450

  3. P.J. Roache. Fundamentals of Verification and Validation. Hermosa, 2009. ISBN-10:0913478121

Note:

csSimulate cannot be called multiple times from python (multiple MPI init and finalize are not allowed). Therefore, the simulation are performed using the csSimulator binary (it has to be in the PATH for this to work).

Files

Source code

tutorial_opencs_dae_5_cv.py

8.7.11. OpenCS Example DAE 6 CV

Code verification using the Method of Manufactured Solutions. It represents re-implementation of DAE Tools code verifications tutorial CV-3 - the 1-D transient convection-diffusion (Burger’s) equation. This example uses Neumann boundary conditions.

References:

  1. G. Tryggvason. Method of Manufactured Solutions, Lecture 33: Predictivity-I, 2011. PDF

  2. K. Salari and P. Knupp. Code Verification by the Method of Manufactured Solutions. SAND2000 – 1444 (2000). doi:10.2172/759450

  3. P.J. Roache. Fundamentals of Verification and Validation. Hermosa, 2009. ISBN-10:0913478121

Note:

csSimulate cannot be called multiple times from python (multiple MPI init and finalize are not allowed). Therefore, the simulation are performed using the csSimulator binary (it has to be in the PATH for this to work).

Files

Source code

tutorial_opencs_dae_6_cv.py

8.7.12. OpenCS Example DAE 7 CV

Code verification using the Method of Manufactured Solutions.

This problem and its solution in COMSOL Multiphysics <https://www.comsol.com> 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)
Note:

csSimulate cannot be called multiple times from python (multiple MPI init and finalize are not allowed). Therefore, the simulation are performed using the csSimulator binary (it has to be in the PATH for this to work).

Files

Source code

tutorial_opencs_dae_7_cv.py

8.7.13. OpenCS Example DAE 8

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:

dc/dt = Diffusivity * nabla^2(mu)
mu = c^3 - c - gamma * nabla^2(c)

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.

Files

Source code

tutorial_opencs_dae_8.py

8.7.14. OpenCS Example DAE 8 Kernels

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:

dc/dt = Diffusivity * nabla^2(mu)
mu = c^3 - c - gamma * nabla^2(c)

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.

This version is implemented using kernels.

Files

Source code

tutorial_opencs_dae_8_kernels.py

8.7.15. OpenCS Example DAE 8 Vector Kernels

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:

dc/dt = Diffusivity * nabla^2(mu)
mu = c^3 - c - gamma * nabla^2(c)

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.

This version is implemented using auto- and explicitly vectorised kernels.

Files

Source code

tutorial_opencs_dae_8_vector_kernels.py

8.7.16. OpenCS Example DAE 9

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.

Files

Source code

tutorial_opencs_dae_9.py

8.7.17. OpenCS Example ODE 1

Reimplementation of CVodes cvsRoberts_dns example. The Roberts chemical kinetics problem with 3 rate equations:

dy1/dt = -0.04*y1 + 1.e4*y2*y3
dy2/dt =  0.04*y1 - 1.e4*y2*y3 - 3.e7*(y2)^2
dy3/dt =  3.e7*(y2)^2

The problem is simulated for 4000 s, with the initial conditions:

y1 = 1.0
y2 = y3 = 0

The problem is stiff. The original results are in tutorial_opencs_ode_1.csv file.

Files

Source code

tutorial_opencs_ode_1.py

Auxiliary functions

tutorial_opencs_aux.py

The original results

tutorial_opencs_ode_1.csv

8.7.18. OpenCS Example ODE 2

Reimplementation of CVodes cvsAdvDiff_bnd example. The problem is simple advection-diffusion in 2-D:

du/dt = d2u/dx2 + 0.5 du/dx + d2u/dy2

on the rectangle:

0 <= x <= 2
0 <= y <= 1

and simulated for 1 s. Homogeneous Dirichlet boundary conditions are imposed, with the initial conditions:

u(x,y,t=0) = x(2-x)y(1-y)exp(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*Ny. The original results are in tutorial_opencs_ode_2.csv file.

Files

Source code

tutorial_opencs_ode_2.py

Auxiliary functions

tutorial_opencs_aux.py

The original results

tutorial_opencs_ode_2.csv

8.7.19. OpenCS Example ODE 3

Reimplementation of CVodes cvsDiurnal_kry example. 2-species diurnal kinetics advection-diffusion PDE system in 2D:

dc(i)/dt = Kh*(d/dx)^2 c(i) + V*dc(i)/dx + (d/dy)(Kv(y)*dc(i)/dy) + Ri(c1,c2,t), i = 1,2

where:

R1(c1,c2,t) = -q1*c1*c3 - q2*c1*c2 + 2*q3(t)*c3 + q4(t)*c2
R2(c1,c2,t) =  q1*c1*c3 - q2*c1*c2 - q4(t)*c2
Kv(y) = Kv0*exp(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)
30 <= y <= 50 (km)

with homogeneous Neumann boundary conditions, and integrated for 86400 sec (1 day). The PDE system is discretised using the central differences on a uniform 10 x 10 mesh. The original results are in tutorial_opencs_ode_3.csv file.

Files

Source code

tutorial_opencs_ode_3.py

Auxiliary functions

tutorial_opencs_aux.py

The original results

tutorial_opencs_ode_3.csv

8.7.20. OpenCS Example ODE 3 Groups

Reimplementation of tutorial_opencs_ode_3 using groups.

Files

Source code

tutorial_opencs_ode_3_groups.py

8.7.21. OpenCS Example ODE 3 Kernels

Reimplementation of tutorial_opencs_ode_3 using groups.

Files

Source code

tutorial_opencs_ode_3_kernels.py