コースのチャプター
トレーニング · トラック 9. SysML v2 の基礎 · チャプター 9.1(全 8 チャプター)
9.1 定義と属性 4:33
値型とコンポーネントを、単位付きの値とともに SysML v2 テキストで記述します。
Holarch 2.22 の画面です。
学習内容
- エディターで列挙型、値型、抽象パート定義を記述する
- `:>` で定義を特化し、`redefines` で継承した属性に単位付きの値を与える
- チェッカーが下線を引いた単位の誤りを見つけて修正する
- 挿入 ▾ と補完で定義を記述し、標準ライブラリで型を調べる
- F2 で要素の名前をすべての場所で変更する(元に戻す操作 1 回分)
小さな Hybrid Car プロジェクトで SysML v2 チュートリアル「Definitions and Attributes」に沿って、Holarch のエディターで SysML v2 の定義と属性を記述します。列挙型、ScalarValue を特化した値型、抽象コンポーネントと単位付きの値を持つその特化、チェッカーが見つける単位の誤り、補完と標準ライブラリ、挿入、F2 による名前の変更を扱います。SysML は Object Management Group, Inc. の登録商標です。
プロジェクトファイル
- 完成したプロジェクト (.holarch.json。プロジェクトを管理 → プロジェクトファイル ▾ → プロジェクトをインポート (.json)…)
動画は holarch.app から再生されます。プライバシーポリシーをご覧ください。
演習
Hybrid Car デモプロジェクト(SysML v2)を使って、Holarch で実際に操作します。
- Hybrid Car デモを作成します:プロジェクトを管理 → プロジェクトファイル ▾ → 新しいデモプロジェクト → Hybrid Car (SysML v2)。モデル → エディターとパッケージ
Vehiclesを開きます。 enum def FuelKindの下に、enum def CoolingMode { enum passive; enum active; }を追加します。part def Bodyの下で 挿入 ▾ → パート定義を選び、part def Radiator :> Componentを、attribute redefines mass = 8 [kg];、attribute coolantVolume : VolumeValue;(Voluと入力し、補完リストのVolumeValueを Enter キーで確定)、attribute mode : CoolingMode;で完成させます。- 質量を
8 [W]に変更し、下線にポインターを合わせてメッセージを読んでから、8 [kg]に戻します。 part def Powertrainにpart radiator : Radiator;を追加します。次に、カーソルをcoolantVolumeに置いて F2 を押し、coolantCapacityに名前を変更します。- チェック付きのウォークスルーを行うには、SysML v2 チュートリアル「Definitions and Attributes」を実行します(ヘルプ → チュートリアル)。
エディターの下のステータスに問題が表示されず、ブラウザーの Vehicles の下に coolantCapacity と mode を持つ Radiator が表示されれば完了です。
確認問題
part def Battery :> Component { attribute redefines mass = 45 [kg]; }で、:>とredefinesはそれぞれ何をしますか?- Component が
abstract part defとして宣言されているのはなぜですか? attribute redefines power = 60 [kg];がエラーになるのはなぜですか?doc /* … */と//の行の違いは何ですか?
解答を表示
part def Battery :> Component { attribute redefines mass = 45 [kg]; }で、:>とredefinesはそれぞれ何をしますか?:>は Battery を Component の特化にするため、Battery は mass、partNumber、power を継承します。redefinesは、Battery 内で継承したmassを独自のフィーチャーで置き換え、ここでは 45 kg にバインドします。Component が
abstract part defとして宣言されているのはなぜですか?単なるコンポーネントというものは存在せず、存在するのはコンポーネントの種類だけです。抽象定義はすべてのコンポーネントに共通するものをまとめ、Battery や Engine などの特化だけが実際の部品を表します。
attribute redefines power = 60 [kg];がエラーになるのはなぜですか?powerの型はPowerValueで、キログラムは質量の単位です。チェッカーは単位を評価するため、単位が[W]などの電力の単位になるまで値に下線を引きます。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.