DAMASK_EICMD/src/config.f90

162 lines
5.0 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
!> @brief Read in the material and numerics configuration from their respective file.
2018-06-10 14:37:17 +05:30
!--------------------------------------------------------------------------------------------------
module config
use IO
use misc
2020-06-16 22:17:19 +05:30
use YAML_parse
use YAML_types
2023-01-19 22:07:45 +05:30
use result
use parallelization
#if defined(MESH) || defined(GRID)
use CLI
#endif
implicit none(type,external)
2019-05-15 02:42:32 +05:30
private
type(tDict), pointer, public :: &
config_material, &
config_numerics
2020-08-15 19:32:10 +05:30
2019-03-29 13:04:44 +05:30
public :: &
config_init, &
2023-02-28 12:25:34 +05:30
config_material_deallocate, &
config_numerics_deallocate, &
config_listReferences
contains
!--------------------------------------------------------------------------------------------------
!> @brief Read *.yaml configuration files.
!--------------------------------------------------------------------------------------------------
2022-04-24 08:13:44 +05:30
subroutine config_init()
print'(/,1x,a)', '<<<+- config init -+>>>'; flush(IO_STDOUT)
2022-04-24 08:13:44 +05:30
call parse_material()
call parse_numerics()
2020-08-15 19:32:10 +05:30
end subroutine config_init
2019-03-29 13:04:44 +05:30
2023-02-28 12:25:34 +05:30
!--------------------------------------------------------------------------------------------------
!> @brief Deallocate config_material.
!--------------------------------------------------------------------------------------------------
subroutine config_material_deallocate()
print'(/,1x,a)', 'deallocating material configuration'; flush(IO_STDOUT)
deallocate(config_material)
end subroutine config_material_deallocate
!--------------------------------------------------------------------------------------------------
!> @brief Deallocate config_numerics if present.
!--------------------------------------------------------------------------------------------------
subroutine config_numerics_deallocate()
if (.not. associated(config_numerics, emptyDict)) then
print'(/,1x,a)', 'deallocating numerics configuration'; flush(IO_STDOUT)
deallocate(config_numerics)
end if
end subroutine config_numerics_deallocate
!--------------------------------------------------------------------------------------------------
!> @brief Return string with references from dict.
!--------------------------------------------------------------------------------------------------
function config_listReferences(config,indent) result(references)
2023-02-28 12:25:34 +05:30
type(tDict), intent(in) :: config
integer, intent(in), optional :: indent
2023-02-28 12:25:34 +05:30
character(len=:), allocatable :: references
type(tList), pointer :: ref
character(len=:), allocatable :: filler
2023-02-28 12:25:34 +05:30
integer :: r
filler = repeat(' ',misc_optional(indent,0))
2023-02-28 12:25:34 +05:30
ref => config%get_list('references',emptyList)
if (ref%length == 0) then
references = ''
else
2023-02-28 12:25:34 +05:30
references = 'references:'
do r = 1, ref%length
2023-06-04 10:47:38 +05:30
references = references//IO_EOL//filler//'- '//IO_wrapLines(ref%get_asStr(r),filler=filler//' ')
2023-02-28 12:25:34 +05:30
end do
end if
end function config_listReferences
2023-02-28 12:25:34 +05:30
2020-08-15 19:32:10 +05:30
!--------------------------------------------------------------------------------------------------
2022-04-24 08:13:44 +05:30
!> @brief Read material.yaml.
2020-08-15 19:32:10 +05:30
!--------------------------------------------------------------------------------------------------
subroutine parse_material()
2019-03-29 13:04:44 +05:30
character(len=:), allocatable :: &
fileContent, fname
2021-07-27 12:05:52 +05:30
if (worldrank == 0) then
2023-06-23 03:36:44 +05:30
print'(/,1x,a)', 'reading material configuration'; flush(IO_STDOUT)
#if defined(MESH) || defined(GRID)
fname = CLI_materialFile
#else
fname = 'material.yaml'
#endif
2023-06-23 03:36:44 +05:30
fileContent = IO_read(fname)
if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:)
2023-01-19 22:07:45 +05:30
call result_openJobFile(parallel=.false.)
2023-06-23 03:36:44 +05:30
call result_writeDataset_str(fileContent,'setup',fname,'material configuration')
call result_closeJobFile()
end if
2021-07-27 12:24:17 +05:30
call parallelization_bcast_str(fileContent)
2021-07-27 12:05:52 +05:30
config_material => YAML_parse_str_asDict(fileContent)
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-09-14 00:58:53 +05:30
!> @brief Read numerics.yaml.
2019-03-13 02:18:33 +05:30
!--------------------------------------------------------------------------------------------------
subroutine parse_numerics()
2020-08-15 19:32:10 +05:30
character(len=:), allocatable :: &
fileContent, fname
logical :: parse
2020-08-15 19:32:10 +05:30
2021-02-13 04:05:06 +05:30
config_numerics => emptyDict
2021-07-27 12:05:52 +05:30
#if defined(MESH) || defined(GRID)
fname = CLI_numericsFile
parse = len_trim(CLI_numericsFile) > 0
#else
fname = 'numerics.yaml'
inquire(file=fname, exist=parse)
#endif
if (parse) then
2021-07-27 12:05:52 +05:30
if (worldrank == 0) then
print'(1x,a)', 'reading numerics configuration'; flush(IO_STDOUT)
fileContent = IO_read(fname)
if (scan(fname,'/') /= 0) fname = fname(scan(fname,'/',.true.)+1:)
call result_openJobFile(parallel=.false.)
call result_writeDataset_str(fileContent,'setup',fname,'numerics configuration')
call result_closeJobFile()
end if
2021-07-27 12:24:17 +05:30
call parallelization_bcast_str(fileContent)
2021-07-27 12:05:52 +05:30
config_numerics => YAML_parse_str_asDict(fileContent)
2021-07-27 12:05:52 +05:30
end if
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
end module config