Dynamic script which creates and deletes parts over time

Dear all,
I wrote a function CoolingCalc that calculates the cooling of a porous material based on the input conditions. I want to simulate adding material into a tank at a certain rate per second (m_in). If CoolingCalc represents a "block" containing m_in material per second, then the total cooling at a given time should be the sum of the cooling from all blocks, considering that blocks were also added earlier.
Additionally, if I set a total mass Mass_setpoint after which I start removing material from the tank, I would need a script that adds CoolingCalc blocks until their combined mass reaches Mass_setpoint, and then begins removing the earliest blocks that were created.
My understanding is that this requires a dynamic script that creates and deletes these blocks over time.
Is it possible to implement this in MATLAB?
I am grateful for any help you can provide.
Best regards,
clear; clc
t_cycle = 200; % [s] simulation time
T = 303.15; % [K] temperature
P = 1; % [MPa] pressure
% Material related
m_in = 0.001; % [kg/s] inlet flowrate
Mass_setpoint = 0.1; % [kg] set point after which material is removed
m_out = 0.002; % [kg/s] outlet flowrate
Xs = 0.002; % [m^3/kg] Pore volume of material
Q_st = 450; % [kJ/kg] Isosteric heat of material
Xeq0 = 1; % Initial value of X
% Plot
[Q_cooling] = CoolingCalc(T, P, Q_st, Xs, Xeq0, m_in, t_cycle);
plot(Q_cooling)
hold on

 Accepted Answer

Create the configuration with all of the blocks.
Pass an additional parameter in, which indicates which blocks are active.
Loop over all of the blocks. If the block is not active, add 0 to the total; if the block is active then add the appropriate amount.

3 Comments

Hi Walter, thank you for the reply.
I will try your method. Since my calculation are over time, how can I restart the block to account that a new block is added?
If I understand correctly your method, and I have three blocks then I should set the "active" parameter as
time=1 time=2 time=3 time=n
1 (start) 1 (start) 1 (start) 1 (restart)
0 1 (started at 1) 1 (started at 2) 1 (started at n-1)
0 0 1 (started at 1, then delete) 1 (started at n-2, then delete)
Best regards,
Paris
The approach you should take depends on your architecture.
If each block contributes a constant amount, and it is a matter of which blocks are currently active or not, then configure all of the blocks and configure some kind of schedule; calculate the contributions from each block, and then run through the schedule of which parts are active at which time.
If the contribution of a block changes over time, but as well there are blocks that are currently active or not, then configure all of the blocks and add a variable which controls which ones are currently active; then loop over all of the blocks calculating current contribution for the block (taking into account that they might be inactive.) Then next timestep do the same thing, just with an updated list of what is currently active (and with the updated timestamp)
Thank you, I will try to implement it.

Sign in to comment.

More Answers (0)

Categories

Find more on General Applications in Help Center and File Exchange

Products

Release

R2022a

Asked:

on 22 Aug 2024

Commented:

on 22 Aug 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!