model order reduction - scilabdoc]scilab... · 2019-12-05 · scilab model reduction toolbox –...

35
MODEL ORDER REDUCTION Proper Orthogonal Decomposition USER GUIDE Toolbox Version 1.0

Upload: others

Post on 07-Apr-2020

35 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

MODEL ORDER REDUCTION

Proper Orthogonal Decomposition

USER GUIDE

Toolbox Version 1.0

Page 2: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 1 of 35

Content Introduction ............................................................................................................................................. 2

Flow around a rotating cylinder .......................................................................................................... 2

Proper Orthogonal Decomposition theory ......................................................................................... 3

From theory to practice....................................................................................................................... 4

Model reduction workflow .................................................................................................................. 5

Offline Learning ............................................................................................................................... 5

Online Evaluation ............................................................................................................................ 5

Limitations of the current toolbox ...................................................................................................... 6

Installation ............................................................................................................................................... 7

Model Order Reduction toolbox features ............................................................................................... 8

Objects ................................................................................................................................................. 8

1st STEP - Case description ................................................................................................................. 11

2nd STEP - Model Training .................................................................................................................. 12

3rd STEP – Model evaluation / Prediction .......................................................................................... 16

Model Order Reduction utilities ........................................................................................................ 19

Model export for visualization .......................................................................................................... 22

Model export for control strategy ..................................................................................................... 22

Demonstrations ..................................................................................................................................... 25

Tutorials ................................................................................................................................................. 26

Flow around an airfoil ....................................................................................................................... 26

Read & Process ASCII data................................................................................................................. 31

Write ASCII data ................................................................................................................................ 34

Page 3: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 2 of 35

Introduction Model Order Reduction (MOR) is a technique for reducing the computational complexity of

mathematical models in numerical simulations (as presented by Wikipedia).

- Train models on simulation data

The Proper Orthogonal Decomposition

method used is a non-intrusive way of building

a reduced model through simulation data. To

assess a system behavior depending on certain

set of parameters, you can infer a reduced

model by training it on specific simulation

datasets.

- Run fast design space exploration

You can then leverage your reduced model for fast and accurate

simulation around a given operating point. This will allow you, for

instance, to perform design space exploration for a wide set of

parameters, including geometry changes. With those results you will then

be able to perform design optimization.

- Deploy beyond simulation experts

Thanks to model order reduction, you can now deploy models beyond simulation specialists to the

engineering and manufacturing departments, and following the product in-service. Reduced models

will allow you to create a new simulation experience through the coupling of system models with finite

element models, but also multi-scale and multi-physics approaches.

Flow around a rotating cylinder In this example we perform a parametric study of the velocity field around a rotating cylinder, at

different values of speed Ω (between 4 and 6 rpm). This represents a use case of model reduction for

wind farm optimization. It proceeds in the following steps:

1. Import data from any fluid dynamics solver

2. Train a reduced order model on those data

3. Evaluate this model as a transfer function on new data

4. Export the model for visualization

Any kind of simulation data can be taken as input to the model reduction process (coming from any

simulation vendor).

Page 4: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 3 of 35

Proper Orthogonal Decomposition theory Proper Orthogonal Decomposition surrogate modeling is based on three main points.

• Linear decomposition

One starts with the following assumption:

𝑓(𝑥, 𝑝) ≈ ∑ 𝛼𝑖(𝑝). 𝛷𝑖(𝑥)

𝐾

𝑖=1

This means that every field depending on space and given parameters could be described as a

linear combination of coefficients (depends on parameters) and modes (depends on space) that

can be seen as a basis.

• POD Modes

To ensure that truncation of previous formula at K-order is the most accurate one (minimizing

error), the second idea of POD is to compute specific quantity for the modes.

Benefits of this very particular process is that modes are characterized by an importance measure

called energy and that first modes are gathering most of the system energy. That is what will allow

