Holarch
課程章節

培訓 · 第 9 單元:SysML v2 基礎 · 第 9.8 章,共 8 章

9.8 變體與組態 3:42

撰寫具有變化點與規則的產品線,以及由編輯器檢查的組態。

展示 Holarch 2.22。

← 9.7 約束與計算 · 所有章節

您將學到

  • 撰寫含有變體的 variation,並將它用作產品線的變化點
  • 以 assert constraint 為產品線新增規則
  • 建立為每個變化點選擇一個變體的組態,並閱讀其判定結果
  • 定義您自己的中繼資料關鍵字,並以 `#` 套用
  • 以單一組態顯示模型

在 Holarch 中撰寫 SysML v2 產品線,依循 SysML v2 教學課程 Variants and Configurations,以一個小型 Hybrid Car 專案進行:Holarch 的變異性套件、含有變體的 variation、具有變化點與斷言的產品線、由編輯器檢查的組態、以中繼資料定義的自訂關鍵字,以及產品線的 General View。SysML 是 Object Management Group, Inc. 的註冊商標。

專案檔案

  • 完成的專案 (.holarch.json;管理專案 → 專案檔案 ▾ → 匯入專案 (.json)…)

影片從 holarch.app 播放;請參閱隱私權政策。

練習

在 Holarch 中於 Hybrid Car 示範專案(SysML v2)上親自操作。

  1. 開啟您的 Hybrid Car 示範專案(如有需要請建立:管理專案 → 專案檔案 ▾ → 新增示範專案 → Hybrid Car (SysML v2)),開啟模型 → 編輯器以及套件 Vehicles。它已經匯入 HolarchVariability。
  2. 在 part def CarLine 中,於 charger variation 之後新增 variation part rims : Wheel { variant part steelRims : Wheel; variant part alloyRims : Wheel { attribute :>> mass = 18 [kg]; } }。編輯器會註明三個組態尚未選擇 rims。
  3. 在 wallboxNeedsLargePack 之後新增規則 assert constraint alloyNeedsLargePack { rims == rims::alloyRims implies pack == BatteryPack::largePack }。
  4. 開啟模型 → 瀏覽器並選取 selfChargingHybrid。在屬性面板的組態區段中,為 rims 選擇 steelRims;為 plugInHybrid 與 longRangeHybrid 選擇 alloyRims。然後在 selfChargingHybrid 上試試 alloyRims,閱讀判定結果,再按 ⌘Z / Ctrl+Z。
  5. 開啟 CarLine 的列選單(⋯),選擇新增組態…。將它命名為 cityHybrid,選擇 standardPack、noCharger 與 steelRims,確認判定結果為「有效」,然後按一下建立。
  6. 按一下頂端列中的檢視方式 ▾並選擇 cityHybrid,然後從圖清單中開啟檢視 carLineVariants:它未選擇的變體會被隱藏。

當屬性面板中 CarLine 的「產品線」區段列出四個組態(全部為「有效」)以及規則 alloyNeedsLargePack 時,即完成。

自我檢查

  1. variation part def BatteryPack { … } 與 variation part charger : Component { … } 有什麼不同?
  2. plugInHybrid 選擇了 BatteryPack::standardPack 與 charger::wallbox。會發生什麼事?為什麼?
  3. 某個組態尚未為每個變化點選擇變體。它的判定結果是什麼?
  4. metadata def <safetyCritical> SafetyCritical 讓您能寫出什麼?其他 SysML v2 工具如何看待它?
顯示答案
  1. variation part def BatteryPack { … } 與 variation part charger : Component { … } 有什麼不同?

    前者是 variation 定義,一組可重複使用的選擇:以它為類型的用法(例如 part pack : BatteryPack;)就是變化點。後者是 variation 用法,是在單一設計內宣告的變化點。

  2. plugInHybrid 選擇了 BatteryPack::standardPack 與 charger::wallbox。會發生什麼事?為什麼?

    規則 wallboxNeedsLargePack 被違反:它規定 wallbox 意味著大型電池組。判定結果會指出該規則,編輯器也會回報失敗的斷言。

  3. 某個組態尚未為每個變化點選擇變體。它的判定結果是什麼?

    不完整,並指出未決的變化點。在某個變化點尚未選擇時,針對它的規則既不算滿足,也不算違反。

  4. metadata def <safetyCritical> SafetyCritical 讓您能寫出什麼?其他 SysML v2 工具如何看待它?

    短名稱會成為關鍵字,例如 #safetyCritical part controller : Controller;。它是一般的 metadata 用法,因此其他 SysML v2 工具會將它視為該零件上的中繼資料。

延伸閱讀

文字稿

顯示文字稿 (旁白與畫面內容)

Introduction

Chapter eight: variants and configurations. A product line offers choices, and a configuration picks one variant for each choice.

In this chapter you write a variation with variants, a product line with a rule, configurations the Editor checks, and a keyword of your own.

Start the tutorial

Start the tutorial Variants and Configurations from Project Files, Start a Tutorial. Its starter project holds the components, the car and the powertrain.

On screen: Project Files ▾ → Start a Tutorial… → SysML v2: Variants and Configurations → Start; Model → Editor.

Variations

Holarch's variability package lets the Editor check configurations. Import it after the other imports.

On screen: After the imports: private import HolarchVariability::*;

A variation lists the choices offered. Before the powertrain, write the battery pack variation: a standard pack and a large pack, each with its own capacity, and the large one with its own mass.

On screen: After Car: variation part def BatteryPack with two variants.

The product line

Below it, the car line. Its pack is typed by the variation, its charger is a variation point with two variants, and an assertion rules out the wallbox with the standard pack.

On screen: Below BatteryPack: part def CarLine :> Car with pack, charger and the assertion.

Configurations

A configuration is a part of the car line, marked Holarch Configuration. Until it chooses a variant for each point, the Editor notes the points still open.

On screen: Below CarLine: part plugInHybrid : CarLine { @HolarchConfiguration; }

Inside the plug-in hybrid, choose the standard pack and the wallbox. The assertion fails: the wallbox needs the large pack.

On screen: In plugInHybrid: pack = BatteryPack::standardPack; charger = charger::wallbox; the assertion error.

Choose the large pack instead, and the configuration checks.

On screen: standardPack → largePack; No problems.

Add a second configuration: a self-charging hybrid, with the standard pack and no charger.

On screen: Below plugInHybrid: part selfChargingHybrid : CarLine.

A keyword of your own

You can also define keywords of your own. At the end of the package, add a metadata definition. Its short name, safety critical, becomes a keyword.

On screen: After Powertrain: metadata def <safetyCritical> SafetyCritical.

In the powertrain, put the keyword before the controller, after a number sign. Other SysML v2 tools see it as ordinary metadata.

On screen: In Powertrain: #safetyCritical part controller : Controller;

The General View

Open Architecture, then General Views, and click New Diagram. Keep General View, choose the Vehicles package under Shows, and click Create.

On screen: Architecture → General Views → + New Diagram; Shows: Vehicles; Create.

The battery pack is marked variation in its heading.

On screen: BatteryPack: «variation part def».

Recap

Every step is ticked off. Click Mark as Done.

On screen: Step panel → Mark as Done.

Let's recap. You imported Holarch's variability package, wrote a variation with variants and a product line with a rule, built configurations that the Editor checks, and defined a keyword of your own.

That completes SysML v2 Fundamentals.