%CREATED: JUNE 2009 by ARC %This code is designed to calculate perfusion in the whole lung, with a symmetric large vessel structure. %%-----------------------INPUT------------------------- %The input to this function is inlet and outlet pressure (or one of these pressures and flow) for the system, %%----------------------OUTPUT---------------------------- % This code outputs pressures and flow solutions in the each blood vessel, along with capillary transit time calculations. function [P_A,P_V,FLOW_ACIN,GUESS_NEW,R_CAP_NEW,TT_CAP_NEW]=RUN_SYMM_PLUS_LADDER(Pin,Pout,Qin,Parameters,Flow) Pin_all=Pin; Pout_all=Pout; Qinguess=Qin; %Solution guesses P_A=[Pin_all 100*(ones(1,Parameters.num_large_gen-1))]; P_V=[Pout_all 100*(ones(1,Parameters.num_large_gen-1))]; x=[Pin_all;Pout_all;Qinguess;Qinguess/2^Parameters.num_large_gen;Qinguess]; %artery and vein lengths and radii for i=1:Parameters.num_large_gen N=2^(i-1); %there is one branch in gen 1, 2 in gen 2 etc... D_A(i)=(N/exp(Parameters.A_A1))^(-1/Parameters.B_A1); D_V(i)=(N/exp(Parameters.A_V1))^(-1/Parameters.B_V1); end rad_A=D_A/2;rad_V=D_V/2; for i=1:Parameters.num_large_gen L_A(i)=exp(Parameters.A_A2)*D_A(i)^Parameters.B_A2; L_V(i)=exp(Parameters.A_V2)*D_V(i)^Parameters.B_V2; end %% Start of iterative loop error=100; iterations=0; while (abs(error)>1e-6)&iterations<=100 RTOT_A=0; RTOT_V=0; iterations=iterations+1; if iterations==1 else if Flow==1 %% Flow Boundary conditions Pout_all=x(3); P_V(1)=Pout_all; elseif Flow==0 %% Pressure Boundary conditions Qinguess=x(3); end end %artery resistances for i=1:Parameters.num_large_gen if (P_A(i)-Parameters.Ppl)<=Parameters.Pub_a_v radupdate(i)=rad_A(i)*(1+(P_A(i)-Parameters.Ppl)*Parameters.alpha_a); else radupdate(i)=rad_A(i)*(1+Parameters.Pub_a_v*Parameters.alpha_a); end R_Agen(i)=(8*Parameters.mu*L_A(i))/(pi*radupdate(i)^4); R_A=R_Agen(i)/2^(i-1); RTOT_A=RTOT_A+R_A; P_A(i+1)=Pin_all-Qinguess*RTOT_A; end Pin_acin=P_A(Parameters.num_large_gen+1); %vein resistances for i=1:Parameters.num_large_gen if (P_V(i)-Parameters.Ppl)<=Parameters.Pub_a_v radupdate(i)=rad_V(i)*(1+(P_V(i)-Parameters.Ppl)*Parameters.alpha_v); else radupdate(i)=rad_V(i)*(1+Parameters.Pub_a_v*Parameters.alpha_v); end R_Vgen(i)=(8*Parameters.mu*L_V(i))/(pi*radupdate(i)^4); R_V=R_Vgen(i)/2^(i-1); RTOT_V=RTOT_V+R_V; P_V(i+1)=Pout_all+Qinguess*RTOT_V; end Pout_acin=P_V(Parameters.num_large_gen+1); %CALCULATE ACINAR FLOW PROPERTIES [FLOW_ACIN,GUESS_NEW,R_CAP_NEW,TT_CAP_NEW]=RUN_LADDER(Pin_acin,Pout_acin,0,Parameters); R_ACIN=(Pin_acin-Pout_acin)/(FLOW_ACIN); if Flow==0 matrix=[-1 0 -RTOT_A 0 0; 1 -1 0 -R_ACIN 0; 0 1 0 0 -RTOT_V; 0 0 1 -1*2^(Parameters.num_large_gen-1) 0; 0 0 1 0 -1]; vector=[-Pin_all; 0; Pout_all; 0; 0]; elseif Flow==1 matrix=[-1 0 0 0 0; 1 -1 0 -R_ACIN 0; 0 1 -1 0 -RTOT_V; 0 0 0 2^(Parameters.num_large_gen-1) 0; 0 0 0 0 1]; vector=[Qinguess*RTOT_A-Pin_all; 0;0; Qinguess;Qinguess]; end %Solve system x2=matrix\vector; error=max(abs((x-x2)./(x2))); x=x2; end %% End iterative loop %% OUTPUTTING SOME NICELY FORMATTED INFO ABOUT THE SYSTEM [FLOW_ACIN,GUESS_NEW,R_CAP_NEW,TT_CAP_NEW]=RUN_LADDER(Pin_acin,Pout_acin,1,Parameters); disp(sprintf('!!!FULL CIRCUIT SUMMARY!!!\n')) if Flow==1 disp(sprintf('Input: Flow = %g \n',Qin)) disp(sprintf('Output: Pin = %g , Pout= %g\n', Pin_all, Pout_all)) else disp(sprintf('Input: Pin = %g , Pout= %g\n', Pin, Pout)) disp(sprintf('Output: Flow = %g \n',Qinguess)) end total_resistance1=(Pin_all-Pout_all)/x(5);%Pa.s /mm^3 total_resistance2=(Pin_all-Pout_all)*10^4/x(5);%dyne s /cm^5 disp(sprintf('Total resistance through the tree is %g (Pa.s/mm^3).\n This is %g (dyne.s/cm^5).\n',total_resistance1,total_resistance2)) total_flow=60*x(5)/10^6; %l/min disp(sprintf('Total flow through the system is %g (mm^3/s). \n This is %g (l/min).\n',x(5),total_flow)) percent_art_pressure_drop=(Pin_all-GUESS_NEW(4*Parameters.num_symm_gen-7))/(Pin_all-Pout_all)*100; disp(sprintf('Percentage pressure drop across the arteries= %g \n',percent_art_pressure_drop)) percent_ac_pressure_drop=(P_A(Parameters.num_large_gen+1)-P_V(Parameters.num_large_gen+1))*100/(Pin_all-Pout_all); disp(sprintf('Percentage pressure drop across the acinus= %g \n',percent_ac_pressure_drop)) disp(sprintf('!!!END FULL CIRCUIT SUMMARY!!!\n'))