us to cut the above formula at a low order, hence producing a “reduced order” model.

• Coefficients interpolation

Last point about POD surrogate modelling is then to interpolate coefficients behaviour for any set

of parameters and proceed with the linear combination in order to get new simulation results for

not-computed set of parameters.

Page 5: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 4 of 35

From theory to practice This part of theory being known, one could deduce that:

POD is a statistical tool

The POD analyses the coherent structure of a system through your DOE snapshots.

What does that mean?

First of all, that the modes (eigenvectors of correlation matrix) you obtain could be real

physical structures evolving with time or other parameters. That is the case, for example, if

you train your model on a turbulent unsteady CFD case. Modes could then be interpreted as

turbulent structures.

Second of all, that the energy associated to the modes (eigenvalues of correlation matrix)

represents the probability for such a mode to appear in your training database (snapshots

simulations).

How to correctly use the POD tool?

It’s all about setting a relevant DOE depending on your case.

- If you would like to leverage a reduced basis (considering only a few modes), and if you

are focusing on a specific dynamic behaviour, try to make it happen more often (more

snapshots) so that the energy associated to that mode will be higher. Considering only the

first more energetic modes will then be OK.

- If you would like to simulate any kind of case, you must make a DOE as bigger and random

as possible. Doing so, you will have to consider all the modes, because no one will be more

relevant than another (Or maybe the few firsts ones. But those won’t capture any specific

dynamic).

So, if you think that your system dynamic is not well reconstructed/predicted, first of all check

your modes and see if the particular dynamic is present. If it’s not, try to generate a new and

more relevant DOE.

POD is just about mode computing

What is different from other surrogate modelling method like RBF interpolation or kriging?

The first step with POD is to generate a modal basis based on a relevant DOE. The idea behind

POD with interpolation prediction is that you assume that your simulation can be linearly

decomposed on this exact same basis.

Page 6: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 5 of 35

Good point: As modes correspond to coherent structures which are evolving following a

parameter (One DOE snapshot for one set of parameters), it is particularly relevant to try to

interpolate the behaviour of that modes in order to predict the whole system behaviour.

Bad point: As said, modelling with POD is about interpolating known behaviours. So, it is hard

to predict strongly non-linear behaviour (transonic shock for example) with a single POD basis.

The idea could then be to generate many local relevant POD-basis.

What about model reduction

Model reduction can be considering only a few modes for your POD basis before interpolating

(non-intrusive) or make a projection of your mathematical model equations on your reduced

basis (intrusive).

Model reduction workflow A typical model reduction workflow can be broken down into 2 distinct parts:

1. Offline Learning

2. Online Evaluation

Offline Learning This traditional workflow around finite element analysis provides us a frame to understand concretely

how model reduction is performing:

1. First by setting up a Design of Experiment (DoE) varying different parameters of the design

This can be saved as a simple table of parameter under Comma Separated Values (CSV)

2. Second by running a bunch of Finite Element Models (FEM) on those parameters’ settings

This can be saved under any simulation dedicated file format, like the ESI Result File (ERF),

basing on HDF5

3. Third by Performing Model Order Reduction (MOR) on the data produced by simulation

This can be saved under a dedicated

Online Evaluation Once the reduced model is generated, it is possible to evaluate new values by submitting a new value

of the input parameters:

Page 7: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 6 of 35

Limitations of the current toolbox • In case of mesh morphing, same topology is required

Page 8: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 7 of 35

Installation The current product is packaged as a Scilab toolbox. To install it follow the next steps:

1/ Open your SCILAB environment

2/ Browse your directory manager and locate the scimor.zip file

3/ Into the SCILAB Console, write the following command

--> atomsInstall(‘scimor.zip’)

4/ Check for error

5/ Close and reopen SCILAB to confirm installation

6/ Check for good installation

7/ Now you have access to Model Order Reduction toolbox features

Page 9: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 8 of 35

