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!
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.