- Author:
- aram148 <42922407+aram148@users.noreply.github.com>
- Date:
- 2022-07-26 11:49:42+12:00
- Desc:
- updated documentation and renamed model
- Permanent Source URI:
- https://models.fieldml.org/workspace/7e5/rawfile/30e6db7fb82a9bb715b0121cdfc131c19e5cb2ff/Peripheral_matlab_dell_updated/generalised_model/coup.asv
function [t,NN,air,U,UVDOT,VVDOT, summ]=coup(order,kappa)%,rinitial)
tic
numBr = 2^order - 1; % number of airways
numOrd1 = (numBr+1)/2;
% initial values for airways (mm)
rimax = [0.296 0.318 0.337 0.358 0.384 0.414 0.445 0.484 0.539 0.608 ...
0.692 0.793 0.913 1.052 1.203 1.374];
rinitial=[];
for k=1:order
rinitial=[rinitial;rimax(k)*ones(2.^(order-k),1)];
end
rinitial=rinitial+0.01*rand(1,length(rinitial))'; % peturbation of rinitial
r(:,1)=rinitial; %airways, order 1 : order n
uv(:,1) = zeros(numBr,1); % pressure in airway
vv(:,1) = zeros(numBr,1); % airflow within the airway
vds(:,1) = zeros((numBr+1)/2,1); % airflow entering alveoli
y0 = [r(:,1); uv(:,1); vv(:,1); vds(:,1)]; %ICs vector
parm = [kappa];
tspan = [0 80];
% Set numerical accuracy options for ODE solver
options = odeset('RelTol', 1e-08, 'AbsTol', 1e-08, 'MaxStep', 0.01);
[t,NN]=ode15s(@(t,y) seven_airway(t,y,order,parm), tspan, y0, options);
U = zeros(length(NN),length(r)); % pressure including viscous damping
UVDOT = zeros(length(NN),length(r));
VVDOT = zeros(length(NN),length(r)); %airflow
VVDOT = zeros(length(NN),length(r)); %airflow
for j = 1:length(NN)
[U(j,:),UVDOT(j,:),VVDOT(j,:)] = seven_airway2(t(j),NN(j,:),order,parm);
end
toc
CM=jet(length(rinitial));
r_new = NN(:,1:numBr);
for i=1:length(rinitial)
if r_new(end,i) <= 0.01
air(i)=0;
else
air(i)=1;
end
end
% for i = 1:length(rinitial)
% figure(1)
% plot(t,r_new(:,i),'-','color',CM(i,:),'LineWidth', 1.5, 'MarkerSize', 8);
% hold on
%
% end
% % %
% % %
% legendStr = cell(1,length(rinitial));
% for i = 1:length(legendStr)
% legendStr{i} = sprintf('r_{%d}',i);
%
% end
% legend(legendStr,'Location','BestOutside');
%% Measure for state of heterogeniety
x = cell(1,numOrd1);
for i = 1:length(x)
x{i} = air(i);
end
summ = zeros(1,length(x{1}));
for i = 1:length(x)
switch i
case 1
neighbour_diff = sqrt((x{i} - x{end}).^2 + (x{i} - x{i+1}).^2);
case length(x)
neighbour_diff = sqrt((x{i} - x{i-1}).^2 + (x{i} - x{1}).^2);
otherwise
neighbour_diff = sqrt((x{i} - x{i-1}).^2 + (x{i} - x{i+1}).^2);
end
summ = summ + neighbour_diff;
end
summ=summ./(2^(order-3)*4*sqrt(2));
% %% graphing airways
% node1 = zeros(1,numBr);
% node2 = zeros(1,numBr);
%
% % e.g. for an order 4: node1 = [1 2 2 3 3 4 4 5 5 6 6 7 7 8 8];
% node1(1) = 1;
% for i = 1:(numBr-1)/2
% node1(2*i:2*i+1) = [i+1 i+1];
% end
%
% % e.g. for an order 4: node2 = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
% for i = 1:numBr
% node2(i) = i+1;
% end
%
% ind = zeros(1,numBr);
% for i = 1:numBr
% ind(i) = i;
% end
% figure,
% A=[fliplr(air)];
%
% G = graph(node1,node2,A);
% h=plot(G,'LineWidth',2);
% h.EdgeCData=A;
% labelnode(h,[node1 node2],'')
% labeledge(h,ind,G.Edges.Weight(ind));
% colormap jet