1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2021 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
#-------------------------------------------------------------------------------
"""
This module describes the script used to run a study/case for Code_Saturne.
This module defines the following functions:
- process_cmd_line
- main
"""
#===============================================================================
# Import required Python modules
#===============================================================================
import os, sys, subprocess
import types, string
from argparse import ArgumentParser
from code_saturne import cs_batch
from code_saturne.cs_exec_environment import enquote_arg, get_shell_type
from code_saturne import cs_run
from code_saturne import cs_runcase
#-------------------------------------------------------------------------------
# Print a help page.
#-------------------------------------------------------------------------------
def print_help(submit_cmd, pkg):
"""
Print a help page.
"""
help_string = \
"""
Usage: %s [batch options]
Options:
Any option provided by the batch submission command (%s)
"""
print(help_string % (sys.argv[0], submit_cmd, pkg.name))
#-------------------------------------------------------------------------------
# Process the command line arguments
#-------------------------------------------------------------------------------
def process_cmd_line(argv, submit_cmd, pkg):
"""
Process the passed command line arguments.
"""
runcase_path = None
need_help = False
if "-h" in argv or "--help" in argv:
need_help = True
if need_help:
print_help(submit_cmd, pkg)
return
#===============================================================================
# Sumbit the calculation
#===============================================================================
def main(argv, pkg):
"""
Main function.
"""
# Use alternate compute (back-end) package if defined
batch = cs_batch.batch(pkg)
submit_cmd = batch.submit_command_prefix()
if not submit_cmd:
submit_cmd = get_shell_type()
epilog = ("Options not listed above are passed to the batch "
"submission commands; see your batch documentation for this.")
run_parser = cs_run.arg_parser(argv)
prog = os.path.basename(sys.argv[0]) + " " + sys.argv[1]
parser = ArgumentParser(parents=[run_parser],
prog=prog,
description="Submit a case or specified run stages.",
usage='%(prog)s [run options] [batch options]',
epilog=epilog,
conflict_handler='resolve')
run_args, submit_args = parser.parse_known_args(argv)
retcode, result_path, r_c = cs_run.run(pkg=pkg,
run_args=run_args,
submit_args=submit_args)
# Now prepare runcase for submission
if retcode != 0 or not result_path:
err_str = ' run not staged due to prior error.'
raise Exception(err_str)
runcase_path = os.path.join(result_path, 'runcase')
runcase = cs_runcase.runcase(runcase_path,
package=pkg,
submit=True,
job_header = r_c['job_header'],
prologue = r_c['run_prologue'],
epilogue = r_c['run_epilogue'])
runcase.save()
# Now submit case
save_wd = os.getcwd()
os.chdir(result_path)
if r_c['job_parameters']:
submit_cmd += ' ' + r_c['job_parameters']
submit_cmd += ' ./runcase'
return subprocess.call(submit_cmd, shell=True)
os.chdir(save_wd)
#-------------------------------------------------------------------------------
if __name__ == '__main__':
# Run package
from code_saturne.cs_package import package
pkg = package()
retval = main(sys.argv[1:], pkg)
sys.exit(retval)
#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
|