Jump to content
robertavarela

Model Initialization versus Diagram Context

Recommended Posts

I'd like to share a few explanations about the differences between Model Initialization and Diagram Context:

image.png.d20cfa6d40f3115a0c13ba4510aee56c.png

In both menus, it is possible to declare variables that will be used along the model, but there are a few fundamental differences to be understood

 

Diagram prevails over Model Initialization

In case a variable A = 1 is declared in Model Initialization and then declared in the same level A = 2 in Diagram, the value to be used on that level and downward is A = 2.

 

A variable declared in Model Initialization may be modified in levels below, which will affect that variable all levels above

Although a variable A was created in the Model Initialization, it may be modified in a certain level, affecting its value not only downwards, but also upwards

 

A variable declared in Diagram may be modified in levels below, but this will not effect the variable in levels above

Different from the Model Initialization, if a variable A was created in Diagram, it may be modified in a certain level and it will affect only its value downards, not upwards

 

It is possible to use the SetSignal block to set a variable value locally

It is possible to use the SetSignal block to set a variable value locally which has the same name of another variable declared in Model Initialization, meaning that in all levels below it will still have the same value declared in Model Initialization

 

I hope this brief explanation will help you understand the differences between these two important features.

 

Regards,

 

Roberta

Share this post


Link to post
Share on other sites

Roberta,

I am not sure I understand correctly what you mean.

The scoping rule of Activate is semi-global, so A variable defined at a level n is known at the level n and recursively in all the subsystems of that level (until it is redefined). 

 

What is the difference between the Model Initialization and the top level diagram Context?

A variable defined in the model initialization can be used by the simulation parameters, but a variable defined at the context level cannot be used by the simulation parameters.

A variable defined in the model initialization can be redefined by an external context, but this is not the case for a variable defined in the diagram context. The external context is an argument of the simulation function when it is called from OML.

vssRunSimulation(model,external_context,workspace,...)

 

So the scripts are executed in that order:

ModelInitialization

ExternalContext

SimulationParameters

DiagramContext

 

All those scripts run at the evaluation level.

The SignalIn block reads the value at runtime from the workspace. When you call the function from OML, the workspace can be any environment.

When you run the simulation from the GUI:

the external context is an empty structure, the workspace is the base environment.

 

I hope that this clarify the difference between the Model Initialization and the diagram context.

 

Thanks

 

Fady

 

 

robertavarela likes this

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...