Skip to content

Commit 72d4fef

Browse files
XZTian64Xuzheng Tiansbryngelson
authored
Wrong integer numbers (#887)
Co-authored-by: Xuzheng Tian <xtian64@login-phoenix-rh9-3.pace.gatech.edu> Co-authored-by: Spencer Bryngelson <sbryngelson@gmail.com>
1 parent b605d41 commit 72d4fef

31 files changed

+278
-238
lines changed

src/common/m_checker_common.fpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ contains
322322
@:PROHIBIT(surface_tension .and. sigma < 0._wp, &
323323
"sigma must be greater than or equal to zero")
324324

325-
@:PROHIBIT(surface_tension .and. sigma == dflt_real, &
325+
@:PROHIBIT(surface_tension .and. f_approx_equal(sigma, dflt_real), &
326326
"sigma must be set if surface_tension is enabled")
327327

328328
@:PROHIBIT(.not. f_is_default(sigma) .and. .not. surface_tension, &
@@ -347,9 +347,12 @@ contains
347347
!! Called by s_check_inputs_common for all three stages
348348
impure subroutine s_check_inputs_moving_bc
349349
#:for X, VB2, VB3 in [('x', 'vb2', 'vb3'), ('y', 'vb3', 'vb1'), ('z', 'vb1', 'vb2')]
350-
if (any((/bc_${X}$%vb1, bc_${X}$%vb2, bc_${X}$%vb3/) /= 0._wp)) then
350+
if (.not. (f_approx_equal(bc_${X}$%vb1, 0._wp) .and. &
351+
f_approx_equal(bc_${X}$%vb2, 0._wp) .and. &
352+
f_approx_equal(bc_${X}$%vb3, 0._wp))) then
351353
if (bc_${X}$%beg == BC_SLIP_WALL) then
352-
if (any((/bc_${X}$%${VB2}$, bc_${X}$%${VB3}$/) /= 0._wp)) then
354+
if (.not. (f_approx_equal(bc_${X}$%${VB2}$, 0._wp) .and. &
355+
f_approx_equal(bc_${X}$%${VB3}$, 0._wp))) then
353356
call s_mpi_abort("bc_${X}$%beg must be -15 if "// &
354357
"bc_${X}$%${VB2}$ or bc_${X}$%${VB3}$ "// &
355358
"is set. Exiting.", CASE_FILE_ERROR_CODE)
@@ -362,9 +365,12 @@ contains
362365
#:endfor
363366

364367
#:for X, VE2, VE3 in [('x', 've2', 've3'), ('y', 've3', 've1'), ('z', 've1', 've2')]
365-
if (any((/bc_${X}$%ve1, bc_${X}$%ve2, bc_${X}$%ve3/) /= 0._wp)) then
368+
if (.not. (f_approx_equal(bc_${X}$%ve1, 0._wp) .and. &
369+
f_approx_equal(bc_${X}$%ve2, 0._wp) .and. &
370+
f_approx_equal(bc_${X}$%ve3, 0._wp))) then
366371
if (bc_${X}$%end == BC_SLIP_WALL) then
367-
if (any((/bc_${X}$%${VE2}$, bc_${X}$%${VE3}$/) /= 0._wp)) then
372+
if (.not. (f_approx_equal(bc_${X}$%${VE2}$, 0._wp) .and. &
373+
f_approx_equal(bc_${X}$%${VE3}$, 0._wp))) then
368374
call s_mpi_abort("bc_${X}$%end must be -15 if "// &
369375
"bc_${X}$%${VE2}$ or bc_${X}$%${VE3}$ "// &
370376
"is set. Exiting.", CASE_FILE_ERROR_CODE)

src/common/m_eigen_solver.f90

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module m_eigen_solver
1010

1111
use m_precision_select
1212

13+
use m_helper_basic !< Functions to compare floating point numbers
14+
1315
implicit none
1416

1517
private;
@@ -124,7 +126,7 @@ pure subroutine cbal(nm, nl, ar, ai, low, igh, scale)
124126

125127
do 110 i = 1, l
126128
if (i == j) go to 110
127-
if (ar(j, i) /= 0.0_wp .or. ai(j, i) /= 0.0_wp) go to 120
129+
if (.not. f_approx_equal(ar(j, i), 0.0_wp) .or. .not. f_approx_equal(ai(j, i), 0.0_wp)) go to 120
128130
110 end do
129131

130132
ml = l
@@ -140,7 +142,7 @@ pure subroutine cbal(nm, nl, ar, ai, low, igh, scale)
140142

141143
do 150 i = k, l
142144
if (i == j) go to 150
143-
if (ar(i, j) /= 0.0_wp .or. ai(i, j) /= 0.0_wp) go to 170
145+
if (.not. f_approx_equal(ar(i, j), 0.0_wp) .or. .not. f_approx_equal(ai(i, j), 0.0_wp)) go to 170
144146
150 end do
145147

146148
ml = k
@@ -164,7 +166,7 @@ pure subroutine cbal(nm, nl, ar, ai, low, igh, scale)
164166
r = r + abs(ar(i, j)) + abs(ai(i, j))
165167
200 end do
166168
! guard against zero c or r due to underflow
167-
if (c == 0.0_wp .or. r == 0.0_wp) go to 270
169+
if (f_approx_equal(c, 0.0_wp) .or. f_approx_equal(r, 0.0_wp)) go to 270
168170
g = r/radix
169171
f = 1.0_wp
170172
s = c + r
@@ -242,7 +244,7 @@ pure subroutine corth(nm, nl, low, igh, ar, ai, ortr, orti)
242244
do 90 i = ml, igh
243245
scale = scale + abs(ar(i, ml - 1)) + abs(ai(i, ml - 1))
244246
90 end do
245-
if (scale == 0._wp) go to 180
247+
if (f_approx_equal(scale, 0._wp)) go to 180
246248
mp = ml + igh
247249
! for i=igh step -1 until ml do
248250
do 100 ii = ml, igh
@@ -254,7 +256,7 @@ pure subroutine corth(nm, nl, low, igh, ar, ai, ortr, orti)
254256

255257
g = sqrt(h)
256258
call pythag(ortr(ml), orti(ml), f)
257-
if (f == 0._wp) go to 103
259+
if (f_approx_equal(f, 0._wp)) go to 103
258260
h = h + f*g
259261
g = g/f
260262
ortr(ml) = (1.0_wp + g)*ortr(ml)
@@ -374,8 +376,8 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
374376
! for i=igh-1 step -1 until low+1 do
375377
105 do 140 ii = 1, iend
376378
i = igh - ii
377-
if (abs(ortr(i)) == 0._wp .and. abs(orti(i)) == 0._wp) go to 140
378-
if (abs(hr(i, i - 1)) == 0._wp .and. abs(hi(i, i - 1)) == 0._wp) go to 140
379+
if (f_approx_equal(abs(ortr(i)), 0._wp) .and. f_approx_equal(abs(orti(i)), 0._wp)) go to 140
380+
if (f_approx_equal(abs(hr(i, i - 1)), 0._wp) .and. f_approx_equal(abs(hi(i, i - 1)), 0._wp)) go to 140
379381
! norm below is negative of h formed in corth
380382
norm = hr(i, i - 1)*ortr(i) + hi(i, i - 1)*orti(i)
381383
ip1 = i + 1
@@ -410,7 +412,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
410412

411413
do 170 i = l, igh
412414
ll = min0(i + 1, igh)
413-
if (abs(hi(i, i - 1)) == 0._wp) go to 170
415+
if (f_approx_equal(abs(hi(i, i - 1)), 0._wp)) go to 170
414416
call pythag(hr(i, i - 1), hi(i, i - 1), norm)
415417
yr = hr(i, i - 1)/norm
416418
yi = hi(i, i - 1)/norm
@@ -458,7 +460,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
458460
tst1 = abs(hr(l - 1, l - 1)) + abs(hi(l - 1, l - 1)) &
459461
+ abs(hr(l, l)) + abs(hi(l, l))
460462
tst2 = tst1 + abs(hr(l, l - 1))
461-
if (tst2 == tst1) go to 300
463+
if (f_approx_equal(tst2, tst1)) go to 300
462464
260 end do
463465
! form shift
464466
300 if (l == en) go to 660
@@ -468,7 +470,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
468470
si = hi(en, en)
469471
xr = hr(enm1, en)*hr(en, enm1)
470472
xi = hi(enm1, en)*hr(en, enm1)
471-
if (xr == 0.0_wp .and. xi == 0.0_wp) go to 340
473+
if (f_approx_equal(xr, 0.0_wp) .and. f_approx_equal(xi, 0.0_wp)) go to 340
472474
yr = (hr(enm1, enm1) - sr)/2.0_wp
473475
yi = (hi(enm1, enm1) - si)/2.0_wp
474476
call csroot(yr**2 - yi**2 + xr, 2.0_wp*yr*yi + xi, zzr, zzi)
@@ -522,7 +524,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
522524
500 end do
523525

524526
si = hi(en, en)
525-
if (abs(si) == 0._wp) go to 540
527+
if (f_approx_equal(abs(si), 0._wp)) go to 540
526528
call pythag(hr(en, en), si, norm)
527529
sr = hr(en, en)/norm
528530
si = si/norm
@@ -567,7 +569,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
567569
590 end do
568570
600 end do
569571

570-
if (abs(si) == 0._wp) go to 240
572+
if (f_approx_equal(abs(si), 0._wp)) go to 240
571573

572574
do 630 i = 1, en
573575
yr = hr(i, en)
@@ -602,7 +604,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
602604
end do
603605
end do
604606

605-
if (nl == 1 .or. norm == 0._wp) go to 1001
607+
if (nl == 1 .or. f_approx_equal(norm, 0._wp)) go to 1001
606608
! for en=nl step -1 until 2 do
607609
do 800 nn = 2, nl
608610
en = nl + 2 - nn
@@ -625,7 +627,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
625627

626628
yr = xr - wr(i)
627629
yi = xi - wi(i)
628-
if (yr /= 0.0_wp .or. yi /= 0.0_wp) go to 765
630+
if (.not. f_approx_equal(yr, 0.0_wp) .or. .not. f_approx_equal(yi, 0.0_wp)) go to 765
629631
tst1 = norm
630632
yr = tst1
631633
760 yr = 0.01_wp*yr
@@ -635,7 +637,7 @@ pure subroutine comqr2(nm, nl, low, igh, ortr, orti, hr, hi, wr, wi, zr, zi, ier
635637
call cdiv(zzr, zzi, yr, yi, hr(i, en), hi(i, en))
636638
! overflow control
637639
tr = abs(hr(i, en)) + abs(hi(i, en))
638-
if (tr == 0.0_wp) go to 780
640+
if (f_approx_equal(tr, 0.0_wp)) go to 780
639641
tst1 = tr
640642
tst2 = tst1 + 1.0_wp/tst1
641643
if (tst2 > tst1) go to 780
@@ -796,11 +798,11 @@ pure elemental subroutine pythag(a, b, c)
796798

797799
real(wp) :: p, r, s, t, u
798800
p = max(abs(a), abs(b))
799-
if (p == 0.0_wp) go to 20
801+
if (f_approx_equal(p, 0.0_wp)) go to 20
800802
r = (min(abs(a), abs(b))/p)**2
801803
10 continue
802804
t = 4.0_wp + r
803-
if (t == 4.0_wp) go to 20
805+
if (f_approx_equal(t, 4.0_wp)) go to 20
804806
s = r/t
805807
u = 1.0_wp + 2.0_wp*s
806808
p = u*p

src/common/m_helper.fpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ contains
163163
phi_nv = (1._wp + sqrt(mu_n/mu_v)*(M_v/M_n)**(0.25_wp))**2 &
164164
/(sqrt(8._wp)*sqrt(1._wp + M_n/M_v))
165165
! internal bubble pressure
166-
pb0 = pl0 + 2._wp*ss/(R0ref*R0)
166+
pb0(:) = pl0 + 2._wp*ss/(R0ref*R0(:))
167167

168168
! mass fraction of vapor
169169
chi_vw0 = 1._wp/(1._wp + R_v/R_n*(pb0/pv - 1._wp))
@@ -179,10 +179,10 @@ contains
179179
rho_m0 = pv/(chi_vw0*R_v*temp)
180180

181181
! mass of gas/vapor computed using dimensional quantities
182-
mass_n0 = 4._wp*(pb0 - pv)*pi/(3._wp*R_n*temp*rhol0)*R0**3
183-
mass_v0 = 4._wp*pv*pi/(3._wp*R_v*temp*rhol0)*R0**3
182+
mass_n0(:) = 4._wp*(pb0(:) - pv)*pi/(3._wp*R_n*temp*rhol0)*R0(:)**3
183+
mass_v0(:) = 4._wp*pv*pi/(3._wp*R_v*temp*rhol0)*R0(:)**3
184184
! Peclet numbers
185-
Pe_T = rho_m0*cp_m0*uu*R0ref/k_m0
185+
Pe_T(:) = rho_m0*cp_m0(:)*uu*R0ref/k_m0(:)
186186
Pe_c = uu*R0ref/D_m
187187

188188
Tw = temp
@@ -191,8 +191,8 @@ contains
191191
!if(.not. qbmm) then
192192
R_n = rhol0*R_n*temp/pl0
193193
R_v = rhol0*R_v*temp/pl0
194-
k_n = k_n/k_m0
195-
k_v = k_v/k_m0
194+
k_n(:) = k_n(:)/k_m0(:)
195+
k_v(:) = k_v(:)/k_m0(:)
196196
pb0 = pb0/pl0
197197
pv = pv/pl0
198198
Tw = 1._wp
@@ -203,7 +203,7 @@ contains
203203
!end if
204204

205205
! natural frequencies
206-
omegaN = sqrt(3._wp*k_poly*Ca + 2._wp*(3._wp*k_poly - 1._wp)/(Web*R0))/R0
206+
omegaN(:) = sqrt(3._wp*k_poly*Ca + 2._wp*(3._wp*k_poly - 1._wp)/(Web*R0))/R0
207207
do ir = 1, Nb
208208
call s_transcoeff(omegaN(ir)*R0(ir), Pe_T(ir)*R0(ir), &
209209
Re_trans_T(ir), Im_trans_T(ir))
@@ -488,7 +488,7 @@ contains
488488
real(wp) :: P
489489
490490
if (l == 0) then
491-
P = 1_wp
491+
P = 1._wp
492492
else if (l == 1) then
493493
P = x
494494
else

src/common/m_helper_basic.f90

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module m_helper_basic
1010

1111
private;
1212
public :: f_approx_equal, &
13+
f_approx_in_array, &
1314
f_is_default, &
1415
f_all_default, &
1516
f_is_integer, &
@@ -20,7 +21,7 @@ module m_helper_basic
2021
!> This procedure checks if two floating point numbers of wp are within tolerance.
2122
!! @param a First number.
2223
!! @param b Second number.
23-
!! @param tol_input Relative error (default = 1e-6_wp).
24+
!! @param tol_input Relative error (default = 1e-10_wp).
2425
!! @return Result of the comparison.
2526
logical pure elemental function f_approx_equal(a, b, tol_input) result(res)
2627
!$acc routine seq
@@ -31,7 +32,7 @@ logical pure elemental function f_approx_equal(a, b, tol_input) result(res)
3132
if (present(tol_input)) then
3233
tol = tol_input
3334
else
34-
tol = 1e-6_wp
35+
tol = 1e-10_wp
3536
end if
3637

3738
if (a == b) then
@@ -43,6 +44,35 @@ logical pure elemental function f_approx_equal(a, b, tol_input) result(res)
4344
end if
4445
end function f_approx_equal
4546

47+
!> This procedure checks if the point numbers of wp belongs to another array are within tolerance.
48+
!! @param a First number.
49+
!! @param b Array that contains several point numbers.
50+
!! @param tol_input Relative error (default = 1e-10_wp).
51+
!! @return Result of the comparison.
52+
logical pure function f_approx_in_array(a, b, tol_input) result(res)
53+
!$acc routine seq
54+
real(wp), intent(in) :: a
55+
real(wp), intent(in) :: b(:)
56+
real(wp), optional, intent(in) :: tol_input
57+
real(wp) :: tol
58+
integer :: i
59+
60+
res = .false.
61+
62+
if (present(tol_input)) then
63+
tol = tol_input
64+
else
65+
tol = 1e-10_wp
66+
end if
67+
68+
do i = 1, size(b)
69+
if (f_approx_equal(a, b(i), tol)) then
70+
res = .true.
71+
exit
72+
end if
73+
end do
74+
end function f_approx_in_array
75+
4676
!> Checks if a real(wp) variable is of default value.
4777
!! @param var Variable to check.
4878
logical pure elemental function f_is_default(var) result(res)

src/common/m_mpi_common.fpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,6 @@ contains
608608
609609
integer :: pack_offset, unpack_offset
610610
611-
real(wp), pointer :: p_send, p_recv
612-
613611
#ifdef MFC_MPI
614612
615613
call nvtxStartRange("RHS-COMM-PACKBUF")

src/common/m_phase_change.fpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module m_phase_change
1717

1818
use ieee_arithmetic
1919

20+
use m_helper_basic !< Functions to compare floating point numbers
21+
2022
implicit none
2123

2224
private;
@@ -748,7 +750,7 @@ contains
748750
! Generic loop iterators
749751
integer :: ns
750752
751-
if ((pSat == 0.0_wp) .and. (TSIn == 0.0_wp)) then
753+
if ((f_approx_equal(pSat, 0.0_wp)) .and. (f_approx_equal(TSIn, 0.0_wp))) then
752754
753755
! assigning Saturation temperature
754756
TSat = 0.0_wp

0 commit comments

Comments
 (0)