Ejemplo n.º 1
0
def run_soft(soft, config_path, wkdir, nb_proc):
    """Function run one of the existing SU2 software

    Function 'run_soft' create the comment line to run correctly a SU2 software
    (SU2_DEF, SU2_CFD, SU2_SOL) with MPI (if installed). The SOFT_DICT is
    create from the SOFT_LIST define at the top of this script.

    Args:
        soft (str): Software to execute (SU2_DEF, SU2_CFD, SU2_SOL)
        config_path (str): Path to the configuration file
        wkdir (str): Path to the working directory

    """

    # Get installation path for the following softwares
    SOFT_DICT = ceaf.get_install_path(SOFT_LIST)

    #mpi_install_path = SOFT_DICT['mpirun.mpich']
    mpi_install_path = SOFT_DICT['mpirun']

    soft_install_path = SOFT_DICT[soft]

    log.info('Number of proc available: ' + str(os.cpu_count()))
    log.info(str(nb_proc) + ' will be use for this calculation.')

    logfile_path = os.path.join(wkdir, 'logfile' + soft + '.log')

    # if mpi_install_path is not None:
    #     command_line =  [mpi_install_path,'-np',str(nb_proc),
    #                      soft_install_path,config_path,'>',logfile_path]
    if mpi_install_path is not None:
        command_line = [
            mpi_install_path, '-np',
            str(nb_proc), soft_install_path, config_path, '>', logfile_path
        ]
    # elif soft == 'SU2_DEF' a disp.dat must be there to run with MPI
    else:
        command_line = [soft_install_path, config_path, '>', logfile_path]

    original_dir = os.getcwd()
    os.chdir(wkdir)

    log.info('>>> ' + soft + ' Start Time')

    os.system(' '.join(command_line))

    log.info('>>> ' + soft + ' End Time')

    os.chdir(original_dir)