Model Order Reduction toolbox features The Model Order Reduction toolbox provides several capabilities one can access using SCILAB

functions. The whole model order reduction process will require to manipulate some specific objects,

generate a modal basis and interpolate a new behavior on it.

To do so, two approaches are possible:

High level API

The Model Order Reduction toolbox provides a high level API providing the user with a light but full

experience of the model generation process, manipulating mandatory objects only. Using this API, the

user will only have to create mesh and simulation objects, train and evaluate a model, and then make

visualization.

Low level API

Advanced user might want to enter into more of the Proper Orthogonal Decomposition method

details, directly dealing with reduced basis, coefficients and so on. This is possible using the

intermediate functions described with prefix mor, functions which are implanted within the main API

for model training and evaluation.

Objects Objects are typical SCILAB structure the user will have to manipulate and which gather some

properties. Properties Prop of a given object Obj can be accessed via the following command line:

--> Obj.Prop

Below are listed the main objects which will be manipulated during model order reduction process.

Page 10: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 9 of 35

Main objects

Here are the main objects every user will have to manipulate to leverage model order reduction

capabilities.

Mesh

Description: Mesh object contains all the information related to the user mesh. Nota: Mesh object is not mandatory when using Euclidean inner product (default) or no visualization within SCILAB

node_coords Nodes coordinates. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑐𝑜𝑜𝑟𝑑𝑖𝑛𝑎𝑡𝑒𝑠

nb_nodes Number of nodes in the mesh

cell_type Scalar. Number of nodes in an element (e.g. Triangle = 3, Square = 4, …)

elements Connectivity. Matrix of size 𝑛𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 × 𝑛𝑛𝑜𝑑𝑒𝑠 𝑖𝑛 𝑎𝑛 𝑒𝑙𝑒𝑚𝑒𝑛𝑡

nb_elements Number of elements in the mesh

Simulation

Description: Simulation object contains all the information related to a simulation or set of simulations (e.g. training simulations)

_mesh Mesh object related to the simulation

nb_case Number of simulations gathered in the simulation object. Several in the case of training data set.

values Physical field over the mesh. List of size 𝑛𝑏𝑐𝑎𝑠𝑒 containing matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝𝑠

nb_samples 𝑛𝑐𝑎𝑠𝑒 array of number of time steps for each unsteady simulation.

doe Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

homogeneous Boolean (%t or %f) that characterizes the homogeneity of the simulation

Model

Description: Model object contains all the information needed for the prediction process.

Model Coefficients interpolation model.

reducedbasis Object gathering the reduced basis information (see below)

Mesh Mesh object needed for visualization

DOE Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadric

Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

Sigma Arrow of kernel radius

Page 11: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 10 of 35

Intermediate objects

Here are intermediate objects advanced user might leverage to have a better understanding of their

process.

Reduced Basis

Description: Reduced Basis object contains all the information related to the POD basis which has been truncated

phi Modes. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑠𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑚𝑜𝑑𝑒𝑠

n_pod Number of selected modes. Scalar.

u_m Mean field. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 1. 0 if simulation is homogeneous.

TotEnergy Total energy of the full POD basis. It corresponds to the sum of the eigenvalues. Scalar.

lambda Energy of each modes. It corresponds to the eigenvalues of the truncated basis. Matrix of size 𝑛𝑝𝑜𝑑 × 1

Page 12: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 11 of 35

1st STEP - Case description First step to set up the model order reduction process is to describe the cases user would like the

model to be trained on. This includes discretization support (e.g. mesh), simulation results and Design

of Experiment (DoE).

This can be done using the following functions:

create_mesh

Description: Generate a mesh object based on the true mesh information

Syntax

(1) myMesh = create_mesh(node_coords) (2) myMesh = create_mesh (node_coords, elements)

IN node_coords Nodes coordinates. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑐𝑜𝑜𝑟𝑑𝑖𝑛𝑎𝑡𝑒𝑠

