课程章节
培训 · 课程 9. SysML v2 基础 · 第 9.7 章,共 8 章
9.7 约束和计算 4:26
编写约束和计算,检查轿车带单位的数值,并标记未定数值。
演示 Holarch 2.22。
您将学到
- 编写带参数的约束定义和计算定义
- 将约束用法的参数绑定到模型中的数值
- 在参数视图中查看约束通过和失败,并使用“全部求解”检查所有约束
- 使用 TBD 和 TBR 元数据标记未定数值,并在 TBD/TBR 登记册中找到它们
- 在预算和 TPM 中汇总部件的质量
在 Holarch 中编写 SysML v2 约束和计算,基于一个小型 Hybrid Car 项目,依照 SysML v2 教程“约束和计算”:一个约束定义和一个计算、绑定到轿车数值的约束用法、检查失败和通过的参数视图、全部求解、一个分析用例、带登记册的 TBD 和 TBR 数值,以及预算中的质量汇总。SysML 是 Object Management Group, Inc. 的注册商标。
练习
在 Holarch 中基于 Hybrid Car 演示项目 (SysML v2) 亲自完成此操作。
- 打开您的 Hybrid Car 演示项目(如有需要,请创建:管理项目 → 项目文件 ▾ → 新建演示项目 → Hybrid Car (SysML v2)),打开 模型 → 编辑器 和包
VehicleRequirements。 - 在
constraint def SpeedLimit之后添加constraint sedanBatteryCheck : MassLimit { in mass = fleet.sedan.powertrain.battery.mass; in limit = 50 [kg]; }。 - 在 图 页面上单击 + 新建图,选择 参数视图,并在 显示 下选择
VehicleRequirements,然后单击 创建。新的检查通过:48 kg 在 50 kg 以内。 - 在包
Vehicles中将轿车电池的质量改为52 [kg];视图显示检查失败。按 ⌘Z / Ctrl+Z,然后单击 全部求解 再次检查所有约束。 - 在
requirement def <'VR-2'> Acceleration中,将attribute zeroToHundred : TimeValue;替换为attribute zeroToHundred : TimeValue { @TBD { owner = "Test lead"; rationale = "The test track is not booked yet."; } }。打开 需要与需求 → TBD/TBR,找到该需求及其负责人。 - 打开 架构 → 预算和 TPM,单击 选择根部件… 并选择
sedan。在 量 下选择 Mass,找到电池的 48 kg。
当 sedanBatteryCheck 在参数视图中显示“通过”,且 TBD/TBR 登记册列出负责人为 Test lead 的 Acceleration 需求时,即完成练习。
自测
constraint def与calc def有什么区别?- 参数视图中的某个约束显示“需要输入”。缺少什么?
- 为什么要用
#TBD或@TBD { … }标记未定数值,而不是将 TBD 写成数值? - 分析用例为计算增加了什么?
显示答案
constraint def与calc def有什么区别?约束定义陈述一个关于其参数、成立或不成立的条件,例如
mass <= limit。计算定义计算并返回一个值,例如return ratio = power / mass;。参数视图中的某个约束显示“需要输入”。缺少什么?
某个参数尚无值。将每个参数绑定到一个值,例如
in mass = fleet.sedan.curbMass;。为什么要用
#TBD或@TBD { … }标记未定数值,而不是将 TBD 写成数值?在数值位置写
TBD不是有效的 SysML。Holarch 的HolarchMetadata包中的元数据可保持文本有效;TBD 和 TBR 特化了标准的StatusInfo元数据,因此其他 SysML v2 工具会将它们读取为状态注解。分析用例为计算增加了什么?
它将计算应用于一个主题(例如轿车),返回结果,并带有一个目标,Holarch 会像评估其他约束一样评估其中的 require 约束。
延伸阅读
文字稿
显示文字稿 (旁白和屏幕内容)
Introduction
Chapter seven: constraints and calculations. They turn the model's values into checks and results that Holarch evaluates with units.
In this chapter you write a constraint and a calculation, bind a check to the sedan's values, see it fail and pass in a Parametric View, run an analysis case, and mark open values.
Start the tutorial
Start the tutorial Constraints and Calculations from Project Files, Start a Tutorial. Its starter project holds the sedan with its engine and battery values, and two targets: the maximum curb mass and the minimum power to weight.
On screen: Project Files ▾ → Start a Tutorial… → SysML v2: Constraints and Calculations → Start; Model → Editor.
Constraints and calculations
A constraint definition states a condition over its parameters. After the constraints comment, write the mass limit: the mass is at most the limit.
On screen: After // ---- Constraints and calculations ----: constraint def MassLimit.
Below it, a calculation: power to weight divides the power by the mass, and returns the ratio.
On screen: Below it: calc def PowerToWeight.
A constraint usage binds each parameter to a value: here, the sedan's curb mass and the maximum curb mass.
On screen: Below it: constraint sedanMassCheck : MassLimit with bound inputs.
The Parametric View
Open the Diagrams page, click New Diagram, and choose Parametric View. Choose the vehicle analysis package under Shows, and click Create.
On screen: Diagrams → + New Diagram → Parametric View; Shows: VehicleAnalysis; Create.
The check shows its expression, with its parameters bound to the values. Fifteen hundred eighty kilograms is within sixteen hundred fifty, so it passes.
On screen: The mass check: pass.
In the Editor, change the sedan's curb mass to seventeen hundred kilograms. Back in the Parametric View, the mass check now fails.
On screen: Model → Editor: curbMass 1580 → 1700; Diagrams → the Parametric View: fail.
Change it back to fifteen hundred eighty in the Editor. In the view, Solve All checks every constraint again, with units.
On screen: Model → Editor: 1700 → 1580; the view → Solve All → Pass; Close.
An analysis case
An analysis case computes a result for a subject. At the end of the package, add the power to weight analysis, and apply it to the sedan. Its objective requires at least the minimum, and the checker evaluates it like any constraint.
On screen: Model → Editor; after sedanMassCheck: analysis def PowerToWeightAnalysis; analysis sedanPowerToWeight.
TBD and TBR
Values that are still open get a mark. First import Holarch's metadata package after the other imports.
On screen: After the imports: private import HolarchMetadata::*;
Then add a charge time requirement. TBR marks the time limit to be reviewed, and TBD marks the charger power to be determined, with an owner, a due date and a rationale. Both come from Holarch's metadata library and specialize the standard status metadata, so other SysML v2 tools see them as status annotations.
On screen: At the end: requirement def <'VR-5'> ChargeTime with #TBR and @TBD.
Open Needs and Requirements, then TBD/TBR. The charge time is listed with the owner and the due date from its metadata. The register only lists them: to change them, edit the metadata in the Editor.
On screen: Needs & Requirements → TBD/TBR; the ChargeTime row with owner and due date.
Budgets
Last, open Architecture, then Budgets, and select the sedan as the root part. The quantity Mass reads each part's mass attribute with its unit: the battery shows the sedan's own forty eight kilograms.
On screen: Architecture → Budgets & TPMs → Select Root Part… → sedan; the battery 48 kg.
Recap
Every step is ticked off. Click Mark as Done.
On screen: Step panel → Mark as Done.
Let's recap. You wrote a constraint and a calculation, bound a check to the sedan's values, saw it fail and pass in a Parametric View, ran an analysis case, marked open values for the register, and rolled up the mass.
Next, variants and configurations describe a product line.