diff --git a/ceasiompy/EdgeRun/edgerun.py b/ceasiompy/EdgeRun/edgerun.py index 12c6ebe39..cd076e43a 100644 --- a/ceasiompy/EdgeRun/edgerun.py +++ b/ceasiompy/EdgeRun/edgerun.py @@ -14,7 +14,7 @@ # ================================================================================================= # IMPORTS # ================================================================================================= - +import os, re from pathlib import Path from cpacspy.cpacspy import CPACS from ceasiompy.EdgeRun.func.edgeconfig import edge_cfd @@ -26,6 +26,12 @@ ) # from ceasiompy.utils.commonnames import AINP_CFD_NAME, SU2_FORCES_BREAKDOWN_NAME +from cpacspy.cpacsfunctions import ( + create_branch, + get_string_vector, + get_value, + get_value_or_default, +) from ceasiompy.utils.commonnames import AINP_CFD_NAME from ceasiompy.utils.commonxpath import EDGE_NB_CPU_XPATH, EDGE_MESH_XPATH from ceasiompy.utils.moduleinterfaces import get_toolinput_file_path, get_tooloutput_file_path @@ -77,6 +83,7 @@ def run_edge_multi(wkdir, input_que_script_path, nb_proc=2): case_dir_path.mkdir() output_path = Path(case_dir_path, AINP_CFD_NAME) + case_dir_list = [dir for dir in wkdir.iterdir() if "Case" in dir.name] if not case_dir_list: raise OSError(f"No Case directory has been found in the working directory: {wkdir}") @@ -112,6 +119,55 @@ def run_edge_multi(wkdir, input_que_script_path, nb_proc=2): # postprocess for results edge_scripts_instance.postprocess_script(case_dir_path, edge_mesh) +def extract_edge_forces(results_dir): + # Use list comprehension to get a list of directory names starting with "Case" + dir_names = [dir_name for dir_name in os.listdir(results_dir) if os.path.isdir(os.path.join(results_dir, dir_name)) and dir_name.startswith("Case")] + + # Define the header for the forcemoments file + header = " alt mach alfa beta CL CD CDP CDV CM " + + + # Loop through the list and perform actions in each directory + for dir_name in dir_names: + dir_path = os.path.join(results_dir, dir_name) + #print(f"Processing directory: {dir_path}") + log.info(f"Extracting forces from Directory : {dir_name}") + + # Extract mach and alfa from directory name + match = re.match(r'.*alt(\d+\.\d+)_mach(\d+\.\d+)_aoa(\d+\.\d+)_aos(\d+\.\d+)*', dir_name) + if match: + alt = float(match.group(1)) + mach = float(match.group(2)) + aoa = float(match.group(3)) + aos = float(match.group(4)) + #print(f" - alt: {alt}, mach: {mach}, aoa: {aoa}, aos: {aos}") + + # Extract information from Edge.log file + filelog = os.path.join(dir_path, 'Edge.log') + with open(filelog, 'r') as log_file: + lines = log_file.readlines() + + total_line_number = next((i for i, line in enumerate(lines) if ' Total:' in line), None) + if total_line_number is not None: + line = total_line_number + 4 + CL = lines[line].split()[0] + CD = lines[line].split()[1] + CM = lines[line].split()[3] + + line += 2 + CDP = lines[line].split()[1] + + line += 2 + CDV = lines[line].split()[1] + + # Append values to forcemoments file + forcemoments = os.path.join(results_dir, 'Edge_force_moment.dat') + with open(forcemoments, 'a') as output_file: + # Check if the file is empty and add the header + if os.stat(forcemoments).st_size == 0: + output_file.write(header + "\n") + output_file.write(f"{alt:.8f} {mach:.8f} {aoa:.8f} {aos:.8f} {CL} {CD} {CDP} {CDV} {CM}\n") + log.info(f"Saving forces to file: {forcemoments}") # ================================================================================================= # MAIN @@ -130,6 +186,8 @@ def main(cpacs_path, cpacs_out_path): cpacs_tmp_cfg = Path(cpacs_out_path.parent, "ConfigTMP.xml") edge_cfd(cpacs_path, cpacs_tmp_cfg, results_dir) + extract_edge_forces(results_dir) + log.info("Edge Postprocess finished") # run_edge_multi(results_dir, nb_proc) # get_su2_results(cpacs_tmp_cfg, cpacs_out_path, results_dir) diff --git a/ceasiompy/EdgeRun/func/edge_queScript_gen.py b/ceasiompy/EdgeRun/func/edge_queScript_gen.py index 902e2a467..9138bb9af 100644 --- a/ceasiompy/EdgeRun/func/edge_queScript_gen.py +++ b/ceasiompy/EdgeRun/func/edge_queScript_gen.py @@ -85,15 +85,15 @@ def run_edgesolver(self, dir_path, nb_proc): os.system(f'{run_solver} {self.EdgeInputFile} {nb_proc} > edge_run.log 2>&1\n') def postprocess_script(self, dir_path,edge_grid): - ffaucut = os.path.join(self.Edge_dir, 'ffaucut') - ffauinterpol = os.path.join(self.Edge_dir, 'ffauinterpol') - ffa2tab = os.path.join(self.Edge_dir, 'ffa2tab') + #ffaucut = os.path.join(self.Edge_dir, 'ffaucut') + #ffauinterpol = os.path.join(self.Edge_dir, 'ffauinterpol') + #ffa2tab = os.path.join(self.Edge_dir, 'ffa2tab') ffa2engold = os.path.join(self.Edge_dir, 'ffa2engold') grid = edge_grid # output file names - walldata1 = "Edge_wall.dat" - walldata2 = "Edge_wall.cf" + #walldata1 = "Edge_wall.dat" + #walldata2 = "Edge_wall.cf" forcemoments = "Edge_force_moment.dat" ensgoldprefix = "zzz" solution1 = "Edge.bout" @@ -102,9 +102,11 @@ def postprocess_script(self, dir_path,edge_grid): # Enter the folder os.chdir(dir_path) - # Extract the boundary - input_data = """1 - 0 + """ + # Extract the boundary + input_data = """ + #1 + #0 """ with subprocess.Popen([ffaucut, grid, 'tmp1'], stdin=subprocess.PIPE, text=True) as process: process.communicate(input=input_data) @@ -121,7 +123,7 @@ def postprocess_script(self, dir_path,edge_grid): # Cleanup for temp_file in ['tmp1', 'tmp11', 'tmp12']: os.remove(temp_file) - + """ # Create ensight gold files subprocess.run([ffa2engold, grid, solution1, ensgoldprefix]) diff --git a/ceasiompy/EdgeRun/func/edgeconfig.py b/ceasiompy/EdgeRun/func/edgeconfig.py index 3d292d9a1..3ef1938eb 100644 --- a/ceasiompy/EdgeRun/func/edgeconfig.py +++ b/ceasiompy/EdgeRun/func/edgeconfig.py @@ -308,15 +308,15 @@ def edge_cfd(cpacs_path, cpacs_out_path, wkdir): if not bedg_files_exist: # edge_scripts_instance.submit_preprocessor_script(case_dir_path) - log.info("Running Edge preprocessor for Case..." + case_dir_name ) + log.info("Running Edge preprocessor ...") edge_scripts_instance.run_preprocessor(case_dir_path) - print("bedg files are generated") + log.info("Preprocessor is done. *.bedg files are generated") - # else: - # print('bedg files exist, not generated') + # edge_scripts_instance.submit_solver_script(case_dir_path,NPART) - log.info("Running Edge solver for Case..." + case_dir_name ) + log.info("Running Edge solver for " + case_dir_name ) edge_scripts_instance.run_edgesolver(case_dir_path, NPART) + log.info("Edge solver is done for" + case_dir_name ) # postprocess for results #edge_scripts_instance.postprocess_script(case_dir_path, edge_mesh)