IN (opt) elements Connectivity table. Index for first nodes must start at 1. Matrix of size 𝑛𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠 × 𝑛𝑛𝑜𝑑𝑒𝑠 𝑖𝑛 𝑎𝑛 𝑒𝑙𝑒𝑚𝑒𝑛𝑡

OUT myMesh Mesh object

create_simulation

Description: Generate a simulation object based on the simulation runs

Syntax

(1) mySimu = create_simulation(mesh, node_values, doe)

IN mesh Mesh object

IN node_values Physical field over the mesh. List of size 𝑛𝑏𝑐𝑎𝑠𝑒 containing matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝𝑠

IN doe Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

OUT mySimu Simulation object

Be careful, for unsteady simulation, each training simulation must have same number of time steps.

Page 13: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 12 of 35

2nd STEP - Model Training Next step is to train the model using the created object and the Proper Orthogonal Decomposition

method.

High level API

For a light experience, open can use the following function

PODTraining

Description: Generate a model object based on the training simulations and RBF interpolation

Syntax

(1) myModel = PODTraining(simu, npod, Gauss, Pol) (2) myModel = PODTraining(simu, npod, Gauss, Pol, log)

IN simu Simulation object

IN npod Number of selected modes. Scalar. Must be lower than number of training simulations.

IN Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadratic

IN Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

IN (opt) log Boolean. If %t displays model computation steps into the SCILAB console

OUT myModel Model object

Information that can be monitored during model computation (PODTraining function) when setting

log argument to TRUE (%t):

Nota: DOE scaling is automated thanks to interpolation method.

Page 14: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 13 of 35

Low Level API

An alternate and longer way to proceed could be to use the following functions. Those will provide the

user with more flexibility in the model computation and direct access to intermediate objects such as

reduced basis and coefficients.

Set up the full POD basis

morComputePodBasis

Description: Generate a POD basis based on the training simulations

Syntax

(1) podBasis = morComputePodBasis(simu) (2) podBasis = morComputePodBasis(simu, log)

IN simu Simulation object

IN (opt) log Boolean. If %t displays POD Basis computation steps into the SCILAB console

OUT podBasis SCILAB structure similar to Reduced Basis object

Information can be monitored during POD Basis computation (morComputePODBasis function) when

setting log argument to TRUE (%t)

Set up reduced POD basis

morReducePodBasis

Description: Reduce POD Basis according to a user specified number of modes

Syntax

(1) redBasis = morReducePodBasis(podBasis, n_pod)

IN podBasis SCILAB structure generated via the compute_pod_basis function

IN n_pod Number of selected modes. Scalar. Must be lower than number of training simulations.

OUT redBasis Reduced Basis object

Page 15: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 14 of 35

Model training

morPODTraining

Description: Scalar equivalent for PODTraining

Syntax

(1) [m, s] = morPODTraining(DOE, nb_samples, values, mesh, n_pod, phi, Gauss, Pol, euclid)

IN DOE Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

IN nb_samples 𝑛𝑐𝑎𝑠𝑒 array of number of time steps for each unsteady simulation.

IN values Physical field over the mesh. List of size 𝑛𝑏𝑐𝑎𝑠𝑒 containing matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝𝑠

IN mesh Mesh object related to the simulation

IN n_pod Number of selected modes. Scalar. Must be lower than number of training simulations.

IN phi Modes. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑠𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑚𝑜𝑑𝑒𝑠

IN Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadratic

IN Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

IN euclid Inner product: Euclidean (%t). Other coming.

OUT m Coefficients interpolation model.

OUT s Arrow of kernel radius

The morPODTraining function implements an interpolation method (offline phase). Two methods for

multiparametric interpolation are available. Both are based on Radial Basis Function. One is tunable,

i.e., user can set up the kernel radius himself. One is automatically tuned using Leave-One-Out Cross

Validation (LOOCV) process. Using different kernel radius per parameters scales the DOE.

