User Tools

Site Tools


bok:eng:mbse:sysml:para

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
bok:eng:mbse:sysml:para [2020/07/26 04:49]
anwlur [Organizing Parametric Modeling]
bok:eng:mbse:sysml:para [2020/08/01 02:25] (current)
anwlur [Customized Functions]
Line 5: Line 5:
  
 Constraints have certain reserved keywords. They are Constraints have certain reserved keywords. They are
-  * diff - ? e.g. diff(x) 
   * der - Derivative, e.g. der(x)   * der - Derivative, e.g. der(x)
-  * minimum ​minimum(1,​2,​3,​4) = 1 +  * sin Sine of radian 
-  * maximum ​maximum(1,2,3,4) = 4 +  * cos Cosine of radian 
-  * sum sum(1,2) = 3+  * tan - Tangent of radian 
 +  * min - Minimum, e.g. min(1,2,4) = 1 
 +  * max Maximum, e.g. max(1,2,4) = 4
  
 Common Built-in Variables can be modified in the 'Edit Constraint Block'​. Click the 'Edit Built-in Variable'​ button. If you have more than one then separate them with a ','​. Recommend to add: Common Built-in Variables can be modified in the 'Edit Constraint Block'​. Click the 'Edit Built-in Variable'​ button. If you have more than one then separate them with a ','​. Recommend to add:
-time+  * time
  
  
 ===== Organizing Parametric Modeling ===== ===== Organizing Parametric Modeling =====
  
