Skip to content

Commit 3e2c63e

Browse files
committed
Merge branch '460-suppression-of-division-by-zero-when-computing-eigenvalues-in-math_eigh33' into 'development'
avoid division by zero Closes #460 See merge request damask/DAMASK!992
2 parents 3600d94 + e820e34 commit 3e2c63e

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/math.f90

+18-1
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ pure subroutine math_eigh33(w,v,m)
10381038

10391039
T = maxval(abs(w))
10401040
U = max(T, T**2)
1041-
threshold = sqrt(5.68e-14_pREAL * U**2)
1041+
threshold = max(sqrt(5.68e-14_pREAL * U**2),PREAL_MIN)
10421042

10431043
v(1:3,1) = [m(1,3)*w(1) + v(1,2), &
10441044
m(2,3)*w(1) + v(2,2), &
@@ -1468,6 +1468,23 @@ subroutine math_selfTest()
14681468
error stop 'math_normal(sigma)'
14691469
end block normal_distribution
14701470

1471+
t33 = 0.0_pREAL
1472+
call math_eigh33(v3_1,t33_2,t33)
1473+
if (any(dNeq0(v3_1))) error stop 'math_eigh33/zero eigenvalues (values)'
1474+
if (any(dNeq(t33_2,math_I3))) error stop 'math_eigh33/zero eigenvalues (vectors)'
1475+
1476+
t33 = math_I3
1477+
call random_number(r)
1478+
d = nint(r*2.0_pREAL) + 1
1479+
t33(d,d) = 5.0_pREAL + r*10.0_pREAL
1480+
t33(mod(d,3)+1,mod(d,3)+1) = 20.0_pREAL + r*10.0_pREAL
1481+
call math_eigh33(v3_1,t33_2,t33)
1482+
if (any(dNeq(v3_1,[1.0_pREAL,t33(d,d),t33(mod(d,3)+1,mod(d,3)+1)]))) &
1483+
error stop 'math_eigh33/non-zero eigenvalues (values)'
1484+
if (any(dNeq(math_I3(1:3,mod(d+1,3)+1),t33_2(1:3,1)))) error stop 'math_eigh33/min eigenvector'
1485+
if (any(dNeq(math_I3(1:3,d ),t33_2(1:3,2)))) error stop 'math_eigh33/mid eigenvector'
1486+
if (any(dNeq(math_I3(1:3,mod(d,3)+1 ),t33_2(1:3,3)))) error stop 'math_eigh33/max eigenvector'
1487+
14711488
end subroutine math_selfTest
14721489

14731490
end module math

src/prec.f90

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module prec
3535

3636

3737
real(pREAL), private, parameter :: PREAL_EPSILON = epsilon(0.0_pREAL) !< minimum positive number such that 1.0 + EPSILON /= 1.0.
38-
real(pREAL), private, parameter :: PREAL_MIN = tiny(0.0_pREAL) !< smallest normalized floating point number
38+
real(pREAL), public, parameter :: PREAL_MIN = tiny(0.0_pREAL) !< smallest normalized floating point number
3939

4040
integer, dimension(0), parameter :: emptyIntArray = [integer::]
4141
real(pREAL), dimension(0), parameter :: emptyRealArray = [real(pREAL)::]

0 commit comments

Comments
 (0)