Merge branch '288-tests-for-misc' into 'development'
testing misc functionality Closes #288 See merge request damask/DAMASK!752
This commit is contained in:
commit
4acf5e10f1
|
@ -8,6 +8,7 @@ module materialpoint
|
||||||
use signal
|
use signal
|
||||||
use CLI
|
use CLI
|
||||||
use prec
|
use prec
|
||||||
|
use misc
|
||||||
use IO
|
use IO
|
||||||
use YAML_types
|
use YAML_types
|
||||||
use YAML_parse
|
use YAML_parse
|
||||||
|
@ -47,6 +48,7 @@ subroutine materialpoint_initAll()
|
||||||
call CLI_init() ! grid and mesh commandline interface
|
call CLI_init() ! grid and mesh commandline interface
|
||||||
call signal_init()
|
call signal_init()
|
||||||
call prec_init()
|
call prec_init()
|
||||||
|
call misc_init()
|
||||||
call IO_init()
|
call IO_init()
|
||||||
#if defined(MESH)
|
#if defined(MESH)
|
||||||
call FEM_quadrature_init()
|
call FEM_quadrature_init()
|
||||||
|
|
83
src/misc.f90
83
src/misc.f90
|
@ -17,11 +17,24 @@ module misc
|
||||||
end interface misc_optional
|
end interface misc_optional
|
||||||
|
|
||||||
public :: &
|
public :: &
|
||||||
|
misc_init, &
|
||||||
misc_optional
|
misc_optional
|
||||||
|
|
||||||
contains
|
contains
|
||||||
|
|
||||||
|
|
||||||
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
!> @brief Do self test.
|
||||||
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
subroutine misc_init()
|
||||||
|
|
||||||
|
print'(/,1x,a)', '<<<+- misc init -+>>>'
|
||||||
|
|
||||||
|
call misc_selfTest()
|
||||||
|
|
||||||
|
end subroutine misc_init
|
||||||
|
|
||||||
|
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
!> @brief Return bool value if given, otherwise default.
|
!> @brief Return bool value if given, otherwise default.
|
||||||
!--------------------------------------------------------------------------------------------------
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
@ -97,4 +110,74 @@ pure function misc_optional_string(given,default) result(var)
|
||||||
|
|
||||||
end function misc_optional_string
|
end function misc_optional_string
|
||||||
|
|
||||||
|
|
||||||
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
!> @brief Check correctness of some misc functions.
|
||||||
|
!--------------------------------------------------------------------------------------------------
|
||||||
|
subroutine misc_selfTest()
|
||||||
|
|
||||||
|
real(pReal) :: r
|
||||||
|
|
||||||
|
call random_number(r)
|
||||||
|
if (test_str('DAMASK') /= 'DAMASK') error stop 'optional_string, present'
|
||||||
|
if (test_str() /= 'default') error stop 'optional_string, not present'
|
||||||
|
if (misc_optional(default='default') /= 'default') error stop 'optional_string, default only'
|
||||||
|
if (test_int(20191102) /= 20191102) error stop 'optional_int, present'
|
||||||
|
if (test_int() /= 42) error stop 'optional_int, not present'
|
||||||
|
if (misc_optional(default=20191102) /= 20191102) error stop 'optional_int, default only'
|
||||||
|
if (dNeq(test_real(r),r)) error stop 'optional_float, present'
|
||||||
|
if (dNeq(test_real(),0.0_pReal)) error stop 'optional_float, not present'
|
||||||
|
if (dNeq(misc_optional(default=r),r)) error stop 'optional_float, default only'
|
||||||
|
if (test_bool(r<0.5_pReal) .neqv. r<0.5_pReal) error stop 'optional_bool, present'
|
||||||
|
if (.not. test_bool()) error stop 'optional_bool, not present'
|
||||||
|
if (misc_optional(default=r>0.5_pReal) .neqv. r>0.5_pReal) error stop 'optional_bool, default only'
|
||||||
|
|
||||||
|
contains
|
||||||
|
|
||||||
|
function test_str(str_in) result(str_out)
|
||||||
|
|
||||||
|
character(len=:), allocatable :: str_out
|
||||||
|
character(len=*), intent(in), optional :: str_in
|
||||||
|
|
||||||
|
|
||||||
|
str_out = misc_optional_string(str_in,'default')
|
||||||
|
|
||||||
|
end function test_str
|
||||||
|
|
||||||
|
|
||||||
|
function test_int(int_in) result(int_out)
|
||||||
|
|
||||||
|
integer :: int_out
|
||||||
|
integer, intent(in), optional :: int_in
|
||||||
|
|
||||||
|
|
||||||
|
int_out = misc_optional_integer(int_in,42)
|
||||||
|
|
||||||
|
end function test_int
|
||||||
|
|
||||||
|
|
||||||
|
function test_real(real_in) result(real_out)
|
||||||
|
|
||||||
|
real(pReal) :: real_out
|
||||||
|
real(pReal), intent(in), optional :: real_in
|
||||||
|
|
||||||
|
|
||||||
|
real_out = misc_optional_real(real_in,0.0_pReal)
|
||||||
|
|
||||||
|
end function test_real
|
||||||
|
|
||||||
|
|
||||||
|
function test_bool(bool_in) result(bool_out)
|
||||||
|
|
||||||
|
logical :: bool_out
|
||||||
|
logical, intent(in), optional :: bool_in
|
||||||
|
|
||||||
|
|
||||||
|
bool_out = misc_optional_bool(bool_in,.true.)
|
||||||
|
|
||||||
|
end function test_bool
|
||||||
|
|
||||||
|
|
||||||
|
end subroutine misc_selfTest
|
||||||
|
|
||||||
end module misc
|
end module misc
|
||||||
|
|
Loading…
Reference in New Issue