%% CREATED: JUNE 2009 by ARC %This code represents the ladder model for perfusion over an acinus %starting at the level below the arteries/veins accompanying the transitional bronchiole. %% NB - THE ACINUS IS DEFINED TO BE ALL GENERATIONS THAT HAVE %% ALVEOLARISATION _ THIS INCLUDES THE TRANSITIONAL BRONCHIOLE THIS CODE DOES NOT INCLUDE THE TRASITIONAL %% BRONCHIOLE WHICH IS ASSUMED TO HAVE INSIGNIFICANT ALVEOLARISATION % %% --------------INPUT----------------------------- %% Pin - %Pressure out of the artery accompanying the transitional bronchiole %% Pout - %Pressure into the vein accompanying the transitional bronchiole %% -----------OUTPUT------------------------------ %% GUESS_NEW - %Pressure and flow solutions throughout the acinus %% R_CAP_NEW - %Resistance across an individual capillary sheet in each % acinar generation %% TT_CAP_NEW - %RBC Transit times across capillary sheets in each acinar generation %% --------------------------------------------------------------------- function [GUESS_NEW,R_CAP_NEW,TT_CAP_NEW]=FCM_NEW_ART_CAP_VEN(Pin_acin,Pout_acin,Parameters,Parameters2) %% --------------INITIAL GUESS FOR SOLUTIONS --------------------------- %PRESSURES and flows.Solution is independent of (reasonably physiological) initial conditions GUESS=[1000; 1000; 100; 100]; for gen=2:Parameters.num_symm_gen-1 GUESS=[GUESS; 1000; 1000; 100; 100]; %GUESS PRESSURES end GUESS=[GUESS;0.1;0.1;0.1]; for gen=2:Parameters.num_symm_gen-1 GUESS=[GUESS; 0.1]; %GUESS FLOWS end %% ---------------INITIALISE ITERATIONS---------------------------- %INITIALISE ITERATIONS it=0; %INITIALISE SOLUTION MATRIX SOLMAT=A, SOL_VEC=B, SOLVE A\B for pressures, %capillary flows and total flow through system matrixsize=5*Parameters.num_symm_gen-3; submatrixsize=4*Parameters.num_symm_gen-4; SOL_MAT=zeros(matrixsize,matrixsize); %DELTA P=QR + continuity of flow = 5N-3 equations SOL_VEC=zeros(matrixsize,1); %BOUNDARY CONDITIONS (PRESSURE BCs) SOL_VEC(1)=-Pin_acin; SOL_VEC(3)=Pout_acin; %ELEMENTS OF THE SOLUTION MATRIX THAT ARE INDEPENDENT OF THE ITERATION for gen=1:Parameters.num_symm_gen-1 if gen==1 %FIRST GENERATION NON CAPILLARY VESSELS delta p=QR SOL_MAT(1,1)=-1;SOL_MAT(2,2)=-1;SOL_MAT(3,3)=1;SOL_MAT(4,4)=1;SOL_MAT(2,1)=1;SOL_MAT(4,3)=-1; % FLOW CONSERVATION %Q=2Qcap1+2Qcap2+...2^NQ_capN SOL_MAT(matrixsize,matrixsize)=1; %Q %Qcap1 and Qcap2 (do for gen above) SOL_MAT(matrixsize,submatrixsize+1)=-2; SOL_MAT(matrixsize,submatrixsize+2)=-2^2; %CONNECTIONS VIA CAPILLARIES delta p=QR SOL_MAT(submatrixsize+gen,1)=1;SOL_MAT(submatrixsize+gen,3)=-1; if Parameters.num_symm_gen==2 %ADDING TERMINAL SHEETS FOR N=2 SOL_MAT(matrixsize-1,submatrixsize)=-1; SOL_MAT(matrixsize-1,submatrixsize-2)=1; end elseif gen==Parameters.num_symm_gen-1 %FINAL GENERATION BEFORE THE TERMINAL SHEETS %NON_CAPILLARY VESSELS delta p=QR SOL_MAT(submatrixsize-3,submatrixsize-3)=-1;SOL_MAT(submatrixsize-2,submatrixsize-2)=-1;SOL_MAT(submatrixsize-1,submatrixsize-1)=1;SOL_MAT(submatrixsize,submatrixsize)=1; SOL_MAT(submatrixsize-2,submatrixsize-3)=1;SOL_MAT(submatrixsize,submatrixsize-1)=-1; %join to previous generation delta p=QR SOL_MAT(submatrixsize-3,submatrixsize-6)=1;SOL_MAT(submatrixsize-1,submatrixsize-4)=-1; %FLOW CONSERVATION%Q=Qcap1+2Qcap2+...2^NQ_capN (this is for final %gen) SOL_MAT(matrixsize,submatrixsize+gen+1)=-2^(gen+1); %CONNECTIONS VIA CAPILLARIES delta p=QR SOL_MAT(submatrixsize+gen,submatrixsize-3)=1;SOL_MAT(submatrixsize+gen,submatrixsize-1)=-1; SOL_MAT(matrixsize-1,submatrixsize)=-1; SOL_MAT(matrixsize-1,submatrixsize-2)=1; else %INTERMEDIATE GENERATIONS %NON_CAPILLARY VESSELS delta p=QR SOL_MAT(4*gen-3,4*gen-3)=-1;SOL_MAT(4*gen-2,4*gen-2)=-1;SOL_MAT(4*gen-1,4*gen-1)=1;SOL_MAT(4*gen,4*gen)=1; SOL_MAT(4*gen-2,4*gen-3)=1;SOL_MAT(4*gen,4*gen-1)=-1; %JOIN TO PREVIOUS GENERATIONS delta p=QR SOL_MAT(4*gen-3,4*gen-6)=1;SOL_MAT(4*gen-1,4*gen-4)=-1; %FLOW CONSERVATION Q=Qcap1+2Qcap2+...2^(N-1)Q_capN (this is for gen %above) SOL_MAT(matrixsize,submatrixsize+gen+1)=-2^(gen+1); %CONNECTIONS VIA CAPILLARIES delta p=QR SOL_MAT(submatrixsize+gen,4*gen-3)=1;SOL_MAT(submatrixsize+gen,4*gen-1)=-1; end end %% START OF ITERATIVE LOOP err=100; it=0; while (abs(err)>1e-15)&it<=100 clear R_art R_ven rad_update it=it+1;%COUNT ITERATIONS Q=GUESS(matrixsize); %UPDATE TOTAL FLOW for gen=1:Parameters.num_symm_gen-1 %FIRST HALF OF ARTERIOLE %Update radius of arteriole based on inlet pressure if (GUESS(4*gen-3)-Parameters.Palv)<=Parameters.Pub_a_v radupdate(gen,1)=Parameters2.rad_a(gen)*(1+(GUESS(4*gen-3)-Parameters.Palv)*Parameters.alpha_a); else radupdate(gen,1)=Parameters2.rad_a(gen)*(1+Parameters.Pub_a_v*Parameters.alpha_a); end %Calculate Poiseuille resistance in first half of arteriole - (only %half total generation length) R_art(gen,1)=(8*Parameters2.mu_app(gen)*Parameters2.L_a(gen)/2)/(pi*radupdate(gen,1)^4); %update solution matrix - delta p =FLOW R - As there is one vessel %generation 1 FLOW=Q, generation 2 FLOW =(Q-Qcap1)/2 this updates %the Q term in each (dividing by 2^(gen-1) - capillary terms are %updated below... SOL_MAT(4*gen-3,matrixsize)=-R_art(gen,1)/2^gen; %FIRST HALF OF VENULE %Update radius of venule based on inlet pressure NB: May need to %update this later to give an average of inlet and outlet radii if (GUESS(4*gen-1)-Parameters.Palv)<=Parameters.Pub_a_v radupdate(gen,1)=Parameters2.rad_v(gen)*(1+(GUESS(4*gen-1)-Parameters.Palv)*Parameters.alpha_v); else radupdate(gen,1)=Parameters2.rad_v(gen)*(1+Parameters.Pub_a_v*Parameters.alpha_v); end %Calculate Poiseuille resistance in first half of venule R_ven(gen,1)=(8*Parameters2.mu_app(gen)*Parameters2.L_v(gen)/2)/(pi*radupdate(gen,1)^4); %update soln matrix - capillary terms updated below SOL_MAT(4*gen-1,matrixsize)=-R_ven(gen,1)/2^gen; %CAPILLARY ELEMENT (arteriole + venule + capillary) %the input sheet number is the total number of sheets in an acinus - sheet_number=num; %pressure into the capillaries Pin_cap=GUESS(4*gen-3); %pressure out Pout_cap=GUESS(4*gen-1); %calulate resistance and transit time through a single capillary [R_cap,TT]=CAP_FUNCTION(Pin_cap,Pout_cap,sheet_number,Parameters); %update resistance flow and TT in a single capillary TT_cap(gen)=TT; Q_cap(gen)=(Pin_cap-Pout_cap)/R_cap; Rcap(gen)=R_cap; % Update soln matrix (delta p=QR across a cap) SOL_MAT(submatrixsize+gen,submatrixsize+gen)=-R_cap; Qsheets(gen)=2^(gen-1)*Q_cap(gen); %SECOND HALF OF ARTERIOLE %Update radius of arteriole based on inlet pressure if (GUESS(4*gen-2)-Parameters.Palv)<=Parameters.Pub_a_v radupdate(gen,2)=Parameters2.rad_a(gen)*(1+(GUESS(4*gen-2)-Parameters.Palv)*Parameters.alpha_a); else radupdate(gen,2)=Parameters2.rad_a(gen)*(1+Parameters.Pub_a_v*Parameters.alpha_a); end %Calculate Poiseuille resistance in second half of arteriole - (only %half total generation length) R_art(gen,2)=(8*Parameters2.mu_app(gen)*Parameters2.L_a(gen)/2)/(pi*radupdate(gen,2)^4); %update soln matrix - capillary terms updated below SOL_MAT(4*gen-2,matrixsize)=-R_art(gen,2)/2^gen; SOL_MAT(4*gen-2,submatrixsize+gen)=R_art(gen,2); %% SECOND HALF OF VENULE % Update radius - linear with pressure or constant at high pressure if (GUESS(4*gen)-Parameters.Palv)<=Parameters.Pub_a_v radupdate(gen,2)=Parameters2.rad_v(gen)*(1+(GUESS(4*gen)-Parameters.Palv)*Parameters.alpha_v); else radupdate(gen,2)=Parameters2.rad_v(gen)*(1+Parameters.Pub_a_v*Parameters.alpha_v); end %Poiseuille resistance in second half of venule R_ven(gen,2)=(8*Parameters2.mu_app(gen)*Parameters2.L_v(gen)/2)/(pi*radupdate(gen,2)^4); %update soln matrix - capillary terms updated below SOL_MAT(4*gen,matrixsize)=-R_ven(gen,2)/2^gen; SOL_MAT(4*gen,submatrixsize+gen)=R_ven(gen,2); for i=2:12 %Fill in gaps in solution matrix if gen>=i SOL_MAT(4*gen-3,submatrixsize+(i-1))=R_art(gen,1)/2^(gen-(i-1)); SOL_MAT(4*gen-2,submatrixsize+(i-1))=R_art(gen,2)/2^(gen-(i-1)); SOL_MAT(4*gen-1,submatrixsize+(i-1))=R_ven(gen,1)/2^(gen-(i-1)); SOL_MAT(4*gen,submatrixsize+(i-1))=R_ven(gen,2)/2^(gen-(i-1)); end end end %% ------------FINAL GENERATION---------------------------- %% --------The capillaries covering the alveolar sacs--------- %These are just capillary beds without an associated arteriole/venule - the %9th generation airways in the acinus are completely alveolarised. %the input sheet number is the total number of sheets in an acinus - sheet_number=num;% Pin_cap=GUESS(4*Parameters.num_symm_gen-6); %pressure into final capillary sheets Pout_cap=GUESS(4*Parameters.num_symm_gen-4); %pressure out of final capillary sheets [R_cap,TT]=CAP_FUNCTION(Pin_cap,Pout_cap,sheet_number,Parameters); %caculate resistance and transit time in a single sheet using CAP_FUNCTION TT_cap(Parameters.num_symm_gen)=TT; %TT in the final sheets Q_cap(Parameters.num_symm_gen)=(Pin_cap-Pout_cap)/(R_cap);%flow through an indiviual cappillary sheet Rcap(Parameters.num_symm_gen)=R_cap;%resistance in each sheet of final generation SOL_MAT(matrixsize-1,matrixsize-1)=-R_cap; %update resistace in solution matrix Qsheets(Parameters.num_symm_gen)=2^Parameters.num_symm_gen*Q_cap(Parameters.num_symm_gen);%flow through all the sheets in the final generation %% -----SOLVE SYSTEM----------------------------------- GUESS2=SOL_MAT\SOL_VEC; err=max(abs((GUESS-GUESS2)./(GUESS2)));%calculate maximum difference between successive iteraions GUESS=GUESS2;%update solution %% END OF ITERATIVE LOOP end %% ---FUNCTION OUTPUT GUESS_NEW=GUESS; R_CAP_NEW=Rcap; TT_CAP_NEW=TT_cap;