% solves the water balance, tracer balance, and master equations numerically
% Calculation period
calc=options.periods.calc;
lg=length(calc)-1;% size of the computation
% age options
dT=options.ages.dT;% age resolution for the calculations, in hours
save_interval=options.ages.save_interval;% interval of time (in the simulation) to save age calculations, in hours (usually a multiple of dT)
iflength(calc)==length(options.periods.warmup)
ifoptions.ages.save_warmup==0
save_interval=Inf;
end
end
init_RTD=options.ages.init_RTD;% initial residence time distribution in the storage unit
age_prctiles=options.ages.age_prctiles;% percentiles of the TTDs and RTDs to be calculated
T_group=options.ages.T_group;% groups to classify water younger than the given ages [days]
% Load data
t=model_input.t(calc);
dt=options.dt;% in hours
tau=dt/dT;% numerical dimensionless parameter, similar to a diffusion term. For example, tau=10% means that in dt hours, 10% of the water of a given age T has aged to T+dT
% tau is thus responsible for the diffusion-like profile of the TTDs.
tfull=model_input.tfull;
J=model_input.J(calc);
Cp=model_input.Cp(calc);
Cpfull=model_input.Cpfull;
PET=model_input.PET(calc);
Q=model_input.Q(calc);
size_true_warmup=model_input.size_true_warmup;
iflength(calc)==length(options.periods.warmup)
ofst=max(0,size_true_warmup-length(options.periods.warmup));% offset for convolution
else
ofst=max(size_true_warmup,length(options.periods.warmup));% offset for convolution