Holarch
Course chapters

Training · Track 9. SysML v2 Fundamentals · Chapter 9.1 of 8

9.1 Definitions and Attributes 4:33

Write value types and components in SysML v2 text, with values in units.

Shows Holarch 2.22.

What you’ll learn

  • Write an enumeration, a value type and an abstract part definition in the Editor
  • Specialize a definition with `:>` and give inherited attributes values with units using `redefines`
  • Find and fix a unit error that the checker underlines
  • Write a definition with Insert ▾ and completion, and look a type up in the Standard Library
  • Rename an element everywhere with F2 in one undo step

Write SysML v2 definitions and attributes in Holarch's Editor, following the SysML v2 tutorial Definitions and Attributes on a small Hybrid Car project: an enumeration, a value type that specializes ScalarValue, an abstract component and its specializations with values in units, a unit error found by the checker, completion and the Standard Library, Insert, and renaming with F2. SysML is a registered trademark of Object Management Group, Inc.

Project files

  • Finished project (.holarch.json; Manage Projects → Project Files ▾ → Import Project (.json)…)

The video plays from holarch.app; see the Privacy Policy.

Practice

Do this yourself in Holarch, on the Hybrid Car demo project (SysML v2).

  1. Create the Hybrid Car demo: Manage Projects → Project Files ▾ → New Demo Project → Hybrid Car (SysML v2). Open Model → Editor and the package Vehicles.
  2. Below enum def FuelKind, add enum def CoolingMode { enum passive; enum active; }.
  3. Below part def Body, choose Insert ▾ → Part Definition and complete part def Radiator :> Component with attribute redefines mass = 8 [kg];, attribute coolantVolume : VolumeValue; (type Volu and accept VolumeValue from the completion list with Enter) and attribute mode : CoolingMode;.
  4. Change the mass to 8 [W], point at the underline to read the message, then change it back to 8 [kg].
  5. In part def Powertrain, add part radiator : Radiator;. Then place the cursor on coolantVolume, press F2 and rename it to coolantCapacity.
  6. For a checked walk-through, run the SysML v2 tutorial Definitions and Attributes (Help → Tutorials).

You're done when the status under the editor reports no problems and the Browser shows Radiator under Vehicles with coolantCapacity and mode.

Check yourself

  1. In part def Battery :> Component { attribute redefines mass = 45 [kg]; }, what do :> and redefines each do?
  2. Why is Component declared abstract part def?
  3. Why does attribute redefines power = 60 [kg]; give an error?
  4. What is the difference between doc /* … */ and a // line?
Show the answers
  1. In part def Battery :> Component { attribute redefines mass = 45 [kg]; }, what do :> and redefines each do?

    :> makes Battery a specialization of Component, so it inherits mass, partNumber and power. redefines replaces the inherited mass in Battery with its own feature, here bound to 45 kg.

  2. Why is Component declared abstract part def?

    Nothing is a component as such, only kinds of components. An abstract definition collects what every component shares, and only its specializations, such as Battery or Engine, describe real parts.

  3. Why does attribute redefines power = 60 [kg]; give an error?

    power is typed PowerValue, and kilograms are a unit of mass. The checker evaluates units, so it underlines the value until the unit is a power unit such as [W].

  4. What is the difference between doc /* … */ and a // line?

    A doc comment is documentation that belongs to the element and is part of the model. A // note stays in the text only and is not part of the model.

Read more

Transcript

Show the transcript (narration and what is on screen)

Introduction

Welcome to SysML v2 Fundamentals. This track teaches the SysML v2 textual notation and views in Holarch, one task per chapter, on the starter projects of Holarch's SysML v2 tutorials, so you can follow along step by step.

In this chapter you write definitions and attributes: an enumeration, a value type, an abstract component and the components that specialize it, with values in units.

Start the tutorial

In Manage Projects, open Project Files and choose Start a Tutorial. Under the tutorials for SysML v2 projects, click Start on Definitions and Attributes. Holarch creates a small Hybrid Car project and opens the step panel, which checks each step as you go.

On screen: Project Files ▾ → Start a Tutorial… → SysML v2: Definitions and Attributes → Start; the step panel opens.

Enumerations and value types

Open Model, then Editor. The package Vehicles holds one part definition, Car, with two attributes. Every declaration is a keyword and a name, then a body in braces, or a semicolon when there is no body.

On screen: Model → Editor: Vehicles; outline part def Car.

An enumeration is a value type with a fixed set of values. Above the car, write the drive mode: economy, normal or sport.

On screen: Caret after the imports; type enum def DriveMode.

Next, a value type of your own. Tire pressure specializes Scalar Value from the standard library. The short symbol after the name means specializes.

On screen: Below DriveMode; type attribute def TirePressure :> ScalarValue;

Specialization and units

Now an abstract component. There is no component as such, only kinds of components, and every one has a mass, a part number and a power. The doc comment is part of the model. Two slashes start a note that stays in the text only.

On screen: Below TirePressure; type abstract part def Component.

The battery is a component, so it has a mass, a part number and a power of its own. Write it with a mistake on purpose: a power in kilograms.

On screen: Below Component; type part def Battery :> Component with power = 60 [kg].

The checker underlines the value, and the status under the editor counts the error. Point at the underline to read the message.

On screen: Problems count; the information card on 60 [kg].

Change kilograms to watts, and the error clears. Redefines gives each inherited attribute the battery's own value, with its unit in square brackets.

On screen: kg → W; No problems, Applied.

Completion and the Standard Library

Completion knows the model and the library. Inside the battery, type attribute capacity, a colon, and the start of Energy Value. Press Enter to take it from the list, and end the line with a semicolon.

On screen: Inside Battery: attribute capacity : Ener → completion → Enter → ;

Point at Energy Value. The card shows that it comes from the I S Q package of the standard library.

On screen: The information card on EnergyValue.

The Standard Library page lists every package and definition of that library. Open Settings, then Standard Library, and search for Energy Value.

On screen: Settings → Standard Library; Find EnergyValue.

Insert

Back in the Editor, Insert writes a construct for you. Place the cursor below the battery, open Insert, and choose Part Definition. Type Engine, and press Tab to move into its body.

On screen: Model → Editor; caret below Battery; Insert ▾ (open on camera) → Part Definition; Engine; Tab.

The engine is a component too. Give it its mass and a number of cylinders, and make it specialize Component.

On screen: Body: mass 110 kg, cylinders : Integer; then :> Component after the name.

Usages and rename

Now use the definitions. Inside the car, add a drive mode, a battery and an engine. Each usage is typed by a definition after the colon, the drive mode by the enumeration you wrote first.

On screen: In Car after curbMass: attribute mode : DriveMode; part battery : Battery; part engine : Engine;

To rename a name everywhere it is used, place the cursor on cylinders and press F2. Enter cylinder count and confirm. Every reference to it changes, in one undo step.

On screen: Caret in cylinders; F2; New name cylinderCount; OK.

Every step is ticked off. Click Mark as Done to finish the tutorial.

On screen: Step panel → Mark as Done.

Recap

Let's recap. You started a SysML v2 tutorial, wrote an enumeration and a value type, an abstract component with specializations and values in units, let the checker find a wrong unit, and used completion, the Standard Library, Insert and rename.

Next, ports and interfaces connect these components.