8.2. Advanced Tutorials

Advanced Tutorial 1 Interactive operating procedures (pyQt GUI).
Advanced Tutorial 2 Solution of a discretized population balance using high resolution upwind schemes with flux limiter.
Advanced Tutorial 3 Using code-generators (Scilab/GNU_Octave/Matlab MEX functions, Simulink S-functions, Modelica/gPROMS/FMI code-generators).
Advanced Tutorial 4 C++ MPI code generator.

8.2.1. Advanced Tutorial 1

This tutorial presents a user-defined simulation which instead of simply integrating the system shows the pyQt graphical user interface (GUI) where the simulation can be manipulated (a sort of interactive operating procedure).

The model in this example is the same as in the tutorial 4.

The simulation.Run() function is modifed to show the graphical user interface (GUI) that allows to specify the input power of the heater (degree of freedom), a time period for integration, and a reporting interval. The GUI also contains the temperature plot updated in real time, as the simulation progresses.

The screenshot of the pyQt GUI:

_images/tutorial_adv_1-screenshot.png

Files

Model report tutorial_adv_1.xml
Runtime model report tutorial_adv_1-rt.xml
Source code tutorial_adv_1.py

8.2.2. Advanced Tutorial 2

This tutorial demonstrates a solution of a discretized population balance using high resolution upwind schemes with flux limiter.

Reference: Qamar S., Elsner M.P., Angelov I.A., Warnecke G., Seidel-Morgenstern A. (2006) A comparative study of high resolution schemes for solving population balances in crystallization. Computers and Chemical Engineering 30(6-7):1119-1131. doi:10.1016/j.compchemeng.2006.02.012

It shows a comparison between the analytical results and various discretization schemes:

  • I order upwind scheme
  • II order central scheme
  • Cell centered finite volume method solved using the high resolution upwind scheme (Van Leer k-interpolation with k = 1/3 and Koren flux limiter)

The problem is from the section 3.1 Size-independent growth.

Could be also found in: Motz S., Mitrović A., Gilles E.-D. (2002) Comparison of numerical methods for the simulation of dispersed phase systems. Chemical Engineering Science 57(20):4329-4344. doi:10.1016/S0009-2509(02)00349-4

The comparison of number density functions between the analytical solution and the high-resolution scheme:

_images/tutorial_adv_2-results.png

The comparison of number density functions between the analytical solution and the I order upwind, II order upwind and II order central difference schemes:

_images/tutorial_adv_2-results2.png

Files

Model report tutorial_adv_2.xml
Runtime model report tutorial_adv_2-rt.xml
Source code tutorial_adv_2.py

8.2.3. Advanced Tutorial 3

This tutorial introduces the following concepts:

  • DAE Tools code-generators
    • Modelica code-generator
    • gPROMS code-generator
    • FMI code-generator (for Co-Simulation)
  • DAE Tools model-exchange capabilities:
    • Scilab/GNU_Octave/Matlab MEX functions
    • Simulink S-functions

The model represent a simple multiplier block. It contains two inlet and two outlet ports. The outlets values are equal to inputs values multiplied by a multiplier “m”:

out1.y   = m1   x in1.y
out2.y[] = m2[] x in2.y[]

where multipliers m1 and m2[] are:

STN Multipliers
   case variableMultipliers:
      dm1/dt   = p1
      dm2[]/dt = p2
   case constantMultipliers:
      dm1/dt   = 0
      dm2[]/dt = 0

(that is the multipliers can be constant or variable).

The ports in1 and out1 are scalar (width = 1). The ports in2 and out2 are vectors (width = 1).

Achtung, Achtung!! Notate bene:

  1. Inlet ports must be DOFs (that is to have their values asssigned), for they can’t be connected when the model is simulated outside of daetools context.
  2. Only scalar output ports are supported at the moment!! (Simulink issue)

The plot of the inlet ‘y’ variable and the multiplied outlet ‘y’ variable for the constant multipliers (m1 = 2):

_images/tutorial_adv_3-results.png

