Dymola 没有在 gui 中提供这样的功能。但是通过ModelManagement 库,可以获得此类信息。该库可通过标准 Dymola 许可证获得并预安装。
您可以在下面找到函数 SO.printComponents(),它使用 ModelManagement 库来获取类中符合给定条件的所有组件。
对于您的模型,打印输出为:
Components in Modelica.Fluid.Examples.HeatingSystem using Modelica.Fluid.System as outer:
tank<Modelica.Fluid.Vessels.BaseClasses.PartialLumpedVessel>.heatTransfer<Modelica.Fluid.Interfaces.PartialHeatTransfer>.system
tank<Modelica.Fluid.Interfaces.PartialLumpedVolume>.system
pump<Modelica.Fluid.Machines.BaseClasses.PartialPump>.heatTransfer<Modelica.Fluid.Interfaces.PartialHeatTransfer>.system
...
valve<Modelica.Fluid.Interfaces.PartialTwoPort>.system
...
您会看到 Modelica.Fluid.Examples.HeatingSystem 中的所有组件,其中包含前缀为outer 的Modelica.Fluid.System 实例。
如果组件通过extends 从基类继承系统实例,则基类以<base-class> 形式在尖括号之间给出。
例如,输出中的第一个组件意味着,tank 组件正在扩展 PartialLumpedVessel 类,其中包含一个组件 heatTransfer,它扩展了包含我们正在寻找的系统实例的 PartialHeatTransfer。
请注意,对于多级继承,只给出了最终的基类,而不是它的完整路径。这是例如与阀门相关,它通过PartialValve和PartialTwoPortTransport从PartialTwoPort继承系统实例。
背景资料
ModelManagement 库在包ModelManagement.Structure 中提供了一些有趣的功能,允许获取有关Modelica 类的信息。
功能分为两种不同的类型:
- ModelManagement.Structure.AST:对于这些函数,仅考虑所选类的 Modelica 代码。不考虑继承的所有内容。
- ModelManagement.Structure.Instantiated:此包中的所有函数都在翻译后的模型上运行
乍一看ModelManagement.Structure.Instantiated.UsedModels 似乎是一个很好的起点。但它的文档说:
不包括可选禁用的组件、基类和调用函数。
由于 Fluid 包大量使用继承,如果不考虑继承,我们很容易错过一个组件。
幸运的是,测试库包含一个函数,它返回所有继承的基类Testing.Utilities.Class.getExtendedClasses。此外,ModelManagement.Structure.AST.ComponentsInClassAttributes 允许我们检索给定类的所有组件(但不包括继承的组件)。
通过这两个函数,我们可以构建一个新函数:
- 检索类的所有组件,包括从基类继承的组件
- 检查组件是否符合我们的搜索条件(在您的情况下,它应该是
Modelica.Fluid.System 的外部实例)
- 递归检查所有组件的子组件,因为系统的使用可能发生在层次结构的更下方
这里是代码。此外还包括一个小打印功能,可以将找到的组件很好地打印到终端。
package SO
function getComponentsUsingClass "Get all components in class c1 which use class c2 as local component"
import ModelManagement.Structure.AST;
import Testing.Utilities.Class.getExtendedClasses;
import Testing.Utilities.Vectors.catStrings;
input String c1 "Full path of class of which components are retrieved";
input String c2 "Full path of class which must be used in the components";
input Boolean isOuter=false "Return only components where c2 is used as an outer instance";
output String cmp[:] "All components in c1 using c2";
protected
String sub[:] "Sub-components";
Boolean baseClass "True if current class is a baseClass of c1 (c1 extends it)";
String prefix "Used to give base classe";
algorithm
cmp :=fill("", 0);
// loop over class c1 and all its base classes
for c in cat(1,{c1}, getExtendedClasses(c1)) loop
baseClass :=c <> c1;
prefix :=if baseClass then "<" + c + ">." else ".";
// loop over all components in the current class
for cmpa in AST.ComponentsInClassAttributes(c) loop
if cmpa.fullTypeName==c2 and cmpa.isOuter==isOuter then
cmp :=cat(1, cmp, {prefix+cmpa.name});
end if;
// if the current component is a Modelica class, obtain all sub-components using c2
// (Mon-Modelica classes would e.g. be the attributes min, max, stateSelect etc. of built in classes)
if cmpa.fullTypeName<>"" then
sub := getComponentsUsingClass(cmpa.fullTypeName, c2, isOuter);
sub :=catStrings(fill(prefix+cmpa.name, size(sub, 1)), sub);
cmp :=cat(1, cmp, sub);
end if;
end for;
end for;
end getComponentsUsingClass;
function printComponents
import Modelica.Utilities.Streams.print;
import DymolaModels.Utilities.Strings.stripLeft;
input String c1="Modelica.Fluid.Examples.HeatingSystem" "Full path of class of which components are retrieved";
input String c2="Modelica.Fluid.System" "Full path of class which must be used in the components";
input Boolean isOuter=true "Return only components where c2 is used as an outer instance";
algorithm
print("Components in " + c1 + " using " + c2 + (if isOuter then " as outer" else "") + ":");
for c in getComponentsUsingClass(c1, c2,isOuter) loop
print(" " + stripLeft(c, "."));
end for;
end printComponents;
annotation (uses(
Modelica(version="4.0.0"),
Testing(version="1.3.1"),
ModelManagement(version="1.2.0"),
DymolaModels(version="1.2")));
end SO;