Dynamic script which creates and deletes parts over time

5 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2024-8-22
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 个评论
Walter Roberson
Walter Roberson 2024-8-22
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)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by