morRBFoffline

Description: Radial Basis Function interpolation training with tunable kernel radius

Syntax

coefModel = morRBFoffline(DOE, Resp, Gauss, Pol, Sigma)

IN DOE Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

IN Resp 1 × 𝑛𝑟𝑢𝑛𝑠 matrix of the basis coefficients to be interpolated.

IN Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadratic

IN Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

IN Sigma Arrow of kernel radius

OUT coefModel Coefficients interpolation model.

Page 16: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 15 of 35

Default selection into morPODTraining

morRBFCVoffline

Description: Radial Basis Function interpolation training with automatic kernel radius tuning

Syntax

[coefModel, sigma] = morRBFCVoffline(DOE, Resp, Gauss, Pol)

IN DOE Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

IN Resp 1 × 𝑛𝑟𝑢𝑛𝑠 matrix of the basis coefficients to be interpolated.

IN Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadratic

IN Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

OUT coefModel Coefficients interpolation model.

OUT sigma Arrow of optimal kernel radius

Page 17: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 16 of 35

3rd STEP – Model evaluation / Prediction Based on the previous process, one can generate a model (output of PODTraining function) and

leverage it for further prediction.

High level API

PODEval

Description: Evaluate model using Model object on new set of parameters

Syntax

(1) predictSimu = PODEval(model, mesh, param) (2) predictSimu = PODEval(model, mesh, param, toMat) (3) predictSimu = PODEval(model, mesh, param, toMat, log)

IN model Model object

IN mesh Mesh object

IN param New set of parameters to evaluate the model on. Should be between DoE limits. Array of size 1 × 𝑛𝑝𝑎𝑟𝑎𝑚

IN (opt) toMat Boolean. If %f (default) predictSimu is a simulation object. If %t, predictSimu corresponds to the values field of the predictSimu object, i.e., a matrix.

IN (opt) log Boolean. If %t displays computation steps into the SCILAB console

OUT predictSimu Simulation object or Matrix (if toMat argument set to %f)

Information can be monitored during model evaluation (PODEval function) when setting log argument

to TRUE (%t):

Page 18: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 17 of 35

Low level API

As for the model training process, one can decompose the evaluation process using

morPODEval

Description: Scalar equivalent for PODEval

Syntax

values = morPODEval(parameters, model, DOE, Gauss, Pol, Sigma, Phi, U_m)

IN parameters New set of parameters to evaluate the model on. Should be between DoE limits. Array of size 1 × 𝑛𝑝𝑎𝑟𝑎𝑚

IN model Coefficients interpolation model.

IN DOE Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

IN Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadratic

IN Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

IN Sigma Arrow of kernel radius

IN Phi Modes. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑠𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑚𝑜𝑑𝑒𝑠

IN U_m Mean field. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 1. 0 if simulation is homogeneous.

OUT values 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝𝑠 matrix of predicted field

As for training phase, the morPODEval function implements an interpolation method (online phase)

which should match the method used for training.

Evaluation for morRBFoffline and morRBFCVoffline

morRBFonline

Description: Generate interpolated coefficients for a new set of parameters based on a Model object

Syntax

interpCoef = morRBFonline(parameters, CoefModel, DOE, Gauss, Pol, Sigma)

IN parameters New set of parameters to evaluate the model on. Should be between DoE limits. Array of size 1 × 𝑛𝑝𝑎𝑟𝑎𝑚

IN CoefModel Coefficients interpolation model.

IN DOE Design of Experiment. Table gathering the values of design parameters for each training run. Matrix of size 𝑛𝑟𝑢𝑛𝑠 × 𝑛𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠

IN Gauss Basis function for RBF interpolation. Boolean: %t = Gaussian ; %f = Multiquadratic

IN Pol Relaxation polynomial for ill-conditioned interpolation. Boolean %t to use it

IN Sigma Arrow of kernel radius

OUT interpCoef Matrix of interpolated coefficients

