Merge branch 'CLI-improvements' into 'development'

Cli improvements

See merge request damask/DAMASK!873
This commit is contained in:
Sharan Roongta 2023-12-14 12:03:12 +00:00
commit 85191cd021
4 changed files with 119 additions and 90 deletions

@ -1 +1 @@
Subproject commit 1f36292500ca01e7164ac6195eba0dc3e952bafb Subproject commit 29ef436acca5417aebc945b688642c34697af911

View File

@ -36,7 +36,7 @@ module CLI
contains contains
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief initializes the solver by interpreting the command line arguments. Also writes !> @brief Initialize the solver by interpreting the command line arguments. Write
!! information on computation to screen !! information on computation to screen
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
subroutine CLI_init() subroutine CLI_init()
@ -45,24 +45,26 @@ subroutine CLI_init()
#if PETSC_VERSION_MAJOR!=3 || PETSC_VERSION_MINOR<PETSC_MINOR_MIN || PETSC_VERSION_MINOR>PETSC_MINOR_MAX #if PETSC_VERSION_MAJOR!=3 || PETSC_VERSION_MINOR<PETSC_MINOR_MIN || PETSC_VERSION_MINOR>PETSC_MINOR_MAX
-- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION --- -- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION --- UNSUPPORTED PETSc VERSION ---
#endif #endif
#if PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR==18
character(len=*), parameter :: PETSc_DOI = '10.2172/1893326'
#elif PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR==19
character(len=*), parameter :: PETSc_DOI = '10.2172/1968587'
#elif PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR==20
character(len=*), parameter :: PETSc_DOI = '10.2172/2205494'
#endif
character(len=:), allocatable :: & character(len=:), allocatable :: &
commandLine, & !< command line call as string commandLine, & !< command line call as string
arg, & !< individual argument flag, & !< individual flag
val, &
geomArg, & !< -g CLI argument geomArg, & !< -g CLI argument
loadArg, & !< -l CLI argument loadArg, & !< -l CLI argument
materialArg, & !< -m CLI argument materialArg, & !< -m CLI argument
numericsArg, & !< -n CLI argument numericsArg, & !< -n CLI argument
workingDirArg !< -w CLI argument workingDirArg !< -w CLI argument
integer :: & integer :: &
stat, & i, s
i
integer, dimension(8) :: & integer, dimension(8) :: &
dateAndTime dateAndTime
logical :: &
hasArg
external :: &
quit
workingDirArg = getCWD() workingDirArg = getCWD()
@ -92,8 +94,11 @@ subroutine CLI_init()
print'(a)', IO_color() print'(a)', IO_color()
print'(1x,a)', 'F. Roters et al., Computational Materials Science 158:420478, 2019' print'(1x,a)', 'F. Roters et al., Computational Materials Science 158:420478, 2019'
print'(1x,a)', 'https://doi.org/10.1016/j.commatsci.2018.04.030' print'(1x,a)', 'https://doi.org/10.1016/j.commatsci.2018.04.030'//IO_EOL
#if PETSC_VERSION_MAJOR==3 && PETSC_VERSION_MINOR>=18
print'(1x,a,i0,a,i0)', 'S. Balay et al., PETSc/TAO User Manual Revision ',PETSC_VERSION_MAJOR,'.',PETSC_VERSION_MINOR
print'(1x,a)', 'https://doi.org/'//PETSc_DOI
#endif
print'(/,1x,a)', 'Version: '//DAMASKVERSION print'(/,1x,a)', 'Version: '//DAMASKVERSION
print'(/,1x,a)', 'Compiled with: '//compiler_version() print'(/,1x,a)', 'Compiled with: '//compiler_version()
@ -110,82 +115,47 @@ subroutine CLI_init()
print'(/,1x,a,1x,2(i2.2,a),i4.4)', 'Date:',dateAndTime(3),'/',dateAndTime(2),'/',dateAndTime(1) print'(/,1x,a,1x,2(i2.2,a),i4.4)', 'Date:',dateAndTime(3),'/',dateAndTime(2),'/',dateAndTime(1)
print'(1x,a,1x,2(i2.2,a),i2.2)', 'Time:',dateAndTime(5),':',dateAndTime(6),':',dateAndTime(7) print'(1x,a,1x,2(i2.2,a),i2.2)', 'Time:',dateAndTime(5),':',dateAndTime(6),':',dateAndTime(7)
if (command_argument_count() == 0) call help()
do i = 1, command_argument_count() do i = 1, command_argument_count()
hasArg = i < command_argument_count() flag = getArg(i)
arg = getArg(i) if (flag == '-h' .or. flag == '--help') call help()
select case(trim(arg)) ! extract key end do
case ('-h','--help')
print'(/,1x,a)','#######################################################################' i = 1
print'(1x,a)', 'DAMASK Command Line Interface:' do while (i <= command_argument_count())
print'(1x,a)', 'Düsseldorf Advanced Material Simulation Kit with PETSc-based solvers' flag = getArg(i)
print'(1x,a,/)','#######################################################################' i = i + 1
print'(1x,a,/)','Valid command line switches:' s = scan(flag,'=')
print'(1x,a)', ' --geom (-g, --geometry)' if (s /= 0) then
print'(1x,a)', ' --load (-l, --loadcase)' val = flag(s+1:)
print'(1x,a)', ' --material (-m, --materialconfig)' flag = flag(:s-1)
print'(1x,a)', ' --numerics (-n, --numericsconfig)' else
print'(1x,a)', ' --jobname (-j, --job)' if (i > command_argument_count()) call IO_error(610,ext_msg=flag)
print'(1x,a)', ' --workingdir (-w, --wd, --workingdirectory)' val = getArg(i)
#if defined(GRID) i = i + 1
print'(1x,a)', ' --restart (-r, --rs)' end if
#endif
print'(1x,a)', ' --help (-h)' select case(flag)
print'(/,1x,a)','-----------------------------------------------------------------------'
print'(1x,a)', 'Mandatory arguments:'
print'(/,1x,a)',' --geom GEOMFILE'
print'(1x,a)', ' specify the file path of the geometry definition'
print'(/,1x,a)',' --load LOADFILE'
print'(1x,a)', ' specify the file path of the load case definition'
print'(/,1x,a)',' --material MATERIALFILE'
print'(1x,a)', ' specify the file path of the material configuration'
print'(/,1x,a)','-----------------------------------------------------------------------'
print'(1x,a)', 'Optional arguments:'
print'(/,1x,a)',' --numerics NUMERICSFILE'
print'(1x,a)', ' Specify the file path of the numerics configuration'
print'(/,1x,a)',' --jobname JOBNAME'
print'(1x,a)', ' specify the job name.'
print'(1x,a)', ' Defaults to GEOM_LOAD_MATERIAL[_NUMERICS].'
print'(/,1x,a)',' --workingdirectory WORKINGDIRECTORY'
print'(1x,a)', ' specify the base directory of relative paths.'
print'(1x,a)', ' Defaults to the current working directory'
#if defined(GRID)
print'(/,1x,a)',' --restart N'
print'(1x,a)', ' read in increment N and continues with calculating'
print'(1x,a)', ' increment N+1, N+2, ... based on this'
print'(1x,a)', ' works only if the restart information for increment N'
print'(1x,a)', ' is available in JOBNAME_restart.hdf5'
print'(1x,a)', ' append to existing results file JOBNAME.hdf5'
#endif
print'(/,1x,a)','-----------------------------------------------------------------------'
print'(1x,a)', 'Help:'
print'(/,1x,a)',' --help'
print'(1x,a,/)',' Prints this message and exits'
call quit(0) ! normal Termination
case ('-g', '--geom', '--geometry') case ('-g', '--geom', '--geometry')
if (.not. hasArg) call IO_error(610,ext_msg='--geom') geomArg = val
geomArg = getArg(i+1)
case ('-l', '--load', '--loadcase') case ('-l', '--load', '--loadcase')
if (.not. hasArg) call IO_error(610,ext_msg='--load') loadArg = val
loadArg = getArg(i+1)
case ('-m', '--material', '--materialconfig') case ('-m', '--material', '--materialconfig')
if (.not. hasArg) call IO_error(610,ext_msg='--material') materialArg = val
materialArg = getArg(i+1)
case ('-n', '--numerics', '--numericsconfig') case ('-n', '--numerics', '--numericsconfig')
if (.not. hasArg) call IO_error(610,ext_msg='--numerics') numericsArg = val
numericsArg = getArg(i+1)
case ('-j', '--job', '--jobname') case ('-j', '--job', '--jobname')
if (.not. hasArg) call IO_error(610,ext_msg='--jobname') solverJobname = val
solverJobname = getArg(i+1)
case ('-w', '--wd', '--workingdir', '--workingdirectory') case ('-w', '--wd', '--workingdir', '--workingdirectory')
if (.not. hasArg) call IO_error(610,ext_msg='--workingdirectory') workingDirArg = val
workingDirArg = getArg(i+1)
#if defined(GRID) #if defined(GRID)
case ('-r', '--rs', '--restart') case ('-r', '--rs', '--restart')
if (.not. hasArg) call IO_error(610,ext_msg='--jobname') CLI_restartInc = IO_strAsInt(val)
arg = getArg(i+1) if (CLI_restartInc < 0) call IO_error(611,ext_msg=val,label1='--restart')
CLI_restartInc = IO_strAsInt(arg)
if (CLI_restartInc < 0 .or. stat /= 0) call IO_error(611,ext_msg=arg)
#endif #endif
case default
call IO_error(613,ext_msg=flag)
end select end select
end do end do
@ -203,7 +173,7 @@ subroutine CLI_init()
if (.not. allocated(solverJobname)) then if (.not. allocated(solverJobname)) then
solverJobname = jobname(CLI_geomFile,CLI_loadFile,CLI_materialFile,CLI_numericsFile) solverJobname = jobname(CLI_geomFile,CLI_loadFile,CLI_materialFile,CLI_numericsFile)
elseif (scan(solverJobname,'/') > 0) then elseif (scan(solverJobname,'/') > 0) then
call IO_error(630) call IO_error(612,ext_msg=solverJobname,label1='--jobname')
endif endif
commandLine = getArg(-1) commandLine = getArg(-1)
@ -235,7 +205,6 @@ function getArg(n)
character(len=:), allocatable :: getArg character(len=:), allocatable :: getArg
integer :: l,err integer :: l,err
external :: quit
allocate(character(len=0)::getArg) allocate(character(len=0)::getArg)
@ -251,14 +220,14 @@ function getArg(n)
else else
call get_command_argument(n,getArg,status=err) call get_command_argument(n,getArg,status=err)
endif endif
if (err /= 0) call quit(1) if (err /= 0) error stop 'getting command arguments failed'
end function getArg end function getArg
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
!> @brief extract working directory from given argument or from location of geometry file, !> @brief Extract working directory from given argument or from location of geometry file,
!! possibly converting relative arguments to absolut path !! possibly converting relative arguments to absolut path.
!-------------------------------------------------------------------------------------------------- !--------------------------------------------------------------------------------------------------
subroutine setWorkingDirectory(workingDirectoryArg) subroutine setWorkingDirectory(workingDirectoryArg)
@ -421,4 +390,62 @@ function relpath(path,start)
end function relpath end function relpath
!--------------------------------------------------------------------------------------------------
!> @brief Print usage instructions to STDOUT and terminate program.
!--------------------------------------------------------------------------------------------------
subroutine help()
external :: quit
print'(/,1x,a)','#######################################################################'
print'(1x,a)', 'DAMASK Command Line Interface:'
print'(1x,a)', 'Düsseldorf Advanced Material Simulation Kit with PETSc-based solvers'
print'(1x,a,/)','#######################################################################'
print'(1x,a,/)','Valid command line flags:'
print'(1x,a)', ' --geom (-g, --geometry)'
print'(1x,a)', ' --load (-l, --loadcase)'
print'(1x,a)', ' --material (-m, --materialconfig)'
print'(1x,a)', ' --numerics (-n, --numericsconfig)'
print'(1x,a)', ' --jobname (-j, --job)'
print'(1x,a)', ' --workingdir (-w, --wd, --workingdirectory)'
#if defined(GRID)
print'(1x,a)', ' --restart (-r, --rs)'
#endif
print'(1x,a)', ' --help (-h)'
print'(/,1x,a)','-----------------------------------------------------------------------'
print'(1x,a)', 'Mandatory flags:'
print'(/,1x,a)',' --geom GEOMFILE'
print'(1x,a)', ' specify the file path of the geometry definition'
print'(/,1x,a)',' --load LOADFILE'
print'(1x,a)', ' specify the file path of the load case definition'
print'(/,1x,a)',' --material MATERIALFILE'
print'(1x,a)', ' specify the file path of the material configuration'
print'(/,1x,a)','-----------------------------------------------------------------------'
print'(1x,a)', 'Optional flags:'
print'(/,1x,a)',' --numerics NUMERICSFILE'
print'(1x,a)', ' Specify the file path of the numerics configuration'
print'(/,1x,a)',' --jobname JOBNAME'
print'(1x,a)', ' specify the job name.'
print'(1x,a)', ' Defaults to GEOM_LOAD_MATERIAL[_NUMERICS].'
print'(/,1x,a)',' --workingdirectory WORKINGDIRECTORY'
print'(1x,a)', ' specify the base directory of relative paths.'
print'(1x,a)', ' Defaults to the current working directory'
#if defined(GRID)
print'(/,1x,a)',' --restart N'
print'(1x,a)', ' read in increment N and continues with calculating'
print'(1x,a)', ' increment N+1, N+2, ... based on this'
print'(1x,a)', ' works only if the restart information for increment N'
print'(1x,a)', ' is available in JOBNAME_restart.hdf5'
print'(1x,a)', ' append to existing results file JOBNAME.hdf5'
#endif
print'(/,1x,a)','-----------------------------------------------------------------------'
print'(1x,a)', 'Help:'
print'(/,1x,a)',' --help'
print'(1x,a,/)',' Prints this message and exits'
call quit(0)
end subroutine help
end module CLI end module CLI

