2012-08-09 16:31:53 +05:30
!--------------------------------------------------------------------------------------------------
2013-09-14 16:29:35 +05:30
!> @author Franz Roters, Max-Planck-Institut für Eisenforschung GmbH
!> @author Philip Eisenlohr, Max-Planck-Institut für Eisenforschung GmbH
!> @author Christoph Kords, Max-Planck-Institut für Eisenforschung GmbH
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
2014-05-08 20:25:19 +05:30
!> @author Luv Sharma, Max-Planck-Institut für Eisenforschung GmbH
2016-03-21 03:50:58 +05:30
!> @brief setting precision for real and int type
2013-09-14 16:29:35 +05:30
!> @details setting precision for real and int type and for DAMASK_NaN. Definition is made
2016-03-21 03:50:58 +05:30
!! depending on makro "INT" defined during compilation
2015-04-13 15:32:52 +05:30
!! for details on NaN see https://software.intel.com/en-us/forums/topic/294680
2012-08-09 16:31:53 +05:30
!--------------------------------------------------------------------------------------------------
2012-03-06 20:22:48 +05:30
module prec
2015-04-15 23:40:56 +05:30
2015-12-22 15:33:15 +05:30
#if !(defined(__GFORTRAN__) && __GNUC__ < 5)
use , intrinsic :: & ! unfortunately not avialable in gfortran <= 5
2015-04-13 15:32:52 +05:30
IEEE_arithmetic
#endif
2012-08-09 16:31:53 +05:30
2012-03-06 20:22:48 +05:30
implicit none
private
2016-03-21 03:50:58 +05:30
#if (FLOAT==8)
2012-08-29 00:40:54 +05:30
integer , parameter , public :: pReal = 8 !< floating point double precision (was selected_real_kind(15,300), number with 15 significant digits, up to 1e+-300)
2015-04-14 10:51:08 +05:30
#ifdef __INTEL_COMPILER
2016-05-27 15:16:34 +05:30
real ( pReal ) , parameter , public :: DAMASK_NaN = Z '7FF8000000000000' !< quiet NaN for double precision (from http://www.hpc.unimelb.edu.au/doc/f90lrm/dfum_035.html)
2015-04-14 10:51:08 +05:30
#endif
#ifdef __GFORTRAN__
2016-05-27 15:16:34 +05:30
real ( pReal ) , parameter , public :: DAMASK_NaN = real ( Z '7FF8000000000000' , pReal ) !< quiet NaN for double precision (from http://www.hpc.unimelb.edu.au/doc/f90lrm/dfum_035.html)
2012-08-28 21:38:17 +05:30
#endif
2012-08-31 01:56:28 +05:30
#else
2013-09-18 19:29:42 +05:30
NO SUITABLE PRECISION FOR REAL SELECTED , STOPPING COMPILATION
2012-02-13 19:38:07 +05:30
#endif
2007-03-20 19:25:22 +05:30
2012-08-28 21:38:17 +05:30
#if (INT==4)
integer , parameter , public :: pInt = 4 !< integer representation 32 bit (was selected_int_kind(9), number with at least up to +- 1e9)
#elif (INT==8)
integer , parameter , public :: pInt = 8 !< integer representation 64 bit (was selected_int_kind(12), number with at least up to +- 1e12)
2012-08-31 01:56:28 +05:30
#else
2013-09-18 19:29:42 +05:30
NO SUITABLE PRECISION FOR INTEGER SELECTED , STOPPING COMPILATION
2012-08-28 21:38:17 +05:30
#endif
integer , parameter , public :: pLongInt = 8 !< integer representation 64 bit (was selected_int_kind(12), number with at least up to +- 1e12)
2013-09-14 16:29:35 +05:30
real ( pReal ) , parameter , public :: tol_math_check = 1.0e-8_pReal !< tolerance for internal math self-checks (rotation)
2012-08-28 21:38:17 +05:30
2015-08-31 22:00:04 +05:30
integer ( pInt ) , allocatable , dimension ( : ) :: realloc_lhs_test
2014-10-14 06:03:38 +05:30
type , public :: p_vec !< variable length datatype used for storage of state
2015-05-28 22:32:23 +05:30
real ( pReal ) , dimension ( : ) , pointer :: p
2014-10-14 06:03:38 +05:30
end type p_vec
2015-04-13 15:32:52 +05:30
2015-05-28 22:32:23 +05:30
type , public :: p_intvec
integer ( pInt ) , dimension ( : ) , pointer :: p
2013-02-25 18:43:52 +05:30
end type p_intvec
2014-04-15 14:50:38 +05:30
!http://stackoverflow.com/questions/3948210/can-i-have-a-pointer-to-an-item-in-an-allocatable-array
type , public :: tState
2014-12-09 17:42:53 +05:30
integer ( pInt ) :: &
sizeState = 0_pInt , & !< size of state
sizeDotState = 0_pInt , & !< size of dot state, i.e. parts of the state that are integrated
2015-06-01 21:32:27 +05:30
sizeDeltaState = 0_pInt , & !< size of delta state, i.e. parts of the state that have discontinuous rates
2014-12-09 17:42:53 +05:30
sizePostResults = 0_pInt !< size of output data
2016-01-22 06:38:36 +05:30
real ( pReal ) , pointer , dimension ( : ) , contiguous :: &
2014-12-09 17:42:53 +05:30
atolState
2015-04-13 15:32:52 +05:30
real ( pReal ) , pointer , dimension ( : , : ) , contiguous :: & ! a pointer is needed here because we might point to state/doState. However, they will never point to something, but are rather allocated and, hence, contiguous
2014-12-09 17:42:53 +05:30
state , & !< state
2015-05-28 22:32:23 +05:30
dotState , & !< state rate
2015-10-30 21:18:30 +05:30
state0
real ( pReal ) , allocatable , dimension ( : , : ) :: &
2014-12-09 17:42:53 +05:30
partionedState0 , &
subState0 , &
state_backup , &
deltaState , &
previousDotState , & !< state rate of previous xxxx
previousDotState2 , & !< state rate two xxxx ago
dotState_backup , & !< backup of state rate
RK4dotState
real ( pReal ) , allocatable , dimension ( : , : , : ) :: &
RKCK45dotState
end type
type , extends ( tState ) , public :: tPlasticState
integer ( pInt ) :: &
nSlip = 0_pInt , &
nTwin = 0_pInt , &
nTrans = 0_pInt
2015-05-28 22:32:23 +05:30
logical :: &
nonlocal = . false . !< absolute tolerance for state integration
2015-04-13 15:32:52 +05:30
real ( pReal ) , pointer , dimension ( : , : ) , contiguous :: &
2014-12-09 17:42:53 +05:30
slipRate , & !< slip rate
accumulatedSlip !< accumulated plastic slip
2014-04-15 14:50:38 +05:30
end type
2014-09-19 23:29:06 +05:30
2015-05-28 22:32:23 +05:30
type , public :: tSourceState
type ( tState ) , dimension ( : ) , allocatable :: p !< tState for each active source mechanism in a phase
end type
type , public :: tHomogMapping
integer ( pInt ) , pointer , dimension ( : , : ) :: p
end type
type , public :: tPhaseMapping
integer ( pInt ) , pointer , dimension ( : , : , : ) :: p
2014-08-21 23:18:20 +05:30
end type
2014-04-15 14:50:38 +05:30
2015-03-30 15:15:10 +05:30
#ifdef FEM
type , public :: tOutputData
integer ( pInt ) :: &
sizeIpCells = 0_pInt , &
sizeResults = 0_pInt
real ( pReal ) , allocatable , dimension ( : , : ) :: &
output !< output data
end type
#endif
2013-02-11 15:14:17 +05:30
public :: &
2015-04-13 15:32:52 +05:30
prec_init , &
2016-03-27 00:25:44 +05:30
prec_isNaN , &
dEq , &
dNeq
2012-03-06 20:22:48 +05:30
contains
2012-08-28 21:38:17 +05:30
2015-04-13 15:32:52 +05:30
2012-08-09 16:31:53 +05:30
!--------------------------------------------------------------------------------------------------
!> @brief reporting precision and checking if DAMASK_NaN is set correctly
!--------------------------------------------------------------------------------------------------
2012-03-06 20:22:48 +05:30
subroutine prec_init
2015-04-13 15:32:52 +05:30
use , intrinsic :: &
iso_fortran_env ! to get compiler_version and compiler_options (at least for gfortran 4.6 at the moment)
2012-03-06 20:22:48 +05:30
implicit none
2014-10-10 18:38:34 +05:30
integer ( pInt ) :: worldrank = 0_pInt
#ifdef PETSc
2015-08-04 20:34:53 +05:30
#include <petsc/finclude/petscsys.h>
2014-10-10 01:53:06 +05:30
PetscErrorCode :: ierr
#endif
2013-02-13 23:24:56 +05:30
external :: &
2015-03-29 18:24:13 +05:30
quit , &
MPI_Comm_rank , &
MPI_Abort
2013-02-13 23:24:56 +05:30
2014-10-10 18:38:34 +05:30
#ifdef PETSc
2014-10-10 01:53:06 +05:30
call MPI_Comm_rank ( PETSC_COMM_WORLD , worldrank , ierr ) ; CHKERRQ ( ierr )
2014-10-10 18:38:34 +05:30
#endif
mainProcess : if ( worldrank == 0 ) then
write ( 6 , '(/,a)' ) ' <<<+- prec init -+>>>'
2012-02-01 00:48:55 +05:30
#include "compilation_info.f90"
2014-10-10 18:38:34 +05:30
write ( 6 , '(a,i3)' ) ' Bytes for pReal: ' , pReal
write ( 6 , '(a,i3)' ) ' Bytes for pInt: ' , pInt
write ( 6 , '(a,i3)' ) ' Bytes for pLongInt: ' , pLongInt
write ( 6 , '(a,e10.3)' ) ' NaN: ' , DAMASK_NaN
2015-04-13 15:32:52 +05:30
write ( 6 , '(a,l3)' ) ' NaN != NaN: ' , DAMASK_NaN / = DAMASK_NaN
write ( 6 , '(a,l3,/)' ) ' NaN check passed ' , prec_isNAN ( DAMASK_NaN )
2014-10-10 18:38:34 +05:30
endif mainProcess
2014-04-15 14:50:38 +05:30
2015-04-13 15:32:52 +05:30
if ( ( . not . prec_isNaN ( DAMASK_NaN ) ) . or . ( DAMASK_NaN == DAMASK_NaN ) ) call quit ( 9000 )
2015-08-31 22:00:04 +05:30
realloc_lhs_test = [ 1_pInt , 2_pInt ]
if ( realloc_lhs_test ( 2 ) / = 2_pInt ) call quit ( 9000 )
2009-08-31 20:39:15 +05:30
2012-03-06 20:22:48 +05:30
end subroutine prec_init
2009-08-31 20:39:15 +05:30
2015-04-13 15:32:52 +05:30
!--------------------------------------------------------------------------------------------------
!> @brief figures out if a floating point number is NaN
2016-03-06 02:07:22 +05:30
! basically just a small wrapper, because gfortran < 5.0 does not have the IEEE module
2015-04-13 15:32:52 +05:30
!--------------------------------------------------------------------------------------------------
2016-03-06 02:07:22 +05:30
logical elemental pure function prec_isNaN ( a )
2015-04-13 15:32:52 +05:30
implicit none
real ( pReal ) , intent ( in ) :: a
2015-12-22 15:33:15 +05:30
#if (defined(__GFORTRAN__) && __GNUC__ < 5)
2015-09-24 14:15:44 +05:30
intrinsic :: isNaN
2015-04-13 15:32:52 +05:30
prec_isNaN = isNaN ( a )
2015-04-15 23:40:56 +05:30
#else
prec_isNaN = IEEE_is_NaN ( a )
2015-04-13 15:32:52 +05:30
#endif
end function prec_isNaN
2016-03-06 02:07:22 +05:30
!--------------------------------------------------------------------------------------------------
!> @brief equality comparison for double precision
2016-03-21 03:50:58 +05:30
! replaces "==" but for certain (relative) tolerance. Counterpart to dNeq
! http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
2016-03-06 02:07:22 +05:30
!--------------------------------------------------------------------------------------------------
logical elemental pure function dEq ( a , b , tol )
2016-05-25 11:22:56 +05:30
implicit none
real ( pReal ) , intent ( in ) :: a , b
real ( pReal ) , intent ( in ) , optional :: tol
2016-05-27 15:16:34 +05:30
real ( pReal ) , parameter :: eps = 2.220446049250313E-16 ! DBL_EPSILON in C
2016-05-25 11:22:56 +05:30
dEq = merge ( . True . , . False . , abs ( a - b ) < = merge ( tol , eps , present ( tol ) ) * maxval ( abs ( [ a , b ] ) ) )
2016-03-06 02:07:22 +05:30
end function dEq
!--------------------------------------------------------------------------------------------------
!> @brief inequality comparison for double precision
2016-03-21 03:50:58 +05:30
! replaces "!=" but for certain (relative) tolerance. Counterpart to dEq
! http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
2016-03-06 02:07:22 +05:30
!--------------------------------------------------------------------------------------------------
logical elemental pure function dNeq ( a , b , tol )
2016-05-25 11:22:56 +05:30
implicit none
real ( pReal ) , intent ( in ) :: a , b
real ( pReal ) , intent ( in ) , optional :: tol
2016-05-27 15:16:34 +05:30
real ( pReal ) , parameter :: eps = 2.220446049250313E-16 ! DBL_EPSILON in C
2016-05-25 11:22:56 +05:30
dNeq = merge ( . False . , . True . , abs ( a - b ) < = merge ( tol , eps , present ( tol ) ) * maxval ( abs ( [ a , b ] ) ) )
2016-03-06 02:07:22 +05:30
end function dNeq
2012-03-06 20:22:48 +05:30
end module prec