Page 19: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 18 of 35

Finally, morPODEval function implements a function to generate proper simulation results based on

interpolated coefficients

morReducedBasisSimulate

Description: Create predicted field based on reduced basis and associated coefficients

Syntax

values = morReducedBasisSimulate(Phi, Coefs, Um)

IN Phi Modes. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑠𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑚𝑜𝑑𝑒𝑠

IN Coefs Array of basis coefficients

IN Um Mean field. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 1. 0 if simulation is homogeneous.

OUT values 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝𝑠 matrix of predicted field

Page 20: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 19 of 35

Model Order Reduction utilities For process validation and customization, some visualization functions are provided within SCILAB. For

the moment the visualization is only available for 2D cases.

show_simulation

Description: Display physical field on mesh based on Simulation object information

Syntax

(1) show_simulation(simu) (2) show_simulation(simu, nvisu)

IN simu Simulation object

IN (opt) nvisu Scalar that defines number of run to visualize for training simulation. Default is 1.

Visualization of pressure around NACA0012 airfoil at angle of attack: -9°

show_basis_energy

Description: Display energy of the basis depending on the number of modes included in the basis. This cumulative plot is a first step to decide how many modes to consider.

Syntax

show_basis_energy(redBas)

IN redBas Reduced basis object

Page 21: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 20 of 35

Considering only 3 modes seems to be sufficient to gather almost 100% of the system energy

show_pod_modes

Description: Display basis vectors (modes)

Syntax

show_pod_modes(mesh, modes, n_pod)

IN mesh Mesh object

IN modes Field phi of Reduced Basis object. Matrix of size 𝑛𝑛𝑜𝑑𝑒𝑠 × 𝑛𝑠𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑚𝑜𝑑𝑒𝑠

IN n_pod Number of selected modes. Scalar.

9 modes of pressure field around a shape varying mesh

Page 22: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 21 of 35

This tool also provides the user with capability to compute relative error between expected and

predicted simulations. This error is computed as the Normalized Root Mean Square Error which

formula is:

𝑒𝑟𝑟 = ‖𝑒𝑥𝑝𝑒𝑐𝑡𝑒𝑑 − 𝑣𝑎𝑙𝑢𝑒‖/‖𝑒𝑥𝑝𝑒𝑐𝑡𝑒𝑑‖

compute_rel_error

Description: Provides Normalized Root Mean Square Error for two simulations

Syntax

(1) err = compute_rel_error(expected, value, mesh) (2) err = compute_rel_error(expected, value, mesh, euclid)

IN expected Matrix gathering expected values for simulation

IN value Matrix gathering predicted values for simulation

IN mesh Mesh object (mandatory for L2 inner product)

IN (opt) euclid Inner product: Euclidean (%t). Other coming.

OUT err NRMSE column vector of size 𝑛𝑡𝑖𝑚𝑒 𝑠𝑡𝑒𝑝

Below is presented an example of NRMSE plot for an unsteady simulation.

Page 23: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 22 of 35

Model export for visualization In this release 1.0, we provide a way to export reduced order model under a file format called EPRF

(for ESI Parametric Result File). This enables the 3D visualization of reduced models in the ESI Player,

depending on time, and one parameter.

The following script enables the creation of an EPRF file example.eprf:

filename = "example.eprf";

data_path = "morFile"

load(data_path+"/myMesh.sod");

load(data_path+"/Modes.sod");

load(data_path+"/CoefList.sod");

// add the Z component

nodes = [myMesh.node_coords, zeros(size(myMesh.node_coords, 'r'), 1)];

// create a 4 nodes element from a 3 nodes element

elems = [myMesh.elements, myMesh.elements(:,$)]-1;

eprfWrite(filename, nodes, elems, linspace(4, 6, 101), Modes, CoefList);

Page 24: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 23 of 35

Model export for control strategy One way to use a Reduced Order Model generated via the POD method is to import it within XCOS for

