3
#-------------------------------------------------------------------------------
5
# This file is part of Code_Saturne, a general-purpose CFD tool.
7
# Copyright (C) 1998-2011 EDF S.A.
9
# This program is free software; you can redistribute it and/or modify it under
10
# the terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
14
# This program is distributed in the hope that it will be useful, but WITHOUT
15
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19
# You should have received a copy of the GNU General Public License along with
20
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
21
# Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#-------------------------------------------------------------------------------
26
This module describes the script used to run a study/case for Code_Saturne.
28
This module defines the following functions:
33
#===============================================================================
34
# Import required Python modules
35
#===============================================================================
39
import types, string, re, fnmatch
40
from optparse import OptionParser
43
import cs_exec_environment
47
#-------------------------------------------------------------------------------
48
# Process the command line arguments
49
#-------------------------------------------------------------------------------
51
def process_cmd_line(argv, pkg):
53
Process the passed command line arguments.
56
parser = OptionParser(usage="usage: %prog [options]")
58
parser.add_option("-p", "--param", dest="param", type="string",
60
help="path or name of the parameters file")
62
parser.add_option("--case", dest="case", type="string",
64
help="path to the case's directory")
66
parser.add_option("--id", dest="id", type="string",
68
help="use the given run id")
70
parser.add_option("--suggest-id", dest="suggest_id",
72
help="suggest a run id for the next run")
74
parser.add_option("--initialize", dest="initialize",
76
help="run the data preparation stage")
78
parser.add_option("--execute", dest="execute",
80
help="run the execution stage")
82
parser.add_option("--finalize", dest="finalize",
84
help="run the results copy/cleanup stage")
86
parser.set_defaults(suggest_id=False)
87
parser.set_defaults(initialize=False)
88
parser.set_defaults(execute=False)
89
parser.set_defaults(finalize=False)
90
parser.set_defaults(param=None)
91
parser.set_defaults(domain=None)
92
parser.set_defaults(id=None)
94
# Note: we could use args to pass a calculation status file as an argument,
95
# which would allow pursuing the later calculation stages.
97
(options, args) = parser.parse_args(argv)
99
# Try to determine case directory
105
param = os.path.basename(options.param)
106
if param != options.param:
107
datadir = os.path.split(os.path.realpath(options.param))[0]
108
(casedir, data) = os.path.split(datadir)
109
if data != 'DATA': # inconsistent paramaters location.
113
casedir = os.path.realpath(options.case)
116
casedir = os.getcwd()
117
while os.path.basename(casedir):
118
data = os.path.join(casedir, 'DATA')
119
src = os.path.join(casedir, 'SRC')
120
if os.path.isdir(data) and os.path.isdir(src):
122
casedir = os.path.split(casedir)[0]
127
# Stages to run (if no filter given, all are done).
131
suggest_id = options.suggest_id
133
prepare_data = options.initialize
134
run_solver = options.execute
135
save_results = options.finalize
137
if not (prepare_data or run_solver or save_results):
142
return (casedir, run_id, param, suggest_id,
143
prepare_data, run_solver, save_results)
145
#===============================================================================
146
# Run the calculation
147
#===============================================================================
154
(casedir, run_id, param, suggest_id,
155
prepare_data, run_solver, save_results) = process_cmd_line(argv, pkg)
158
now = datetime.datetime.now()
159
run_id = now.strftime('%Y%m%d-%H%M')
163
# Use alternate compute (back-end) package if defined
165
config = ConfigParser.ConfigParser()
166
config.read([pkg.get_configfile()])
169
if config.has_option('install', 'compute_versions'):
170
compute_versions = config.get('install', 'compute_versions').split(':')
171
if compute_versions[0]:
172
pkg_compute = pkg.get_alternate_version(compute_versions[0])
174
# Values in case and associated domain set from parameters
176
d = cs_case_domain.domain(pkg, package_compute=pkg_compute, param=param)
178
# Now handle case for the corresponding calculation domain(s).
180
c = cs_case.case(pkg,
181
package_compute=pkg_compute,
187
retval = c.run(mpi_environment=None,
189
prepare_data=prepare_data,
190
run_solver=run_solver,
191
save_results=save_results)
195
#-------------------------------------------------------------------------------
197
if __name__ == '__main__':
199
# Retrieve package information (name, version, installation dirs, ...)
200
from cs_package import package
203
retval = main(sys.argv[1:], pkg)
207
#-------------------------------------------------------------------------------
209
#-------------------------------------------------------------------------------