Example #1
0
def run_gmsh(in_file, out_file, dims, **kwargs):
    """
    Convenience function to run gmsh.

    Parameters:
        in_file (str): Name of gmsh configuration file (.geo)
        out_file (str): Name of output file for gmsh (.msh)
        dims (int): Number of dimensions gmsh should grid. If dims is less than
            the geometry dimensions, gmsh will grid all lower-dimensional
            objcets described in in_file (e.g. all surfaces embeded in a 3D
            geometry).
        **kwargs: Options passed on to gmsh. See gmsh documentation for
            possible values.

    Returns:
        double: Status of the generation, as returned by os.system. 0 means the
            simulation completed successfully, >0 signifies problems.

    """
    if not os.path.isfile(in_file):
        raise FileNotFoundError("file " + in_file + " not found")

    # Import config file to get location of gmsh executable.
    config = read_config.read()
    path_to_gmsh = config["gmsh_path"]

    opts = " "
    for key, val in kwargs.items():
        # Gmsh keywords are specified with prefix '-'
        if key[0] != "-":
            key = "-" + key
        opts += key + " " + str(val) + " "

    if dims == 1:
        cmd = [path_to_gmsh, "-1", in_file, "-o", out_file, opts]
    elif dims == 2:
        cmd = [path_to_gmsh, "-2", in_file, "-o", out_file, opts]
    elif dims == 3:
        cmd = [path_to_gmsh, "-3", in_file, "-o", out_file, opts]
    else:
        raise ValueError

    status = subprocess.check_call(cmd)

    return status
Example #2
0
def run_gmsh(in_file, out_file, dims, **kwargs):
    """
    Convenience function to run gmsh.

    Parameters:
        in_file (str): Name of gmsh configuration file (.geo)
        out_file (str): Name of output file for gmsh (.msh)
        dims (int): Number of dimensions gmsh should grid. If dims is less than
            the geometry dimensions, gmsh will grid all lower-dimensional
            objcets described in in_file (e.g. all surfaces embeded in a 3D
            geometry).
        **kwargs: Options passed on to gmsh. See gmsh documentation for
            possible values.

    Returns:
        double: Status of the generation, as returned by os.system. 0 means the
            simulation completed successfully, >0 signifies problems.

    """
    # Import config file to get location of gmsh executable.
    config = read_config.read()
    path_to_gmsh = config['gmsh_path']

    opts = ' '
    for key, val in kwargs.items():
        # Gmsh keywords are specified with prefix '-'
        if key[0] != '-':
            key = '-' + key
        opts += key + ' ' + str(val) + ' '

    if dims == 2:
        cmd = path_to_gmsh + ' -2 ' + in_file + ' -o ' + out_file + opts
    else:
        cmd = path_to_gmsh + ' -3 ' + in_file + ' -o ' + out_file + opts

    status = os.system(cmd)

    return status