option to specify numerics configuration file and jobname

default jobname now includes all CLI arguments (for mesh/grid only)
This commit is contained in:
Martin Diehl 2023-07-09 13:25:37 +02:00
parent bb49289b76
commit 3af61233c9
3 changed files with 163 additions and 113 deletions

@ -1 +1 @@
Subproject commit 9f4ffce8b2df951191a14dc3229de1aee6e544e6
Subproject commit 3c4052994318bf41620af2e4c8795f36cabc3645

View File

@ -21,14 +21,16 @@ module CLI
implicit none(type,external)
private
integer, public, protected :: &
CLI_restartInc = 0 !< Increment at which calculation starts
CLI_restartInc = 0 !< increment at which calculation starts
character(len=:), allocatable, public, protected :: &
CLI_geomFile, & !< parameter given for geometry file
CLI_loadFile, & !< parameter given for load case file
CLI_materialFile
CLI_geomFile, & !< location of the geometry file
CLI_loadFile, & !< location of the load case file
CLI_materialFile, & !< location of the material configuration file
CLI_numericsFile, & !< location of the numerics configuration file
solverJobname
public :: &
getSolverJobName, &
getSolverJobname, &
CLI_init
contains
@ -47,10 +49,11 @@ subroutine CLI_init()
character(len=:), allocatable :: &
commandLine, & !< command line call as string
arg, & !< individual argument
loadCaseArg, & !< -l argument given to the executable
geometryArg, & !< -g argument given to the executable
materialArg, & !< -m argument given to the executable
workingDirArg !< -w argument given to the executable
geomArg, & !< -g CLI argument
loadArg, & !< -l CLI argument
materialArg, & !< -m CLI argument
numericsArg, & !< -n CLI argument
workingDirArg !< -w CLI argument
integer :: &
stat, &
i
@ -62,94 +65,105 @@ subroutine CLI_init()
workingDirArg = getCWD()
print '(/,1x,a)', '<<<+- CLI init -+>>>'
print'(/,1x,a)', '<<<+- CLI init -+>>>'
! http://patorjk.com/software/taag/#p=display&f=Lean&t=DAMASK%203
#ifdef DEBUG
print '(a)', achar(27)//'[31m'
print '(1x,a,/)', 'debug version - debug version - debug version - debug version - debug version'
print'(a)', achar(27)//'[31m'
print'(1x,a,/)', 'debug version - debug version - debug version - debug version - debug version'
#else
print '(a)', achar(27)//'[94m'
print'(a)', achar(27)//'[94m'
#endif
print '(1x,a)', ' _/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/ _/_/_/'
print '(1x,a)', ' _/ _/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/ _/'
print '(1x,a)', ' _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/_/ _/_/ _/_/ _/_/'
print '(1x,a)', ' _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/'
print '(1x,a)', '_/_/_/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/ _/_/_/'
print'(1x,a)', ' _/_/_/ _/_/ _/ _/ _/_/ _/_/_/ _/ _/ _/_/_/'
print'(1x,a)', ' _/ _/ _/ _/ _/_/ _/_/ _/ _/ _/ _/ _/ _/'
print'(1x,a)', ' _/ _/ _/_/_/_/ _/ _/ _/ _/_/_/_/ _/_/ _/_/ _/_/'
print'(1x,a)', ' _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/'
print'(1x,a)', '_/_/_/ _/ _/ _/ _/ _/ _/ _/_/_/ _/ _/ _/_/_/'
#if defined(GRID)
print '(1x,a)', 'Grid solver'
print'(1x,a)', 'Grid solver'
#elif defined(MESH)
print '(1x,a)', 'Mesh solver'
print'(1x,a)', 'Mesh solver'
#endif
#ifdef DEBUG
print '(/,1x,a)', 'debug version - debug version - debug version - debug version - debug version'
print'(/,1x,a)', 'debug version - debug version - debug version - debug version - debug version'
#endif
print '(a)', achar(27)//'[0m'
print'(a)', achar(27)//'[0m'
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)', '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)', 'Version: '//DAMASKVERSION
print'(/,1x,a)', 'Version: '//DAMASKVERSION
print '(/,1x,a)', 'Compiled with: '//compiler_version()
print '(1x,a)', 'Compiled on: '//CMAKE_SYSTEM
print '(1x,a)', 'Compiler options: '//compiler_options()
print'(/,1x,a)', 'Compiled with: '//compiler_version()
print'(1x,a)', 'Compiled on: '//CMAKE_SYSTEM
print'(1x,a)', 'Compiler options: '//compiler_options()
! https://github.com/jeffhammond/HPCInfo/blob/master/docs/Preprocessor-Macros.md
print '(/,1x,a)', 'Compiled on: '//__DATE__//' at '//__TIME__
print'(/,1x,a)', 'Compiled on: '//__DATE__//' at '//__TIME__
print '(/,1x,a,1x,i0,a,i0,a,i0)', &
print'(/,1x,a,1x,i0,a,i0,a,i0)', &
'PETSc version:',PETSC_VERSION_MAJOR,'.',PETSC_VERSION_MINOR,'.',PETSC_VERSION_SUBMINOR
call date_and_time(values = dateAndTime)
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),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)
do i = 1, command_argument_count()
arg = getArg(i)
select case(trim(arg)) ! extract key
case ('-h','--help')
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 switches:'
print '(1x,a)', ' --geom (-g, --geometry)'
print '(1x,a)', ' --load (-l, --loadcase)'
print '(1x,a)', ' --material (-m, --materialconfig)'
print '(1x,a)', ' --workingdir (-w, --wd, --workingdirectory)'
print '(1x,a)', ' --restart (-r, --rs)'
print '(1x,a)', ' --help (-h)'
print '(/,1x,a)','-----------------------------------------------------------------------'
print '(1x,a)', 'Mandatory arguments:'
print '(/,1x,a)',' --geom PathToGeomFile/NameOfGeom'
print '(1x,a)', ' Specifies the location of the geometry definition file.'
print '(/,1x,a)',' --load PathToLoadFile/NameOfLoadFile'
print '(1x,a)', ' Specifies the location of the load case definition file.'
print '(/,1x,a)',' --material PathToMaterialConfigurationFile/NameOfMaterialConfigurationFile'
print '(1x,a)', ' Specifies the location of the material configuration file.'
print '(/,1x,a)','-----------------------------------------------------------------------'
print '(1x,a)', 'Optional arguments:'
print '(/,1x,a)',' --workingdirectory PathToWorkingDirectory'
print '(1x,a)', ' Specifies the base directory of relative paths.'
print '(/,1x,a)',' --restart N'
print '(1x,a)', ' Reads in increment N and continues with calculating'
print '(1x,a)', ' increment N+1, N+2, ... based on this.'
print '(1x,a)', ' Appends to existing results file'
print '(1x,a)', ' "NameOfGeom_NameOfLoadFile_NameOfMaterialConfigurationFile.hdf5".'
print '(1x,a)', ' Works only if the restart information for increment N'
print '(1x,a)', ' is available in the base directory.'
print '(/,1x,a)','-----------------------------------------------------------------------'
print '(1x,a)', 'Help:'
print '(/,1x,a)',' --help'
print '(1x,a,/)',' Prints this message and exits'
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 switches:'
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)'
print'(1x,a)', ' --restart (-r, --rs)'
print'(1x,a)', ' --help (-h)'
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'
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'
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 ('-l', '--load', '--loadcase')
loadCaseArg = getArg(i+1)
case ('-g', '--geom', '--geometry')
geometryArg = getArg(i+1)
geomArg = getArg(i+1)
case ('-l', '--load', '--loadcase')
loadArg = getArg(i+1)
case ('-m', '--material', '--materialconfig')
materialArg = getArg(i+1)
case ('-n', '--numerics', '--numericsconfig')
numericsArg = getArg(i+1)
case ('-j', '--job', '--jobname')
solverJobname = getArg(i+1)
case ('-w', '--wd', '--workingdir', '--workingdirectory')
workingDirArg = getArg(i+1)
case ('-r', '--rs', '--restart')
@ -162,33 +176,46 @@ subroutine CLI_init()
end select
end do
if (.not. all([allocated(loadcaseArg),allocated(geometryArg),allocated(materialArg)])) then
print '(/,1x,a)', 'ERROR: Please specify geometry AND load case AND material configuration (-h for help)'
if (.not. all([allocated(loadArg),allocated(geomArg),allocated(materialArg)])) then
print'(/,1x,a)', 'ERROR: Please specify geometry AND load case AND material configuration (-h for help)'
call quit(1)
end if
call setWorkingDirectory(trim(workingDirArg))
CLI_geomFile = getPathRelCWD(geometryArg,'geometry')
CLI_loadFile = getPathRelCWD(loadCaseArg,'load case')
CLI_geomFile = getPathRelCWD(geomArg,'geometry')
CLI_loadFile = getPathRelCWD(loadArg,'load case')
CLI_materialFile = getPathRelCWD(materialArg,'material configuration')
if (allocated(numericsArg)) then
CLI_numericsFile = getPathRelCWD(numericsArg,'numerics configuration')
else
CLI_numericsFile = ''
endif
if (.not. allocated(solverJobname)) then
solverJobname = jobname(CLI_geomFile,CLI_loadFile,CLI_materialFile,CLI_numericsFile)
elseif (scan(solverJobname,'/') > 0) then
print'(/,1x,a)', 'ERROR: JOBNAME must not contain any slashes'
call quit(1)
endif
commandLine = getArg(-1)
print '(/,1x,a)', 'Host name: '//getHostName()
print '(1x,a)', 'User name: '//getUserName()
print'(/,1x,a)', 'Host name: '//getHostName()
print'(1x,a)', 'User name: '//getUserName()
print '(/,1x,a,/)', 'Command line call: '//trim(commandLine)
print '(1x,a)', 'Working directory: '//IO_glueDiffering(getCWD(),workingDirArg)
print '(1x,a)', 'Geometry: '//IO_glueDiffering(CLI_geomFile,geometryArg)
print '(1x,a)', 'Load case: '//IO_glueDiffering(CLI_loadFile,loadCaseArg)
print '(1x,a)', 'Material config: '//IO_glueDiffering(CLI_materialFile,materialArg)
print '(1x,a)', 'Solver job name: '//getSolverJobName()
print'(/,1x,a,/)', 'Command line call: '//trim(commandLine)
print'(1x,a)', 'Working directory: '//IO_glueDiffering(getCWD(),workingDirArg)
print'(1x,a)', 'Geometry: '//IO_glueDiffering(CLI_geomFile,geomArg)
print'(1x,a)', 'Load case: '//IO_glueDiffering(CLI_loadFile,loadArg)
print'(1x,a)', 'Material config: '//IO_glueDiffering(CLI_materialFile,materialArg)
print'(1x,a)', 'Solver job name: '//getSolverJobname()
if (CLI_restartInc > 0) &
print '(1x,a,i6.6)', 'Restart from increment: ', CLI_restartInc
print'(1x,a,i6.6)', 'Restart from increment: ', CLI_restartInc
end subroutine CLI_init
!--------------------------------------------------------------------------------------------------
!> @brief Get argument from command line.
!--------------------------------------------------------------------------------------------------
@ -242,7 +269,7 @@ subroutine setWorkingDirectory(workingDirectoryArg)
workingDirectory = trim(normpath(workingDirectory))
error = setCWD(trim(workingDirectory))
if (error) then
print '(1x,a)', 'ERROR: Invalid Working directory: '//trim(workingDirectory)
print'(1x,a)', 'ERROR: Invalid Working directory: '//trim(workingDirectory)
call quit(1)
end if
@ -250,26 +277,43 @@ end subroutine setWorkingDirectory
!--------------------------------------------------------------------------------------------------
!> @brief solver job name (no extension) as combination of geometry and load case name
!> @brief Return solver job name (MSC.Marc compatible).
!--------------------------------------------------------------------------------------------------
function getSolverJobName()
function getSolverJobname()
character(len=:), allocatable :: getSolverJobName
integer :: posExt,posSep
character(len=:), allocatable :: getSolverJobname
posExt = scan(CLI_geomFile,'.',back=.true.)
posSep = scan(CLI_geomFile,'/',back=.true.)
getSolverJobname = solverJobname
getSolverJobName = CLI_geomFile(posSep+1:posExt-1)
end function getSolverJobname
posExt = scan(CLI_loadFile,'.',back=.true.)
posSep = scan(CLI_loadFile,'/',back=.true.)
getSolverJobName = getSolverJobName//'_'//CLI_loadFile(posSep+1:posExt-1)
!--------------------------------------------------------------------------------------------------
!> @brief Determine solver job name.
!--------------------------------------------------------------------------------------------------
function jobname(geomFile,LoadFile,materialsFile,numericsFile)
end function getSolverJobName
character(len=:), allocatable :: jobname
character(len=*), intent(in) :: geomFile,loadFile,materialsFile,numericsFile
jobname = stem(geomFile)//'_'//stem(loadFile)//'_'//stem(materialsFile)
if (len_trim(numericsFile) > 0) jobname = jobname//'_'//stem(numericsFile)
contains
function stem(fullname)
character(len=:), allocatable :: stem
character(len=*), intent(in) :: fullname
stem = fullname(scan(fullname,'/',back=.true.)+1:scan(fullname,'.',back=.true.)-1)
end function stem
end function jobname
!--------------------------------------------------------------------------------------------------
@ -291,7 +335,7 @@ function getPathRelCWD(path,fileType)
inquire(file=getPathRelCWD, exist=file_exists)
if (.not. file_exists) then
print '(1x,a)', 'ERROR: '//fileType//' file does not exist: '//trim(getPathRelCWD)
print'(1x,a)', 'ERROR: '//fileType//' file does not exist: '//trim(getPathRelCWD)
call quit(1)
end if

