A Cardiovascular Simulator for Research 1.0.0

File: <base>/src/param_change.m (3,003 bytes)
% The function param_change.m determines whether an on-line parameter
% update is relevant to the status of the current simulation.  For 
% example, an update to Cls is meaningful when the intact circulation
% and heart-lung unit preparations are implemented, but is not
% relevant when the systemic circulation preparation is executed.
%
% Function arguments:%
%	th - updated parameter values
%	thold - previous parameter values
%	flag - status parameters (cannot be updated)
%
% Function output:
%	difference - boolean, scalar 
%                    = 1, if there is a relevant difference between
%		          the updated and previous parameter values
%	             = 0, if there is no relevant difference between
%		          the updated and previous parameter values
%

function difference = param_change(th,thold,flag)

% Assigning status variables.
preparation = flag(1);
breathing = flag(2);
dncm = flag(3);
baro = flag(4);
dra = flag(5);
df = flag(7);

% Checking if any relevant parameters of the pulsatile heart and
% circulation (intact (nominal), heart-lung unit, systemic circulation
% preparations) were updated.
if (preparation == 0)

   one = max(abs(th([1:27 31:32 91 98])-thold([1:27 31:32 91 98])));

elseif (preparation == 1)

   one = max(abs(th([1:2 5:9 12:15 17:20 22:27 29:32 88 90:91 98])-thold([1:2 5:9 12:15 17:20 22:27 29:32 88 90:91 98])));

elseif (preparation == 2)

   one = max(abs(th([3:6 10:12 16:18 22:25 27:28 32:33 89 91 98])-thold([3:6 10:12 16:18 22:25 27:28 32:33 89 91 98])));

end

% Checking if any relevant breathing parameters were updated.
if (breathing == 0)

   two = max(abs(th([36 101:102])-thold([36 101:102])));

elseif (breathing == 1)

   two = max(abs(th([36 42 77 100:102])-thold([36 42 77 100:102])));

elseif (breathing == 2)

   two = max(abs(th([36 42 77 99:102])-thold([36 42 77 99:102])));

end

% Checking if any relevant direct neural coupling mechanism
% parameters were updated.
if (dncm == 0)

   three = 0;

elseif (dncm == 1)

   three = max(abs(th([38:39 52:53])-thold([38:39 52:53])));

end

% Checking if any relevant baroreflex parameters were updated.
if (baro == 0)

elseif (baro == 1)

   four = max(abs(th([37:40 46 54 92:93 95 97])-thold([37:40 46 54 92:93 95 97])));

elseif (baro == 3)

   four = max(abs(th([37:39 41 55:56 58 60 92 94 96])-thold([37:39 41 55:56 58 60 92 94 96])));

elseif (baro == 4);

   four = max(abs(th([37:41 46 54:56 58 60 92:97])-thold([37:41 46 54:56 58 60 92:97])));

end

% Checking if any relevant exogenous disturbance to Ra parameters
% were updated.
if (dra == 0)

   five = 0;

elseif (dra == 2)

   five = max(abs(th([44 47])-thold([44 47])));

end

% Checking if any relevant exogenous disturbance to F parameters
% were updated.
if (df == 0)

   six = 0;

elseif (df == 1)

   six = max(abs(th([38:39 48 59])-thold([38:39 48 59])));

end

% Accumulating the results and determining if any relevant
% parameter updates were made.
difference = max([one two three four five six]>10e-8);