Beispiel #1
0
def main():
    """ Main function of partel.py """
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    parser = argparse.ArgumentParser(description='Translate a keyword')
    parser = add_config_argument(parser)
    parser.add_argument("module",
                        choices=[
                            'postel3d', 'telemac2d', 'telemac3d', 'tomawac',
                            'artemis', 'sisyphe', 'waqtel', 'khione', 'stbtel'
                        ],
                        help="Name of the module for which to translate")
    parser.add_argument(
        "cas_file",
        help="Name of the steering file to translatefile to be partitionned")
    args = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(args)
    cfg = CFGS.configs[CFGS.cfgname]
    CFGS.compute_execution_info()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # Searching for the dictionary associated with the steering case
    dico_file = path.join(cfg['MODULES'][args.module]['path'],
                          args.module + '.dico')
    if not path.exists(dico_file):
        raise TelemacException(\
            'Could not find the dictionary file: {}'.format(dico_file))
    cas = TelemacCas(args.cas_file, dico_file, check_files=False)

    cas.write_fr_gb()

    print('\n\nMy work is done\n\n')
    sys.exit(0)
Beispiel #2
0
def main():
    """ Main function of partel.py """
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    parser = argparse.ArgumentParser(
        description='Run the partitionning step (partel)')
    parser = add_config_argument(parser)
    parser.add_argument("--input-file",
                        dest="input_file",
                        default='',
                        help="Name of partel parameter file (PARTEL.PAR)."
                        " This option will surcharge all the others")
    parser.add_argument("--file",
                        dest="geo_file",
                        default='T2DGEO',
                        help="Name of the file to be partitionned")
    parser.add_argument(
        "--file-format",
        dest="geo_file_fmt",
        default='SERAFIN',
        help="Format of the geometry file(SERAFIN,SERAFIND or MED), "
        "default is SERAFIN")
    parser.add_argument(
        "--bnd-file",
        dest="bnd_file",
        default='T2DCLI',
        help="Name of the boundary file associated to the mesh file, "
        "default is T2DCLI")
    parser.add_argument(
        "--ncsize",
        dest="ncsize",
        default=8,
        help="Number of partitions (should be equal to number of "
        "parallel processors), default is 8")
    parser.add_argument(
        "--section-name",
        dest="section_file",
        default='',
        help="Name of the section file, default no section file")
    parser.add_argument("--zone-name",
                        dest="zone_file",
                        default='',
                        help="Name of the zone file, default no zone file")
    parser.add_argument("--weir-name",
                        dest="weir_file",
                        default='',
                        help="Name of the weir file, default no weir file")
    parser.add_argument(
        "--partitioning-method",
        dest="part_method",
        default=1,
        help="Method used for the partitionning (1:metis, 2:scotch)")
    parser.add_argument("--concat",
                        dest="concat",
                        action="store_true",
                        default=False,
                        help="If true concatenate partel output")
    parser.add_argument(
        "--mpi",
        dest="mpi",
        action="store_true",
        default=False,
        help="Run partel as executable (note using command given in systel.cfg)"
    )
    args = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(args)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    CFGS.compute_execution_info()

    if args.input_file != "":
        with open(args.input_file, 'r') as f:
            geo_file = f.readline().strip('\n')
            geo_file_fmt = f.readline().strip('\n')
            bnd_file = f.readline().strip('\n')
            ncsize = f.readline().strip('\n')
            part_method = f.readline().strip('\n')
            section_file = f.readline().strip('\n')
            zone_file = f.readline().strip('\n')
            weir_file = f.readline().strip('\n')
            _ = f.readline().strip('\n')
            _ = f.readline().strip('\n')
            concat = f.readline().strip('\n')
    else:
        concat = 'YES' if args.concat else 'NO'
        geo_file = args.geo_file
        geo_file_fmt = args.geo_file_fmt
        bnd_file = args.bnd_file
        ncsize = args.ncsize
        section_file = args.section_file
        zone_file = args.zone_file
        weir_file = args.weir_file
        part_method = args.part_method

    # Getting partel command from configuration
    pbin = path.join(CFGS.get_root(), 'builds', CFGS.cfgname, 'bin')
    if args.mpi:
        exe_ext = CFGS.configs[CFGS.cfgname]['SYSTEM']['sfx_exe']
        parcmd = path.join(pbin, 'partel'+exe_ext+\
                                 ' < <partel.par> >> <partel.log>')
    else:
        parcmd = get_partel_cmd(pbin, CFGS.configs[CFGS.cfgname], '')
    # Running paritionning

    run_partel(parcmd, geo_file, geo_file_fmt, bnd_file, ncsize, False,
               section_file, zone_file, weir_file, geo_file, geo_file_fmt,
               part_method, concat)

    print('\n\nMy work is done\n\n')
    sys.exit(0)
