PRISM
All lessonsLesson 9 of 9 · about 25 minutes

Allocation and views

Learn how SysML v2 assigns behaviour to structure and shows models in views: allocate ... to ..., view with expose and render, and a first look at viewpoint. With exercises, for beginners and SysML v1 users.

After this lesson you can

  • Assign an action to a part with allocate ... to ...
  • Say what an allocation does in the model and what it does not
  • Define a view on part of the model with view and expose
  • Recognize a viewpoint as the question a view answers

The model now says what the machine does (actions) and what it consists of (parts). What is open is who does what: which part takes over which step? That is allocation. After that the question is how to show only what a reader needs out of a larger model: the view. The example stays the invented coffee machine; its actions are the process Prepare espresso from lesson 6, here without parameters.

Assigning: allocate

allocate prepare.brew to machine.brewUnit; says that the step brew of the process prepare is taken over by the brew unit of the machine. On the left stands what is assigned, on the right to whom it is assigned. Both sides are paths to features: prepare is the usage of the process, machine that of the machine.

With allocation and a name you can name the assignment, as with connections in lesson 5.

// Excerpt of the coffee machine model
part machine : CoffeeMachine;
action prepare : PrepareEspresso;

allocate prepare.brew to machine.brewUnit;
allocation tampAllocation allocate prepare.tamp to machine.tamper;

What is an allocation for?

An allocation records who carries the function. With it you can ask which steps do not have a carrier yet and which parts have no task. The allocation changes neither the step nor the part: it links the two, just as a satisfy links part and requirement.

The diagram below draws the assignment: the process on the left, the machine on the right, and a dashed arrow for each allocation.

Views: view and expose

A model grows large. A view selects what is shown for a particular purpose. expose names which elements belong to it: expose machine; shows the machine. With ::* you take the direct elements of a namespace, with ::** all those below it as well.

render says how the selection is presented. asTreeDiagram comes from the standard library and presents it as a tree; so that tools find the name, you import it in the same package.

// Excerpt of the coffee machine model
private import Views::asTreeDiagram;

view machineView {
    expose machine;
    render asTreeDiagram;
}

Viewpoint

A viewpoint frames the concern of a stakeholder: whose question a view answers. It is a kind of requirement, not a kind of view; the definition of a kind of view is view def. A view can say with satisfy that it meets a viewpoint. That is enough for a start. Whoever maintains many views for different readers later ties them to viewpoints.

// Excerpt of the coffee machine model
viewpoint def StructureViewpoint {
    doc /* Shows how the machine is built from its parts, for the mechanical team. */
}

Our model so far

The process with its three steps, the machine with three parts and one allocation: grinding is with the grinder. Two assignments are still missing, and there is no view on the machine either. Both are your task below.

// The coffee machine model of this lesson
package CoffeeMachine {
    action def Grind;
    action def Tamp;
    action def Brew;

    action def PrepareEspresso {
        first start;
        then action grind : Grind;
        then action tamp : Tamp;
        then action brew : Brew;
        then done;
    }

    part def Grinder;
    part def Tamper;
    part def BrewUnit;

    part def CoffeeMachine {
        part grinder : Grinder;
        part tamper : Tamper;
        part brewUnit : BrewUnit;
    }

    part machine : CoffeeMachine;
    action prepare : PrepareEspresso;

    allocate prepare.grind to machine.grinder;
}

Source

Statements follow the OMG SysML v2 specification, Part 1 (Language Specification), in the clauses on allocations and on views and viewpoints (view, expose, rendering, viewpoint), and the standard library for views, which asTreeDiagram comes from. PRISM reads these constructs, draws the allocations and knows render asTreeDiagram. PRISM does not evaluate the filters of a view; they are therefore not part of this lesson.

Try it

This is the coffee machine model of the lesson: the process Prepare espresso on the left, the machine with its parts on the right, and the dashed lines are the allocations. What is drawn is the assignment; the view stands in the text, PRISM draws only the allocations here. Edit the text; the diagram redraws while you type. Everything runs in your browser, nothing is sent anywhere. At the end of the page you can download the file and open it in any tool that reads SysML v2 textual notation.

The editor loads when you scroll here.

The editor contains open-source components. Third-party notices · Source offer

Exercises

10 short exercises. Every answer gets feedback right away. Exercises you get wrong come back at the end. Your progress stays in this browser.

Exercise 1 of 10

What does allocate prepare.brew to machine.brewUnit; do?

Exercise 2 of 10

Match each SysML v1 term with its counterpart in SysML v2.

SysML v1SysML v2

Dependency «allocate»
View
Viewpoint
Elements a view shows

Exercise 3 of 10

Which keyword assigns the step to the brew unit?

part machine : CoffeeMachine;
action prepare : PrepareEspresso;

___ prepare.brew to machine.brewUnit;

Exercise 4 of 10

Tap the line that is not valid SysML v2.

package CoffeeMachine {
    action def PrepareEspresso { action brew; }
    part def CoffeeMachine { part brewUnit; }
    part machine : CoffeeMachine;
    action prepare : PrepareEspresso;
    allocate prepare.brew machine.brewUnit;
}

Tap a line, or move to it with the Tab key and press Enter.

Exercise 5 of 10

Put the pieces in the order of the line that assigns the step brew to the brew unit.

Drag the pieces, or use the arrow buttons.

  • to
  • machine.brewUnit
  • allocate
  • ;
  • prepare.brew

Exercise 6 of 10

What sets allocate apart from satisfy?

Exercise 7 of 10

What does expose machine; do in a view?

view machineView {
    expose machine;
    render asTreeDiagram;
}

Exercise 8 of 10

Type the keyword that defines a view.

___ machineView {
    expose machine;
}

Exercise 9 of 10

Which line assigns the step tamp to the part tamper?

package CoffeeMachine {
    action def PrepareEspresso { action tamp; }
    part def CoffeeMachine { part tamper; }
    part machine : CoffeeMachine;
    action prepare : PrepareEspresso;
}

Exercise 10 of 10

What does a viewpoint stand for?

viewpoint def StructureViewpoint {
    doc /* Shows how the machine is built from its parts, for the mechanical team. */
}

Take the model with you

The coffee machine model as a SysML v2 text file.

Download coffee-machine.sysml

See it as a diagram

PRISM turns SysML v2 text like this into diagrams and views. Try it on the sample model.

Try it now
Lesson complete

That was the learning path

You now know the building blocks a SysML v2 model is made of: definition and usage, parts, attributes, ports, connections, actions, states, requirements, allocation and views. Everything you learned is text in a file that any tool with SysML v2 textual notation reads. If you want to work on a model, not only read it: PRISM draws it as a diagram and lets you keep working in the diagram and in the text.