Example2.Analysis.PFVariants.AutomationFunctions

Provides functions for automation of simulation and linearization using the models of the upper layer package

Information

This package contains functions that automate the simulation, plotting and linearization of the models under Example2.Analysis.PFVariants.

Extends from Modelica.Icons.FunctionsPackage (Icon for packages containing functions).

Package Content

Name Description
Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_ramping_pf simulate_and_plot_ramping_pf Simulates and plots the "Ramping_pf" model
Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_inputs_pf simulate_and_plot_inputs_pf Simulates and plots the "RampingRandomLoadAndInput_pf" which includes random load and the designed input signal.
Example2.Analysis.PFVariants.AutomationFunctions.linearize_KchangeLinRamping_pf linearize_KchangeLinRamping_pf Function to linearize the model "KchangeLinRamping_pf" at any point in time.

Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_ramping_pf Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_ramping_pf

Simulates and plots the "Ramping_pf" model

Information

Usage:

  1. In the Package Browser, right click on the function and select "Call function...". This will open the function's window.
  2. In the new function window, click on "Execute", if successful, messages/results are displayed in the command window and plots will appear in Simulation tab.
  3. Go back to the function's own window and click on "Close".


Sample Output:

Running the function will result in the following plot.

Extends from Modelica.Icons.Function (Icon for functions).

Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_inputs_pf Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_inputs_pf

Simulates and plots the "RampingRandomLoadAndInput_pf" which includes random load and the designed input signal.

Information

Usage:

  1. In the Package Browser, right click on the function and select "Call function...". This will open the function's window.
  2. Enter the desired number of cores to use in "corenum". The number of cores to use depends on your computer's resources. , if your computer has more than 12 cores, you can enter the desired number of cores to use in the function's main window. Note that it will take some trial an error to find a trade off on the number of cores to use in your system as per Amdahl's law. See the note below the sample output for more details.
  3. In the new function window, click on "Execute", if successful, messages/results are displayed in the command window and plots will appear in Simulation tab.
  4. Go back to the function's own window and click on "Close".


Sample output:

Running the function will result in the following plot.

Note:

Please observe that running this function involves simulating the Example2.Analysis.PFVariants.RampingRandomLoadAndInput_pf model, which takes subtantially more time compared to example Example2.Analysis.PFVariants.Ramping_pf, the reason is that both random load and probing signals are added to the model which results in an additional computation burden.

This function calls the Example2.Utilities.SetupSolverSettings.On function that configures several flags to improve simulation speed, however, even by enabling these features, the simulation is time consuming.

For example, running the model using a computer with an 13th Gen Intel(R) Core(TM) i9-13900K, 3.00 GHz, processor and 128 GB DDR4 RAM, setup to use 12 cores, gave the following metrics:

Integration terminated successfully at T = 4050

CPU-time for integration : 1.17e+03 seconds

CPU-time for one grid interval : 234 milliseconds

CPU-time for initialization : 0.005 seconds

Number of result points : 959331

Number of grid points : 5001

Number of accepted steps : 9172936

Number of f-evaluations (dynamics) : 18295816

Number of crossing function evaluations : 9668298

Number of Jacobian-evaluations : 4006190

Number of model time events : 476996

Number of input time events : 0

Number of state events : 2744

Number of step events : 0

Minimum integration stepsize : 2.78e-10

Maximum integration stepsize : 0.00922

Maximum integration order : 5

Looking at the first two lines of the metrics shows that running the model for 67.5 min (4050 sec.) took 19.5 min (1.17e+03 sec.).

Naturally, using a computer with a weaker processor and lower memory will lead to longer run times.

If there is no interest to take into account the random load and probing signal, it is recommended that you run instead the function Example2.Analysis.PFVariants.AutomationFunctions.simulate_and_plot_ramping_pf, which takes substantially less time to execute.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
corenumNumber of processor cores to use

Example2.Analysis.PFVariants.AutomationFunctions.linearize_KchangeLinRamping_pf Example2.Analysis.PFVariants.AutomationFunctions.linearize_KchangeLinRamping_pf

Function to linearize the model "KchangeLinRamping_pf" at any point in time.

Information

Usage:

  1. In the Package Browser, right click on the function and select "Call function...". This will open the function's window.
  2. Enter the time for linearization, Example2.Analysis.PFVariants.KchangeLinRamping_pf will be simulated until that point in time and linearized.
  3. In the new function window, click on "Execute", if successful, messages/results are displayed in the command window and plots will appear in Simulation tab.
  4. Go back to the function's own window and click on "Close".


Sample Output:

Executing the function will produce the following output in the "Commands" window.

Example2.Analysis.PFVariants.AutomationFunctions.linearize_KchangeLinRamping_pf();

Setting up things...

DAE Mode is turned off.

Global optimization is disabled.

