Ameset3 R17
Ameset3 R17
Editor 17
Restricted © Siemens 2019 Where today meets tomorrow.
Simcenter Submodel Editor
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Icon
Options
Getting started
Step 1: create a category
Step 2: create an icon
Step 3: create a submodel
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Add category
Icon designer
Draw icon
Load existing
bitmap
Save
Getting started
Step 1: create a category
Step 2: create an icon
Step 3: create a submodel
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Getting started
Step 1: create a category
Step 2: create an icon
Step 3: create a submodel
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Submodel name
Uppercase letters only
Starts with a letter
Underscore allowed
Submodel Editor generates a code skeleton, i.e. a piece of code containing pre-defined functions called by
Amesim during simulation
Initialization function
Called once at the start of simulation.
Contains initialization statements (parameter checks, data file reading…)
Access to state variable initial values
Calculation function
Called at each time step by the solver
Contains calculation statements
Calculation equations
Successful
compilation
with gcc
In Amesim:
Requires to remove
the submodel
currently associated
to the spring
damper
Right click on
component +
remove submodel
menu item
More explanations on
implicit loops on
modeler chapter
v1 is changed from
“basic” variable to
“duplicate”
It is set as duplicate of v3
F3 is changed from
“basic” variable to
“duplicate”
It is set as duplicate of F1
Save as
POWER_SENSOR2
Replace
POWER_SENSOR1 by
POWER_SENSOR2
Go to simulation mode
The modeller can not determine a calling sequence between spring and sensor
X1 X2 (dX2/dt = …)
F1(X1) F2
X1=X2 X2 (dX2/dt = …)
F1(X2) F2
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Port 1 has 2
variables
Restricted © Siemens 2019
Page 56 2019-06-29 Siemens Digital Industries Software
External variables
Parameter Variable
Examples
Diameter, mass
Number of cells
File name
Variables
Common uses
Basic
Explicit state
Implicit state
Discrete
Constraint
Fixed
Duplicate
One line macro
Multi line macro
Activity
Activity state For internal
Power variables only
Energy
Energy state
Simplest type
Example of sensor or
spring SPR50
𝑑𝑥
= 𝑓 (𝑥 ,𝑡 ,𝑢)
𝑑𝑡
In submodel code, it is represented by is a couple of C variables (x, dx)
Integrator example
𝑑𝑥
=𝑘 . 𝑖𝑛𝑝𝑢𝑡
𝑑𝑡
x is sent to initialization
function => its starting value
can be modified by
submodel
Submodel computes dx
𝑑𝑥
𝑓 (𝑥 , ,𝑡 ,𝑢)=0
𝑑𝑡
In submodel code, it is represented by is a couple of C variables (x, dx)
Differentiator example
Constraint equation
forces x to follow input
𝑑𝑥
𝑜𝑢𝑡𝑝𝑢𝑡=
𝑑𝑡
𝑟𝑒𝑠 ( 𝑥 )=𝑥 − 𝑖𝑛𝑝𝑢𝑡
dx is overwritten by the
residual of the DAE
𝑓 ( 𝑥 ,𝑡 ,𝑢)= 0
In submodel code, it is represented by is a couple of C variables (x, rx)
Illustration in code
generated by Amesim
model
V[0] is the output from the
sine wave
X1
V1
F1
Depends on acam
variable (cam angle)
X1 is a return value
Code comments
Submodel Editor inserts some test No automatic code for real parameters and
code for integer parameters only variables because boundaries may be
accepted or refused
V3 V2 = V3*V1
V1
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Objectives of exercise:
A parameter dialog
similar to Amesim
dialog appears
Simplify title
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
This chapter contains 2 examples of spring and 2 examples of mass (1D Mechanical)
𝐹 =𝑘 ∆ 𝑥
X2=0 X1=0
Displacements and velocities
orientation correspond to the orientation
of the flux arrows
𝐹 = 𝑓 0+ 𝑘( 𝑥 1+ 𝑥 2)
F = f0
X2
F = f0 + k.X2
X2 X1
F = f0 + k.X2 + k.X1
Restricted © Siemens 2019
Page 114 2019-06-29 Siemens Digital Industries Software
Example 1: Spring
for v + + for v
Constitutive law using a differential
equation
𝑑𝐹
Velocity orientation correspond to the =𝑘 ∆ 𝑣
orientation of the flux arrows 𝑑𝑡
F is declared as an explicit state
variable.
{
As CPU time depends directly on the
number of state variables, this type of 𝑑𝐹
modelling must be used only when
=𝑘 ( 𝑣 1+ 𝑣 2 )
necessary: when the displacements at ports
are not available. 𝑑𝑡
𝐹 ( 𝑡 0 )= 𝑓 0
SPR50 SPR51
{
𝑑𝐹
𝐹 = 𝑓 0+ 𝑘( 𝑥 1+ 𝑥 2) =𝑘 ( 𝑣 1+ 𝑣 2 )
𝑑𝑡
𝐹 ( 𝑡 0 )= 𝑓 0
Test both submodels in Amesim with several mass/springs
Compare RUN STAT results
SPR51 SPR50
CPU 7 times
bigger !!!!
The global tendency for CPU is F(N²) with or without optimized solver for stiff
systems (i.e. using BDF methods)
CPU [s]
- with optimized solver
- without optimized solver
Input/output variables
Inputs: force [N]
Outputs: velocity [m/s]
internal variables:
Acceleration [m/s/s] (optional)
𝑑𝑣
=∑ 𝐹
Parameters
Mass [kg] 𝑚
Constitutive law
𝑑𝑡
Restricted © Siemens 2019
Page 127 2019-06-29 Siemens Digital Industries Software
Example 2: Mass
MAS50
Constitutive law expressed with an explicit state variable (v1, dv1)
dv1 symbolises the instantaneous derivative of v1
𝐹 2−𝐹 1
𝑎𝑐𝑐 1=𝑑𝑣 1=
𝑚
MAS51
Constitutive law expressed with an implicit state variable (v1, resv1)
resv1 symbolises the residual of differential algebraic equation
resv1 = dv1 / dt
Note the resv1 variable stores the derivative of v1 on input to the submodel
Conclusions
Number of function
evaluation is similar
Config 4 always in
BDF (DASSL)
Config 3 Config 4
Stabilizing run
Stabilizing run
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Problem: a submodel can be called only when its inputs are known
A can be called when vB is known
B can be called when vA is known
vB
A vA B
V = Yi
X = Yj
SPRING(V, X, F)
MASS(F, V, V', X, X')
Y'i = V'
Y'j = X'
inpA vB
A vA inpB B
inpA vB
A vA inpB B
Z1
inpB = Z1
B(inpB, vB)
inpA = vB
A(inpA, vA)
Residual(Z1) = inpB – vA
inpA vB
A vA inpB B
Z1
Strategy consists in indicating to the modeler how outputs can be computed with
fewer inputs
v1 V1 and x1 are
x1 explicit states
inpA
A
dv1 = F(inpA)
vA = F(v1)
U
Signal output is a one line
macro
U = a.V3 + b
U is determined without F1
V3 F1
Duplicate of v3
V3
X3
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Definition
Examples of discontinuities
Backlash Hysteresis
Endstops
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Example 1: Absolute value
Example 2: more than 2 regions
Example 3: time discontinuity sampler
Example 4: check valve with hysteresis
Example 5: bouncing ball (elastic contact)
Example 6: bouncing ball (restitution coeff.)
Dynamic block example
User library
Without
discontinuity
handling
With
discontinuity
handling
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Example 1: Absolute value
Example 2: more than 2 regions
Example 3: time discontinuity sampler
Example 4: check valve with hysteresis
Example 5: bouncing ball (elastic contact)
Example 6: bouncing ball (restitution coeff.)
Dynamic block example
User library
-1 0 1
Definitions
Example 1: Absolute value
Example 2: more than 2 regions
Example 3: sampler (time
discontinuity)
Example 4: check valve (hysteresis)
Example 5: bouncing ball (elastic contact)
Example 6: bouncing ball with restitution
coefficient (resetting states)
X is input signal
Y is the value of x at last sample time
Constant sampling period in s
Variables
X is input signal
Y is basic output
Xk is internal discrete state
Tnext internal discrete state
Parameters
Period is real parameter
X Xk tnext period
Definitions
Example 1: Absolute value
Example 2: more than 2 regions
Example 3: sampler (time discontinuity)
Example 4: check valve (hysteresis)
Example 5: bouncing ball (elastic contact)
Example 6: bouncing ball with restitution
coefficient (resetting states)
Definitions
Example 1: Absolute value
Example 2: more than 2 regions
Example 3: sampler (time discontinuity)
Example 4: check valve (hysteresis)
Example 5: bouncing ball (elastic
contact)
Example 6: bouncing ball with restitution
coefficient (resetting states)
The ball is moving freely under gravity The ball is in contact with the floor
Times at which the ball hits the floor are unknown events
These will be handled as discontinuities
Inputs
Velocity [m/s]
Displacement [m]
Output
Force [N]
Internal variable
𝐹 =𝑘 . ∆ 𝑦 + 𝑏 .𝑣
With the Mechanical sign convention, positive
quantities are in the direction of the arrow
Definition of 2 zones
Not ok Not ok Ok
Y=0 not handled Overlap on y=0
Details of variables
Test in Amesim
Direct impact on
number of steps and
function evaluations
Definitions
Example 1: Absolute value
Example 2: more than 2 regions
Example 3: sampler (time discontinuity)
Example 4: check valve (hysteresis)
Example 5: bouncing ball (elastic contact)
Example 6: bouncing ball with
restitution coefficient (resetting states)
When the ball hits the floor, its velocity is reversed in sign and its magnitude is
multiplied by a constant factor lower than one.
The factor is called the coefficient of restitution
Displacement and
velocity can be reset
when flag == 0
getgravity : standard
Amesim function
2 solutions to improve it
Reduce print interval
Activate “discontinuity printout”
Standard printout
points are identical
Tolerance on velocity
Tolerance on velocity
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Main objectives
Create and manipulate a dynamic block
Create multiple sine wave source
Use ‘force recompilation’ feature
Limitations
Limited to C code (no Fortran)
Optional intensive calculations (e.g. friction model, PID -> PI) where
dimension is set to 1 or 0
Define 1 basic
output variable
freq and amp are not simple parameters, but groups of parameters frequency1, frequency2, … frequencyN
Curves produced by
both models are
identical
Test is successful
Getting started
Submodel definitions
Enumeration example
Mass-spring examples
Modeler - sorting components
Discontinuity handling examples
Dynamic block example
User library
Difficulties
Various compilers (GCC, Microsoft, Intel…)
Various languages (Fortran, C)
Static or dynamic library?
How to link it with Amesim model?
Advantages
An archive file is created (.lib or .a) gathering object files: source code is no
longer visible, protecting the IP (if compiled in RELEASE mode)
Static library is incorporated within the simulation executable during the
compilation (link process): the library is no longer needed after the model is
compiled
C and Fortran are compatible (some rules must be followed)
Drawbacks
Objects must be compiled with compatible compilers: gcc libraries are not
compatible with Microsoft Visual libraries
Libraries must be compiled with different compilers such that they can be
used by the end user independently of the compiler used; this is exactly
what is done for standard libraries and submodels
my_utils.c
In source directory, create a header and a source file
my_utils.h
$(CC) -I"$(AME)/lib" -c
$(CC)
-L"$(THISNODE)/lib/$(MACHINETYPE)" -lMYTEST
win32:"$(THISNODE)\lib\$(MACHINETYPE)\MYTEST.lib"
win64:"$(THISNODE)\lib\$(MACHINETYPE)\MYTEST.lib"
In submodel code
[email protected]
Thank you for your attention.
Any question?
How does the solver work?
Step 1: predictor
Predict y(1)n+1 with explicit
y(1)n+1
method
y’n
yn
yn+1 = yn + h.y’n
tn tn+1
t
h
Restricted © Siemens 2019
Page 240 2019-06-29 Siemens Digital Industries Software
How does the solver work?
Step 1: predictor
Predict y(1)n+1 with explicit
y(1)n+1 y’(1)n+1
method
Step 2: corrector
evaluate y’(1)n+1
y’n
yn
tn tn+1
t
h
Restricted © Siemens 2019
Page 241 2019-06-29 Siemens Digital Industries Software
How does the solver work?
Step 1: predictor
Predict y(1)n+1 with explicit
y(1)n+1 y’(1)n+1
method
Step 2: corrector
evaluate y’(1)n+1 y(2)n+1
refine y(2)n+1 with implicit
method y’n
yn
yn+1 = yn + h.y’n+1
tn tn+1
t
h
Restricted © Siemens 2019
Page 242 2019-06-29 Siemens Digital Industries Software
How does the solver work?
Step 1: predictor
Predict y(1)n+1 with explicit
y(1)n+1 y’(1)n+1
method
Step 2: corrector
evaluate y’(1)n+1 y(2)n+1 y’(2)n+1
refine y(2)n+1 with implicit
method y’n
y(3)n+1
yn
Step k: corrector
Evaluate y’(k)n+1
Refine y(k)n+1 with implicit
method
tn tn+1
t
h
Restricted © Siemens 2019
Page 243 2019-06-29 Siemens Digital Industries Software