220 likes | 365 Views
Assignment. Colebrook Formula:. Source Code. PROGRAM colebrook !e = pipe roughness (mm) !d = pipe inside diameter (in) !relruff = relative roughness (dim) !re = Reynolds Number (dim) !f = Darcy-Weisbach Friction Factor (dim) IMPLICIT NONE REAL :: f, f0, f1, re, e, d, relruff
E N D
Assignment • Colebrook Formula:
Source Code • PROGRAM colebrook • !e = pipe roughness (mm) • !d = pipe inside diameter (in) • !relruff = relative roughness (dim) • !re = Reynolds Number (dim) • !f = Darcy-Weisbach Friction Factor (dim) • IMPLICIT NONE • REAL:: f, f0, f1, re, e, d, relruff • INTEGER:: k • WRITE(*,*)'Enter e in mm & D in inches' • READ(*,*) e, d • WRITE(*,*)'Pipe Roughness, e =',e,'mm ','Pipe Diameter, D =',d,'inches' • relruff = e/(d*25.4) • WRITE(*,*)'relative roughness =', relruff • WRITE(*,*)'Enter Reynolds No' • DO k = 1, 6 • READ(*,*) re • f0 = .25*((LOG10((relruff/3.7)+(5.74/(re**.9))))**(-2)) • f1 = (-2.)*LOG10(((relruff/3.7)+(2.51/(re*(f0**.5))))) • f = (1./f1)**2 • WRITE(*,*)'For Reynolds No =',re,'Darcy-Weisbach Friction Factor =',f • END DO • END
Output #1 • c:\FortranSources>colebrook • Enter e in mm & D in inches • .26,.622 • Pipe Roughness, e = 0.26 mm Pipe Diameter, D = 0.622 inches • relative roughness = 1.6456947E-02 • Enter Reynolds No • 3000 • For Reynolds No = 3000.00 D-W Friction Factor = 5.6546558E-02 • 10000 • For Reynolds No = 10000.00 D-W Friction Factor = 4.9191877E-02 • 100000 • For Reynolds No = 100000.0 D-W Friction Factor = 4.5635339E-02 • 1.e06 • For Reynolds No = 1000000. D-W Friction Factor = 4.5242310E-02 • 1.e07 • For Reynolds No = 1.000E+07 D-W Friction Factor = 4.5202494E-02 • 1.e08 • For Reynolds No = 1.000E+08 D-W Friction Factor = 4.5198508E-02
Output #2 • c:\FortranSources>colebrook • Enter e in mm & D in inches • .26,2.067 • Pipe Roughness, e = 0.26 mm Pipe Diameter, D = 2.067 inches • relative roughness = 4.9522114E-03 • Enter Reynolds No • 3000 • For Reynolds No = 3000.000 D-W Friction Factor = 4.7594767E-02 • 10000 • For Reynolds No = 10000.00 D-W Friction Factor = 3.7515681E-02 • 100000 • For Reynolds No = 100000.0 D-W Friction Factor = 3.1220451E-02 • 1.e6 • For Reynolds No = 1000000. D-W Friction Factor = 3.0377490E-02 • 1.e7 • For Reynolds No = 1.000E+07 D-W Friction Factor = 3.0289246E-02 • 1.e8 • For Reynolds No = 1.000E+08 D-W Friction Factor = 3.0280370E-02
Good Practice Summary • Use meaningful variable names whenever possible. • Always use the IMPLICIT NONE statement. • Create a data dictionary. • Use a consistent number of significant digits in constants. • Specify all constants with as much precision as your computer will support. • Use integer arithmetic only for things that are intrinsically integer, such as indexes and counters. • Avoid mixed-mode arithmetic except for exponentiation. • Use extra parentheses whenever necessary. • Always echo ( i.e. Print) variables you enter into a program. • Initialize all variables in a program before using them. • Always print the physical units associated with any value being written out.
Scientific Programming More & More Basics
New Input Instruction • To input values into a program during execution: • WRITE (*,*) ‘Input a,b,c,etc.’ • READ (*,*) a,b,c,…..
Top Down Program Design An algorithm (pronounced AL-go-rith-um) is a procedure or formula for solving a problem. The word derives from the name of the mathematician, Mohammed ibn-Musa al-Khwarizmi, who was part of the royal court in Baghdad and who lived from about 780 to 850. Al-Khwarizmi's work is the likely source for the word algebra as well.
Programming Aids • Flowcharts • Pseudocode
Pseudocode Write each Fortran instruction in the language of your choice • i.e., for the flowchart example: • Prompt user to enter temperature in oF • Read this temperature input • Calculate temperature in K • Write temperature in K
Program Design Summary • I’m going to suggest a less structured approach: • Flowcharting is useful but don’t get stressed trying to use the conventional symbols – the important thing in flowcharting is developing the proper sequence of operations • Use pseudocode to annotate (fill in) the flowchart
Logical Constants & Variables • Logical Constants • C1 = .TRUE. or, C2 = .FALSE. • Logical Variables • a1, a2, a3 – values, .TRUE. or .FALSE., may vary as a result of operation of the program • i.e. – a1 = (logical expression) • LOGICAL:: a1, a2, a3, etc – include with INTEGER:: & REAL:: type statements • READ(*,*) a1, a2, a3 – The input value must begin w/ T or F
Relational Operators • Relational Operators • == Equal To (Note doubling - ==) • /= Not Equal To • > Greater Than • >= Greater Than or Equal To • < Less Than • <= Less Than or Equal To • Examples • 6<8 .TRUE. , 6>8 .FALSE., 6==8 .FALSE. • 6<=8 .TRUE., 6>=8 .FALSE., 6>=6 .TRUE.
Combinational Operators • L1.AND.L2 • .TRUE. If both are .TRUE. • L1.OR.L2 • .TRUE. If either or both are .TRUE. • L1.EQV.L2 • .TRUE. If L1 & L2 are the same • L1.NEQV.L2 • .TRUE. If L1 & L2 are different • .NOT.L1 • Opposite L1
Combinational Operators • Hierarchy of Operations • Arithmetic • Relational L to R • .NOT. • .AND. L to R • .OR. L to R • .EQV. & .NEQV. L to R • Use ( ) to control the order
In-Class Exercise • Given: • REAL:: a=-10., b=.1, c=2.1 • LOGICAL:: L1=.TRUE., L2=.FALSE., L3=.FALSE. • a>b.OR.b>c • (.NOT.a).OR.L1 • L1.AND..NOT.L2 • a<b.EQV.b<c • L1.OR.L2.AND.L3. • L1.OR.(L2.AND.L3) • (L1.OR.L2).AND.L3 • a.OR.b.AND.L1
In-Class Exercise • Given: • REAL:: a=-10., b=.1, c=2.1 • LOGICAL:: L1=.TRUE., L2=.FALSE., L3=.FALSE. • a>b.OR.b>c FALSE • (.NOT.a).OR.L1 INVALID • L1.AND..NOT.L2 TRUE • a<b.EQV.b<c TRUE • L1.OR.L2.AND.L3. TRUE • L1.OR.(L2.AND.L3) TRUE • (L1.OR.L2).AND.L3 FALSE • a.OR.b.AND.L1 INVALID
Assignment • Read & Understand The Material In This Slide Set • Construct A Flowchart w/ Pseudocode To Evaluate The Roots Of A Quadratic Equation, Including Complex Roots