名称: sysml-modeling 描述: 用于系统工程和复杂系统设计的系统建模语言(SysML) 允许工具: 读取, 全局搜索, 查找, 写入, 编辑
SysML建模技能
何时使用此技能
使用此技能当:
- SysML建模任务 - 处理用于系统工程和复杂系统设计的系统建模语言(sysml)
- 规划或设计 - 需要关于SysML建模方法的指导
- 最佳实践 - 想要遵循已建立的模式和标准
概述
用于基于模型的系统工程(MBSE)和复杂系统设计的系统建模语言(SysML)。
强制性:文档优先方法
在创建SysML模型之前:
- 调用
docs-management技能 用于系统工程模式 - 通过MCP服务器验证SysML 2.0语法
- 基于OMG SysML规范提供所有指导
SysML vs UML
| 方面 | UML | SysML |
|---|---|---|
| 焦点 | 软件系统 | 所有类型的系统 |
| 需求 | 不包括 | 一等图表 |
| 结构 | 类, 组件 | 块, 部件 |
| 参数 | 不包括 | 约束块 |
| 分配 | 不包括 | 分配关系 |
| 领域 | 软件工程 | 系统工程 |
SysML图表类型
行为图表
| 图表 | 目的 | 来自UML |
|---|---|---|
| 活动图 | 动作和数据的流 | 扩展 |
| 序列图 | 对象随时间的交互 | 相同 |
| 状态机图 | 生命周期行为 | 相同 |
| 用例图 | 系统-参与者交互 | 相同 |
结构图表
| 图表 | 目的 | SysML特定 |
|---|---|---|
| 块定义图(BDD) | 系统结构层次 | 是 |
| 内部块图(IBD) | 内部组件连接 | 是 |
| 包图 | 模型组织 | 扩展 |
需求图表
| 图表 | 目的 | SysML特定 |
|---|---|---|
| 需求图 | 需求和关系 | 是 |
| 参数图 | 约束方程 | 是 |
需求图
PlantUML语法
@startuml
skinparam rectangle {
BackgroundColor<<requirement>> LightBlue
BackgroundColor<<testCase>> LightGreen
}
rectangle "<<requirement>>
REQ-001: 系统性能" as REQ001 {
id = "REQ-001"
text = "系统应处理1000个请求/秒"
risk = "高"
verifyMethod = "测试"
}
rectangle "<<requirement>>
REQ-002: 响应时间" as REQ002 {
id = "REQ-002"
text = "系统应在100毫秒内响应(p95)"
risk = "中"
verifyMethod = "测试"
}
rectangle "<<requirement>>
REQ-003: 可用性" as REQ003 {
id = "REQ-003"
text = "系统应达到99.9%的运行时间"
risk = "高"
verifyMethod = "分析"
}
rectangle "<<testCase>>
TC-001: 负载测试" as TC001 {
id = "TC-001"
verifies = "REQ-001, REQ-002"
}
REQ001 <-- REQ002 : <<deriveReqt>>
REQ001 <-- REQ003 : <<deriveReqt>>
REQ002 <.. TC001 : <<verify>>
REQ001 <.. TC001 : <<verify>>
@enduml
需求关系
<<deriveReqt>> 派生需求(从父需求)
<<refine>> 元素细化需求
<<satisfy>> 设计元素满足需求
<<verify>> 测试用例验证需求
<<trace>> 一般可追溯性
<<copy>> 需求复制(重用)
<<containment>> 嵌套需求
块定义图(BDD)
PlantUML语法
@startuml
skinparam class {
BackgroundColor<<block>> LightYellow
BackgroundColor<<valueType>> LightGreen
}
class "<<block>>
车辆系统" as Vehicle {
values
--
+ maxSpeed: Speed
+ weight: Mass
+ range: Distance
operations
--
+ start()
+ stop()
+ accelerate(targetSpeed: Speed)
}
class "<<block>>
动力总成子系统" as Powertrain {
values
--
+ power: Power
+ efficiency: Real
parts
--
+ engine: Engine[1]
+ transmission: Transmission[1]
}
class "<<block>>
引擎" as Engine {
values
--
+ displacement: Volume
+ cylinders: Integer
+ fuelType: FuelType
operations
--
+ ignite()
+ shutoff()
}
class "<<block>>
变速箱" as Transmission {
values
--
+ gearRatios: Real[6]
+ currentGear: Integer
operations
--
+ shiftUp()
+ shiftDown()
}
class "<<block>>
底盘子系统" as Chassis {
parts
--
+ wheels: Wheel[4]
+ suspension: Suspension[4]
+ brakes: BrakeSystem[1]
}
class "<<valueType>>
速度" as Speed {
unit = km/h
}
class "<<valueType>>
质量" as Mass {
unit = kg
}
class "<<enumeration>>
燃料类型" as FuelType {
Gasoline
Diesel
Electric
Hybrid
}
Vehicle *-- Powertrain : <<block>>
Vehicle *-- Chassis : <<block>>
Powertrain *-- Engine
Powertrain *-- Transmission
Engine --> FuelType
@enduml
块刻板印象
<<block>> 系统元素(硬件、软件、人)
<<constraintBlock>> 参数约束
<<valueType>> 带有单位的类型
<<flowPort>> 物质/能量/数据的流
<<proxy>> 外部元素的代理
<<full>> 完全内部访问
内部块图(IBD)
PlantUML语法
@startuml
skinparam component {
BackgroundColor<<part>> LightYellow
}
package "车辆系统 [IBD]" {
component "powertrain : 动力总成子系统" as powertrain <<part>> {
portin "fuelIn" as p_fuel
portout "torqueOut" as p_torque
portout "heatOut" as p_heat
}
component "chassis : 底盘子系统" as chassis <<part>> {
portin "torqueIn" as c_torque
portout "motionOut" as c_motion
}
component "cooling : 冷却子系统" as cooling <<part>> {
portin "heatIn" as cool_heat
portout "coolantOut" as cool_out
}
component "fuelSystem : 燃料子系统" as fuel <<part>> {
portout "fuelOut" as f_out
}
' 连接(项目流)
f_out --> p_fuel : <<itemFlow>>
fuel: 燃料
p_torque --> c_torque : <<itemFlow>>
torque: 扭矩
p_heat --> cool_heat : <<itemFlow>>
heat: 热能
}
@enduml
参数图
约束块
@startuml
skinparam class {
BackgroundColor<<constraintBlock>> LightCoral
}
class "<<constraintBlock>>
牛顿第二定律" as Newton {
constraints
--
{ F = m * a }
parameters
--
F: 力
m: 质量
a: 加速度
}
class "<<constraintBlock>>
动能" as KE {
constraints
--
{ E = 0.5 * m * v^2 }
parameters
--
E: 能量
m: 质量
v: 速度
}
class "<<constraintBlock>>
范围方程" as Range {
constraints
--
{ R = (fuelCapacity * efficiency) / consumption }
parameters
--
R: 距离
fuelCapacity: 体积
efficiency: 实数
consumption: 每距离体积
}
@enduml
参数使用
@startuml
package "车辆性能 [参数]" {
object "newton : 牛顿第二定律" as n {
F = thrustForce
m = vehicleMass
a = acceleration
}
object "energy : 动能" as e {
E = kineticEnergy
m = vehicleMass
v = velocity
}
object "vehicle : 车辆" as v {
mass = 1500 kg
thrust = 5000 N
}
n::m --> v::mass
n::F --> v::thrust
e::m --> v::mass
}
@enduml
活动图(增强)
SysML扩展
@startuml
title 车辆启动序列 [活动图]
start
:接收启动命令;
note right: <<objectFlow>>
StartRequest
fork
:验证钥匙扣;
fork again
:检查安全互锁;
end fork
if (有效?) then (是)
:电源开启ECU;
fork
:初始化引擎;
:<<allocate>>
引擎ECU;
fork again
:初始化变速箱;
:<<allocate>>
变速箱ECU;
fork again
:初始化仪表板;
:<<allocate>>
车身控制模块;
end fork
:启动引擎;
:<<objectFlow>>
EngineStatus = 运行中;
:报告就绪;
else (否)
:报告错误;
:<<objectFlow>>
ErrorCode;
endif
stop
@enduml
对象流和控制流
控制流: 动作序列(实线箭头)
对象流: 数据/材料流(虚线箭头带 <<objectFlow>>)
速率: 流速率规范 { rate = 100/sec }
概率: 分支概率 { probability = 0.8 }
流式传输: 连续流 { streaming }
分配
分配关系
@startuml
skinparam rectangle {
BackgroundColor<<requirement>> LightBlue
BackgroundColor<<block>> LightYellow
BackgroundColor<<activity>> LightGreen
}
rectangle "<<requirement>>
REQ-001: 处理订单" as R1
rectangle "<<activity>>
ProcessOrder" as A1
rectangle "<<block>>
订单处理器" as B1
R1 <.. A1 : <<satisfy>>
A1 <.. B1 : <<allocate>>
note bottom of B1
功能 ProcessOrder
被分配到块
订单处理器
end note
@enduml
分配矩阵
| 功能/行为 | 分配到(块) |
|-------------------|----------------------|
| ProcessOrder | 订单处理器 |
| ValidatePayment | 支付网关 |
| ShipOrder | 履行系统 |
| NotifyCustomer | 通知服务 |
C# 模型表示
// SysML 块作为 C# 类
public abstract class Block
{
public string Name { get; init; }
public IReadOnlyDictionary<string, object> Values { get; init; }
public IReadOnlyList<Block> Parts { get; init; }
public IReadOnlyList<Port> Ports { get; init; }
}
public sealed class VehicleSystem : Block
{
// 值属性
public Speed MaxSpeed { get; init; }
public Mass Weight { get; init; }
public Distance Range { get; init; }
// 部件
public PowertrainSubsystem Powertrain { get; init; }
public ChassisSubsystem Chassis { get; init; }
public CoolingSubsystem Cooling { get; init; }
// 操作
public void Start() { /* ... */ }
public void Stop() { /* ... */ }
public void Accelerate(Speed targetSpeed) { /* ... */ }
}
// 值类型带单位
public readonly record struct Speed(double Value, SpeedUnit Unit = SpeedUnit.KmPerHour)
{
public static Speed FromKmPerHour(double value) => new(value, SpeedUnit.KmPerHour);
public static Speed FromMilesPerHour(double value) =>
new(value * 1.60934, SpeedUnit.KmPerHour);
}
public readonly record struct Mass(double Value, MassUnit Unit = MassUnit.Kilogram);
public readonly record struct Distance(double Value, DistanceUnit Unit = DistanceUnit.Kilometer);
// 约束块
public sealed class NewtonSecondLaw : IConstraint
{
public Force CalculateForce(Mass mass, Acceleration acceleration)
=> new(mass.Value * acceleration.Value);
public Acceleration CalculateAcceleration(Force force, Mass mass)
=> new(force.Value / mass.Value);
}
// 需求
public sealed record Requirement(
string Id,
string Text,
RiskLevel Risk,
VerificationMethod VerifyMethod,
IReadOnlyList<string> DerivedFrom,
IReadOnlyList<string> SatisfiedBy,
IReadOnlyList<string> VerifiedBy);
public enum RiskLevel { Low, Medium, High }
public enum VerificationMethod { Analysis, Inspection, Demonstration, Test }
MBSE 工作流程
创建SysML模型时:
- 定义需求:在需求图中捕获利益相关者需求
- 模型结构:创建BDD进行系统分解
- 定义接口:使用IBD进行部件连接和流
- 指定行为:活动图、序列图和状态图
- 添加约束:参数图用于物理/数学
- 分配功能:将行为映射到结构元素
- 追溯和验证:通过验证链接需求
最佳实践
模型组织
模型
├── 1_需求/
│ ├── 利益相关者需求.req
│ ├── 系统需求.req
│ └── 派生需求.req
├── 2_结构/
│ ├── 系统上下文.bdd
│ ├── 系统架构.bdd
│ └── 子系统/
│ ├── 动力总成结构.bdd
│ └── 动力总成内部.ibd
├── 3_行为/
│ ├── 用例.uc
│ ├── 系统序列.seq
│ └── 状态机/
│ └── 车辆状态.stm
├── 4_参数/
│ └── 性能约束.par
└── 5_分配/
└── 功能分配.alloc
命名约定
| 元素 | 约定 | 示例 |
|---|---|---|
| 块 | PascalCase 名词 | VehicleSystem |
| 部件 | camelCase 名词 | powertrain |
| 端口 | camelCase + In/Out | fuelIn, torqueOut |
| 需求 | REQ-### | REQ-001 |
| 约束 | PascalCase 方程 | NewtonSecondLaw |
参考文献
详细指南:
最后更新: 2025-12-26