Search code examples
modelicaopenmodelica

Modelica: Class not found in scope


I am trying to create my own GreenEnergy library in OpenModelica. I reproduced a similar structure of the library to Modelica Standard Library, but unfortunately receiving the next error:

...
[GreenEnergy.Validation.Wall: 5:3-5:312]: Class GreenEnergy.HeatTransfer.Components.Wall not found in scope GreenEnergy.Validation.Wall.
...

I have next file(and its content) structure:

GreenEnergy

  • package.mo

    within ;
    package GreenEnergy
    extends Modelica.Icons.Package;
    end GreenEnergy;
    
  • HeatTransfer

    • package.mo
    within GreenEnergy;
    package HeatTransfer
    extends Modelica.Thermal.HeatTransfer;
    end HeatTransfer;
    
    • Components
      • 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, 0}, extent = {{-18, -18}, {18, 18}}, 
      rotation = 0)));
      HeatTransfer.Interfaces.HeatPort_a port_a 
      annotation(Placement(visible = true, transformation(origin = 
      {-100, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), 
      iconTransformation(origin = {-66, 0}, extent = {{-10, -10}, {10, 
      10}}, rotation = 0)));
      HeatTransfer.Interfaces.HeatPort_b port_b 
      annotation(Placement(visible = true, transformation(origin = {100, 
      0}, extent = {{-10, -10}, {10, 10}}, rotation = 0), 
      iconTransformation(origin = {62, 0}, extent = {{-10, -10}, {10, 
      10}}, rotation = 0)));
      HeatTransfer.Celsius.TemperatureSensor temperatureSensor 
      annotation(Placement(visible = true, transformation(origin = {58, 
      52}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
      Modelica.Blocks.Interfaces.RealOutput temperature 
      annotation(Placement(visible = true, transformation(origin = {106, 
      52}, extent = {{-10, -10}, {10, 10}}, rotation = 0), 
      iconTransformation(origin = {0, -102}, extent = {{-10, -10}, {10, 
      10}}, rotation = -90)));
      
      equation
      
      connect(thermalConductorOuter.port_b, heatCapacitor.port) 
      annotation(Line(points = {{-38, 0}, {2, 0}, {2, -10}}, color = 
      {191, 0, 0}, smooth = Smooth.Bezier));
      
      connect(thermalConductorInner.port_a, heatCapacitor.port) 
      annotation(Line(points = {{38, 0}, {2, 0}, {2, -10}}, color = 
      {191, 0, 0}, smooth = Smooth.Bezier));
      
      connect(port_a, thermalConductorOuter.port_a) 
      annotation(Line(points = {{-100, 0}, {-74, 0}}, color = {191, 0, 
      0}));
      
      connect(thermalConductorInner.port_b, port_b) 
      annotation(Line(points = {{74, 0}, {100, 0}}, color = {191, 0, 
      0}));
      
      connect(temperatureSensor.port, heatCapacitor.port) 
      annotation(Line(points = {{48, 52}, {2, 52}, {2, -10}}, color = 
      {191, 0, 0}, smooth = Smooth.Bezier));
      
      connect(temperatureSensor.T, temperature) annotation(Line(points = 
      {{68, 52}, {106, 52}}, color = {0, 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, 0, 255}, extent = {{-59, 25}, {59, -25}}, 
      textString = "%name"), Text(origin = {-15, -83}, lineColor = {170, 
      0, 0}, extent = {{-13, 21}, {13, -21}}, textString = "T"), 
      Text(origin = {-34, 2}, extent = {{-20, 12}, {20, -12}}, 
      textString = "outer"), Text(origin = {29, 2}, extent = {{-27, 10}, 
      {27, -10}}, textString = "inner"), Text(origin = {-2, 57}, extent 
      = {{-60, 19}, {60, -19}}, textString = "C=%heat_capacity"), 
      Text(origin = {22, 33}, extent = {{-84, 25}, {84, -25}}, 
      textString = "G=%thermal_conductance")}));
      
      end Wall;
      
      
  • Validation

    • 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, 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}, 
      extent = {{-10, -10}, {10, 10}}, rotation = 0)));
    
      //Modelica.Thermal.HeatTransfer.Sources.FixedTemperature 
      fixedTemperature1(T = 303.15)  annotation(
      //Placement(visible = true, transformation(origin = {68, 22}, 
      extent 
      = {{-10, -10}, {10, 10}}, rotation = 180)));
    
      Modelica.Thermal.HeatTransfer.Sources.FixedTemperature 
      fixedTemperature annotation(Placement(visible = true, 
      transformation(origin = {-70, -0}, extent = {{-10, -10}, {10, 
      10}}, 
      rotation = 0)));
    
      Modelica.Thermal.HeatTransfer.Sources.FixedTemperature 
      fixedTemperature1 annotation(Placement(visible = true, 
      transformation(origin = {70, 0}, extent = {{-10, -10}, {10, 
      10}}, 
      rotation = -180)));
    
      equation
    
      connect(fixedTemperature.port, wall1.port_a) 
      annotation(Line(visible 
      = true, origin = {-44.85, -0}, points = {{-15.15, -0}, {15.15, 
      0}}, 
      color = {191, 0, 0}));
    
      connect(wall1.port_b, fixedTemperature1.port) 
      annotation(Line(visible = true, origin = {43.95, 0}, points = 
      {{-16.05, 0}, {16.05, 0}}, color = {191, 0, 0}));
    
      end Wall;
    
    

And then I am trying to run Validation.Wall model... So, why I am receiving error that component is not found in scope?

Best


Solution

  • The problem is in the next packages code:

    extends Modelica.Thermal.HeatTransfer;
    

    and

    extends Modelica.Thermal.HeatTransfer.Components;
    

    When I replaced those lines with the simpler line:

    extends Modelica.Icons.Package;
    

    Problem disappeared.

    Modelica.Thermal.HeatTransfer package contains those lines at the beginning:

    within Modelica.Thermal;
    

    but Modelica.Icons.Package is declared in a different way by using partial keyword. More details about partial keyword here.

    Best.