model predictive control purposes. To do so, the user will start launching XCOS.

Within the SCIMOR directory, two blocks are available:

• MOR_POD_EVAL which will evaluate trained POD model on parameters set as block inputs

• MOR_SHOW_SIMULATION which will provide 2D visualization of a given simulation

Page 25: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 24 of 35

The user can check the provided demonstration to see how to set up a full model. The example below

is for NACA0012 polar plot.

To parametrize your XCOS simulation, you can use Simulation >> Modify Context

Model and mesh must be loaded within your SCILAB environment.

Page 26: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 25 of 35

Demonstrations Some demonstrations are provided along with the Model Order Reduction toolbox. The user can

access those via the demonstration manager.

Under SCIMOR section, you will find code to set up mesh, simulation, a full 2D airfoil case depending

on angle of attack as well as the polar set up of this airfoil using XCOS.

Page 27: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 26 of 35

Tutorials The following tips and associated content will help the user importing and exporting their simulation

data. Full content can be found on SCILAB official website: www.scilab.org

Flow around an airfoil This tutorial operates on data produced by OpenFOAM simulations around an airfoil. In this study,

we will consider the influence of the angle of attack (alpha) on the flow around the airfoil.

First let’s load the data that have been saved as .sod files (for Scilab Open Data, that HDF5-based):

///////////////////////////////////////////////////

// Load simulation data //

///////////////////////////////////////////////////

path = scimor_getpath();

Airfoil2DAoA_path=path+"\data\Airfoil2DAoA\";

load(Airfoil2DAoA_path+"Mesh/my2Dfaces.sod");

load(Airfoil2DAoA_path+"Mesh/my2Dpoints.sod");

load(Airfoil2DAoA_path+"SimulationData/my2Dpressure.sod");

load(Airfoil2DAoA_path+"SimulationData/DOE.sod");

Before the training of the reduced order model, we need to prepare the data:

- Create a mesh object:

///////////////////////////////////////////////////

// Set training data //

///////////////////////////////////////////////////

myMesh = create_mesh(my2Dpoints, my2Dfaces);

NodalVal = list();

for i=1:size(my2Dpressure, 2)

NodalVal(i) = my2Dpressure(:,i);

end

The mesh object is structured this way:

--> myMesh = create_mesh(my2Dpoints, my2Dfaces)

myMesh =

node_coords: [10906x2 constant]

nb_nodes: 10906

cell_type: 4

elements: [10720x4 constant]

Page 28: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 27 of 35

nb_elements: 10720

- Displaying the results of the OpenFOAM simulation

mySimu = create_simulation(myMesh, NodalVal, doe);

show_simulation(mySimu, 2);

The simulation object is structured this way:

--> mySimu

mySimu =

_mesh: [1x1 struct]

nb_case: 21

values: list

nb_samples: [21x1 constant]

doe: [21x1 constant]

homogeneous: %t

We actually computed 21 values of the pressure field for every degree from -10° to 10°. With the

function show_simulation we can plot the result. When asking for the second value we obviously get

the results for -9°:

If you want to zoom on the airfoil profile, you can do so by applying the following zoombox:

Page 29: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 28 of 35

a=gca();

a.zoom_box = [-30,-27,25,27,-0.11,0.11];

In order to visualize the pressure fields over some particular values:

NodalVal1 = list();

NodalVal1(1) = my2Dpressure(:,1);

NodalVal1(2) = my2Dpressure(:,21);

NodalVal1(3) = my2Dpressure(:,11);

mySimu1 = create_simulation(myMesh, NodalVal1, doe1);

show_simulation(mySimu1);a=gca();

a.zoom_box = [-30,-27,25,27,-0.11,0.11];

show_simulation(mySimu1,2);a=gca();

a.zoom_box = [-30,-27,25,27,-0.11,0.11];

show_simulation(mySimu1,3);a=gca();

