ATF_PROJECT_1 (2)

docx

School

Florida Atlantic University *

*We aren’t endorsed by this school

Course

4127

Subject

Mechanical Engineering

Date

Jan 9, 2024

Type

docx

Pages

6

Uploaded by ChancellorZebraPerson942

Report
Matlab: This is a program that will determine (a) the flow rate distribution in a loop network system by the Hardy-Cross method and (b) the total head at ach node. Parameters are given, and they are follows; allow for a maximum of ten loops with a maximum of ten lines in a loop, calculate the flow rates before the total head with respect to the give dimensions of the created program. A test case 1 is given with known flow rates distribution and total head values; this given case will be tested with the created Matlab program, once this is tested and it function properly, it will be apply to the following pipe system where the values will be randomly generated. MATLAB code for the first system of pipes %Project1test.m %EML 4127 (Applied Thermal Fluids) %Manuel Armatrading & Mattew Lawrence clear; clc; %Input/Known Data NL = 3 %Number of Loops NJ = [4 4 4] %Number of Lines in Each Loop ID = [2 3 0 0;0 0 0 1;0 0 0 1] %Identifies Which Line is a Common Line Qin = 10.8; %Flow Rate at inlet EPSLN = 0.0001; %Maximum allowable difference in flow rates g = 32.2; %Gravitational acceleration p=1.94; u=1.082*10^(-5); e=.00085 D1 = 10/12; %Pipe # 1 Diameters (in Feet) D2 = 12/12; %Pipe # 2 Diameters (in Feet) D3 = 14/12; %Pipe # 3 Diameters (in Feet) D4 = 16/12; %Pipe # 4 Diameters (in Feet) %Assumes no minor losses %Define matrices which describe pipe diameters and pipe lengths ZL = [10560 15840 10560 15840; 15840 13200 10560 10560;... 15840 15840 15840 15840]; D = [D4 D2 D3 D4;D4 D3 D2 D4;D2 D1 D2 D2]; K= [0 0 0 0 ; 0 0 0 0 ; 0 0 0 0]; %Initial Guess for Flow Rates Q = [3 1.5 -1.6 -4; 3.8 1.7 0.3 -3; 1.8 0.4 -1 -1.5] %Flow Rate (gpm) %% ======================================================================%
%Start value for flow difference (1 was chosen randomly) err=1; %Index for the while loop IW=0; while err> EPSLN %Sets condition that as long as difference is %greater than EPSNL the loop will run. IW=IW+1; for i=1:NL for j=1:NJ Re(i,j)=p*abs(Q(i,j))/(pi/4*(D(i,j))^2)*ZL(i,j)/u; f(i,j)=1.325/(log(e/3.7/D(i,j)+5.74/(Re(i,j))^.9))^2; dfdQ(i,j)=(13.69*(e/3.7/D(i,j)+5.74/(Re(i,j))^.9)^(-1))/... ((Re(i,j))^2*abs(Q(i,j))*log(e/... 3.7/D(i,j)+5.74/(Re(i,j))^.9)); A(i,j)=8*ZL(i,j)/(pi^2*g*(D(i,j))^5); B(i,j)=(8*K(i,j))/(pi^2*g*(D(i,j))^4); %Calculation of head loss if Q(i,j)>0; HF(i,j)=A(i,j)*(Q(i,j))^2*f(i,j)+B(i,j)*Q(i,j)^2; DHDQ(i,j)=2*A(i,j)*Q(i,j)+... A(i,j)*(Q(i,j))^2*dfdQ(i,j)+... 2*B(i,j)*Q(i,j)+B(i,j)*(Q(i,j))^2*dfdQ(i,j); elseif Q(i,j)==0 HF(i,j)=0; DHDQ(i,j)=0; else HF(i,j)=-(A(i,j)*(Q(i,j))^2*f(i,j)+B(i,j)*Q(i,j)^2); DHDQ(i,j)=-(2*A(i,j)*Q(i,j)+... A(i,j)*(Q(i,j))^2*dfdQ(i,j)+... 2*B(i,j)*Q(i,j)+B(i,j)*(Q(i,j))^2*dfdQ(i,j)); end SHF(i)=sum(HF(i,:)); SDHDQ(i)=sum(DHDQ(i,:)); DELQ(i)=-SHF(i)/SDHDQ(i); HFo(i,j)=HF(i,j); end end for i=1:NL for j=1:NJ if ID(i,j)==0 NEWQ(i,j)=Q(i,j)+DELQ(i); elseif ID(i,j)==911 NEWQ(i,j)=Q(i,j); else NEWQ(i,j)=Q(i,j)+DELQ(i)-DELQ(ID(i,j)); end err=abs(NEWQ(i,j)-Q(i,j)); Q(i,j)=NEWQ(i,j); end end if IW>100 break end IW;
end %% Total Head Calculation for each node %% for i=1:NL disp('enter head at node 1 of loop') HPo(i)=input('') HP(i,1)=HPo(i); for j=1:NJ(i) if j~=1 HP(i,j)=HP(i,j-1)-HFo(i,j-1); end end HP end fid=fopen('Test_results.dat','w') fprintf(fid,'TEST CASE RESULTS\n'); fprintf(fid,'\n\n'); fprintf(fid,'\n\n Flow Rate Distribution\n'); fprintf(fid,' LOOP # | LINE 1 LINE 2 LINE 3 LINE 4 \n'); fprintf(fid,'***************************************************************** **********\n'); for i=1:NL fprintf(fid, '\n%5.0f | ', i); for j=1:NJ fprintf(fid,'\t %7.3f ', Q(i,j) ); end fprintf(fid, '\n'); end fprintf(fid,'\n\n Head Loss at each node \n'); fprintf(fid,' LOOP # | NODE 1 NODE 2 NODE 3 NODE 4 \n'); fprintf(fid,'***************************************************************** **********\n'); for i=1:NL fprintf(fid, '\n%5.0f | ', i); for j=1:NJ fprintf(fid,'\t %7.3f ', HP(i,j) ); end fprintf(fid, '\n'); end fprintf(fid,'\n\n Numbers of Iterations :'); fprintf(fid,'%7.3f ', IW );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
MATLAB code for the second system of pipes %Project1.m %EML 4127 (Applied Thermal Fluids) %Manuel Armatrading and Mattew Lawrence clear clc NL = 3; %Number of Loops NJ = [5 4 4]; %Number of Lines in Each Loop ID = [0 0 0 1 1; 1 1 0 0 0; 1 0 0 1 0]; %Identifies Which Line is a Common Line Qin = 5; %Flow Rate at inlet EPSLN = 0.0001; %Maximum allowable difference in flow rates g = 32.2; %Gravitational acceleration p=1.46; u=1.082*10^(-5); e=.00085; D1 = 10/12; %Pipe # 1 Diameters (in Feet) D2 = 10/12; %Pipe # 2 Diameters (in Feet) D3 = 10/12; %Pipe # 3 Diameters (in Feet) D4 = 10/12; %Pipe # 4 Diameters (in Feet) D5 = 10/12; D6 = 10/12; D7 = 10/12; D8 = 10/12; D9 = 10/12; D10= 10/12; D11= 10/12; D12= 10/12; %Assumes no minor losses %Define matrices' which describe pipe diameters and pipe lengths ZL = [2000 2000 2000 1000 1000; 1000 1600 1000 1600 0; 1000 1600 1000 1600 0]; D = [D1 D3 D9 D7 D4; D4 D6 D5 D2 0; D7 D10 D8 D6 0]; K= [.40 .75 .40 .40 .40; .40 .40 .40 .75 0; .40 .40 .75 .40 0]; %Initial Guess for Flow Rates Q = [2.1, 2.1, 2.9, 1.5, 0.3; 0.3, 1.2, 2.6, 2.4, 0; 1.5, 1.4, 1.4, 1.2, 0]; %Start value for flow difference (1 was chosen randomly) err=1; %Index for the while loop IW=0; while err> EPSLN %Sets condition that as long as difference is %greater than EPSNL the loop will run. IW=IW+1; for i=1:NL for j=1:NJ Re(i,j)=p*abs(Q(i,j))/(pi/4*(D(i,j))^2)*ZL(i,j)/u; f(i,j)=1.325/(log(e/3.7/D(i,j)+5.74/(Re(i,j))^.9))^2; dfdQ(i,j)=(13.69*(e/3.7/D(i,j)+5.74/(Re(i,j))^.9)^(-1))/ ... ((Re(i,j))^2*abs(Q(i,j))*log(e/ ...
3.7/D(i,j)+5.74/(Re(i,j))^.9)); A(i,j)=8*ZL(i,j)/(pi^2*g*(D(i,j))^5); B(i,j)=(8*K(i,j))/(pi^2*g*(D(i,j))^4); %Calculation of head loss if Q(i,j)>0; HF(i,j)=A(i,j)*(Q(i,j))^2*f(i,j)+B(i,j)*Q(i,j)^2; DHDQ(i,j)=2*A(i,j)*Q(i,j)+ ... A(i,j)*(Q(i,j))^2*dfdQ(i,j)+ ... 2*B(i,j)*Q(i,j); elseif Q(i,j)==0 HF(i,j)=0; DHDQ(i,j)=0; else HF(i,j)=-(A(i,j)*(Q(i,j))^2*f(i,j)+B(i,j)*Q(i,j)^2); DHDQ(i,j)=-(2*A(i,j)*Q(i,j)+ ... A(i,j)*(Q(i,j))^2*dfdQ(i,j)+ ... 2*B(i,j)*Q(i,j)); end SHF(i)=sum(HF(i,:)); SDHDQ(i)=sum(DHDQ(i,:)); DELQ(i)=-SHF(i)/SDHDQ(i); HFo(i,j)=HF(i,j); end end for i=1:NL for j=1:NJ if ID(i,j)==0 NEWQ(i,j)=Q(i,j)+DELQ(i); elseif ID(i,j)==24 NEWQ(i,j)=Q(i,j); else NEWQ(i,j)=Q(i,j)+DELQ(i)-DELQ(ID(i,j)); end err=abs(NEWQ(i,j)-Q(i,j)); Q(i,j)=NEWQ(i,j); end end if IW>100 break end IW; end %% Total Head Calculation for each node %% for i=1:NL disp( 'enter head at node 1 of loop' ) HPo(i)=input( '' ) HP(i,1)=HPo(i); for j=1:NJ(i) if j~=1 HP(i,j)=HP(i,j-1)-HFo(i,j-1); end
end HP end fid=fopen( 'Test_results1.dat' , 'w' ) fprintf(fid, 'TEST CASE RESULTS\n' ); fprintf(fid, '\n\n' ); fprintf(fid, '\n\n Flow Rate Distribution\n' ); fprintf(fid, ' LOOP # LINE 1 LINE 2 LINE 3 LINE 4 \n' ); fprintf(fid, '***************************************************************** **********\n' ); for i=1:NL fprintf(fid, '\n%5.0f | ' , i); for j=1:NJ fprintf(fid, '\t %7.3f ' , Q(i,j) ); end fprintf(fid, '\n' ); end fprintf(fid, '\n\n Head Loss at each node \n' ); fprintf(fid, ' LOOP # | NODE 1 NODE 2 NODE 3 NODE 4 \n' ); fprintf(fid, '***************************************************************** **********\n' ); for i=1:NL fprintf(fid, '\n%5.0f | ' , i); for j=1:NJ fprintf(fid, '\t %7.3f ' , HP(i,j) ); end fprintf(fid, '\n' ); end fprintf(fid, '\n\n Numbers of Iterations :' ); fprintf(fid, '%7.3f ' , IW );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help