正割方法,否定答案

时间:2015-12-14 01:43:55

标签: fortran numerical-methods fluid-dynamics

我正在尝试编写一个程序来解决我设计的泵系统的管道直径。我已经在纸上和excel中完成了这项工作并理解了方程式的机制。我很感激任何指导。

此时我正在编译但在第一次迭代时得到否定答案,我现在的猜测是它与我的初始猜测,传递给函数的变量或割线计算代码本身有关。 phead,pump和hf的三项检查是正确的。

MODULE Sec
CONTAINS

SUBROUTINE Secant(fx,xold,xnew,xolder)
IMPLICIT NONE
INTEGER,PARAMETER::DP=selected_real_kind(15)
REAL(DP), PARAMETER:: gamma=62.4
REAL(DP)::z,phead,hf,L,Q,mu,rho,rough,eff,pump,nu,ppow,fric,pres,xnew,xold,xolder,D
INTEGER::I,maxit

INTERFACE
FUNCTION fx(D,L,Q,hf,rho,mu,rough)
Omitted
END FUNCTION
END INTERFACE

Q=0.0353196
Pres=-3600.0
z=-10.0
L=50.0
mu=0.0000273 
rho=1.940
nu=0.5
rough=0.000005
ppow=412.50
xold=1.0
xolder=0.5

phead = (pres/gamma)
WRITE(*,*) phead

pump = (nu*ppow)/(gamma*Q)
WRITE(*,*)pump

hf = phead + z + pump
WRITE(*,*)hf

maxit=20
I = 1

DO
xnew=xold-fx(xold,L,Q,hf,rho,mu,rough)*((xolder-xold)/(fx(xolder,L,Q,hf,rho,mu,rough)-fx(xold,L,Q,hf,rho,mu,rough)))

xolder = xold
xold = xnew
I=I+1
WRITE(*,*) "Diameter = ", xnew
IF (ABS(fx(xnew,L,Q,hf,rho,mu,rough)) <= 0.05) THEN
EXIT
END IF

IF (I >= maxit) THEN
EXIT
END IF 
END DO

END SUBROUTINE Secant
END MODULE Sec

PROGRAM Pipes
USE Sec
IMPLICIT NONE
INTEGER,PARAMETER::DP=selected_real_kind(15)
REAL(DP)::xold,xolder,xnew

INTERFACE
FUNCTION f(D,L,Q,hf,rho,mu,rough)
Omitted
END INTERFACE

CALL Secant(f,xold,xnew,xolder)

END PROGRAM Pipes

FUNCTION f(D,L,Q,hf,rho,mu,rough)
IMPLICIT NONE
INTEGER,PARAMETER::DP=selected_real_kind(15)
REAL(DP), PARAMETER::pi=3.14159265, g=9.81
REAL(DP), INTENT(IN)::L,Q,rough,rho,mu,hf,D
REAL(DP)::f

f=(1/(hf/((L/D)*((4*Q)/pi*D))))+2.0*log((rough/(3.7*D))+(2.51/(((rho*((4*Q)/pi*D))/mu)*(hf/((L/D)*((4*Q)/pi*D))))))
END FUNCTION

0 个答案:

没有答案