Sparse options disabled.

Number of cores reset to default:1

Starting simulation and linearization...

Declaring Modelica_LinearSystems2.StateSpace ss 

System not printed since too large (only dimensions):

   ss.A[52,52]

   ss.B[52,2]

   ss.C[1,52]

   ss.D[1,2]

The linear model is in your working directory.

Open the dslin.mat file following the instructions in the documentation.

You can also analyze the linear model using Dymola, for example typing in the commands window

  Modelica_LinearSystems2.StateSpace.Plot.polesAndZeros(ss, zeros=false, print=true);

  will give you the polte plot shown in the Simulation tab and printed below.

Must translate function Modelica_LinearSystems2.Math.Matrices.LAPACK.dgeevx_eigenValues.

Compilation of function Modelica_LinearSystems2.Math.Matrices.LAPACK.dgeevx_eigenValues successful.

Finished 


Eigenvalues

number

eigenvalue

time constant [s]

freq. [Hz]

damping

  1

  -9.6242e+01

  0.0104

  ---

  ---

  2

  -3.6655e+01

  0.0273

  ---

  ---

  3

  -3.5047e+01

  0.0285

  ---

  ---

  4

  -3.1561e+01

  0.0317

  ---

  ---

  5

  -3.0650e+01

  0.0326

  ---

  ---

  6

  -2.7641e+01

  0.0362

  ---

  ---

  7

  -2.6939e+01

  0.0371

  ---

  ---

  8

  -8.3670e+00

  0.1195

  ---

  ---

  9

  -2.9564e+00

  0.3383

  ---

  ---

  10

  -2.6309e+00

  0.3801

  ---

  ---

  11

  -2.6309e+00

  0.3801

  ---

  ---

  12

  -2.6309e+00

  0.3801

  ---

  ---

  13

  -2.6309e+00

  0.3801

  ---

  ---

  14

  -2.6253e-01

  3.8090

  ---

  ---

  15

  -2.0230e-01

  4.9432

  ---

  ---

  16

  -1.0029e-01

  9.9714

  ---

  ---

  17

  -1.0000e-03

  1000.0000

  ---

  ---

  18

  -1.0000e-03

  1000.0000

  ---

  ---

  19

  -1.0000e-03

  1000.0000

  ---

  ---

  20

  -1.0000e-03

  1000.0000

  ---

  ---

  21

  -1.0000e-03

  1000.0000

  ---

  ---

  22

  -1.0000e-03

  1000.0000

  ---

  ---

  23

  -1.0000e-03

  1000.0000

  ---

  ---

  24

  -1.0000e-03

  1000.0000

  ---

  ---

  25

  -1.0000e-03

  1000.0000

  ---

  ---

  26

  -1.0000e-03

  1000.0000

  ---

  ---

  27

  -1.0000e-03

  1000.0000

  ---

  ---

  28

  -2.0208e-11

  49484936402.3992

  ---

  ---

  29/30

  -5.6534e-01 ± 6.0529e-01j

  ---

  0.1318

  0.6826

  31/32

  -7.8941e-01 ± 6.8557e-01j

  ---

  0.1664

  0.7550

  33/34

  -1.1437e+00 ± 8.2408e-01j

  ---

  0.2243

  0.8113

  35/36

  -6.0262e+00 ± 8.5651e-01j

  ---

  0.9687

  0.9900

  37/38

  -3.5830e+01 ± 1.5444e+00j

  ---

  5.7079

  0.9991

  39/40

  -7.7495e+00 ± 2.2560e+00j

  ---

  1.2846

  0.9601

  41/42

  -9.0151e-01 ± 2.2664e+00j

  ---

  0.3882

  0.3696

  43/44

  -1.9111e+00 ± 3.2618e+00j

  ---

  0.6017

  0.5055

  45/46

  -6.1276e-01 ± 4.2935e+00j

  ---

  0.6903

  0.1413

  47/48

  -5.2430e-01 ± 7.7021e+00j

  ---

  1.2287

  0.0679

  49/50

  -4.4286e-01 ± 1.2244e+01j

  ---

  1.9500

  0.0361

  51/52

  -1.9317e+01 ± 1.5323e+01j

  ---

  3.9242

  0.7834



The following pole plot is generated in the Simulation tab:

Post-processing in MATLAB:

The obtained linear model can be used in any other environment. The linear model is available in the file, dslin.mat, that will appear under your Dymola working directory. It can be loaded in MATLAB using the function:

[A,B,C,D,xName,uName,yName] = tloadlin('dslin.mat')

To use this function, add to the MATLAB workspace the directory and sub-directories under: C:\Program Files\Dymola 2024x\Mfiles

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

NameDescription
tlin[s], time for linearization.
pathToNonlinearPlantModel 
Automatically generated Wed Mar 13 11:47:13 2024.