Dynamic script which creates and deletes parts over time

5 visualizaciones (últimos 30 días)
Paris
Paris el 22 de Ag. de 2024
Comentada: Paris el 22 de Ag. de 2024
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Ag. de 2024
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 comentarios
Walter Roberson
Walter Roberson el 22 de Ag. de 2024
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)
Paris
Paris el 22 de Ag. de 2024
Thank you, I will try to implement it.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Sources en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by