Silverfrost Forums

Welcome to our forums

Value of argument (DHYD) not being passed.

23 May 2022 4:15 #28993

The value of argument (DHYD) is not being passed from SUBROUTINE to a FUNCTION. I verified the value exists in the SUBROUTINE but when I print out the value in the FUNCTION it is 0.0 instead of 0.177013. Output from PLATO DEBUG:

S E T V A R I A B L E S AT TIME = 0.000 DAYS FLOWING OPTION = TWO-PHASE STEAM PRODUCTION STEAM QUALITY = 0.160 INLET TEMPERATURE = 460. F FLOW RATE = 580. GAL/MIN TIME TO CHANGE DATA = 1.000 DAYS 510.928 1.124066E-04 2.337134E+06 -59358.3 0.00000 0.177013 2 2.337134E+06 -59358.3 0.00000 0.00000 2

FIRST STATEMENT IS WRITE IN SUBROUTINE AND SECOND WRITE IS WRITE IN FUNCTION.

SUBROUTINE (PORTION OF CODE RESPONSIBLE - SEE FRAC) C BUBBLE FLOW C 20 RE=D2DHYDV2/SLVIS(T1) C C DEBUG WRITE(6,)RE,WN,SN,DHYD,2 C FRAC=FR2P(RE,WN,SN,DYHD,2) RL=RLORK(V1,V2) DPFR=.5FRAC/DHYDD2(V2/RL)*2DZ DPGR=GG(RL(D2-D1)+D1)*DZ IFRG=2

FUNCTION FR2P(RE,WN,SN,DHYD,IK) C C DEBUG WRITE(6,)RE,WN,SN,DHYD,IK C C DARCY FRICTION FACTOR FOR TWO PHASE FLOW C C IK = 1 COMMERCIAL STEEL RR=.0000457/DHYD C C IK = 2 GALVANIZED IRON IF(IK.EQ.2)RR=.000152/DHYD C C IK = 3 DUNN AND ROS MIST FLOW E/D IF(IK.NE.3)GO TO 1 IF(WN.GT.0.005)RR=174.8SNWN0.302 IF(WN.LE.0.005)RR=34.SN IF(RR.GT.0.5)RR=0.5 IF(RR.LT.1.E-3)RR=1.E-3 C 1 CONTINUE A=.026RR.225+0.133RR B=22.RR**0.44 C=-1.62RR0.134 FRIC=A+B*REC FR2P=4.*FRIC FRICL=64./RE IF(FRICL.GT.FR2P)FR2P=FRICL RETURN END

24 May 2022 12:23 #28994

Jim, as is often the case when we can see only snippets of code, there is nothing that I can see that could have caused the discrepancy. Please make the entire code available (preferably, zip up the sources, upload to a cloud service, and post a link to the file with public access enabled).

P.S. I just noticed that WN, which is reported to have the value -59358.3, is compared to 0.005 and one of two relations is selected depending on the comparison. Something fishy here, no?

The explanation for DHYD 'switching' to zero across the subroutine call: you misspelled the fourth actual argument to FR2P as DYHD instead of DHYD. If you are not protected against making such errors, use IMPLICIT NONE in your subprograms. Doing so will get the compiler to catch such errors.

25 May 2022 8:50 #28995

Here is a cleaned-up and reformatted version of Jim's program in a form fit to present to the compiler. I have retained the bug in the reference to the function fr2p.

program jhydr
   implicit none
   real re, wn, sn, dhyd, frac
   integer ik
 
   re = 2.337134e+06 
   wn = -59358.3 
   sn = 0.00000 
   dhyd = 0.177013
   ik = 2

   frac=fr2p(re,wn,sn,dyhd,ik) ! bug on this line
   print *,frac

contains

   real function fr2p(re,wn,sn,dhyd,ik)
   implicit none
   integer ik
   real re,wn,sn,dhyd,rr,a,b,c,fric,fricl

   write(*,*)re,wn,sn,dhyd,ik
   select case(ik)
      case(1)
! ik = 1 commercial steel
          rr=.0000457/dhyd
      case(2)
! ik = 2 galvanized iron
         rr=.000152/dhyd
      case(3)
! ik = 3 dunn and ros mist flow e/d
         if(wn.gt.0.005)then
            rr=174.8*sn*wn**0.302
         else
            rr=34.*sn
         endif
         rr = max(min(rr,0.5),1e-3)
   end select
   a=.026*rr**.225+0.133*rr
   b=22.*rr**0.44
   c=-1.62*rr**0.134
   fric=a+b*re**c
   fr2p=max(4.*fric,64./re)
   return
end function
end program
25 May 2022 5:54 #28996

Hi mecej4,

Thank you for catching that typo! I looked and looked for the error and it was right in front of me! 😮ops:

Would you make a suggestion for a cloud service to upload to per your comment below?

'Please make the entire code available (preferably, zip up the sources, upload to a cloud service, and post a link to the file with public access enabled).'

25 May 2022 11:20 #28997

Jim, many of the popular free email providers such as Google, Microsoft, Yahoo, etc., provide some cloud storage as a perk. For short programs such as yours, services such as https://paste.ofcode.org/87ieDtWUeWNqqbTRNEn8VH can also be used. That particular site holds posts for just one week, so it is suitable for exchange codes and mark-ups that are not needed to be stored 'permanently'.

Please login to reply.