I am trying to write a program to solve for pipe diameter for a pump system I've designed. I've done this on paper and understand the mechanics of the equations. I would appreciate any guidance.EDIT: I have updated the code with some suggestions from users, still seeing quick divergence. The guesses in there are way too high. If I figure this out I will update it to working.
It seems that the initial values for xold and xolder are too far from the solution. If we change them as xold = 3.0d-5xolder = 9.0d-5and changing the threshold for convergence more tightly as IF (ABS(fx(xnew,L,Q,hf,rho,mu,rough)). Thank you for taking the time out of your day to help me. I originally solved this problem in excel using solver and was given 0.799 inches, reasonable for the size of this system (according to my mentor). As far as the solution goes, I've tried cleaning up the parenthesis and ended up getting the same answers. Units have also been checked multiple times, and I am certain that those are right.
I rewrote the function using my empirical derivation which took all factors besides D out of the function and got the same thing. I didn't want to hard-wire the program and limit its usefulness.–Dec 14 '15 at 4:44. @Jake Hmm, I see. And if you can calculate the answer by Excel, does it agree with the Fortran solution above (e.g.
After some unit conversion etc)? At least, the secant code itself seems to be working correctly.
Also, by 'pre-calculate the constant factors', I mean using some temporary variables to store constant factors as a whole, e.g. CoeffA = hf/(L. 4.Q/pi) to make it easy to see the structure of the expression (not hard-coding the literal numbers). This is also useful for the reader of this site, because it takes time to 'decode' the program.–Dec 14 '15 at 5:25. Yes on excel the answer is reported in feet, so the number is multiplied by 12 to get to inches which ends up being 0.799.
I thought about doing coefficients but thought I couldn't because it would mess the function up but I am working on that now. I also realized I forgot a few terms from the colebrook equation which would explain a lot I am currently working with f=(1/SQRT(hf/((L/D).(((4.0.Q)/(pi D 2))/2.g)))) & +2.0.log10((rough/(3.7.D))+ & ((2.51/((rho.(4.0.Q/piD2).D/mu) & SQRT(hf/((L/D).(((4.0.Q)/(piD.2))/2.g))))))) But am going to simplify it.
Thanks for your help–Dec 14 '15 at 5:30. You very clearly declare the function in the interface (and the implementation) as FUNCTION f(L,D,Q,hf,rho,mu,rough)IMPLICIT NONEINTEGER,PARAMETER::DP=selectedrealkind(15)REAL(DP), PARAMETER::pi=3.14159265, g=9.81REAL(DP), INTENT(IN)::L,Q,rough,rho,mu,hf,DREAL(DP)::fxEND FUNCTIONSo you need to pass 7 arguments to it. And none of them are optional.But when you call it, you call it as xnew=xold-fx(xold).((xolder-xold)/(fx(xolder)-fx(xold))supplying a single argument to it.
When you try to compile it with gfortran for example, the compiler will complain for not getting any argument for D (the second dummy argument), because it stops with the first error.