Search code examples
modelicaopenmodelicadymola

Modelica buildings outputs error when connecting the terminal


I am trying to connect the grid to a line in the modelica building.electrical library. I get this error:

[2] 18:20:02 Translation Error [Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Line: 4:5-4:47]: Type mismatch in binding terminal_n = grid_connection, expected subtype of Buildings.Electrical.AC.ThreePhasesBalanced.Interfaces.Terminal_n, got type Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid

I found this unusual since I am connecting it like the example which does not have an error

My code:

model building
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid grid_connection annotation(
    Placement(visible = true, transformation(origin = {-82, 60}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Sources.PVSimpleOriented solar_array(A = 10)  annotation(
    Placement(visible = true, transformation(origin = {-106, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 180)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Resistive building_load annotation(
    Placement(visible = true, transformation(origin = {-4, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Storage.Battery BESS(EMax = 1800000000, SOC_start = 20)  annotation(
    Placement(visible = true, transformation(origin = {-82, -46}, extent = {{-10, -10}, {10, 10}}, rotation = 270)));
  Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Line grid_line(terminal_n = grid_connection)  annotation(
    Placement(visible = true, transformation(origin = {-40, 12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));

  Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weather_data(filNam = "weather.mos")  annotation(
    Placement(visible = true, transformation(origin = {-184, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Sources.CombiTimeTable load_data(columns = 15:44640, fileName = "data.txt", tableOnFile = true, timeScale = 60, verboseRead = true)  annotation(
    Placement(visible = true, transformation(origin = {29, 13}, extent = {{9, -9}, {-9, 9}}, rotation = 0)));
  Modelica.Blocks.Sources.CombiTimeTable bess_data annotation(
    Placement(visible = true, transformation(origin = {-48, -46}, extent = {{8, -8}, {-8, 8}}, rotation = 0)));
equation
  connect(BESS.terminal, grid_line.terminal_n) annotation(
    Line(points = {{-82, -36}, {-48, -36}, {-48, 12}, {-50, 12}}, color = {255, 255, 255}));
  connect(grid_line.terminal_n, BESS.terminal) annotation(
    Line(points = {{-50, 12}, {-82, 12}, {-82, -36}}));
  connect(grid_line.terminal_n, solar_array.terminal) annotation(
    Line(points = {{-50, 12}, {-96, 12}}));
  connect(grid_line.terminal_p, building_load.terminal) annotation(
    Line(points = {{-30, 12}, {-14, 12}}));
  connect(load_data.y, building_load.Pow) annotation(
    Line(points = {{19, 13}, {13.5, 13}, {13.5, 12}, {6, 12}}, color = {0, 0, 127}));
  connect(bess_data.y, BESS.P) annotation(
    Line(points = {{-56, -46}, {-72, -46}}, color = {0, 0, 127}));
  connect(weather_data.weaBus, solar_array.weaBus) annotation();
  annotation(
    uses(Buildings(version = "9.1.0"), Modelica(version = "4.0.0")));
end building;

Example Code:

within Buildings.Electrical.Examples;
model RenewableSources
  AC.ThreePhasesBalanced.Sources.Grid gri(
    f=f,
    V=V_nominal,
    phiSou=0) "Grid model that provides power to the system"
  AC.ThreePhasesBalanced.Lines.Line line1(mode=Buildings.Electrical.Types.CableMode.automatic,
      l=1500,
    V_nominal=V_nominal,
    P_nominal=7*(PLoa_nominal + PSun) + PWin) "Electrical line"
              annotation (Placement(transformation(extent={{-80,10},{-60,30}})));
equation
  connect(gri.terminal, line1.terminal_n) annotation (Line(
      points={{-90,40},{-90,20},{-80,20}},
      color={0,120,120},
      smooth=Smooth.None));

Thank you all for the help


Solution

  • What I found:

    • There are two connections from BESS.terminal to grid_line.terminal.n. One of them is white, so likely this is the reason it wasn't noticed.
    • The modifier grid_connection in grid_line for terminal_n does not make sense to me. I guess it should be removed.
    • The connection between bess_data.y[] and BESS.P is not correct, as the output of the table is a vector. It should be something like connect(bess_data.y[1], BESS.P).
    • The connection between weather_data and solar_array has no annotation and is therefore invisible.
    • I had to change weather_data.filNam from wheather.mos to Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos") as the used script is not provided here.
    • Removed modifier from load_data.columns.

    If you then connect grid_connection to any of the electric components and add data for the two tabled, the model should work.

    The result is...

    model building
      Buildings.Electrical.AC.ThreePhasesBalanced.Sources.Grid grid_connection annotation (
        Placement(visible = true, transformation(origin={-20,48},    extent = {{-10, -10}, {10, 10}}, rotation = 0)));
      Buildings.Electrical.AC.ThreePhasesBalanced.Sources.PVSimpleOriented solar_array(A = 10)  annotation (
        Placement(visible = true, transformation(origin={-44,0},      extent = {{-10, -10}, {10, 10}}, rotation = 180)));
      Buildings.Electrical.AC.ThreePhasesBalanced.Loads.Resistive building_load annotation (
        Placement(visible = true, transformation(origin={58,0},     extent = {{-10, -10}, {10, 10}}, rotation = 0)));
      Buildings.Electrical.AC.ThreePhasesBalanced.Storage.Battery BESS(EMax = 1800000000, SOC_start = 20)  annotation (
        Placement(visible = true, transformation(origin={-20,-58},    extent = {{-10, -10}, {10, 10}}, rotation = 270)));
      Buildings.Electrical.AC.ThreePhasesBalanced.Lines.Line grid_line(l=1e3, P_nominal=1e4) annotation (
        Placement(visible = true, transformation(origin={22,0},      extent = {{-10, -10}, {10, 10}}, rotation = 0)));
    
      Buildings.BoundaryConditions.WeatherData.ReaderTMY3 weather_data(filNam=Modelica.Utilities.Files.loadResource("modelica://Buildings/Resources/weatherdata/USA_CA_San.Francisco.Intl.AP.724940_TMY3.mos"))
        annotation (Placement(visible = true, transformation(origin={-82,-40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
      Modelica.Blocks.Sources.CombiTimeTable load_data(table=[0.0,0.0; 1,0.0], fileName = "data.txt", timeScale = 60, verboseRead = true)  
        annotation (Placement(visible = true, transformation(origin={91,0}, extent = {{9, -9}, {-9, 9}}, rotation = 0)));
      Modelica.Blocks.Sources.CombiTimeTable bess_data(table=[0.0,0.0; 1,0.0])
        annotation (Placement(visible = true, transformation(origin={14,-58}, extent = {{8, -8}, {-8, 8}}, rotation = 0)));
    equation 
      connect(grid_line.terminal_n, BESS.terminal) annotation (
        Line(points={{12,0},{-20,0},{-20,-48}}));
      connect(grid_line.terminal_n, solar_array.terminal) annotation (
        Line(points={{12,0},{-34,0}}));
      connect(grid_line.terminal_p, building_load.terminal) annotation (
        Line(points={{32,0},{48,0}}));
      connect(load_data.y, building_load.Pow) annotation (
        Line(points={{81.1,0},{68,0}}, color = {0, 0, 127}));
      connect(bess_data.y[1], BESS.P) annotation (
        Line(points={{5.2,-58},{-10,-58}}, color={0,0,127}));
      connect(grid_connection.terminal, solar_array.terminal)
        annotation (Line(points={{-20,38},{-20,0},{-34,0}},   color={0,120,120}));
      connect(weather_data.weaBus, solar_array.weaBus)
        annotation (Line(
          points={{-72,-40},{-44,-40},{-44,-9}},
          color={255,204,51},
          thickness=0.5));
      annotation (
        uses(Buildings(version = "9.1.0"), Modelica(version = "4.0.0")));
    end building;
    

    ...which at least works, but I would NOT trust the results it generates. At best, this is a starting point to understand which errors were made when creating the model (which is why the above list is added) and to do better next time.

    Disclaimer: The model is still a pretty big mess (incompatible units, unset parameters etc.) and it would probably make sense to start from scratch...