MSL4.x中自定义修改DynamicPipe模型的编译错误求解
解决MSL4.x自定义DynamicPipe副本的编译错误
问题背景
因特定需求需修改Modelica.Fluid.DynamicPipe模型(无法用FlowModel替代),MSL3.x可直接修改本地库副本,但MSL4.x无法修改官方库,只能自建模型副本。当前自定义模型代码如下:
model w2DynamicPipe1 "Dynamic pipe model with storage of mass and energy" import Modelica.Fluid.Types.ModelStructure; // extending PartialStraightPipe extends Modelica.Fluid.Pipes.BaseClasses.PartialStraightPipe(final port_a_exposesState = modelStructure == ModelStructure.av_b or modelStructure == ModelStructure.av_vb, final port_b_exposesState = modelStructure == ModelStructure.a_vb or modelStructure == ModelStructure.av_vb); // extending PartialTwoPortFlow extends Modelica.Fluid.Pipes.BaseClasses.PartialTwoPortFlow (final lengths = fill(length / n, n), final crossAreas = fill(crossArea, n), final dimensions = fill(4 * crossArea / perimeter, n), final roughnesses = fill(roughness, n), final dheights = height_ab * dxs); // Wall heat transfer end w2DynamicPipe1;
编译验证返回错误信息:
[86] 12:23 Validation of w2DynamicPipe1 finished Notification: Modelica.Fluid.Interfaces.PartialTwoPort [3:5-3:5] Missing inner. Outer declaration system is missing a corresponding inner declaration. An inner declaration will be added using the outer declaration. Error: Modelica.Fluid.Interfaces.PartialDistributedVolume [34:5-34:5] Invalid instantiation. Modelica.Media.Interfaces.PartialMedium.BaseProperties is partial. Validation of model w2_Models.w2pipes.w2DynamicPipe1 completed with 1 error.
解决方案
1. 修复PartialMedium.BaseProperties is partial错误
这个错误源于底层Partial类依赖具体介质模型,而非抽象的PartialMedium。有两种解决方式:
方式1:显式声明介质并传递给继承类
在自定义模型中添加介质参数,并确保继承的Partial类使用该介质:model w2DynamicPipe1 "Dynamic pipe model with storage of mass and energy" import Modelica.Fluid.Types.ModelStructure; // 声明具体介质(可替换为你需要的介质) replaceable package Medium = Modelica.Media.Water.StandardWater "Medium model" annotation( choicesAllMatching = true); // 传递介质给PartialStraightPipe extends Modelica.Fluid.Pipes.BaseClasses.PartialStraightPipe( final port_a_exposesState = modelStructure == ModelStructure.av_b or modelStructure == ModelStructure.av_vb, final port_b_exposesState = modelStructure == ModelStructure.a_vb or modelStructure == ModelStructure.av_vb, redeclare package Medium = Medium); // 传递介质给PartialTwoPortFlow extends Modelica.Fluid.Pipes.BaseClasses.PartialTwoPortFlow ( final lengths = fill(length / n, n), final crossAreas = fill(crossArea, n), final dimensions = fill(4 * crossArea / perimeter, n), final roughnesses = fill(roughness, n), final dheights = height_ab * dxs, redeclare package Medium = Medium); // Wall heat transfer end w2DynamicPipe1;方式2:直接继承原DynamicPipe再修改
复用原模型的介质传递逻辑,避免手动处理底层依赖:model w2DynamicPipe1 "Dynamic pipe model with storage of mass and energy" import Modelica.Fluid.Types.ModelStructure; // 继承原DynamicPipe并覆盖需要修改的参数 extends Modelica.Fluid.DynamicPipe( final port_a_exposesState = modelStructure == ModelStructure.av_b or modelStructure == ModelStructure.av_vb, final port_b_exposesState = modelStructure == ModelStructure.a_vb or modelStructure == ModelStructure.av_vb, final lengths = fill(length / n, n), final crossAreas = fill(crossArea, n), final dimensions = fill(4 * crossArea / perimeter, n), final roughnesses = fill(roughness, n), final dheights = height_ab * dxs); // 在这里添加自定义修改(比如替换FlowModels/HeatTransfer) end w2DynamicPipe1;
2. 处理Missing inner/outer通知
这个通知是因为Fluid模型需要顶层的inner System声明:
- 在使用w2DynamicPipe1的顶层模型中添加:
inner Modelica.Fluid.System system; - 或者在
w2DynamicPipe1中显式声明:
推荐前者,确保所有子模型共享同一个System实例。outer Modelica.Fluid.System system;
后续替换自定义FlowModels/HeatTransfer指导
- 替换FlowModels:找到
PartialTwoPortFlow中定义的replaceable model FlowModel参数,在w2DynamicPipe1中用redeclare替换为自定义模型,确保自定义模型与原FlowModel的接口一致(输入输出变量、参数匹配)。 - 替换HeatTransfer:同理,找到
PartialStraightPipe或相关类中的HeatTransfer模型,用redeclare替换,保证热传递逻辑的接口兼容(比如温度、热流量的传递方式)。
内容的提问来源于stack exchange,提问作者Chris B
相关产品推荐
相关产品推荐

