예제 #1
0
def load_case_setup_from_xml(xml_file, pkg=None):
    """
    Load case from XML file.
    @param xml_file: path to xml file
    """

    pkg = None
    if not pkg:
        from code_saturne.base.cs_package import package
        pkg = package()

    from code_saturne.model.XMLengine import Case

    try:
        case_setup = Case(package=pkg, file_name=xml_file)
        case_setup['xmlfile'] = xml_file
    except:
        print("Error while reading parameters files.")
        print("This file is not in accordance with XML specifications.")
        sys.exit(1)

    module_name = case_setup.module_name()

    if module_name == 'code_saturne':
        from code_saturne.model.XMLinitialize import XMLinit
    elif module_name == 'neptune_cfd':
        from code_saturne.model.XMLinitializeNeptune import XMLinitNeptune as XMLinit

    # internal functions of code_saturne to properly initialize the
    # xml structure
    case_setup.xmlCleanAllBlank(case_setup.xmlRootNode())
    XMLinit(case_setup).initialize()

    return case_setup
예제 #2
0
def symbols_to_lines(argv, pkg):
    """
    For each debug symbol, get the corresponding file and line.
    """

    if not pkg:
        from code_saturne.base.cs_package import package
        pkg = package()

    options = process_cmd_line(argv, pkg)

    translator = cs_debug_symbol_translator(pkg,
                                            path=options.path,
                                            solver=options.solver)

    for sym in options.symbols:
        file_line = translator.symbol2line(sym)

        if "??:?" in file_line:
            sys.stdout.write("Symbol '%s' yielded no file/line.\n" % sym)
            sys.stdout.write(
                "Please rerun case with an instance compiled with --debug option.\n"
            )

        else:
            res = "%s -> %s" % (sym, file_line)
            sys.stdout.write(res)

    return 0
예제 #3
0
    def __init__(self, pkg=None):

        # package
        self.pkg = None
        if pkg:
            self.pkg = pkg
        else:
            from code_saturne.base.cs_package import package
            self.pkg = package()
    def __init__(self, path=None, pkg=None, import_legacy=False):
        """
        Constructor.
        """

        self.pkg = pkg
        if self.pkg is None:
            from code_saturne.base.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.base 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]
예제 #5
0
def generate_header(batch_template=None, job_name=None, package=None):
    """
    Generate batch header lines based on batch template configuration
    """

    lines = []

    if not package:
        from code_saturne.base import cs_package
        package = cs_package.package()

    if not batch_template:
        config = configparser.ConfigParser()
        config.read(package.get_configfiles())
        if config.has_option('install', 'batch'):
            batch_template = config.get('install', 'batch')

    if not batch_template:
        return lines

    if not job_name:
        job_name = package.name + ':' + os.path.basename(os.getcwd())

    # For some systems, name lengths may be limited.
    # With SLURM 18.08, the max. length seems to be 37 characters.
    job_name = job_name[:38]

    if not os.path.isabs(batch_template):
        batch_template = os.path.join(package.get_batchdir(),
                                      'batch.' + batch_template)

    fdt = open(batch_template, 'r')

    import re, string
    kwd1 = re.compile('nameandcase')

    # Determine or build default names if required

    for line in fdt:
        line = line.rstrip()
        line = re.sub(kwd1, job_name, line)
        lines.append(line)

    fdt.close()

    return lines
예제 #6
0
    def get_help_text(self, package=None):
        """
        Read batch help text based on configuration
        """

        text = None
        help_path = None

        if not package:
            from code_saturne.base import cs_package
            package = cs_package.package()

        config = configparser.ConfigParser()
        config.read(package.get_configfiles())
        if config.has_option('install', 'batch_help'):
            help_path = config.get('install', 'batch_help')
            if not os.path.isabs(help_path):
                i = help_path.rfind(".")
                if i > -1:
                    help_path = 'batch_help.' + help_path
                help_path = os.path.join(package.get_batchdir(), help_path)

        elif self.rm_template != None:
            help_path = os.path.join(package.get_batchdir(),
                                     'batch_help.' + self.rm_template)
            if not os.path.isfile(help_path):
                help_path = os.path.join(package.get_batchdir(),
                                         'batch_help.' + self.rm_type)

        if help_path != None:
            try:
                fdt = open(help_path, 'r')
                text = fdt.read()
                fdt.close()
            except Exception:
                print('help file: ' + help_path + ' not present or readable.')
                pass

        return text
