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: The problem is solved on the time interval from 0.0 <= t <= 4.e10, with initial conditions: 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: 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: 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: where 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: BCs: Homogenous Neumann. ICs: 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):
Run instructions: dae_example_4_cv
|
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:
The terms in the new sources Su and Sv are computed by differentiation of
the manufactured solution equations for um and vm.
The Dirichlet boundary conditions are applied at boundaries:
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.
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: for x = {0, Nx-1}. The Dirichlet boundary conditions are applied at boundaries: 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.
Run instructions: python dae_example_8.py Nx Ny
If Nx and Ny are omitted, the default grid 100 x 100 is used.
|
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.
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:
Run instructions: python dae_example_9.py Nx Ny
If Nx and Ny are omitted, the default grid 50 x 50 is used.
|
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.