-  ​Create a package ​labelled ​'model of x+  ​*   Create a package ​where you want to do your parametric modeling. I've kept it simple and called it '​Modeling' 
-  ​Create a block diagram for this package +{{ :​bok:​eng:​mbse:​sysml:​parametric:​modeling1.png?​400 |}} 
-  ​Inside BDD insert ​<​block>​ labelled ​'modeling_x'​. ​It can not contain ​any special characters ​including a space +  ​*   Create a block diagram for this package 
-  ​Add relevant Constraint Blocks. Add aggregation ​relationships between constraint blocks (source) to the Modeling X block (target). +{{ :​bok:​eng:​mbse:​sysml:​parametric:​modeling2.png?​400 |}} 
-  ​Add equations to your Constrain Blocks. If you will use an equation more than once add another ​aggregation ​relationship between the Constrain ​Block and the Modeling X blockIn such case be sure to assign ​a name to the source of each relationship ​to avoid confusion later +  ​*   Inside ​the BDD insert ​a Block and give it the name of your parametric model. I've called it 'Water_Quality_Model'​ 
-  ​You can't just have equations, you need inputs and outputs. Add to the BDD relevant Blocks that holds these inputs and outputs. Add a reference ​link between these blocks and the Modeling X block +{{ :​bok:​eng:​mbse:​sysml:​parametric:​modeling3.png?400 |}} 
-  - NOTE if you are linking blocks that reside in a different namespace then you will need to add a Package Import relationship between the Model of X package to the package that contains your blocks+<WRAP center round tip 60%> 
 +When you want to run the simulation Modelica is relatively harsh when it comes to parsing your model. Make sure to remove spaces and any special characters ​from your element names. Legal special characters include the underscore (_). Illegal special characters include the hyphen (-) 
 +</​WRAP>​ 
 + 
 + 
 +  ​Add to the package ​relevant Constraint Blocks. Add part association ​relationships between constraint blocks (source) to the model block (target). 
 + 
 +<WRAP center round tip 60%> 
 +Modelica will assign classes to your Constraint Blocks. If the usage of the block is not assigned a name Sparx EA assigns it '​unnamed element'​. Because Modelica doesn'​t like spaces within names it throws an error therefore you need to assign a name to each Constraint Block instance. Double click the part association relationship to open the Properties editor. In Source tab assign a name without spaces or special characters. 
 +</​WRAP>​ 
 + 
 +  ​Add equations to your Constrain Blocks. If you will use an equation more than once (e.g. Inversion: a = 1/b) add another ​part association ​relationship between the Constraint ​Block and the Model BlockDon't forget ​to add a name to the additional usage to avoid confusion later. 
 +  ​You can't just have equations, you need inputs and outputs. Add to the BDD relevant Blocks that holds these inputs and outputs. Add a reference ​association relationship ​between these blocks and the Model Block 
 + 
 +<WRAP center round tip 60%> 
 +If you are linking blocks that reside in a different namespace then you will need to add a Package Import relationship between the Modeling ​package to the package that contains ​the elements you want to use 
 +</​WRAP>​ 
 + 
 +  * With the building blocks ready for your parametric model you need to actually create the parametric relationships between the inputs, outputs and equation variables. Right click the Model Block -> Add Child Diagram... -> Parametric Diagram 
 +  * In the PAR diagram make sure to use the Binding Connector between variables. If you have a variable that doesn'​t have a connection it may suggest that you've missed something 
 +<WRAP center round help 60%> 
 +This should be a Warning and not an Error. E.g. if you have a summation equation that is '​a=b+c+d'​ but you only want to add 2 variables, b and c then d doesn'​t have a connection. 
 +</​WRAP>​ 
 +  * Making PAR diagrams look presentable is //hard// and probably takes as long if not longer than making all the connections. If you have a coffee break and looking for something to do then get to making your parametric model look presentable. Welcome to the churn! 
 + 
 +==== Customized Functions ==== 
 + 
 +The below is largely based on Creating a Parametric Model: Simulation Functions by Sparx Enterprise Architect which can be found [[https://​www.sparxsystems.com/​enterprise_architect_user_guide/​15.1/​model_simulation/​create_paramet_model.html|here]]. 
 +  * Modelica supports a limited number of mathematical functions, like '​min()'​ to return minimum value of a set, out of the box. If you want to create a function, say range() then that's where you come in. Note the below created function is obsolete as min() already exists (at the time of writing this function I didn't know that...) 
 +  * Insert a Constraint Block, call it '​Minimum'​ (it doesn'​t have to be the same name of your function). 
 +  * Add an Operation (right click -> Features -> Operations...). Click 'New Operation...'​ 
 +  * Give it the same name as your intended function (here I've given it '​min'​). 
 +  * In Parameters give each parameter a name, type and direction. 
 +{{ :​bok:​eng:​mbse:​sysml:​parametric:​modeling4.png?​400 |}} 
 +<WRAP center round tip 60%> 
 +Need at least one input and one output. 
 +</​WRAP>​ 
 +  * The Return Type is the same as the output. I've always kept Scope Public. 
 +  * In Stereotype if you can't find '​SimFunction'​ then just create it 
 +  * With the Features window still visible right click your newly minted operation and choose Properties... 
 +  * In the code section add the following code and save it. 
 + 
 +<​code>​ 
 +min_output :=  
 + 
 +if min_input_1 <= min_input_2 then  
 + min_input_1 
 +else  
 + min_input_2;​ 
 +</​code>​ 
 + 
 +<WRAP center round tip 60%> 
 +Note that you have more code writing options if you click on the 'Code Editor...'​ button and ostensibly you can change the language. However I found that the chosen language is ignored and Modelica must be using its own interpreter to interpret your code. 
 +</​WRAP>​ 
 + 
 +  * Now that the min() operation has been defined you can use it in your equations. 
 +  * In the Constrain Block define an equation using your function, e.g. a=min(b,​c) 
 + 
 +<WRAP center round help 60%> 
 +Can I use this function in other constraint ​blocks
 +</​WRAP>​
  
 ===== Troubleshooting ===== ===== Troubleshooting =====
 +
 +  * If you are getting a '​parameter x of constrain y does not have an input or output relationship'​ when it appears to be then check the model tree. It has been known that parameters are replicated (so it looks like you have 2 parameter x where only one should be)
 +  * Likewise if you are getting 'Too many equations, over-determined system'​ you have unwittingly binded the replicated parameters to form more equations then you actually need.
 +  * As of the time of writing parameters are replicated if you removed a property from the parametric diagram and reintroduced the same property
   * Are your blocks in a different namespace to the package that contains your simulation artifact? If so then add a package import relationship to the namespace that contains these blocks   * Are your blocks in a different namespace to the package that contains your simulation artifact? If so then add a package import relationship to the namespace that contains these blocks
   * Always use Binding Connector to connect parameters   * Always use Binding Connector to connect parameters
-  * If you are getting a '​parameter x of constrain y does not have an input or output relationship'​ when it appears to be then check the model tree. It has been known that parameters are replicated (so it looks like you have 2 parameter x where only one should be)+  * Models, parameters, constraints and blocks name can not have any special characters, including space 
bok/eng/mbse/sysml/para.1595738981.txt.gz · Last modified: 2020/07/26 04:49 by anwlur