def __init__(self, parent, case): """ Constructor """ QWidget.__init__(self, parent) Ui_BatchRunningDialogForm.__init__(self) self.setupUi(self) self.case = case self.parent = parent case_is_saved = not self.case.isModified() title = self.tr("Run computation") self.setWindowTitle(title) self.case.undoStopGlobal() self.mdl = ScriptRunningModel(self.case) # Check if the script file name is already defined if self.case['scripts_path']: if not self.case['runcase']: if self.case['package'].runcase in os.listdir(self.case['scripts_path']): runcase_path = os.path.join(self.case['scripts_path'], self.case['package'].runcase) self.case['runcase'] = cs_runcase.runcase(runcase_path, package=self.case['package'])
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, pkg) parser = ArgumentParser( parents=[run_parser], 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)
def __init__(self, path=None, pkg=None, import_legacy=False): """ Constructor. """ self.pkg = pkg if self.pkg == None: from code_saturne.cs_package import package pkg = package() self.run_conf = None self.path = path # Configuration-based information i_c = cs_run_conf.get_install_config_info(self.pkg) self.resource_name = cs_run_conf.get_resource_name(i_c) self.compute_builds = i_c['compute_builds'] self.batch = cs_batch.batch(self.pkg) # Convert from legacy runcase if not updated yet # (delaying application of file changes to save). # in this case, the run_conf object is pre-loaded so that # the "save" operation can apply the (conversion) changes # even when the configuration file has not been loaded. self.runcase_path = None if self.path: if import_legacy and not os.path.isfile(self.path): dirname = os.path.dirname(self.path) if os.path.basename(dirname) == 'DATA': dirname = os.path.join(os.path.basename(dirname), 'SCRIPTS') runcase_path = os.path.join(dirname, 'runcase') if os.path.isfile(runcase_path): self.runcase_path = runcase_path if self.runcase_path: from code_saturne import cs_runcase runcase = cs_runcase.runcase(runcase_path, package=self.pkg) sections = runcase.run_conf_sections(resource_name=self.resource_name, batch_template=i_c['batch']) self.run_conf = cs_run_conf.run_conf(self.path, package=self.pkg, create_if_missing=True) for sn in sections: if not sn in self.run_conf.sections: run_conf.sections[sn] = {} for kw in sections[sn]: self.run_conf.sections[sn][kw] = sections[sn][kw]
def build_batch_file(self, distrep, casename, coupling=None, cathare_path=None): """ Retrieve batch file for the current system Update batch file for the study """ batch_file = os.path.join(distrep, 'runcase') if sys.platform.startswith('win'): batch_file = batch_file + '.bat' if self.copy is not None: ref_runcase_path = os.path.join(self.copy, 'SCRIPTS', 'runcase') if sys.platform.startswith('win'): ref_runcase_path += '.bat' try: shutil.copy(ref_runcase_path, batch_file) except Exception: pass # Add info from parent in case of copy runcase = cs_runcase.runcase(batch_file, package=self.package, rebuild=True, study_name=self.name, case_name=casename) if coupling: runcase.set_coupling(coupling) # If a cathare LIBPATH is given, it is added to LD_LIBRARY_PATH. # This modification is needed for the dlopen of the cathare .so file if cathare_path: v25_3_line = "export v25_3=%s" % cathare_path new_line = "export LD_PATH_LIBRARY=$v25_3/%s/" + ":$LD_LIBRARY_PATH" il = 0 for line in runcase.lines: il += 1 if 'export PATH' in line: runcase.lines.insert(il, new_line % ("lib/ICoCo")) runcase.lines.insert(il, new_line % ("lib")) runcase.lines.insert(il, v25_3_line) runcase.run_cmd_line_id += 3 break runcase.save()
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() submit_args = [] for a in argv: submit_args.append(a) retcode, result_path, r_c = cs_run.run(pkg=pkg, 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)
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() runcase_path = process_cmd_line(argv, submit_cmd, pkg) if not runcase_path: return 1 scripts_dir = os.path.abspath(os.path.dirname(runcase_path)) runcase = cs_runcase.runcase(runcase_path) # Adjust run command for staging only run_args = runcase.get_run_args() for a in ['--stage', '--initialize', '--execute', '--finalize']: while a in run_args: run_args.remove(a) run_args.append('--stage') retcode, run_id, result_path = cs_run.run(run_args, pkg) # 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) run_args = runcase.get_run_args() while '--stage' in run_args: run_args.remove(a) stages = [] for a in ['--initialize', '--execute', '--finalize']: if a in run_args: stages.append(a) if not stages: run_args.append('--initialize') run_args.append('--finalize') runcase.set_run_args(run_args) runcase.set_run_id(run_id=run_id) runcase_path = os.path.join(result_path, os.path.basename(runcase_path)) runcase.save(runcase_path) # Now submit case save_wd = os.getcwd() os.chdir(result_path) for a in argv: if os.path.isfile(a) and runcase_path: submit_cmd += ' ' + enquote_arg(runcase_path) runcase_path = None else: submit_cmd += ' ' + enquote_arg(a) return subprocess.call(submit_cmd, shell=True) os.chdir(save_wd)
def update_case(options, pkg): topdir = os.getcwd() study_name = os.path.basename(os.getcwd()) i_c = cs_run_conf.get_install_config_info(pkg) resource_name = cs_run_conf.get_resource_name(i_c) for case in options.case_names: os.chdir(topdir) if case == ".": case, staging_dir = get_case_dir() if not case: sys.stderr.write(" o Skipping '%s', which does not seem " "to be a case directory\n" % topdir) continue casename = os.path.basename(case) else: casename = case if options.verbose > 0: sys.stdout.write(" o Updating case '%s' paths...\n" % casename) datadir = os.path.join(pkg.get_dir("pkgdatadir")) os.chdir(case) # Write a local wrapper to main command data = 'DATA' if not os.path.isdir(data): os.mkdir(data) dataref_distpath = os.path.join(datadir, 'user') user = os.path.join(data, 'REFERENCE') # Only update user_scripts reference, not data # (we should try to deprecate the copying of reference data # or use the GUI to align it with the active options) if os.path.exists(user): abs_f = os.path.join(datadir, 'data', 'user', 'cs_user_scripts.py') shutil.copy(abs_f, user) unset_executable(user) for s in ("SaturneGUI", "NeptuneGUI"): old_gui_script = os.path.join(data, s) if os.path.isfile(old_gui_script): os.remove(old_gui_script) # Rebuild launch script create_local_launcher(pkg, data) # User source files directory src = 'SRC' if not os.path.isdir(src): os.mkdir(src) user_ref_distpath = os.path.join(datadir, 'user_sources') for srcdir in ('REFERENCE', 'EXAMPLES', 'EXAMPLES_neptune_cfd'): if os.path.isdir(os.path.join(user_ref_distpath, srcdir)): copy_directory(os.path.join(user_ref_distpath, srcdir), os.path.join(src, srcdir), True) unset_executable(os.path.join(src, srcdir)) # Results directory (only one for all instances) resu = 'RESU' if not os.path.isdir(resu): os.mkdir(resu) # Script directory (only one for all instances) run_conf_file = os.path.join(topdir, case, 'DATA', 'run.cfg') batch_file = os.path.join(topdir, case, 'SCRIPTS', 'runcase') if sys.platform.startswith('win'): batch_file = batch_file + '.bat' run_conf = cs_run_conf.run_conf(run_conf_file, package=pkg, rebuild=True) if os.path.isfile(batch_file): runcase = cs_runcase.runcase(batch_file, package=pkg) sections = runcase.run_conf_sections(resource_name=resource_name, batch_template=i_c['batch']) for sn in sections: if not sn in run_conf.sections: run_conf.sections[sn] = {} for kw in sections[sn]: run_conf.sections[sn][kw] = sections[sn][kw] os.remove(batch_file) scripts_dir = os.path.join(topdir, case, 'SCRIPTS') try: os.rmdir(scripts_dir) except Exception: pass run_conf.save()
def create_case(self, casename): """ Create a case for a Code_Saturne study. """ casedirname = casename datadir = self.package.get_dir("pkgdatadir") data_distpath = os.path.join(datadir, 'data') if os.path.exists(casedirname): sys.stdout.write(" o Case '%s' already exists\n" % casename) return if self.verbose > 0: sys.stdout.write(" o Creating case '%s'...\n" % casename) os.mkdir(casedirname) os.chdir(casedirname) if self.copy is not None: if not (os.path.exists(os.path.join(self.copy, 'DATA', 'REFERENCE')) \ or os.path.exists(os.path.join(self.copy, 'SRC', 'REFERENCE'))): self.use_ref = False # Data directory data = 'DATA' os.mkdir(data) abs_setup_distpath = os.path.join(data_distpath, 'setup.xml') if os.path.isfile(abs_setup_distpath) and not self.copy: shutil.copy(abs_setup_distpath, data) unset_executable(data) if self.use_ref: thch_distpath = os.path.join(data_distpath, 'user') ref = os.path.join(data, 'REFERENCE') shutil.copytree(thch_distpath, ref) unset_executable(ref) # Write a wrapper for code and launching create_local_launcher(self.package, data) # Generate run.cfg file or copy one run_conf = None run_conf_path = os.path.join(data, 'run.cfg') if not self.copy: run_conf = cs_run_conf.run_conf(run_conf_path, package=self.package, rebuild=True) # User source files directory src = 'SRC' if self.use_ref: user_distpath = os.path.join(datadir, 'user_sources') shutil.copytree(user_distpath, src) unset_executable(src) else: os.mkdir(src) # Copy data and source files from another case if self.copy is not None: # Data files ref_data = os.path.join(self.copy, data) data_files = os.listdir(ref_data) for f in data_files: abs_f = os.path.join(ref_data, f) if os.path.isfile(abs_f) and \ f not in ["SaturneGUI", "NeptuneGUI", self.package.name]: shutil.copy(abs_f, data) unset_executable(os.path.join(data, f)) # Source files ref_src = os.path.join(self.copy, src) if os.path.exists(ref_src): src_files = os.listdir(ref_src) else: src_files = [] for f in src_files: abs_f = os.path.join(ref_src, f) if os.path.isfile(abs_f): shutil.copy(abs_f, src) unset_executable(os.path.join(src, f)) # If run.cfg was not present in initial case, generate it if not os.path.isfile(run_conf_path): run_conf = cs_run_conf.run_conf(run_conf_path, package=self.package, rebuild=True) # Runcase (for legacy structures) runcase_path = os.path.join(self.copy, 'SCRIPTS', 'runcase') if os.path.isfile(runcase_path): i_c = cs_run_conf.get_install_config_info(self.package) resource_name = cs_run_conf.get_resource_name(i_c) runcase = cs_runcase.runcase(runcase_path, package=self.package) sections = runcase.run_conf_sections(resource_name=resource_name, batch_template=i_c['batch']) for sn in sections: if not sn in run_conf.sections: run_conf.sections[sn] = {} for kw in sections[sn]: run_conf.sections[sn][kw] = sections[sn][kw] # Now write run.cfg if not copied if run_conf != None: run_conf.save() # Results directory resu = 'RESU' if not os.path.isdir(resu): os.mkdir(resu)
def create_case(self, casename): """ Create a case for a Code_Saturne study. """ casedirname = casename if self.verbose > 0: sys.stdout.write(" o Creating case '%s'...\n" % casename) datadir = self.package.get_dir("pkgdatadir") data_distpath = os.path.join(datadir, 'data') try: os.mkdir(casedirname) except: sys.exit(1) os.chdir(casedirname) if self.copy is not None: if not (os.path.exists(os.path.join(self.copy, 'DATA', 'REFERENCE')) \ or os.path.exists(os.path.join(self.copy, 'SRC', 'REFERENCE'))): self.use_ref = False # Data directory data = 'DATA' os.mkdir(data) abs_setup_distpath = os.path.join(data_distpath, 'setup.xml') if os.path.isfile(abs_setup_distpath) and not self.copy: shutil.copy(abs_setup_distpath, data) unset_executable(data) if self.use_ref: thch_distpath = os.path.join(data_distpath, 'thch') ref = os.path.join(data, 'REFERENCE') os.mkdir(ref) for f in [ 'dp_C3P', 'dp_C3PSJ', 'dp_C4P', 'dp_ELE', 'dp_FUE', 'dp_transformers', 'meteo' ]: abs_f = os.path.join(thch_distpath, f) if os.path.isfile(abs_f): shutil.copy(abs_f, ref) unset_executable(ref) abs_f = os.path.join(datadir, 'cs_user_scripts.py') shutil.copy(abs_f, ref) unset_executable(ref) # Write a wrapper for code and launching create_local_launcher(self.package, data) # Generate run.cfg file or copy one run_conf = None run_conf_path = os.path.join(data, 'run.cfg') if not self.copy: run_conf = cs_run_conf.run_conf(run_conf_path, package=self.package, rebuild=True) # User source files directory src = 'SRC' os.mkdir(src) if self.use_ref: user_distpath = os.path.join(datadir, 'user') user_examples_distpath = os.path.join(datadir, 'user_examples') user = os.path.join(src, 'REFERENCE') user_examples = os.path.join(src, 'EXAMPLES') shutil.copytree(user_distpath, user) shutil.copytree(user_examples_distpath, user_examples) add_datadirs = [] if self.package.name == 'neptune_cfd': add_datadirs.append( os.path.join(self.package.get_dir("datadir"), self.package.name)) for d in add_datadirs: user_distpath = os.path.join(d, 'user') user_examples_distpath = os.path.join(d, 'user_examples') if os.path.isdir(user_distpath): s_files = os.listdir(user_distpath) for f in s_files: shutil.copy(os.path.join(user_distpath, f), user) if os.path.isdir(user_examples_distpath): s_files = os.listdir(user_examples_distpath) for f in s_files: shutil.copy(os.path.join(user_examples_distpath, f), user_examples) unset_executable(user) unset_executable(user_examples) # Copy data and source files from another case if self.copy is not None: # Data files ref_data = os.path.join(self.copy, data) data_files = os.listdir(ref_data) for f in data_files: abs_f = os.path.join(ref_data, f) if os.path.isfile(abs_f) and \ f not in [self.package.guiname, self.package.name]: shutil.copy(abs_f, data) unset_executable(os.path.join(data, f)) # Source files ref_src = os.path.join(self.copy, src) if os.path.exists(ref_src): src_files = os.listdir(ref_src) else: src_files = [] for f in src_files: abs_f = os.path.join(ref_src, f) if os.path.isfile(abs_f): shutil.copy(abs_f, src) unset_executable(os.path.join(src, f)) # If run.cfg was not present in initial case, generate it if not os.path.isfile(run_conf_path): run_conf = cs_run_conf.run_conf(run_conf_path, package=self.package, rebuild=True) # Runcase (for legacy structures) runcase_path = os.path.join(self.copy, 'SCRIPTS', 'runcase') if os.path.isfile(runcase_path): i_c = cs_run_conf.get_install_config_info(self.package) resource_name = cs_run_conf.get_resource_name(i_c) runcase = cs_runcase.runcase(runcase_path, package=self.package) sections = runcase.run_conf_sections( resource_name=resource_name, batch_template=i_c['batch']) for sn in sections: if not sn in run_conf.sections: run_conf.sections[sn] = {} for kw in sections[sn]: run_conf.sections[sn][kw] = sections[sn][kw] # Now write run.cfg if not copied if run_conf != None: run_conf.save() # Results directory resu = 'RESU' if not os.path.isdir(resu): os.mkdir(resu)
def coupling(package, domains, casedir, staging_dir=None, verbose=True, package_compute=None): use_saturne = False use_syrthes = False use_neptune = False use_cathare = False use_py_code = False # Use alternate compute (back-end) package if defined config = configparser.ConfigParser() config.read(package.get_global_configfile()) if package_compute == None: package_compute = package # Initialize code domains sat_domains = [] syr_domains = [] nep_domains = [] cat_domains = [] py_domains = [] if domains == None: raise RunCaseError('No domains defined.') for d in domains: if (d.get('script') == None or d.get('domain') == None): msg = 'Check your coupling definition.\n' msg += 'script or domain key is missing.' raise RunCaseError(msg) if (d.get('solver') == 'Code_Saturne' or d.get('solver') == 'NEPTUNE_CFD'): script = d.get('script') if script[-4:] == '.xml': param = script else: runcase_path = os.path.join(os.getcwd(), d.get('domain'), 'SCRIPTS', script) try: runcase = cs_runcase.runcase(runcase_path) param = runcase.get_parameters() except Exception: err_str = 'Cannot read ' + d.get('solver') \ + ' script: ' + runcase_path raise RunCaseError(err_str) d['script'] = param dom = domain(package, package_compute=package_compute, name=d.get('domain'), param=param, n_procs_weight=d.get('n_procs_weight'), n_procs_min=d.get('n_procs_min'), n_procs_max=d.get('n_procs_max')) if (d.get('solver')) == 'Code_Saturne': use_saturne = True sat_domains.append(dom) elif (d.get('solver')) == 'NEPTUNE_CFD': use_neptune = True nep_domains.append(dom) elif (d.get('solver') == 'SYRTHES'): try: dom = syrthes_domain(package, cmd_line=d.get('opt'), name=d.get('domain'), param=d.get('script'), n_procs_weight=d.get('n_procs_weight'), n_procs_min=d.get('n_procs_min'), n_procs_max=d.get('n_procs_max')) except Exception: err_str = 'Cannot create SYRTHES domain. Opt = ' + d.get( 'opt') + '\n' err_str += ' domain = ' + d.get('domain') err_str += ' script = ' + d.get('script') + '\n' err_str += ' n_procs_weight = ' + str( d.get('n_procs_weight')) + '\n' raise RunCaseError(err_str) use_syrthes = True syr_domains.append(dom) elif (d.get('solver') == 'CATHARE'): # Current version using Cathare2: the cathare case is converted to a # .so library which is opened and launched by a NEPTUNE_CFD executable script = d.get('script') if script[-4:] == '.xml': param = script else: d['script'] = d['paramfile'] param = d['script'] dom = cathare_domain(package, package_compute=package_compute, name=d.get('domain'), param=d.get('script'), n_procs_weight=d.get('n_procs_weight'), n_procs_min=d.get('n_procs_min'), n_procs_max=d.get('n_procs_max'), cathare_case_file=d.get('cathare_case_file'), neptune_cfd_dom=d.get('neptune_cfd_domain')) use_cathare = True cat_domains.append(dom) elif (d.get('solver') == 'PYTHON_CODE'): # Generic Code_Saturne/Python Script coupling # The python script can contain any MPI compatible code or supevisor try: dom = python_domain(package, name=d.get('domain'), cmd_line=d.get('command_line'), script_name=d.get('script')) except Exception: err_str = 'Cannot create Python code domain.\n' err_str += ' domain = ' + d.get('domain') + '\n' err_str += ' script = ' + d.get('script') + '\n' raise RunCaseError(err_str) use_py_code = True py_domains.append(dom) else: err_str = 'Unknown code type : ' + d.get('solver') + '.\n' raise RunCaseError(err_str) # Now handle case for the corresponding calculation domain(s). coupling_parameters = \ """ # -*- coding: utf-8 -*-" domains = [ """ d_first = True for d in domains: if not d_first: coupling_parameters += ",\n\n" d_first = False k_first = True for k in ('solver', 'domain', 'script', 'n_procs_weight', 'n_procs_min', 'cathare_case_file', 'neptune_cfd_domain'): v = d.get(k) if v: if type(v) == str: s_v = "'" + v + "'" else: s_v = str(v) if k_first: coupling_parameters += " {" k_first = False else: coupling_parameters += ",\n " coupling_parameters += "'" + k + "': " + s_v coupling_parameters += "}" coupling_parameters += "\n\n ]\n\n" c = case(package, package_compute=package_compute, case_dir=casedir, staging_dir=staging_dir, coupling_parameters=coupling_parameters, domains=sat_domains + nep_domains + cat_domains, syr_domains=syr_domains, py_domains=py_domains) if verbose: msg = ' Coupling execution between: \n' if use_saturne == True: msg += ' o Code_Saturne [' + str( len(sat_domains)) + ' domain(s)];\n' if use_syrthes == True: msg += ' o SYRTHES [' + str( len(syr_domains)) + ' domain(s)];\n' if use_neptune == True: msg += ' o NEPTUNE_CFD [' + str( len(nep_domains)) + ' domain(s)];\n' if use_cathare == True: msg += ' o CATHARE2 [' + str( len(cat_domains)) + ' domain(s)];\n' if use_py_code == True: msg += ' o Python Script [' + str( len(py_domains)) + ' domain(s)];\n' sys.stdout.write(msg + '\n') return c
def coupling(package, domains, casedir, dest_dir=None, staging_dir=None, verbose=True, package_compute=None): use_saturne = False use_syrthes = False use_neptune = False use_cathare = False use_py_code = False # Use alternate compute (back-end) package if defined config = configparser.ConfigParser() config.read(package.get_global_configfile()) if package_compute == None: package_compute = package # Initialize code domains sat_domains = [] syr_domains = [] nep_domains = [] cat_domains = [] py_domains = [] if domains == None: raise RunCaseError('No domains defined.') for d in domains: domain_s = d.get('domain') solver_s = d.get('solver').lower() script_s = None param_s = None if (domain_s == None): msg = 'Check your coupling definition.\n' msg += 'domain key is missing.' raise RunCaseError(msg) # First, determine parameter file to use for code_saturne # or associated modules (ensuring backwards compatibiliy) if solver_s in package.config.solver_modules.keys() \ or solver_s == 'cathare': param = None script = d.get('script') # v6.1 and older structure if script != None: if script[-4:] == '.xml': param = script else: param = d.get('param') if not param: param = d.get('paramfile') # older_name s_dir = staging_dir if not s_dir: s_dir = casedir if not s_dir: s_dir = os.getcwd() if param == None: run_conf_path = os.path.join(s_dir, domain_s, 'DATA', 'run.cfg') if os.path.isfile(run_conf_path): run_conf = cs_run_conf.run_conf(run_conf_path) if 'setup' in run_conf.sections: if 'param' in run_conf.sections['setup']: param = run_conf.sections['setup']['param'] if script and not param: # v6.1 and older case structure runcase_path = os.path.join(s_dir, domain_s, 'SCRIPTS', script) if os.path.isfile(runcase_path): try: runcase = cs_runcase.runcase(runcase_path) param = runcase.get_parameters() except Exception: err_str = 'Cannot read ' + d.get('solver') \ + ' script: ' + runcase_path raise RunCaseError(err_str) # Remark: if param is undefined, the code_saturne domain will # default to 'setup.xml' if present. d['param'] = param # Now build case domain for the different solvers: if solver_s in package.config.solver_modules.keys(): dom = domain(package, package_compute=package_compute, name=domain_s, param=d.get('param'), n_procs_weight=d.get('n_procs_weight'), n_procs_min=d.get('n_procs_min'), n_procs_max=d.get('n_procs_max')) if solver_s == 'code_saturne': use_saturne = True sat_domains.append(dom) elif solver_s == 'neptune_cfd': use_neptune = True nep_domains.append(dom) elif solver_s == 'syrthes': param_s = d.get('param') if param_s == None: param_s = d.get('script') # older name if (param_s == None): msg = 'Check your coupling definition.\n' msg += 'parameters file selection is missing for domain: ' msg += domain_s + '.\n' raise RunCaseError(msg) try: dom = syrthes_domain(package, cmd_line=d.get('opt'), name=domain_s, param=d.get('param'), n_procs_weight=d.get('n_procs_weight'), n_procs_min=d.get('n_procs_min'), n_procs_max=d.get('n_procs_max'), verbose=verbose) except Exception: err_str = 'Cannot create SYRTHES domain. Opt = ' + d.get( 'opt') + '\n' err_str += ' domain = ' + domain_s + '\n' err_str += ' n_procs_weight = ' + str( d.get('n_procs_weight')) + '\n' raise RunCaseError(err_str) use_syrthes = True syr_domains.append(dom) elif solver_s == 'cathare': # Current version using Cathare2: the cathare case is converted to a # .so library which is opened and launched by a neptune_cfd executable dom = cathare_domain(package, package_compute=package_compute, name=domain_s, param=d.get('param'), n_procs_weight=None, n_procs_min=1, n_procs_max=1, cathare_case_file=d.get('cathare_case_file'), neptune_cfd_dom=d.get('neptune_cfd_domain')) use_cathare = True cat_domains.append(dom) elif solver_s == 'python_code': script_s = d.get('script') if (script_s == None): msg = 'Check your coupling definition.\n' msg += 'Python script file selection is missing for domain: ' msg += domain_s + '.\n' raise RunCaseError(msg) # Generic Code_Saturne/Python Script coupling # The python script can contain any MPI compatible code or supervisor try: dom = python_domain(package, name=domain_s, cmd_line=d.get('command_line'), script_name=script_s) except Exception: err_str = 'Cannot create Python code domain.\n' err_str += ' domain = ' + domain_s + '\n' err_str += ' script = ' + str(d.get('script')) + '\n' raise RunCaseError(err_str) use_py_code = True py_domains.append(dom) else: err_str = 'Unknown code type : ' + d.get('solver') + '.\n' raise RunCaseError(err_str) # Now handle case for the corresponding calculation domain(s). c = case(package, package_compute=package_compute, case_dir=casedir, dest_dir=dest_dir, staging_dir=staging_dir, domains=sat_domains + nep_domains + cat_domains, syr_domains=syr_domains, py_domains=py_domains) if verbose: msg = ' Coupling execution between: \n' if use_saturne == True: msg += ' o code_saturne [' + str( len(sat_domains)) + ' domain(s)];\n' if use_syrthes == True: msg += ' o SYRTHES [' + str( len(syr_domains)) + ' domain(s)];\n' if use_neptune == True: msg += ' o neptune_cfd [' + str( len(nep_domains)) + ' domain(s)];\n' if use_cathare == True: msg += ' o CATHARE2 [' + str( len(cat_domains)) + ' domain(s)];\n' if use_py_code == True: msg += ' o Python Script [' + str( len(py_domains)) + ' domain(s)];\n' sys.stdout.write(msg + '\n') return c
def update_case(options, pkg): repbase = os.getcwd() study_name = os.path.basename(os.getcwd()) for case in options.case_names: os.chdir(repbase) if case == ".": casename = os.path.split(repbase)[-1] else: casename = case if options.verbose > 0: sys.stdout.write(" o Updating case '%s' paths...\n" % casename) datadir = os.path.join(pkg.get_dir("pkgdatadir")) os.chdir(case) # Write a wrapper for GUI launching data = 'DATA' if not os.path.isdir(data): os.mkdir(data) guiscript = os.path.join(data, pkg.guiname) fd = open(guiscript, 'w') cs_exec_environment.write_shell_shebang(fd) cs_exec_environment.write_script_comment( fd, 'Ensure the correct command is found:\n') cs_exec_environment.write_prepend_path(fd, 'PATH', pkg.get_dir("bindir")) fd.write('\n') cs_exec_environment.write_script_comment(fd, 'Run command:\n') # On Linux systems, add a backslash to prevent aliases if sys.platform.startswith('linux'): fd.write('\\') fd.write(pkg.name + ' gui ' + cs_exec_environment.get_script_positional_args() + '\n') fd.close() set_executable(guiscript) # User source files directory src = 'SRC' if not os.path.isdir(src): os.mkdir(src) user_distpath = os.path.join(datadir, 'user') user_examples_distpath = os.path.join(datadir, 'user_examples') user = os.path.join(src, 'REFERENCE') user_examples = os.path.join(src, 'EXAMPLES') copy_directory(user_distpath, user) copy_directory(user_examples_distpath, user_examples) add_datadirs = [] if pkg.name == 'neptune_cfd': add_datadirs.append(os.path.join(pkg.get_dir("datadir"), pkg.name)) for d in add_datadirs: user_distpath = os.path.join(d, 'user') if os.path.isdir(user_distpath): copy_directory(user_distpath, user) user_examples_distpath = os.path.join(d, 'user_examples') if os.path.isdir(user_examples_distpath): copy_directory(user_examples_distpath, user_examples) unset_executable(user) unset_executable(user_examples) # Results directory (only one for all instances) resu = 'RESU' if not os.path.isdir(resu): os.mkdir(resu) # Script directory (only one for all instances) scripts = 'SCRIPTS' if not os.path.isdir(scripts): os.mkdir(scripts) batch_file = os.path.join(repbase, case, scripts, 'runcase') if sys.platform.startswith('win'): batch_file = batch_file + '.bat' # Add info from parent in case of copy runcase = cs_runcase.runcase(batch_file, package=pkg, rebuild=True, study_name=study_name, case_name=case) runcase.save()