View File

@ -68,11 +68,10 @@ end subroutine config_numerics_deallocate
!--------------------------------------------------------------------------------------------------
function config_listReferences(config,indent) result(references)
type(tDict) :: config
integer, optional :: indent
type(tDict), intent(in) :: config
integer, intent(in), optional :: indent
character(len=:), allocatable :: references
type(tList), pointer :: ref
character(len=:), allocatable :: filler
integer :: r
@ -97,13 +96,13 @@ end function config_listReferences
!--------------------------------------------------------------------------------------------------
subroutine parse_material()
logical :: fileExists
character(len=:), allocatable :: &
fileContent, fname
if (worldrank == 0) then
print'(/,1x,a)', 'reading material configuration'; flush(IO_STDOUT)
#if defined(MESH) || defined(GRID)
#if defined(MESH) || defined(GRID)
fname = CLI_materialFile
#else
fname = 'material.yaml'
@ -126,23 +125,30 @@ end subroutine parse_material
!--------------------------------------------------------------------------------------------------
subroutine parse_numerics()
logical :: fileExists
character(len=:), allocatable :: fileContent
character(len=:), allocatable :: &
fileContent, fname
logical :: parse
config_numerics => emptyDict
inquire(file='numerics.yaml', exist=fileExists)
if (fileExists) then
#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
if (worldrank == 0) then
print'(1x,a)', 'reading numerics.yaml'; flush(IO_STDOUT)
fileContent = IO_read('numerics.yaml')
if (len(fileContent) > 0) then
call result_openJobFile(parallel=.false.)
call result_writeDataset_str(fileContent,'setup','numerics.yaml','numerics configuration')
call result_closeJobFile()
end if
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
call parallelization_bcast_str(fileContent)