Yuhao - sorry for the delayed response - I’ve been traveling.
When in doubt, print more numbers out. I modified your code to compute the numerator and denominator of the fraction separately. It’s sometimes helpful to break up computations like this, so you can just test if the denominator is zero before attempting to divide. I think that your checks for zero are not sufficient, since if either DPM
or VRELA
are 0, you get a 0 in the denominator. Instead of trying to check every factor, just compute the denominator and check it, like so:
if((ep_s(IJK,1) .GT. ZERO) .AND. (Mug .GT. ZERO) &
.AND. (ep_g(IJK) .GT. ZERO)) then
!if (DEAD_CELL_AT(I,J,K)) cycle
N_Power = -VOLPARTICLE * P_Grad_diff * VPARTICLE + &
DgA * VRELA * VPARTICLE
write(*,*) "Mug=", Mug
write(*,*) "DPM=", DPM
write(*,*) "ep_g(", IJK, ")=", ep_g(IJK)
write(*,*) "VRELA=", VRELA
NUM = (-VOLPARTICLE * P_Grad_diff + DgA * VRELA)
write(*,*) "NUM=", NUM
DENOM = (3.0d0 * pi * Mug * DPM * ep_g(IJK) * VRELA)
write(*,*) "DENOM=", DENOM
if (DENOM .EQ. 0) then
write(*,*) "WE HAVE A PROBLEM HERE!"
else
write(*,*) "FRACTION=", NUM/DENOM
N_Fd = NUM/DENOM
end if
Running this I get:
Mug= 1.8499999999999999E-005
DPM= 1.1999999999999999E-003
ep_g( 815 )= 0.55539130995879105
VRELA= 1.2600606582530112
NUM= 1.8629709923230549E-004
Mug= 1.8499999999999999E-005
DPM= 0.0000000000000000
ep_g( 0 )= 1.1931191281420263E-319
VRELA= 0.0000000000000000
NUM= 0.0000000000000000
DENOM= 0.0000000000000000
WE HAVE A PROBLEM HERE!
VRELA
is a square root of a sum of squares, so it’s non-negative, but I don’t see why you say it’s nonzero. And there’s not a nonzero test for DPM
anywhere that I can see.
You still can’t divide 0 by 0 and I don’t think the checks you had were sufficient to prevent this.
I hope this helps, please let me know!