Ejemplo n.º 2
0
def create_SU2_mesh(cpacs_path, cpacs_out_path):
    """ Function to create a simple SU2 mesh form an SUMO file (.smx)

    Function 'create_mesh' is used to generate an unstructured mesh with  SUMO
    (which integrage Tetgen for the volume mesh) using a SUMO (.smx) geometry
    file as input.
    Meshing option could be change manually (only in the script for now)

    Source :
        * sumo help, tetgen help (in the folder /doc)

    Args:
        cpacs_path (str): Path to the CPACS file
        cpacs_out_path (str): Path to the output CPACS file

    """

    tixi = cpsf.open_tixi(cpacs_path)

    wkdir = ceaf.get_wkdir_or_create_new(tixi)
    sumo_dir = os.path.join(wkdir, 'SUMO')
    if not os.path.isdir(sumo_dir):
        os.mkdir(sumo_dir)
    su2_mesh_path = os.path.join(sumo_dir, 'ToolOutput.su2')

    meshdir = os.path.join(wkdir, 'MESH')
    if not os.path.isdir(meshdir):
        os.mkdir(meshdir)

    original_dir = os.getcwd()
    os.chdir(sumo_dir)

    sumo_file_xpath = '/cpacs/toolspecific/CEASIOMpy/filesPath/sumoFilePath'
    sumo_file_path = cpsf.get_value_or_default(tixi, sumo_file_xpath, '')
    if sumo_file_path == '':
        raise ValueError('No SUMO file to use to create a mesh')

    # Set mesh parameters
    log.info('Mesh parameter will be set')
    refine_level_xpath = '/cpacs/toolspecific/CEASIOMpy/mesh/sumoOptions/refinementLevel'
    refine_level = cpsf.get_value_or_default(tixi, refine_level_xpath, 0.0)
    log.info('Refinement level is {}'.format(refine_level))
    add_mesh_parameters(sumo_file_path, refine_level)

    # Check current Operating System
    current_os = platform.system()

    if current_os == 'Darwin':
        log.info('Your OS is Mac\n\n')
        log.info(
            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
        log.info('On MacOS the mesh has to be generated manually.')
        log.info('To create a SU2Mesh you have to :')
        log.info('Open the .smx geometry that you will find there:')
        log.info(sumo_file_path)
        log.info('Click on the button "Mesh"')
        log.info('Click on "Create Mesh"')
        log.info('Click on "Volume Mesh"')
        log.info('Click on "Run"')
        log.info('When the mesh generation is completed, click on "Close"')
        log.info('Go to the Menu "Mesh" -> "Save volume mesh..."')
        log.info('Chose "SU2 (*.su2)" as File Type"')
        log.info('Copy/Paste the following line as File Name')
        log.info(su2_mesh_path)
        log.info('Click on "Save"')
        log.info('You can now close SUMO, your workflow will continue.')
        log.info(
            'More information: https://ceasiompy.readthedocs.io/en/latest/user_guide/modules/SUMOAutoMesh/index.html'
        )
        log.info(
            '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n'
        )

        # For now, I did not find a way to run "sumo -batch" on Mac...
        # The command just open SUMO GUI, the mesh has to be generate and save manually
        command = ['open', '/Applications/SUMO/dwfsumo.app/']
        os.system(' '.join(command))

    elif current_os == 'Linux':
        log.info('Your OS is Linux')

        # Check if SUMO is installed
        soft_dict = ceaf.get_install_path(['sumo'])

        # Run SUMO in batch
        output = '-output=su2'
        options = '-tetgen-options=pq1.16VY'  # See Tetgen help for more options, maybe transform that as an input
        # Command line to run: sumo -batch -output=su2 -tetgen-options=pq1.16VY ToolOutput.smx
        command = [
            soft_dict['sumo'], '-batch', output, options, sumo_file_path
        ]
        os.system(' '.join(command))

    elif current_os == 'Windows':
        log.info('Your OS is Windows')
        # TODO: develop this part

        log.warning('OS not supported yet by SUMOAutoMesh!')
        raise OSError('OS not supported yet!')

    else:
        raise OSError('OS not recognize!')

    # Copy the mesh in the MESH directory
    aircraft_name = cpsf.aircraft_name(tixi)
    su2_mesh_name = aircraft_name + '_baseline.su2'
    su2_mesh_new_path = os.path.join(meshdir, su2_mesh_name)
    shutil.copyfile(su2_mesh_path, su2_mesh_new_path)

    if os.path.isfile(su2_mesh_new_path):
        log.info('An SU2 Mesh has been correctly generated.')
        su2_mesh_xpath = '/cpacs/toolspecific/CEASIOMpy/filesPath/su2Mesh'
        cpsf.create_branch(tixi, su2_mesh_xpath)
        tixi.updateTextElement(su2_mesh_xpath, su2_mesh_new_path)
        os.remove(su2_mesh_path)

    else:
        raise ValueError('No SU2 Mesh file has been generated!')

    cpsf.close_tixi(tixi, cpacs_out_path)
    os.chdir(original_dir)
Ejemplo n.º 3
0
def create_SU2_mesh(cpacs_path, cpacs_out_path):
    """ Function to create a simple SU2 mesh form an SUMO file (.smx)

    Function 'create_mesh' is used to generate an unstructured mesh with  SUMO
    (which integrage Tetgen for the volume mesh) using a SUMO (.smx) geometry
    file as input.
    Meshing option could be change manually (only in the script for now)

    Source :
        * sumo help, tetgen help (in the folder /doc)

    Args:
        cpacs_path (str): Path to the CPACS file
        cpacs_out_path (str): Path to the output CPACS file

    """

    tixi = cpsf.open_tixi(cpacs_path)

    wkdir = ceaf.get_wkdir_or_create_new(tixi)
    sumo_dir = os.path.join(wkdir, 'SUMO')
    if not os.path.isdir(sumo_dir):
        os.mkdir(sumo_dir)

    mesh_dir = os.path.join(wkdir, 'MESH')
    if not os.path.isdir(mesh_dir):
        os.mkdir(mesh_dir)

    original_dir = os.getcwd()
    os.chdir(sumo_dir)

    sumo_file_xpath = '/cpacs/toolspecific/CEASIOMpy/filesPath/sumoFilePath'
    sumo_file_path = cpsf.get_value_or_default(tixi, sumo_file_xpath, '')
    if sumo_file_path == '':
        raise ValueError('No SUMO file to use to create a mesh')

    # Check if SUMO is installed
    soft_dict = ceaf.get_install_path(['sumo'])

    # Run SUMO to create a create a mesh
    # sumo - batch -output=su2 -tetgen-options=pq1.16VY mesh.smx
    sumo_output = '-output=su2'  # For now, must be SU2
    tetgen_options = '-tetgen-options=pq1.16VY'  # See Tetgen help for more options, maybe transform that as an input
    command_line = [
        soft_dict['sumo'], '-batch', sumo_output, tetgen_options,
        sumo_file_path
    ]

    # print(' '.join(command_line))
    os.system(' '.join(command_line))

    # Copy the mesh in the MESH directory
    su2_mesh_path = os.path.join(sumo_dir, 'ToolOutput.su2')
    aircraft_name = cpsf.aircraft_name(tixi)
    su2_mesh_name = aircraft_name + '_baseline.su2'
    su2_mesh_new_path = os.path.join(mesh_dir, su2_mesh_name)
    shutil.copyfile(su2_mesh_path, su2_mesh_new_path)

    if os.path.isfile(su2_mesh_new_path):
        log.info('An SU2 Mesh has been correctly generated.')
        su2_mesh_xpath = '/cpacs/toolspecific/CEASIOMpy/filesPath/su2Mesh'
        cpsf.create_branch(tixi, su2_mesh_xpath)
        tixi.updateTextElement(su2_mesh_xpath, su2_mesh_new_path)

        os.remove(su2_mesh_path)

    else:
        raise ValueError('No SU2 Mesh file has been generated!')

    cpsf.close_tixi(tixi, cpacs_out_path)

    os.chdir(original_dir)
Ejemplo n.º 4
0
def create_SU2_mesh(cpacs_path, cpacs_out_path):
    """ Function to create a simple SU2 mesh form an SUMO file (.smx)

    Function 'create_mesh' is used to generate an unstructured mesh with  SUMO
    (which integrage Tetgen for the volume mesh) using a SUMO (.smx) geometry
    file as input.
    Meshing option could be change manually (only in the script for now)

    Source :
        * sumo help, tetgen help (in the folder /doc)

    Args:
        cpacs_path (str): Path to the CPACS file
        cpacs_out_path (str): Path to the output CPACS file

    """

    tixi = cpsf.open_tixi(cpacs_path)

    wkdir = ceaf.get_wkdir_or_create_new(tixi)
    sumo_dir = os.path.join(wkdir, 'SUMO')
    if not os.path.isdir(sumo_dir):
        os.mkdir(sumo_dir)

    mesh_dir = os.path.join(wkdir, 'MESH')
    if not os.path.isdir(mesh_dir):
        os.mkdir(mesh_dir)

    original_dir = os.getcwd()
    os.chdir(sumo_dir)

    sumo_file_xpath = '/cpacs/toolspecific/CEASIOMpy/filesPath/sumoFilePath'
    sumo_file_path = cpsf.get_value_or_default(tixi, sumo_file_xpath, '')
    if sumo_file_path == '':
        raise ValueError('No SUMO file to use to create a mesh')

    # Check current Operating System
    current_os = platform.system()

    if current_os == 'Darwin':
        log.info('Your OS is Mac')
        # TODO: chck install path
        log.info('On Mac the mesh has to be generated manually.')
        log.info('You can find your geometry there:')
        log.info(sumo_file_path)
        # For now, I did find a way to run sumo -batch on Mac...
        # The command just open SUMO GUI
        command_line = ['open', '/Applications/SUMO/dwfsumo.app/']
        os.system(' '.join(command_line))

    elif current_os == 'Linux':
        log.info('Your OS is Linux')

        # Check if SUMO is installed
        soft_dict = ceaf.get_install_path(['sumo'])

        # Run SUMO to create a create a mesh
        # sumo -batch -output=su2 -tetgen-options=pq1.16VY mesh.smx
        sumo_output = '-output=su2'
        tetgen_options = '-tetgen-options=pq1.16VY'  # See Tetgen help for more options, maybe transform that as an input
        command_line = [
            soft_dict['sumo'], '-batch', sumo_output, tetgen_options,
            sumo_file_path
        ]
        os.system(' '.join(command_line))

    elif current_os == 'Windwos':
        log.info('Your OS is Windows')
        log.warning('OS not supported yet by SUMOAutoMesh!')
        # TODO

    else:
        raise OSError('OS not recognize!')

    # Copy the mesh in the MESH directory
    su2_mesh_path = os.path.join(sumo_dir, 'ToolOutput.su2')
    aircraft_name = cpsf.aircraft_name(tixi)
    su2_mesh_name = aircraft_name + '_baseline.su2'
    su2_mesh_new_path = os.path.join(mesh_dir, su2_mesh_name)
    shutil.copyfile(su2_mesh_path, su2_mesh_new_path)

    if os.path.isfile(su2_mesh_new_path):
        log.info('An SU2 Mesh has been correctly generated.')
        su2_mesh_xpath = '/cpacs/toolspecific/CEASIOMpy/filesPath/su2Mesh'
        cpsf.create_branch(tixi, su2_mesh_xpath)
        tixi.updateTextElement(su2_mesh_xpath, su2_mesh_new_path)

        os.remove(su2_mesh_path)

    else:
        raise ValueError('No SU2 Mesh file has been generated!')

    cpsf.close_tixi(tixi, cpacs_out_path)

    os.chdir(original_dir)