Can't retrieve value from previous time step.
2 次查看(过去 30 天)
显示 更早的评论
I am doing a energy storage and transport project in simulink in matlab. It is formed by a file which contains constant variables and an interactive model that attempts to simulate the flow of energy of this sytem, this is possible because inside of this model formulas and calculations can be implemented. The system consist of 5 blocks. Transport to supply, injection, storage, extraction, transport to demand, inside of each block you add the different formulas/calculations. The system also accounts for power losses. I am stuck in the storage subsystem.
I have a function block that simulates the storage. I have as inputs some constants and the variable power supply from a data file. I have as outputs the energy lossses and the energy storage. My type of storage is a water thermal battery (very simple). I have time step of 5mins, which means that there is a point every 5 mins, in the data file time there is data for 525600 minutes (one year). Every time step energy is added tothe storage, raising the temperature, the thing is in my code i can only take into account the enegy of the storage at that time step. I would like to retrieve the temperature of the previous step and add it to the new one, like this i will have the energy being stored in the system, but i dont know how to do this.
function [DStorage, EdotStorage]= Storage(PtoStorage, PfromStorage, kWater,TEnv, tankheight, tankradius, mwateronetank,cWater, ITank)
PreviousT = 0; %This should retrieve me the temperature of the tank in the previous time step, or the output from the previous step is even fine (from here I can calculate the temperature rise, make it a variabe and add it ot "Atank")
ATank= 2*pi*tankradius*(tankradius+tankheight); %Area of the tank
Ttank= TEnv + ((PtoStorage/125)/((mwateronetank)*cWater)) + PreviousT ; %Actual temperature of each tank
Dofonetank = ((kWater* ATank * ((Ttank-TEnv))/ITank)); %Power loss due to conduction in one tank
DStorage= Dofonetank*125; %Power loss due to conduction in all tanks
EdotStorage = PtoStorage - PfromStorage - DStorage; %Amount of energy in the storage
回答(1 个)
Jasvin
2024-6-10
An approach with the "Unit Delay" block does make sense here, but I'll suggest an alternate approach using the "Data Store" blocks.
You can define the current temperature of the tank, which I assume is "Ttank", as an output of the "MATLAB Function" block. Then you can send this data to a "Data Store Write" block, so that it gets stored in a Data Store, say "temp".
Now you can redefine the function to take "PreviousT" as an input, and connect a "Data Store Read" block with the same data store name "temp" to this input.
To summarize, your function definition will now look like:
function [DStorage, EdotStorage,Ttank]= Storage(PtoStorage, PfromStorage, kWater,TEnv, tankheight, tankradius, mwateronetank,cWater, ITank,PreviousT)
The output line for "Ttank" will go to the "Data Store Write" block and the input line for "PreviousT" will come from "Data Store Read" block.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large-Scale Modeling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!