예제 #7
0
    """

    (exec_dir) = process_cmd_line(argv, pkg)

    c = controller(exec_dir, pkg)

    c.advance(3)
    c.advance(3)

    return 0

#-------------------------------------------------------------------------------

if __name__ == '__main__':

    # Run package

    try:
        from code_saturne.base.cs_package import package
        pkg = package()
    except Exception:
        pkg = None

    retval = main(sys.argv[1:], pkg)

    sys.exit(retval)

#-------------------------------------------------------------------------------
# End
#-------------------------------------------------------------------------------
예제 #8
0
    #---------------------------------------------------------------------------

    def __init__(self, case=None, pkg=None):
        """
        Constructor.
        @param case: XML case object
        @param pkg: package
        """

        # package
        self.pkg = None
        if pkg:
            self.pkg = pkg
        else:
            from code_saturne.base.cs_package import package
            self.pkg = package()

        from code_saturne.model.XMLengine import Case

        self.case = case

        self.outputModel   = None
        self.bcModel       = None
        self.bndModel      = None
        self.restartModel  = None
        self.timeStepModel = None
        self.meshModel     = None
        self.notebookModel = None
        self.numParamModel = None
        self.numParamEquationModel = None
예제 #9
0
def run(argv=[], pkg=None, run_args=None, submit_args=None):
    """
    Run calculation;
    returns return code, run id, and results directory path when created.
    """

    if not pkg:
        from code_saturne.base.cs_package import package
        pkg = package()

    if run_args is None:
        options = parse_cmd_line(argv)
    else:
        options = run_args

    i_c = cs_run_conf.get_install_config_info(pkg)

    if options.resource_name != None:
        i_c['resource_name'] = options.resource_name.lower()

    r_c, s_c, run_conf = process_options(options, pkg)

    if not r_c['casedir'] and not r_c['staging_dir']:
        return 1, None, None

    # Read run configuration

    read_run_config_file(i_c, r_c, s_c, pkg, run_conf=run_conf)

    # Determine compute stages

    update_run_steps(s_c, None, final=True)

    stages = {
        'prepare_data': s_c['stage'],
        'initialize': s_c['initialize'],
        'run_solver': s_c['compute'],
        'save_results': s_c['finalize']
    }

    # Use alternate compute (back-end) package if defined

    pkg_compute = None
    if not r_c['compute_build']:
        if i_c['compute_builds']:
            r_c['compute_build'] = i_c['compute_builds'][0]
    if r_c['compute_build']:
        pkg_compute = pkg.get_alternate_version(r_c['compute_build'])

    # Specific case for coupling

    if r_c['coupled_domains'] != []:

        from code_saturne.base import cs_case_coupling

        domains = r_c['coupled_domains']

        verbose = True
        if r_c['suggest_id']:
            verbose = False

        c = cs_case_coupling.coupling(pkg,
                                      domains,
                                      r_c['casedir'],
                                      r_c['dest_dir'],
                                      staging_dir=r_c['staging_dir'],
                                      verbose=verbose,
                                      package_compute=pkg_compute)

    else:
        # Values in case and associated domain set from parameters
        d = cs_case_domain.domain(pkg,
                                  package_compute=pkg_compute,
                                  param=r_c['param'])

        # Now handle case for the corresponding calculation domain(s).
        c = cs_case.case(pkg,
                         package_compute=pkg_compute,
                         case_dir=r_c['casedir'],
                         dest_dir=r_c['dest_dir'],
                         staging_dir=r_c['staging_dir'],
                         domains=d)

    # Determine run id if not forced

    if not r_c['run_id']:
        r_c['run_id'] = c.suggest_id(r_c['id_prefix'], r_c['id_suffix'])

    if r_c['suggest_id']:
        print(r_c['run_id'])
        return 0, r_c['run_id'], None

    # Check stages

    if submit_args != None:
        submit_stages = {'prepare_data': False}
        for s in ('initialize', 'run_solver', 'save_results'):
            submit_stages[s] = stages[s]
            stages[s] = False

    # Set script hooks

    c.run_prologue = r_c['run_prologue']
    c.run_epilogue = r_c['run_epilogue']
    c.compute_prologue = r_c['compute_prologue']
    c.compute_epilogue = r_c['compute_epilogue']

    c.debug_args = r_c['debug_args']
    c.tool_args = r_c['tool_args']
    c.mpi_tool_args = r_c['mpi_tool_args']

    # Now run case

    retval = c.run(n_procs=r_c['n_procs'],
                   n_threads=r_c['n_threads'],
                   time_limit=r_c['time_limit'],
                   run_id=r_c['run_id'],
                   force_id=r_c['force_id'],
                   stages=stages,
                   notebook_args=options.notebook_args,
                   parametric_args=options.parametric_args,
                   kw_args=options.kw_args)

    if submit_args != None:
        resource_name = cs_run_conf.get_resource_name(i_c)
        run_cfg_path = os.path.join(c.result_dir, 'run.cfg')
        if len(submit_args) > 1:
            job_parameters = cs_exec_environment.assemble_args(submit_args)
            r_c['job_parameters'] = job_parameters
        generate_run_config_file(run_cfg_path, resource_name, r_c,
                                 submit_stages, pkg)

    return retval, c.result_dir, r_c
예제 #10
0
    def build_template(self, job_header=None, prologue=None, epilogue=None):
        """
        Build batch file template
        """

        import os, stat
        from code_saturne.base.cs_exec_environment import append_shell_shebang, \
            append_script_comment

        if not self.package:
            from code_saturne.base import cs_package
            self.package = cs_package.package()

        # Use alternate wrapper if configured

        wrapper_postfix = None

        config = configparser.ConfigParser()
        config.read(self.package.get_configfiles())
        if config.has_option('install', 'wrapper_postfix'):
            wrapper_postfix = config.get('install', 'wrapper_postfix')

        self.lines = []

        append_shell_shebang(self.lines)

        # Add batch system info and user prologue if necessary

        if job_header:
            for line in job_header.split(os.linesep):
                self.lines.append(line)
            self.lines.append('')

        # Ensure switch to script directory

        append_script_comment(self.lines,
                              'Set working directory:' + os.linesep)
        self.lines.append('cd ' + enquote_arg(os.path.dirname(self.path)))
        self.lines.append('')

        if prologue:
            append_script_comment(self.lines, 'User prologue:' + os.linesep)
            for line in prologue.split(os.linesep):
                self.lines.append(line)
            self.lines.append('')

        # Add command to execute.

        append_script_comment(self.lines, 'Run command:' + os.linesep)

        if wrapper_postfix is None:
            exec_path = os.path.join(self.package.get_dir("bindir"),
                                     self.package.name)
        else:
            exec_path = '\\' + self.package.name + wrapper_postfix

        run_cmd = enquote_arg(exec_path) + ' run'
        self.cmd_name = self.package.name
        self.run_cmd_line_id = len(self.lines)
        self.lines.append(run_cmd)
        self.lines.append('')

        if epilogue:
            append_script_comment(self.lines, 'User epilogue:' + os.linesep)
            for line in epilogue.split(os.linesep):
                self.lines.append(line)
            self.lines.append('')

        self.save()

        st = os.stat(self.path)
        mode = st[stat.ST_MODE]
        os.chmod(self.path, mode | stat.S_IEXEC)
예제 #11
0
            print(cfg.libs[opts.cppflags].flags['cppflags'])

    if opts.ldflags is not None:
        # Specific handling of code_saturne has pkgincludedir has to be
        # correctly expended. Likewise for PLE, if internal version is used
        if opts.ldflags == "saturne":
            print("-L" + pkg.get_dir("libdir"))
        elif opts.ldflags == "ple":
            if cfg.libs['ple'].variant == "internal":
                print("-L" + pkg.get_dir("libdir"))
            else:
                print(cfg.libs[opts.cppflags].flags['ldflags'])
        else:
            if cfg.libs[opts.ldflags].dynamic_load == False:
                print(cfg.libs[opts.ldflags].flags['ldflags'])

    if opts.libs is not None:
        if cfg.libs[opts.libs].dynamic_load == False:
            print(cfg.libs[opts.libs].flags['libs'])

    if opts.print_pythondir: print(pkg.get_dir("pythondir"))
    if opts.print_datarootdir: print(pkg.get_dir("datarootdir"))

#-------------------------------------------------------------------------------

if __name__ == '__main__':
    import sys
    from code_saturne.base import cs_package
    pkg = cs_package.package()
    main(sys.argv[1:], pkg)