问题描述
我正在尝试在 OpenModelica 中创建我自己的 GreenEnergy 库。我复制了一个与 Modelica 标准库类似的库结构,但不幸的是收到了下一个错误:
...
[GreenEnergy.Validation.Wall: 5:3-5:312]: Class GreenEnergy.HeatTransfer.Components.Wall not found in scope GreenEnergy.Validation.Wall.
...
绿色能源
-
package.mo
within ; package GreenEnergy extends Modelica.Icons.Package; end GreenEnergy;
-
传热
- package.mo
within GreenEnergy; package HeatTransfer extends Modelica.Thermal.HeatTransfer; end HeatTransfer;
- 组件
- package.mo
within GreenEnergy.HeatTransfer; package Components extends Modelica.Thermal.HeatTransfer.Components; end Components;
- Wall.mo
within GreenEnergy.HeatTransfer.Components; model Wall import Modelica.Units.SI; import Modelica.Thermal.HeatTransfer; parameter SI.Area area = 1 "Wall area"; parameter SI.Length thickness = 0.5 "Thickness of wall"; parameter SI.Density density = 2000 "Wall density"; parameter SI.ThermalConductivity thermal_conductivity = 0.62 "https://en.wikipedia.org/wiki/Thermal_conductivity"; parameter SI.SpecificHeatCapacity specific_heat_capacity = 800 "Wall material specific heat capacity"; parameter SI.Temperature initial_temperature = 288.15 "Initial temperature of wall"; final constant SI.HeatCapacity heat_capacity = area * thickness * density * specific_heat_capacity; final constant SI.CoefficientOfheatTransfer coefficient_of_heat_transfer = thermal_conductivity * thickness; final constant SI.ThermalConductance thermal_conductance = area * coefficient_of_heat_transfer; HeatTransfer.Components.HeatCapacitor heatCapacitor(C = heat_capacity,T(displayUnit = "degC",fixed = true,start = initial_temperature)) annotation(Placement(visible = true,transformation(origin = {1,-33},extent = {{-23,-23},{23,23}},rotation = 180))); HeatTransfer.Components.ThermalConductor thermalConductorOuter(G = thermal_conductance / 2) annotation(Placement(visible = true,transformation(origin = {-56,0},extent = {{-18,-18},{18,18}},rotation = 0))); HeatTransfer.Components.ThermalConductor thermalConductorInner(G = thermal_conductance / 2) annotation(Placement(visible = true,transformation(origin = {56,rotation = 0))); HeatTransfer.Interfaces.HeatPort_a port_a annotation(Placement(visible = true,transformation(origin = {-100,extent = {{-10,-10},{10,10}},rotation = 0),iconTransformation(origin = {-66,rotation = 0))); HeatTransfer.Interfaces.HeatPort_b port_b annotation(Placement(visible = true,transformation(origin = {100,iconTransformation(origin = {62,rotation = 0))); HeatTransfer.Celsius.TemperatureSensor temperatureSensor annotation(Placement(visible = true,transformation(origin = {58,52},rotation = 0))); Modelica.Blocks.Interfaces.RealOutput temperature annotation(Placement(visible = true,transformation(origin = {106,iconTransformation(origin = {0,-102},rotation = -90))); equation connect(thermalConductorOuter.port_b,heatCapacitor.port) annotation(Line(points = {{-38,{2,-10}},color = {191,smooth = Smooth.Bezier)); connect(thermalConductorInner.port_a,heatCapacitor.port) annotation(Line(points = {{38,smooth = Smooth.Bezier)); connect(port_a,thermalConductorOuter.port_a) annotation(Line(points = {{-100,{-74,0}},color = {191,0})); connect(thermalConductorInner.port_b,port_b) annotation(Line(points = {{74,{100,0})); connect(temperatureSensor.port,heatCapacitor.port) annotation(Line(points = {{48,smooth = Smooth.Bezier)); connect(temperatureSensor.T,temperature) annotation(Line(points = {{68,{106,52}},color = {0,127})); annotation(Icon(graphics = {Rectangle(origin = {-1.75,-0.54},fillColor = {142,142,142},fillPattern = FillPattern.Backward,extent = {{-63.75,99.46},{63.75,-99.46}}),Text(origin = {-3,83},lineColor = {85,255},extent = {{-59,25},{59,-25}},textString = "%name"),Text(origin = {-15,-83},lineColor = {170,extent = {{-13,21},{13,-21}},textString = "T"),Text(origin = {-34,2},extent = {{-20,12},{20,-12}},textString = "outer"),Text(origin = {29,extent = {{-27,10},{27,textString = "inner"),Text(origin = {-2,57},extent = {{-60,19},{60,-19}},textString = "C=%heat_capacity"),Text(origin = {22,33},extent = {{-84,{84,textString = "G=%thermal_conductance")})); end Wall;
-
验证
- package.mo
within GreenEnergy; package Validation extends Modelica.Icons.ExamplesPackage; end Validation;
- Wall.mo
within GreenEnergy.Validation; model Wall extends Modelica.Icons.Example; GreenEnergy.HeatTransfer.Components.Wall wall1(area = 1,density(displayUnit = "kg/m3") = 1,initial_temperature = 274.15,specific_heat_capacity = 1,thermal_conductivity = 1,thickness = 1) annotation(Placement(visible = true,transformation(origin = {0,extent = {{-45,-45},{45,45}},rotation = 0))); //Modelica.Thermal.HeatTransfer.sources.FixedTemperature fixedTemperature(T = 283.15) annotation( //Placement(visible = true,transformation(origin = {-76,22},rotation = 0))); //Modelica.Thermal.HeatTransfer.sources.FixedTemperature fixedTemperature1(T = 303.15) annotation( //Placement(visible = true,transformation(origin = {68,extent = {{-10,rotation = 180))); Modelica.Thermal.HeatTransfer.sources.FixedTemperature fixedTemperature annotation(Placement(visible = true,transformation(origin = {-70,-0},rotation = 0))); Modelica.Thermal.HeatTransfer.sources.FixedTemperature fixedTemperature1 annotation(Placement(visible = true,transformation(origin = {70,rotation = -180))); equation connect(fixedTemperature.port,wall1.port_a) annotation(Line(visible = true,origin = {-44.85,points = {{-15.15,{15.15,0})); connect(wall1.port_b,fixedTemperature1.port) annotation(Line(visible = true,origin = {43.95,points = {{-16.05,{16.05,0})); end Wall;
然后我正在尝试运行 Validation.Wall 模型... 那么,为什么我会收到在范围内找不到组件的错误消息?
最佳
解决方法
问题出在下一个包代码中:
extends Modelica.Thermal.HeatTransfer;
和
extends Modelica.Thermal.HeatTransfer.Components;
当我用更简单的行替换这些行时:
extends Modelica.Icons.Package;
问题消失了。
Modelica.Thermal.HeatTransfer
包的开头包含这些行:
within Modelica.Thermal;
但是 Modelica.Icons.Package
是通过使用 partial
关键字以不同的方式声明的。有关部分关键字 here 的更多详细信息。
最好的。