Book a Demo

Author Topic: How are variables scoped during SysML activity diagram simulations?  (Read 2791 times)

tgallagher

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
We're new to SysML/MBSE and this type of modeling in general, but we're trying to jump right into the sysml-as-executable-model level of things. To get started, I'm porting over an existing Excel+VBA based design calculator into an activity called Design, and I'm trying to stay as-true to the existing flow and tool as possible. Since this is exploratory, we're looking to find out if moving a design tool into SysML works/makes sense/etc..

Anyway, I am having a hard time wrapping my head around how the Effects are scoped during a dynamic simulation. Consider a simple example that mimics the flow I'm setting up for the real tool:

https://imgur.com/a/t9Ijw7v

https://imgur.com/a/DBbba3j

where I want to calculate the hypotenuse of a right triangle. For this example, the two legs are 3 and 4 giving the hypotenuse of 5.

When I put a breakpoint down in the ComputeC activity, the Locals window shows:

https://imgur.com/a/vdKRPDE

I am confused about how all of this is scoped. It appears that my main activity invokes the anonymous Call Behavior action linked to ComputeHypotenuse that it gives the name Action, which takes in a and b and passes those through to a ComputeHypotenuse scope. All good there.

However, inside of the ComputeHypotenuse activity, it appears this always dereferences to sim. And the CreateTemporary action, which right now has aa = 2.0;, creates the aa variable on the same level as sim rather than something local to ComputeHypotenuse. If I try something like this.aa = 2.0; then I am changing the value of sim.aa.

I'm also not sure why the let PH = this.ComputeHypotenuse; in the first action of the ComputeHypotenuse activity doesn't create a variable called PH] in the locals window, even though it works in future actions.

How are variables scoped in activity diagram simulations? How can I create variables local to an activity without hacking something like creating a this.locals = {} at the start of every activity to give it a working space?

In my (wrong) mental model of things, I would have expected things to be local to an activity diagram and each activity diagram had a reference to sim. I would have expected this to refer to the owning activity. At the very least, I thought each activity would be within its own set of braces to scope actions taken. But it seems like everything just executes in a single scope?
« Last Edit: July 26, 2022, 01:11:45 am by tgallagher »

tgallagher

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How are variables scoped during SysML activity diagram simulations?
« Reply #1 on: July 26, 2022, 12:39:36 pm »
I'm also not sure why the let PH = this.ComputeHypotenuse; in the first action of the ComputeHypotenuse activity doesn't create a variable called PH] in the locals window, even though it works in future actions.

After playing with things more, I'm still confused about scope. With regards to let PH = ... not creating a variable that shows up in the Locals window, I had figured that meant it was a variable local to the invocation of the activity. But, it seems that when ActivityA activity invokes ActivityB via a CallBehavior action, all the variables declared with let in ActivityA are still in scope in ActivityB.

And further wrinkles, if ActivityA invokes ActivityB multiple times, any variables in ActivityB created with let seem to persist between invocations and it triggers and redeclaration error.

Not quite sure where to go from here to figure out how to get local variables in activity diagrams. Any help would be appreciated!

rutherford

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: How are variables scoped during SysML activity diagram simulations?
« Reply #2 on: August 01, 2022, 08:26:03 pm »
These models have continuously running software components (referred to as actors) that communicate by delivering messages across linked ports. Simulink from MathWorks, LabVIEW from National Instruments, SystemC, component and activity diagrams in SysML, and UML 2 are examples of software that supports such designs.  cookie clicker

tgallagher

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: How are variables scoped during SysML activity diagram simulations?
« Reply #3 on: August 02, 2022, 03:21:55 am »
Hi -- thanks for pointers, I think I get the interactions part between the actors.

But what I am not understanding is how to declare and use variables that have a scope within an action or activity. Something like Simulink, LabVIEW, and SystemC all allow locally-scoped variables within the actors. Things like intermediates/helper variables.

Every variable I seem to declare while simulating inside EA ends up in a scope that is global to the simulation and I cannot figure out how to get local variables within an action or activity scope.

Thanks for an additional insight!