# A function that solves the n coupled airway BG model function seven_airway2(t,y,order,parm) numBr = 2^order - 1; r = y[1:numBr] uv = y[numBr+1: 2*numBr]' vv = y[2*numBr+1:3*numBr]' vds = y[3*numBr+1:( return [U,UVDOT,VVDOT,force,phosphorylation,pmid] end-4)]' # RR = y[end-6:end]' RR = y[end-3:end]' M = RR[1]; Mp = RR[2]; AMp = RR[3]; AM = RR[4] ## Construct the constant array as a persistent variable # So that repeated calls to this function doesn't result in repeated # calculations of C persistent C if isempty(C) @sprintf("Constructing the structure array of constants...\n") C = createConstSymm[order] @sprintf("Finished.\n") end ## Parameters for MoC model rho=2 ## Define the constants f = 0.2 A = 5e5; # Used to be 5e5 # Pref = 10+ 10*sin(2*pi*f*t).*(t<=60)+ 120*sin(2*pi*f*t).*(t>60 && t<62)+ 10*sin(2*pi*f*t).*(t>=62) # Rref = 0.2792 P0 = 10 Pref = 10 + P0*sin(2*pi*f*t) Rref=0.4140 ptop = Pref # kappa = 0.25*parm[1,:].*(t<=60) + 0.5*parm[1,:].*(t>60 && t<=120) + 0.75*parm[1,:].*(t>120 && t<=180) + (parm[1,:]).*(t>=180); kappa = parm[1,:] # epsilon = 10^(parm[2,:]); # A parameter that controls sliding between Type II & Type I + II epsilon = 0 qhat = -50 N = 2^order - 1; # number of branches for symmetric trees numOrd1 = (N+1)/2 E1 = 2.5; #cmH20/ml ## Setting up BG parameters E = 25 h1 = 0.9732 k11 = 0.0057 k22 = 0.2096 k33 = 0.0904 rho1 = 1.225 R = zeros(N,1) Rv = zeros(N,1) CC = zeros(N,1) I = zeros(N,1) pa_bar = zeros(N,1) alph = zeros(N,1) pbot = zeros(N,1) u=zeros(N,1) pmid = zeros(N,1) for i=1:N air_ord = C.order[i] # CC[i] = (2*pi*C.L[air_ord].*r[i]^3)/(E*h1) WT[i] = (k11.*(2*r[i])^2)/4 + (k22.*(2.*r[i]))/2 +k33;#wall thickness CC[i] = (C.L[air_ord]*(2*r[i])^3)/(4*E*WT[i]);# I[i] = rho1*C.L[air_ord]/(pi.*r[i]^2) R[i] = C.alpha(air_ord).*r[i]^(-4) Rv[i] = 0.01/CC[i] pa_bar[i] = (P0*E1)./sqrt(E1^2 + (2*pi*f*R[i])^2) alph[i] = atan((2*pi*f*R[i])./E1) pbot[i] = 10+pa_bar[i]*sin(2*pi*f*t-alph[i]) end ## for a = numOrd1+1:N uv[a] = (vv[a]-vv[2*(a-numOrd1)]-vv[2*(a-numOrd1)-1])/CC[a] u[a] = uv[a] +Rv[a]*((2*(a-numOrd1))-vv[2*(a-numOrd1)-1]) end for b = 1:numOrd1 uv[b] = (vv[b]-vds[b])/CC[b] u[b] = uv[b] + Rv[b]*(vv[b]-vds[b]) vds[b] = (uv[b]-pbot[b]-(R[b]/2)*vds[b])/(I[b]/2) end for d = 1:N-1 a[d] =((2*d) - 1) aa = a[a5); k6 =k1 # dt=0.5*t # force=kappa*(rr[2]+rr[5]) force = kappa*(AMp+AM) # stiffness =rr[1]+rr[4] phosphorylation = AMp+Mp # pmid = 0.5*(gammajplus + gammajminus) # Ptm = zeros(N,1) Ptm = pmid - (force*Rref./r')+ tau for i=1:N air_ord = C.order[i]; # Determine the order of the current airway # Ptm[i] = pmid[i] - (force*Rref/r[i])+ tau[i] if Ptm[i] <= 0 R[i] = sqrt((C.Ri[air_ord]^2)*(1 - Ptm[i]./C.P1[air_ord])^(-C.n1[air_ord])) elseif Ptm[i] >= 0 R[i] = sqrt(C.rimax[air_ord]^2 - (C.rimax[air_ord]^2 - C.Ri[air_ord]^2)*(1 - Ptm[i]/C.P2[air_ord])^(-C.n2[air_ord])) end # # drdt[i]=rho*(R[i]-(r[i])); # V[i]=-((gamma)/(2*pi*Rref))*drdt[i]; RDOT=rho*((R)-r') end F = [-k1*M+k2*Mp+k7*AM k4*AMp+k1*M-(k2+k3)*Mp k3*Mp+k6*AM-(k5+k4)*AMp k5*AMp-(k6+k7)*AM]' RRDOT=RDOT' # size(RRDOT) UVDOT = uv' # size(UVDOT) VVDOT = vv' # size(VVDOT) VDSDOT = vds' # size(VDSDOT) # NN = [RRDOT UVDOT VVDOT VDSDOT]' U=u' end