Beispiel #3
0
def main():
    """ Main function of gretel """
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    parser = argparse.ArgumentParser(\
            description='Run the merging step (gretel)')
    parser = add_config_argument(parser)
    parser.add_argument(\
              "--input-file",
              dest="input_file",
              default='',
              help="Name of gretel parameter file (GRETEL.PAR). "\
                     "This option will surcharge all the others")
    parser.add_argument(\
              "--geo-file",
              dest="geo_file",
              default='T2DGEO',
              help="Name of the geometry file associated with the "\
                     "file to be merged")
    parser.add_argument(\
              "--geo-file-format",
              dest="geo_file_fmt",
              default='SERAFIN',
              help="Format of the geometry file(SERAFIN,SERAFIND or MED), "\
                     "default is SERAFIN")
    parser.add_argument(\
              "--res-file",
              dest="res_file",
              default='T2DRES',
              help="Name of the file to be merged")
    parser.add_argument(\
              "--res-file-format",
              dest="res_file_fmt",
              default='SERAFIN',
              help="Format of the geometry file(SERAFIN,SERAFIND or MED), "\
                     "default is SERAFIN")
    parser.add_argument(\
              "--bnd-file",
              dest="bnd_file",
              default='T2DCLI',
              help="Name of the boundary file")
    parser.add_argument(\
              "--ncsize",
              dest="ncsize",
              default=8,
              help="Number of partitions (should be equal to number of "\
                     "parallel processors), default is 8")
    parser.add_argument(\
              "--nplan",
              dest="nplan",
              default=0,
              help="Number of horizontal levels ,default is 0")
    args = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(args)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for all configurations unless specified ~~~~~~~~~~~~~~~
    CFGS.compute_execution_info()

    if args.input_file != "":
        with open(args.input_file, 'r') as f:
            geo_file = f.readline().strip('\n')
            geo_file_fmt = f.readline().strip('\n')
            bnd = f.readline().strip('\n')
            res_file = f.readline().strip('\n')
            res_file_fmt = f.readline().strip('\n')
            ncsize = f.readline().strip('\n')
            nplan = f.readline().strip('\n')
    else:
        geo_file = args.geo_file
        geo_file_fmt = args.geo_file_fmt
        bnd = args.bnd_file
        res_file = args.res_file
        res_file_fmt = args.res_file_fmt
        ncsize = args.ncsize
        nplan = args.nplan

    # Getting partel command from configuration
    pbin = path.join(CFGS.get_root(), 'builds', CFGS.cfgname, 'bin')
    grecmd = get_gretel_cmd(pbin, CFGS.configs[CFGS.cfgname])
    # Running paritionning

    run_gretel(grecmd, res_file, res_file_fmt, geo_file, geo_file_fmt, bnd,
               ncsize, nplan, False)

    print('\n\nMy work is done\n\n')
    sys.exit(0)
Beispiel #4
0
def run_mascaret():
    """
    Main function that runs the mascaret executable in the current folder
    """

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n'+72*'~'+'\n')
    parser = ArgumentParser(
        formatter_class=RawDescriptionHelpFormatter,
        description=('''\n\
Run the mascaret executable in the current folder, given a CAS file.
        '''))
    parser.add_argument("args", nargs='*')
    # ~~> Environment
    parser = add_config_argument(parser)
    parser.add_argument(
        "-s", "--sortiefile", action="store_true", dest="sortie_file",
        default=False,
        help="specify whether there is a sortie file, default is no")
    parser.add_argument(
        "-b", "--bypass", action="store_true",
        dest="bypass", default=False,
        help="will bypass execution failures and try to carry on "
             "(final report at the end)")
    options = parser.parse_args()

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root())

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if len(options.args) < 1:
        print('\nThe name of the CAS file is required\n')
        parser.print_help()
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    cas = options.args[0]
# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    xcpts = Messages()

    # still in lower case
    # parsing for proper naming
    CFGS.compute_execution_info()
    cfg = CFGS.configs[CFGS.cfgname]

    create_mascaret_files(cfg, cas)

    mascaret_exe = path.join(cfg['root'], 'builds', CFGS.cfgname, 'bin',
                             'mascaret' + cfg['sfx_exe'])
    _, code = xcpts.run_cmd(mascaret_exe, options.bypass)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty() or code != 0:
        print('\n\nHummm ... I could not complete my work.\n'+'~'*72
              + xcpts.except_messages())
        sys.exit(1)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else:
        print('\n\nMy work is done\n\n')
        sys.exit(0)