The plot of the inlet ‘y’ variable and the multiplied outlet ‘y’ variable for the variable multipliers (dm1/dt = 10, m1(t=0) = 2):

_images/tutorial_adv_3-results2.png

FMI Cross-Check results:

  1. Start the DAEPlotter (or change the data reporter below).

  2. Execute:

    ./fmuCheck.linux64 -n 10 tutorial_adv_3.fmu
    
  3. Results:

    [INFO][FMUCHK] FMI compliance checker 2.0 [FMILibrary: 2.0] build date: Aug 22 2014
    [INFO][FMUCHK] Will process FMU tutorial_adv_3.fmu
    [INFO][FMILIB] XML specifies FMI standard version 2.0
    [INFO][FMUCHK] Model name: tutorial_adv_3
    [INFO][FMUCHK] Model GUID: e9654532-0998-11e6-957b-9cb70d5dfdfc
    [INFO][FMUCHK] Model version:
    [INFO][FMUCHK] FMU kind: CoSimulation
    [INFO][FMUCHK] The FMU contains:
    0 constants
    3 parameters
    0 discrete variables
    4 continuous variables
    2 inputs
    2 outputs
    0 local variables
    0 independent variables
    0 calculated parameters
    6 real variables
    0 integer variables
    0 enumeration variables
    0 boolean variables
    1 string variables
    
    [INFO][FMUCHK] Printing output file header
    time,out_1.y,out_2.y
    [INFO][FMUCHK] Model identifier for CoSimulation: tutorial_adv_3
    [INFO][FMILIB] Loading 'linux64' binary with 'default' platform types
    [INFO][FMUCHK] Version returned from CS FMU:   2.0
    ***********************************************************************
                                     Version:   1.5.0
                                     Copyright: Dragan Nikolic
                                     Homepage:  http://www.daetools.com
           @                       @
           @   @@@@@     @@@@@   @@@@@    @@@@@    @@@@@   @      @@@@@
      @@@@@@        @   @     @    @     @     @  @     @  @     @
     @     @   @@@@@@   @@@@@@     @     @     @  @     @  @      @@@@@
     @     @  @     @   @          @     @     @  @     @  @           @
      @@@@@@   @@@@@@    @@@@@      @@@   @@@@@    @@@@@    @@@@  @@@@@
    ***********************************************************************
    DAE Tools is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3
    as published by the Free Software Foundation.
    DAE Tools is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program. If not, see <http://www.gnu.org/licenses>.
    ***********************************************************************
    Creating the system...
    The system created successfully in: 0.002 s
    Starting the initialization of the system... Done.
    [INFO][FMUCHK] Initialized FMU for simulation starting at time 0
    0,1.0000000010000001E+00,2.0000000039999999E+00
    10,1.0100000000000001E+02,4.0200000000000006E+02
    20,2.0099999999999994E+02,8.0199999999999977E+02
    30,3.0100000000000000E+02,1.2020000000000000E+03
    40,4.0100000000000000E+02,1.6020000000000000E+03
    50,5.0099999999999989E+02,2.0019999999999995E+03
    60,6.0100000000000000E+02,2.4020000000000000E+03
    70,7.0100000000000000E+02,2.8020000000000000E+03
    80,8.0100000000000000E+02,3.2020000000000000E+03
    90,9.0099999999999977E+02,3.6019999999999991E+03
    100,1.0009999999999998E+03,4.0019999999999991E+03
    [INFO][FMUCHK] Simulation finished successfully at time 100
    FMU check summary:
    FMU reported:
            0 warning(s) and error(s)
    Checker reported:
            0 Warning(s)
            0 Error(s)
    

Files

Model report tutorial_adv_3.xml
Runtime model report tutorial_adv_3-rt.xml
Source code tutorial_adv_3.py

8.2.4. Advanced Tutorial 4

This tutorial illustrates the C++ MPI code generator. The model is identical to the model in the tutorial 11.

The temperature plot (at t=100s, x=0.5128, y=*):

_images/tutorial_adv_4-results.png

Files

Model report tutorial_adv_4.xml
Runtime model report tutorial_adv_4-rt.xml
Source code tutorial_adv_4.py