a.zoom_box = [-30,-27,25,27,-0.11,0.11];

Those are the results of 3 values of from our Design of Experiment (-10°, 0° and 10°):

In this example, we will train our reduced model with the complete 21 values of our Design of

Experiment, and we will consider 4 modes of the reduced basis:

///////////////////////////////////////////////////

// Training phase //

///////////////////////////////////////////////////

npod = 4;

Gauss = %t;

Pol = %f;

LOG = %t;

HaveAVector = %f;

model = PODTraining(mySimu, npod, Gauss, Pol, LOG);

This is the POD modes and the associated values of those modes:

show_basis_energy(model.reducedbasis)

show_pod_modes(mySimu._mesh, model.reducedbasis.phi, model.reducedbasis.n_pod);

Page 30: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 29 of 35

Once trained, we can predict the pressure field on a new parameter value (here 1.2°):

///////////////////////////////////////////////////

// Prediction phase //

///////////////////////////////////////////////////

NewParam = 1.2;

myPredictSimu = PODEval(model, myMesh, NewParam, HaveAVector, LOG);

show_simulation(myPredictSimu)

f=gcf();f.figure_name="Pressure around an Airfoil";

a=gca();

a.zoom_box = [-30,-27,25,27,-0.11,0.11];

a.title.text="Angle of Attack: " + string(NewParam);

Page 31: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 30 of 35

We can even add a slider to vary the field continuously between the training values (from -10° to 10°):

///////////////////////////////////////////////////

// Slider //

///////////////////////////////////////////////////

function updateSlider(h)

NewParam=get(h, "value")

myPredictSimu = PODEval(model, myMesh, NewParam, HaveAVector, LOG);

disp(NewParam)

disp("-------")

// show_simulation(myPredictSimu)

a=gca();

a.children(1).children(1).data(:,3)=myPredictSimu.values(1);

a.title.text="Angle of Attack: " + string(NewParam);

endfunction

f = createWindow();

f.figure_size=[626,90];

f.figure_name="Reduced model slider"

Page 32: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 31 of 35

Read & Process ASCII data In this section we will see how leverage csvRead function to import ASCII data within Scilab and how

to process those data.

1st Example

Let’s say that we have a first data file Data1.txt

This file is mainly about text information but is also providing a few quantitative information regarding

some sensors. Let’s see how to get sensors IDs (2341 and 453) and coordinates ([3 2 1] and [-22 3 1]).

First of all, import text within a SCILAB matrix, using default csvRead function, settings for separators

and decimals and forcing conversion to string (default is conversion to double).

This provides the following matrix:

Based on this, one can locate the %SENSOR sub-string

Split text into parts in order to get the needed information (ID and POS)

Page 33: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 32 of 35

And finally, change string into doubles (removing parenthesis for coordinates)

At the end of the process, one dispose of the following data

2nd Example

Let’s say that we have a second data file Data3.csv

Page 34: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 33 of 35

This file is just about numerical data. Imagine we want to take line from 2 to 5 and column from 2 to

4. Separator will be set at ‘;’, decimals at ‘,’ and will keep default settings for the other options

(including conversion to double). This can be written in SCILAB as follow

At the end of the process, one dispose of the following data

Remark: At any time of the process, one can save SCILAB variables as binary data with the save

function. Once this is done, one can load those variables any time using the load function.

Page 35: MODEL ORDER REDUCTION - ScilabDOC]Scilab... · 2019-12-05 · Scilab Model Reduction Toolbox – User Guide Page 2 of 35 Introduction Model Order Reduction (MOR) is a technique for

Scilab Model Reduction Toolbox – User Guide

Page 34 of 35

Write ASCII data Once the computation done, user might want to export data as ASCII file to process it or visualize it in

another software. In SCILAB, you just have to use the csvWrite function.

Starting with your data, concatenate the content into an homogeneous variable

And write it in a .txt file

This looks like