View File

@ -595,18 +595,17 @@ subroutine IO_error(error_ID,ext_msg,label1,ID1,label2,ID2)
case (603) case (603)
msg = 'invalid data for table' msg = 'invalid data for table'
case (610) case (610)
msg = 'missing argument for option' msg = 'missing value for command line flag'
case (611) case (611)
msg = 'could not parse restart increment' msg = 'invalid value for command line flag'
case (612) case (612)
msg = 'missing option' msg = 'missing command line flag'
case (630) case (613)
msg = 'JOBNAME must not contain any slashes' msg = 'invalid command line flag'
case (640) case (640)
msg = 'invalid working directory' msg = 'invalid working directory'
!------------------------------------------------------------------------------------------------ !------------------------------------------------------------------------------------------------
! errors related to YAML data ! errors related to YAML data
case (701) case (701)

View File

@ -168,7 +168,10 @@ subroutine spectral_utilities_init()
print'( 1x,a)', 'https://doi.org/10.1016/j.ijplas.2014.02.006'//IO_EOL print'( 1x,a)', 'https://doi.org/10.1016/j.ijplas.2014.02.006'//IO_EOL
print'( 1x,a)', 'P. Shanthraj et al., Handbook of Mechanics of Materials, 2019' print'( 1x,a)', 'P. Shanthraj et al., Handbook of Mechanics of Materials, 2019'
print'( 1x,a)', 'https://doi.org/10.1007/978-981-10-6855-3_80' print'( 1x,a)', 'https://doi.org/10.1007/978-981-10-6855-3_80'//IO_EOL
print'( 1x,a)', 'M. Frigo and S.G. Johnson, Proceedings of the IEEE 93(2):216231, 2005'
print'( 1x,a)', 'https://doi.org/10.1109/jproc.2004.840301'
num_solver => config_numerics%get_dict('solver',defaultVal=emptyDict) num_solver => config_numerics%get_dict('solver',defaultVal=emptyDict)
num_grid => num_solver%get_dict('grid',defaultVal=emptyDict) num_grid => num_solver%get_dict('grid',defaultVal=emptyDict)