0

I am just started to learn modelica and I have one (newbie) question. The problem for me is to change the way of thinking from convential programming thinking to modelica way of thinking.

I want to do simple program. I have input array with PV output values in 5 minutes resolution. I have input array with heat load values in 60 minutes resolution. I have a energy storage that stores excess energy or takes energy fro meeting the heat demand in real time.

I wrote this in openmodelica:

`class Add
 Real PV[:] = 100:10:1000;
 Real Heat[:] = 200:300:6000;
 Real Storage;
 Real p;
 Integer j;
 Integer i;
 Boolean power,heat;
 equation
 power=sample(0,5);
 heat=sample(0,60);
 when power then
 j=j+1;
end when;

when heat then
i=i+1;

end when;

Storage= PV[j] * 2.375-Heat[i];

p=Storage+ pre(p);

end Add;`

But when I c/p to dymola it gets an error on this " p=Storage+ pre(p); " part because it says pre() cannot be used for continuous model. When I delete pre() then it says it cannot devide by 0.

Can you explain me what I am doing wrong?

Thanks!

bmorvaj
  • 55
  • 1
  • 7
  • 1
    It is not clear at all what you are trying to do. Do you want `p` to be continuous or discrete? Are you trying to integrate `p` or something. It would be best if you included some equations. – Michael Tiller Feb 11 '14 at 01:22
  • I want storage to be cont. I don't actually need variable p but that is how it worked for me. I want to say Storage=Storage + PV[j]-Heat[j] This is basic problem: •A discrete series of heat demands, assumed to be constant over each time period (1 hour) •A discrete series of inputs e.g. pv generation, again constant over each period but with a different period (5 min) •A continuous conversion equation •A continuous storage term I don't have the exact equation for storing. I just want to mimic the continuous energy charging or discharging with inputs that are cont but change at specific times. – bmorvaj Feb 11 '14 at 10:30
  • 1
    That doesn't really explain it but I think marcu1000s made the right assumption. What you want to do is *integrate* the heat output over time to determine the total amount of energy consumed. At least that's what marcu1000s did (very nicely), and I'm pretty sure that is what you want. – Michael Tiller Feb 12 '14 at 13:16

1 Answers1

2

I hope I understand your problem correctly. And I used Dymola to solve a simple example - I hope this works in OpenModelica, too.

If you are trying to use a time series of input data I would suggest using the model Modelica.Blocks.Sources.TimeTable. In your case the table's first column would denote hourly timesteps, i.e. 0, 3600, 7200, ...; the second column could give values for the heat demand in kW, if it is constant at 300 kW like in your example this could mean 300, 300, 300, ...;

You can reference the output of the TimeTable model in equations using its RealOutput as TimeTable.y.

A very simple example for your test case could thus look like this:

model heatStorage

  Modelica.SIunits.Conversions.NonSIunits.Energy_kWh storage "Energy content of storage in kWh";

  Modelica.Blocks.Sources.TimeTable solarThermal(table=[0,50; 3600,70; 7200,40; 10800,73]);
  Modelica.Blocks.Sources.TimeTable heatDemand(table=[0,300; 3600,300; 7200,300; 10800,
    300]);

equation
  der(storage) = (solarThermal.y - heatDemand.y)/3600;

end heatStorage;

I assumed time-varying output of a solar thermal collector. If you use PV to heat water you could include another variable and conversion equation. For the variable storage I used the definition of energy in kWh, therefore I divide the given equation by 3600. As Modelica is equation-based, writing der(storage) is the same as having the right side of the equation integrated. Thus, the calculated value for storage is the integral of the difference between input and output.

I hope this helps.

marcu1000s
  • 177
  • 1
  • 8
  • 1
    Good answer. This is what I suspected as well. – Michael Tiller Feb 12 '14 at 13:18
  • 1
    Thank you very much. This is the starting info I was lookin for. – bmorvaj Feb 12 '14 at 18:59
  • 1
    I'm glad I was able to help. As this example shows and you said yourself in the question, Modelica sometimes requires you to think a little different compared to other programming. And thank you Michael for the kind words to my solution. – marcu1000s Feb 13 '14 at 06:32