def run_mesh_deformation(tixi, wkdir): """Function to run all the configuration files with SU2_DEF. Function 'run_mesh_deformation' will check in all config file directory and run SU2_DEF for each config file in order. Args: tixi (handles): TIXI Handle wkdir (str): Path to the working directory """ log.info('All mesh deromation will be preformed.') mesh_dir = os.path.join(wkdir, 'MESH') if not os.path.exists(mesh_dir): raise OSError('The MESH directory : ' + mesh_dir + 'does not exit!') os.chdir(mesh_dir) su2_def_mesh_list = [] ted_dir_list = [dir for dir in os.listdir(mesh_dir) if '_TED_' in dir] # Iterate in all TED directory for dir in sorted(ted_dir_list): ted_dir = os.path.join(mesh_dir, dir) os.chdir(ted_dir) cfg_file_list = [ file for file in os.listdir(ted_dir) if 'Config' in file ] # Run all the config file in the directory with SU2_DEF, in alphabetical # order to respect the order of execution (DEF,ROT_,ROT_sym) for cfg_file in sorted(cfg_file_list): if os.path.isfile(cfg_file): su2f.run_soft('SU2_DEF', cfg_file, ted_dir) else: raise ValueError("Not correct configuration file to run!") tmp_su2_mesh_list = [ file for file in os.listdir(ted_dir) if '.su2' in file ] # Copy in the completly deform mesh in the MESH directory for su2_mesh in tmp_su2_mesh_list: if not su2_mesh.startswith('_'): shutil.copyfile(su2_mesh, os.path.join('..', su2_mesh)) log.info(su2_mesh + ' mesh has been copied in the MESH dir.') su2_def_mesh_list.append(su2_mesh) # Remove all SU2 mesh from the config folder (to save space) os.remove(su2_mesh) log.info(su2_mesh + ' mesh has been deleted from the temp mesh.') # Add the list of available SU2 deformed mesh in the CPACS file su2_def_mesh_xpath = SU2_XPATH + '/availableDeformedMesh' cpsf.add_string_vector(tixi, su2_def_mesh_xpath, su2_def_mesh_list)
def run_SU2_multi(wkdir): """Function to run a multiple SU2 claculation. Function 'run_SU2_multi' will run in the given working directory SU2 calculations (SU2_CFD then SU2_SOL). The working directory must have a folder sctructure created by 'SU2Config' module. Args: wkdir (str): Path to the working directory """ if not os.path.exists(wkdir): raise OSError('The working directory : ' + wkdir + 'does not exit!') original_dir = os.getcwd() os.chdir(wkdir) # Check if there is some case directory case_dir_list = [dir for dir in os.listdir(wkdir) if 'Case' in dir] if case_dir_list == []: raise OSError('No folder has been found in the working directory: ' + wkdir) for dir in sorted(case_dir_list): config_dir = os.path.join(wkdir, dir) os.chdir(config_dir) find_config_cfd = False for file in os.listdir(config_dir): if file == 'ConfigCFD.cfg': if find_config_cfd: raise ValueError( 'More than one "ConfigCFD.cfg" file in this directory!' ) config_cfd_path = os.path.join(config_dir, file) find_config_cfd = True if not find_config_cfd: raise ValueError( 'No "ConfigCFD.cfg" file has been found in this directory!') su2f.run_soft('SU2_CFD', config_cfd_path, config_dir) # su2f.run_soft('SU2_SOL',config_file_path,config_dir) # Only useful if you need surface/volume flow file, # if not forces_breakdown.dat will be generated by SU2_CFD. os.chdir(wkdir)
def run_SU2_single(config_path, wkdir): """Function to run a single SU2 claculation. Function 'run_SU2_single' will run in the given working directory a SU2 calculation (SU2_CFD then SU2_SOL) with the given config_path. Args: config_path (str): Path to the configuration file wkdir (str): Path to the working directory """ if not os.path.exists(wkdir): raise OSError('The working directory : ' + wkdir + 'does not exit!') original_dir = os.getcwd() os.chdir(wkdir) su2f.run_soft('SU2_CFD', config_path, wkdir) su2f.run_soft('SU2_SOL', config_path, wkdir) os.chdir(original_dir)
def run_SU2_fsi(config_path, wkdir): """Function to run a SU2 claculation for FSI . Function 'run_SU2_fsi' deforms an element of the mesh (e.g. wing) from point file 'disp.dat' given by a sctructural model and then runs a SU2 calculation (SU2_CFD then SU2_SOL) with the given config_path. Finally a load file is saved, to be send to the sctructural model. Args: config_path (str): Path to the configuration file wkdir (str): Path to the working directory """ if not os.path.exists(wkdir): raise OSError('The working directory : ' + wkdir + 'does not exit!') original_dir = os.getcwd() os.chdir(wkdir) # Modify config file for SU2_DEF config_def_path = os.path.join(wkdir, 'ConfigDEF.cfg') cfg_def = su2f.read_config(config_path) cfg_def['DV_KIND'] = 'SURFACE_FILE' cfg_def['DV_MARKER'] = 'Wing' cfg_def[ 'DV_FILENAME'] = 'disp.dat' # TODO: Should be a constant or find in CPACS ? # TODO: Do we need that? if yes, find 'WING' in CPACS cfg_def['DV_PARAM'] = ['WING', '0', '0', '1', '0.0', '0.0', '1.0'] cfg_def['DV_VALUE'] = 0.01 su2f.write_config(config_def_path, cfg_def) # Modify config file for SU2_CFD config_cfd_path = os.path.join(wkdir, 'ConfigCFD.cfg') cfg_cfd = su2f.read_config(config_path) cfg_cfd['MESH_FILENAME'] = 'mesh_out.su2' su2f.write_config(config_cfd_path, cfg_cfd) su2f.run_soft('SU2_DEF', config_def_path, wkdir) su2f.run_soft('SU2_CFD', config_cfd_path, wkdir) su2f.run_soft('SU2_SOL', config_cfd_path, wkdir) extract_loads(wkdir) os.chdir(original_dir)