Holarch
Розділи курсів

Навчання · Курс 9. Основи SysML v2 · Розділ 9.1 з 8

9.1 Визначення та атрибути 4:33

Пишіть типи значень і компоненти в тексті SysML v2 зі значеннями в одиницях.

Показано Holarch 2.22.

Усі розділи · 9.2 Порти та інтерфейси →

Що ви дізнаєтеся

  • Написати в Редакторі перелічення, тип значення й абстрактне визначення частини
  • Спеціалізувати визначення через `:>` і задати успадкованим атрибутам значення з одиницями через `redefines`
  • Знайти й виправити помилку одиниць, яку підкреслює засіб перевірки
  • Написати визначення через «Вставити ▾» і доповнення та знайти тип у Стандартній бібліотеці
  • Перейменувати елемент усюди через F2 за один крок відмінення

Пишіть визначення й атрибути SysML v2 у Редакторі Holarch за навчальним посібником SysML v2 Definitions and Attributes на невеликому проєкті Hybrid Car: перелічення, тип значення, що спеціалізує ScalarValue, абстрактний компонент і його спеціалізації зі значеннями в одиницях, помилка одиниць, знайдена засобом перевірки, доповнення й Стандартна бібліотека, «Вставити» і перейменування через F2. SysML є зареєстрованою торговельною маркою Object Management Group, Inc.

Файли проєкту

  • Готовий проєкт (.holarch.json; Керування проєктами → Файли проєкту ▾ → Імпортувати проєкт (.json)…)

Відео відтворюється з holarch.app; див. Політику конфіденційності.

Практика

Виконайте це самі в Holarch на демопроєкті Hybrid Car (SysML v2).

  1. Створіть демо Hybrid Car: Керування проєктами → Файли проєкту ▾ → Новий демопроєкт → Hybrid Car (SysML v2). Відкрийте Модель → Редактор і пакет Vehicles.
  2. Під enum def FuelKind додайте enum def CoolingMode { enum passive; enum active; }.
  3. Під part def Body оберіть Вставити ▾ → Визначення частини і доповніть part def Radiator :> Component рядками attribute redefines mass = 8 [kg];, attribute coolantVolume : VolumeValue; (введіть Volu і прийміть VolumeValue зі списку доповнення клавішею Enter) і attribute mode : CoolingMode;.
  4. Змініть масу на 8 [W], наведіть вказівник на підкреслення, щоб прочитати повідомлення, і поверніть 8 [kg].
  5. У part def Powertrain додайте part radiator : Radiator;. Потім поставте курсор на coolantVolume, натисніть F2 і перейменуйте на coolantCapacity.
  6. Для покрокового проходження з перевіркою запустіть навчальний посібник SysML v2 Definitions and Attributes (Довідка → Посібники).

Завдання виконано, коли рядок стану під редактором не повідомляє про проблеми, а Браузер показує Radiator під Vehicles з coolantCapacity і mode.

Перевірте себе

  1. Що роблять :> і redefines у part def Battery :> Component { attribute redefines mass = 45 [kg]; }?
  2. Чому Component оголошено як abstract part def?
  3. Чому attribute redefines power = 60 [kg]; дає помилку?
  4. Чим відрізняються doc /* … */ і рядок //?
Показати відповіді
  1. Що роблять :> і redefines у part def Battery :> Component { attribute redefines mass = 45 [kg]; }?

    :> робить Battery спеціалізацією Component, тож він успадковує mass, partNumber і power. redefines замінює успадковану mass у Battery власною характеристикою, тут прив’язаною до 45 kg.

  2. Чому Component оголошено як abstract part def?

    Компонента як такого не існує, є лише види компонентів. Абстрактне визначення збирає те, що спільне для всіх компонентів, і лише його спеціалізації, як-от Battery чи Engine, описують реальні частини.

  3. Чому attribute redefines power = 60 [kg]; дає помилку?

    power має тип PowerValue, а кілограми — одиниця маси. Засіб перевірки обчислює одиниці, тому підкреслює значення, доки одиниця не стане одиницею потужності, як-от [W].

  4. Чим відрізняються doc /* … */ і рядок //?

    Коментар doc — це документація, що належить елементу й є частиною моделі. Примітка // лишається лише в тексті й не є частиною моделі.

Докладніше

Стенограма

Показати стенограму (озвучення і те, що на екрані)

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.