PRISM
All lessonsLesson 6 of 9 · about 25 minutes

Actions

Learn how SysML v2 describes what a system does: action def with parameters, actions as steps, the order with first and then, and flows between actions. With exercises, for beginners and SysML v1 users.

After this lesson you can

  • Define a behaviour with input and output parameters using action def
  • Place actions as steps inside a larger action
  • Set the order of the steps with first and then
  • Describe with flow which item travels from step to step

So far the model has described what the coffee machine consists of and what travels between its parts. This lesson describes what it does. In SysML v2 such behaviour is called an action. The example is a process of the invented coffee machine: preparing an espresso, in the steps grind and brew.

Defining a behaviour: action def

An action def defines a kind of behaviour, just as part def defines a kind of part. What goes in and what comes out stands as parameters in the definition. A parameter is a feature with a direction, like the items in the port from lesson 4: in item beans : Beans; means the step receives beans, out item grounds : Grounds; means it delivers ground coffee.

The items are the same types you already know: item def describes what is given or produced.

// Excerpt of the coffee machine model
item def Beans;
item def Grounds;

action def Grind {
    in item beans : Beans;
    out item grounds : Grounds;
}

Placing steps

An action can contain other actions. An action inside an action def is a step: it has a name and is typed by another action definition, just like part pump : Pump; in a part def.

PrepareEspresso is a process of two steps. The process has parameters of its own: beans and water come in, coffee comes out.

// Excerpt of the coffee machine model
action def PrepareEspresso {
    in item beans : Beans;
    in item water : Water;
    out item coffee : Coffee;

    action grind : Grind;
    action brew : Brew;
}

Order: first and then

Steps without further information are not ordered: they can run in any order or at the same time. first grind then brew; says that brew comes after grind. That is a succession: it orders, nothing more.

The chain is shorter to write: a then at the start of a line means “afterwards” and refers to the step before it. first start; and then done; set the beginning and the end. Every action has start and done by default; they come from the standard library.

// Excerpt of the coffee machine model
action def PrepareEspresso {
    first start;
    then action grind : Grind;
    then action brew : Brew;
    then done;
}

Items from step to step: flow

The order does not say what the first step gives the second. The same flow as in lesson 5 describes that. The ends are now parameters of steps: grind.grounds is the output parameter of grind, brew.grounds the input parameter of brew.

You pass the process’s own parameters on to the steps with bind: bind grind.beans = beans; sets the input parameter of the step equal to the input parameter of the process.

// Excerpt of the coffee machine model
action def PrepareEspresso {
    flow of Grounds from grind.grounds to brew.grounds;

    bind grind.beans = beans;
    bind brew.water = water;
    bind coffee = brew.coffee;
}

Our model so far

The process of two steps, with order, an item flow and the parameters passed through. One gap remains: before brewing, the ground coffee has to be pressed into the portafilter. That step is missing, and it is your task below.

// The coffee machine model of this lesson
package CoffeeMachine {
    item def Water;
    item def Coffee;
    item def Beans;
    item def Grounds;
    item def Puck;

    action def Grind {
        in item beans : Beans;
        out item grounds : Grounds;
    }

    action def Brew {
        in item grounds : Grounds;
        in item water : Water;
        out item coffee : Coffee;
    }

    action def PrepareEspresso {
        in item beans : Beans;
        in item water : Water;
        out item coffee : Coffee;

        first start;
        then action grind : Grind;
        then action brew : Brew;
        then done;

        flow of Grounds from grind.grounds to brew.grounds;

        bind grind.beans = beans;
        bind brew.water = water;
        bind coffee = brew.coffee;
    }
}

Source

Statements follow the OMG SysML v2 specification, Part 1 (Language Specification), in the clauses on actions (action definitions and usages, successions, flow connections, binding) and the standard library for actions, which start and done come from. PRISM does not load that library and therefore reports start and done as a notice, not as an error; in the diagram they appear as start and end nodes.

Try it

This is the process of the lesson: preparing an espresso, in two steps. The diagram is an action flow: the steps are boxes, the dashed arrows show the order, the solid lines show the items that travel from parameter to parameter; the filled circle is the start, the circle with a dot is the end. 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 in item beans : Beans; say in an action def?

action def Grind {
    in item beans : Beans;
    out item grounds : Grounds;
}

Exercise 2 of 10

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

SysML v1SysML v2

Activity
Call Behavior Action
Control Flow
Object Flow

Exercise 3 of 10

Which word says that brew comes after grind?

action def PrepareEspresso {
    action grind : Grind;
    action brew : Brew;

    first grind ___ brew;
}

Exercise 4 of 10

Tap the line that is not valid SysML v2.

package CoffeeMachine {
    item def Beans;
    activity def Grind {
        in item beans : Beans;
    }
}

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 adds grind as the next step.

Drag the pieces, or use the arrow buttons.

  • Grind
  • then
  • :
  • grind
  • ;
  • action

Exercise 6 of 10

Which statement about then and flow between two steps is true?

Exercise 7 of 10

What does bind grind.beans = beans; do in the process?

action def PrepareEspresso {
    in item beans : Beans;
    action grind : Grind;
    bind grind.beans = beans;
}

Exercise 8 of 10

Which line says that tamp comes after grind?

action def PrepareEspresso {
    action grind : Grind;
    action tamp : Tamp;
}

Exercise 9 of 10

Type the keyword that places a step in a process.

action def PrepareEspresso {
    ___ grind : Grind;
}

Exercise 10 of 10

What is start in first start;?

action def PrepareEspresso {
    first start;
    then action grind : Grind;
}

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
Next lesson

States

How the machine reacts to events: states, transitions and what triggers them.