课程章节
培训 · 课程 9. SysML v2 基础 · 第 9.8 章,共 8 章
9.8 变体和配置 3:42
编写带变体点和规则的产品线,以及由编辑器检查的配置。
演示 Holarch 2.22。
您将学到
- 编写带变体的变体定义,并将其用作产品线的变体点
- 使用 assert constraint 为产品线添加规则
- 创建为每个变体点选择一个变体的配置,并查看其判定结果
- 定义您自己的元数据关键字,并用 `#` 应用它
- 以某一个配置显示模型
在 Holarch 中编写 SysML v2 产品线,基于一个小型 Hybrid Car 项目,依照 SysML v2 教程“变体和配置”:Holarch 的可变性包、带变体的变体定义、带变体点和断言的产品线、由编辑器检查的配置、通过元数据定义的自有关键字,以及产品线的 General View。SysML 是 Object Management Group, Inc. 的注册商标。
练习
在 Holarch 中基于 Hybrid Car 演示项目 (SysML v2) 亲自完成此操作。
- 打开您的 Hybrid Car 演示项目(如有需要,请创建:管理项目 → 项目文件 ▾ → 新建演示项目 → Hybrid Car (SysML v2)),打开 模型 → 编辑器 和包
Vehicles。它已经导入了HolarchVariability。 - 在
part def CarLine中,在charger变体点之后添加variation part rims : Wheel { variant part steelRims : Wheel; variant part alloyRims : Wheel { attribute :>> mass = 18 [kg]; } }。编辑器会提示三个配置尚未选择rims。 - 在
wallboxNeedsLargePack之后添加规则assert constraint alloyNeedsLargePack { rims == rims::alloyRims implies pack == BatteryPack::largePack }。 - 打开 模型 → 浏览器 并选择
selfChargingHybrid。在属性面板的 配置 部分,为 rims 选择 steelRims;为plugInHybrid和longRangeHybrid选择 alloyRims。然后在selfChargingHybrid上尝试 alloyRims,阅读判定结果,再按 ⌘Z / Ctrl+Z。 - 打开
CarLine的行菜单(⋯),选择 新建配置…。将其命名为cityHybrid,选择 standardPack、noCharger 和 steelRims,确认判定结果为“有效”,然后单击 创建。 - 单击顶栏中的 查看方式 ▾ 并选择
cityHybrid,然后从 图 列表中打开视图carLineVariants:未被选择的变体会被隐藏。
当属性面板中 CarLine 的“产品线”部分列出四个均为“有效”的配置以及规则 alloyNeedsLargePack 时,即完成练习。
自测
variation part def BatteryPack { … }与variation part charger : Component { … }有什么区别?plugInHybrid选择了BatteryPack::standardPack和charger::wallbox。会发生什么?为什么?- 某个配置尚未为每个变体点都选择变体。它的判定结果是什么?
metadata def <safetyCritical> SafetyCritical让您能够写什么?其他 SysML v2 工具如何看待它?
显示答案
variation part def BatteryPack { … }与variation part charger : Component { … }有什么区别?前者是变体定义,即一组可重用的选择:以它为类型的用法(例如
part pack : BatteryPack;)就是一个变体点。后者是变体用法,即在某一个设计内部声明的变体点。plugInHybrid选择了BatteryPack::standardPack和charger::wallbox。会发生什么?为什么?违反了规则
wallboxNeedsLargePack:它规定 wallbox 意味着大电池组。判定结果会指出该规则,编辑器会报告断言失败。某个配置尚未为每个变体点都选择变体。它的判定结果是什么?
不完整,并指出未选择的变体点。当某个变体点没有选择时,涉及它的规则既不算满足也不算违反。
metadata def <safetyCritical> SafetyCritical让您能够写什么?其他 SysML v2 工具如何看待它?短名称会成为一个关键字,例如
#safetyCritical part controller : Controller;。它是一个普通的元数据用法,因此其他 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.