From dab5ba1e605a801d5d7a9132916698ddc5286e83 Mon Sep 17 00:00:00 2001 From: Philip Eisenlohr Date: Tue, 26 Sep 2023 18:31:09 -0400 Subject: [PATCH] call polynomials_selfTest in DAMASK_test --- src/polynomials.f90 | 21 +++++++++++++-------- src/test/DAMASK_test.f90 | 5 +++++ src/test/test_polynomials.f90 | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/test/test_polynomials.f90 diff --git a/src/polynomials.f90 b/src/polynomials.f90 index 84961a57e..3bbe5f28f 100644 --- a/src/polynomials.f90 +++ b/src/polynomials.f90 @@ -25,7 +25,8 @@ module polynomials public :: & polynomial, & - polynomials_init + polynomials_init, & + polynomials_selfTest contains @@ -37,7 +38,7 @@ subroutine polynomials_init() print'(/,1x,a)', '<<<+- polynomials init -+>>>'; flush(IO_STDOUT) - call selfTest() + call polynomials_selfTest() end subroutine polynomials_init @@ -114,7 +115,7 @@ end function eval !-------------------------------------------------------------------------------------------------- !> @brief Check correctness of polynomical functionality. !-------------------------------------------------------------------------------------------------- -subroutine selfTest() +subroutine polynomials_selfTest() type(tPolynomial) :: p1, p2 real(pREAL), dimension(5) :: coef @@ -129,9 +130,9 @@ subroutine selfTest() call random_number(x_ref) call random_number(x) - coef = coef*10_pREAL -0.5_pREAL - x_ref = x_ref*10_pREAL -0.5_pREAL - x = x*10_pREAL -0.5_pREAL + coef = 10_pREAL*(coef-0.5_pREAL) + x_ref = 10_pREAL*(x_ref-0.5_pREAL) + x = 10_pREAL*(x-0.5_pREAL) p1 = polynomial([coef(1)],x_ref) if (dNeq(p1%at(x),coef(1))) error stop 'polynomial: eval(constant)' @@ -153,7 +154,11 @@ subroutine selfTest() dict => YAML_parse_str_asDict(trim(YAML_s)) p2 = polynomial(dict,'C','T') if (dNeq(p1%at(x),p2%at(x),1.0e-6_pREAL)) error stop 'polynomials: init' - y = coef(1)+coef(2)*(x-x_ref)+coef(3)*(x-x_ref)**2+coef(4)*(x-x_ref)**3+coef(5)*(x-x_ref)**4 + y = coef(1)*(x-x_ref)**0 & + + coef(2)*(x-x_ref)**1 & + + coef(3)*(x-x_ref)**2 & + + coef(4)*(x-x_ref)**3 & + + coef(5)*(x-x_ref)**4 if (dNeq(p1%at(x),y,1.0e-6_pREAL)) error stop 'polynomials: eval(full)' YAML_s = 'C: 0.0'//IO_EOL//& @@ -185,6 +190,6 @@ subroutine selfTest() if (dNeq(p1%at(x_ref+x),p1%at(x_ref-x),1.0e-6_pREAL)) error stop 'polynomials: eval(quartic)' -end subroutine selfTest +end subroutine polynomials_selfTest end module polynomials diff --git a/src/test/DAMASK_test.f90 b/src/test/DAMASK_test.f90 index ae7a714b8..003519ba3 100644 --- a/src/test/DAMASK_test.f90 +++ b/src/test/DAMASK_test.f90 @@ -7,6 +7,7 @@ program DAMASK_test use test_prec use test_misc use test_math + use test_polynomials use test_tables use test_crystal use test_rotations @@ -36,6 +37,10 @@ program DAMASK_test call test_math_run() write(IO_STDOUT,fmt='(a)') ok + write(IO_STDOUT,fmt=fmt, advance='no') 'polynomials','...' + call test_polynomials_run() + write(IO_STDOUT,fmt='(a)') ok + write(IO_STDOUT,fmt=fmt, advance='no') 'tables','...' call test_tables_run() write(IO_STDOUT,fmt='(a)') ok diff --git a/src/test/test_polynomials.f90 b/src/test/test_polynomials.f90 new file mode 100644 index 000000000..dea6206a5 --- /dev/null +++ b/src/test/test_polynomials.f90 @@ -0,0 +1,17 @@ +module test_polynomials + use polynomials + + implicit none(type,external) + + private + public :: test_polynomials_run + + contains + +subroutine test_polynomials_run() + + call polynomials_selfTest() + +end subroutine test_polynomials_run + +end module test_polynomials