def main(module=None):
    """
    @brief Main function of the runcode.py module

    @param module (string): the name of the module to run (
      available modules are: telemac2d, telemac3d, artemis, tomawac,
      sisyphe, artemis, postel3d, ...)

    @return None
    """

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    if module is None:
        parser = ArgumentParser(
            formatter_class=RawDescriptionHelpFormatter,
            description=('''\n
runcode is the execution launcher for all TELEMAC modules.\n
where module can be:\n
    mascaret     the 1D hydrodyanmic / tracer / water quality solver
    telemac2d    the 2D hydrodyanmic / tracer / water quality solver
    telemac3d    the 3D hydrodynamic / tracer / water quality solver
    artemis      the phase resolving wave solver
    tomawac      the 3rd generation wave transformation solver
    sisyphe      the sediment transport and geomorphogical solver
    stbtel       a pre-processor for the modules
    postel3d     a post-processor for telemac3d
            '''),
            usage=' (--help for help)\n---------\n        =>  '
            '%(prog)s module [options] casfile(s)\n---------',
            epilog=('''\nexamples:\n---------
1:     => runcode.py telemac2d -s t2d.cas
---------'''))
        parser.add_argument("module",
                            default=None,
                            choices=[
                                'telemac2d', 'telemac3d', 'artemis', 'tomawac',
                                'stbtel', 'postel3d', 'sisyphe', 'partel',
                                'estel3d', 'mascaret'
                            ])
    else:
        parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter,
                                description=('''\n
%(prog)s is one of the execution launcher for the TELEMAC system.
            '''),
                                epilog=('''\nexamples:\n---------
1:     => %(prog)s -s t2d.cas
---------'''))
        parser.set_defaults(module=module)

    parser = add_runcode_argument(parser, module=module)
    # Arguments
    parser.add_argument("args", metavar='cas file(s)', nargs="+")

    options = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(options)

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ banners ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    svn_banner(CFGS.get_root())

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for one configuration only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # Checking if symlink is available
    if options.use_link and not check_sym_link(options.use_link):
        raise TelemacException(\
                '\nThe symlink option is only '
                'available on Linux systems. '
                'Remove the option and try again')

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reads command line arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    code_name = options.module
    cas_files = options.args

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Works for only one configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # bypass errors and carries on
    options.bypass = False
    if options.split or options.merge or options.run:
        if options.w_dir == '':
            raise TelemacException(\
                    '\nPlease use option -w (--workdirectory)'
                    ' with either of the options '
                    '--split, --run or --merge\n')
    # parsing for proper naming
    CFGS.compute_execution_info()
    cfg = CFGS.configs[CFGS.cfgname]

    print('\n\nRunning your CAS file(s) for:\n' + '~' * 72 + '\n')
    CFGS.light_dump()
    if options.w_dir != '':
        print('     +> directory        ' + options.w_dir)
        options.tmpdirectory = False
    print('\n\n' + '~' * 72 + '\n')

    # >>> Check wether the config has been compiled for the runcode
    if options.compileonly:
        cfg['REBUILD'] = 1
    if code_name not in cfg['MODULES']:
        raise TelemacException(\
                '\nThe code requested is not installed '
                'on this system : {}\n'.format(code_name))

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xcpts = Messages()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Run the Code from the CAS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    for cas_file in cas_files:
        run_study(cas_file, code_name, options)

# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Reporting errors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if xcpts.not_empty():
        raise TelemacException(\
                '\n\nHummm ... I could not complete '
                'my work.\n{}{}'.format('~'*72, xcpts.except_messages()))


# <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
# ~~~~ Jenkins' success message ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nMy work is done\n\n')
    sys.exit(0)
Beispiel #6
0
def main():
    """ Main function of manip_cas.py """
    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~ Reads config file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    print('\n\nLoading Options and Configurations\n' + 72 * '~' + '\n')
    parser = argparse.ArgumentParser(description='Translate a keyword')
    parser = add_config_argument(parser)
    parser.add_argument("module",
                        choices=[
                            'postel3d', 'telemac2d', 'telemac3d', 'tomawac',
                            'artemis', 'sisyphe', 'waqtel', 'khione', 'stbtel'
                        ],
                        help="Name of the module for which to translate")
    parser.add_argument(
        "-t",
        "--translate",
        action="store_true",
        dest="translate",
        default=False,
        help="Generate a french and english version of the steering file "
        "(cas_file suffixed with _fr and _gb)")

    parser.add_argument(
        "-s",
        "--sort",
        action="store_true",
        dest="sort",
        default=False,
        help="Rewrites the steering file using rubriques to sort the keywords "
        "cas_file suffixed with _sorted")

    parser.add_argument("--keep-comments",
                        action="store_true",
                        dest="keep_comments",
                        default=False,
                        help="When sorting will append all original comments "
                        "at the end of the file")

    parser.add_argument("cas_file", help="Name of the steering file to read")

    args = parser.parse_args()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # ~~~~ Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    update_config(args)
    cfg = CFGS.configs[CFGS.cfgname]
    CFGS.compute_execution_info()

    # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    # Searching for the dictionary associated with the steering case
    dico_file = path.join(cfg['MODULES'][args.module]['path'],
                          args.module + '.dico')
    if not path.exists(dico_file):
        raise TelemacException(\
            'Could not find the dictionary file: {}'.format(dico_file))
    cas = TelemacCas(args.cas_file, dico_file, check_files=False)

    check_cas(cas)

    if args.translate:
        translate(cas)
    if args.sort:
        sort(cas, args.keep_comments)

    print('\n\nMy work is done\n\n')
    sys.exit(0)