DAMASK_EICMD/src/config.f90

156 lines
5.8 KiB
Fortran
Raw Normal View History

2020-01-27 00:26:30 +05:30
!--------------------------------------------------------------------------------------------------
2018-06-10 14:37:17 +05:30
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
2020-08-15 19:32:10 +05:30
!> @brief Reads in the material, numerics & debug configuration from their respective file
!> @details Reads the material configuration file, where solverJobName.yaml takes
!! precedence over material.yaml.
2018-06-10 14:37:17 +05:30
!--------------------------------------------------------------------------------------------------
module config
2019-05-15 02:42:32 +05:30
use prec
use DAMASK_interface
use IO
2020-06-16 22:17:19 +05:30
use YAML_parse
use YAML_types
2019-03-29 13:04:44 +05:30
2020-08-15 19:32:10 +05:30
#ifdef PETSc
#include <petsc/finclude/petscsys.h>
use petscsys
#endif
!$ use OMP_LIB
2019-03-29 13:04:44 +05:30
implicit none
2019-05-15 02:42:32 +05:30
private
2020-08-15 19:32:10 +05:30
class(tNode), pointer, public :: &
material_root, &
numerics_root, &
debug_root
integer, protected, public :: &
worldrank = 0, & !< MPI worldrank (/=0 for MPI simulations only)
worldsize = 1 !< MPI worldsize (/=1 for MPI simulations only)
integer(4), protected, public :: &
DAMASK_NumThreadsInt = 0 !< value stored in environment variable DAMASK_NUM_THREADS, set to zero if no OpenMP directive
2019-03-29 13:04:44 +05:30
public :: &
config_init, &
config_deallocate
contains
!--------------------------------------------------------------------------------------------------
2020-08-15 19:32:10 +05:30
!> @brief calls subroutines that reads material, numerics and debug configuration files
!--------------------------------------------------------------------------------------------------
subroutine config_init
2020-08-15 19:32:10 +05:30
write(6,'(/,a)') ' <<<+- config init -+>>>'; flush(6)
call parse_material
call parse_numerics
call parse_debug
end subroutine config_init
2019-03-29 13:04:44 +05:30
2020-08-15 19:32:10 +05:30
!--------------------------------------------------------------------------------------------------
!> @brief reads material.yaml
!--------------------------------------------------------------------------------------------------
subroutine parse_material
2019-03-29 13:04:44 +05:30
2020-08-15 19:32:10 +05:30
logical :: fileExists
character(len=:), allocatable :: fname,flow
2019-03-29 13:04:44 +05:30
2020-08-15 19:32:10 +05:30
fname = getSolverJobName()//'.yaml'
inquire(file=fname,exist=fileExists)
if(.not. fileExists) then
fname = 'material.yaml'
inquire(file=fname,exist=fileExists)
if(.not. fileExists) call IO_error(100,ext_msg=fname)
2019-03-29 13:04:44 +05:30
endif
2020-08-15 19:32:10 +05:30
write(6,'(/,a)') ' reading '//fname; flush(6)
flow = to_flow(IO_read(fname))
material_root => parse_flow(flow)
2018-06-09 17:18:37 +05:30
2020-08-15 19:32:10 +05:30
end subroutine parse_material
2019-03-13 02:18:33 +05:30
!--------------------------------------------------------------------------------------------------
2020-08-15 19:32:10 +05:30
!> @brief reads in parameters from numerics.yaml and sets openMP related parameters. Also does
! a sanity check
2019-03-13 02:18:33 +05:30
!--------------------------------------------------------------------------------------------------
2020-08-15 19:32:10 +05:30
subroutine parse_numerics
!$ integer :: gotDAMASK_NUM_THREADS = 1
integer :: ierr
character(len=:), allocatable :: &
numerics_inFlow
logical :: fexist
!$ character(len=6) DAMASK_NumThreadsString ! environment variable DAMASK_NUM_THREADS
#ifdef PETSc
call MPI_Comm_rank(PETSC_COMM_WORLD,worldrank,ierr);CHKERRQ(ierr)
call MPI_Comm_size(PETSC_COMM_WORLD,worldsize,ierr);CHKERRQ(ierr)
#endif
!$ call GET_ENVIRONMENT_VARIABLE(NAME='DAMASK_NUM_THREADS',VALUE=DAMASK_NumThreadsString,STATUS=gotDAMASK_NUM_THREADS) ! get environment variable DAMASK_NUM_THREADS...
!$ if(gotDAMASK_NUM_THREADS /= 0) then ! could not get number of threads, set it to 1
!$ call IO_warning(35,ext_msg='BEGIN:'//DAMASK_NumThreadsString//':END')
!$ DAMASK_NumThreadsInt = 1_4
!$ else
!$ read(DAMASK_NumThreadsString,'(i6)') DAMASK_NumThreadsInt ! read as integer
!$ if (DAMASK_NumThreadsInt < 1_4) DAMASK_NumThreadsInt = 1_4 ! in case of string conversion fails, set it to one
!$ endif
!$ call omp_set_num_threads(DAMASK_NumThreadsInt) ! set number of threads for parallel execution
numerics_root => emptyDict
inquire(file='numerics.yaml', exist=fexist)
2019-03-13 02:18:33 +05:30
2020-08-15 19:32:10 +05:30
if (fexist) then
write(6,'(a,/)') ' using values from config.yaml file'
flush(6)
numerics_inFlow = to_flow(IO_read('numerics.yaml'))
numerics_root => parse_flow(numerics_inFlow)
2019-03-13 02:18:33 +05:30
endif
!--------------------------------------------------------------------------------------------------
2020-08-15 19:32:10 +05:30
! openMP parameter
!$ write(6,'(a24,1x,i8,/)') ' number of threads: ',DAMASK_NumThreadsInt
2019-03-13 02:18:33 +05:30
2020-08-15 19:32:10 +05:30
end subroutine parse_numerics
2019-03-13 02:18:33 +05:30
!--------------------------------------------------------------------------------------------------
2020-08-15 19:32:10 +05:30
!> @brief reads in parameters from debug.yaml
!--------------------------------------------------------------------------------------------------
2020-08-15 19:32:10 +05:30
subroutine parse_debug
2020-08-15 19:32:10 +05:30
character(len=:), allocatable :: debug_inFlow
logical :: fexist
2020-08-15 19:32:10 +05:30
#ifdef DEBUG
write(6,'(a)') achar(27)//'[31m <<<+- DEBUG version -+>>>'//achar(27)//'[0m'
#endif
2020-08-15 19:32:10 +05:30
debug_root => emptyDict
inquire(file='debug.yaml', exist=fexist)
fileExists: if (fexist) then
debug_inFlow = to_flow(IO_read('debug.yaml'))
debug_root => parse_flow(debug_inFlow)
endif fileExists
2020-08-15 19:32:10 +05:30
end subroutine parse_debug
2020-08-15 19:32:10 +05:30
!--------------------------------------------------------------------------------------------------
!> @brief deallocates material.yaml structure
!--------------------------------------------------------------------------------------------------
subroutine config_deallocate
2020-08-15 19:32:10 +05:30
deallocate(material_root) !ToDo: deallocation of numerics and debug (slightly different for optional files)
end subroutine config_deallocate
end module config