From 3abf78034eaf03b74938dd7211c21b574caa52d1 Mon Sep 17 00:00:00 2001 From: GBenedett Date: Wed, 7 Feb 2024 15:54:15 +0100 Subject: [PATCH] formatting --- ceasiompy/EdgeRun/edgerun.py | 24 +-- ceasiompy/EdgeRun/func/edge_queScript_gen.py | 138 ----------------- ceasiompy/EdgeRun/func/edge_que_script_gen.py | 141 ++++++++++++++++++ ceasiompy/EdgeRun/func/edgeconfig.py | 7 +- ceasiompy/EdgeRun/func/edgeutils.py | 8 +- ceasiompy/EdgeRun/tests/test_edgerun_mpi.py | 19 ++- .../EdgeRun/tests/test_edgerun_submit.py | 16 +- 7 files changed, 166 insertions(+), 187 deletions(-) delete mode 100644 ceasiompy/EdgeRun/func/edge_queScript_gen.py create mode 100644 ceasiompy/EdgeRun/func/edge_que_script_gen.py diff --git a/ceasiompy/EdgeRun/edgerun.py b/ceasiompy/EdgeRun/edgerun.py index f53f0d39b..cd05323b1 100644 --- a/ceasiompy/EdgeRun/edgerun.py +++ b/ceasiompy/EdgeRun/edgerun.py @@ -14,29 +14,14 @@ # ================================================================================================= # IMPORTS # ================================================================================================= -import os, re +import os +import re from pathlib import Path from cpacspy.cpacspy import CPACS from ceasiompy.EdgeRun.func.edgeconfig import edge_cfd from ceasiompy.utils.ceasiomlogger import get_logger -from ceasiompy.utils.ceasiompyutils import ( - get_reasonable_nb_cpu, - get_results_directory, - # run_software, -) - -# 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.ceasiompyutils import get_results_directory from ceasiompy.utils.moduleinterfaces import get_toolinput_file_path, get_tooloutput_file_path -from cpacspy.cpacsfunctions import get_value_or_default, open_tixi -from ceasiompy.EdgeRun.func.edge_queScript_gen import EdgeScripts from ceasiompy.EdgeRun.func.edgeutils import get_edge_queScript_template log = get_logger() @@ -55,6 +40,7 @@ # ================================================================================================= input_que_script_path = get_edge_queScript_template() + def extract_edge_forces(results_dir): # Use list comprehension to get a list of directory names starting with "Case" dir_names = [ @@ -135,7 +121,7 @@ def main(cpacs_path, cpacs_out_path): log.info("Edge postprocessing finished") cpacs.save_cpacs(cpacs_out_path, overwrite=True) - + log.info("----- End of " + MODULE_NAME + " -----") diff --git a/ceasiompy/EdgeRun/func/edge_queScript_gen.py b/ceasiompy/EdgeRun/func/edge_queScript_gen.py deleted file mode 100644 index 9138bb9af..000000000 --- a/ceasiompy/EdgeRun/func/edge_queScript_gen.py +++ /dev/null @@ -1,138 +0,0 @@ -""" -CEASIOMpy: Conceptual Aircraft Design Software - -Developed for Airinnova AB, Stockholm, Sweden - -Functions to generate queuing script for Edge: queue_preprocessor.script and queue_edgesolver.script - -Python version: >=3.8 - -| Author : Mengmeng Zhang -| Creation: 2024-01-05 -""" - -# ================================================================================================= -# IMPORTS -# ================================================================================================= - -import os -import subprocess -from pathlib import Path - - - -class EdgeScripts: - def __init__(self, dir_path, jobname, input_que_script_path, edge_input_file): - self.jobname = jobname - self.dir_path = dir_path - self.input_que_script_path = input_que_script_path - self.Edge_dir = '/pdc/software/22.06/other/m-edge/3.2/gnu/bin/' - self.EdgeInputFile = edge_input_file - #self.GridDir = 'grid' - #os.chdir(os.path.join(caseDir, self.GridDir)) - - def submit_preprocessor_script(self,dir_path): - preprocessor = os.path.join(self.Edge_dir, 'preprocessor') - #dir_path = self.dir_path - QueScript = f'queue_preprocessor.script' - Submitcommand = 'sbatch' - os.chdir(dir_path) - with open(self.input_que_script_path, 'r') as template_file, open(QueScript, 'w') as que_script: - for line in template_file: - if '-J jobname' in line: - line = line.replace('-J jobname', f'-J {self.jobname}prepro') - que_script.write(line) - que_script.write(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') - print(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') - os.system(f'{Submitcommand} {que_script}') - - def run_preprocessor(self,dir_path): - #preprocessor = os.path.join(self.Edge_dir, 'preprocessor') - #dir_path = self.dir_path - #QueScript = f'queue_preprocessor.script' - #Submitcommand = 'sbatch' - os.chdir(dir_path) - """ - with open(self.input_que_script_path, 'r') as template_file, open(QueScript, 'w') as que_script: - for line in template_file: - if '-J jobname' in line: - line = line.replace('-J jobname', f'-J {self.jobname}prepro') - que_script.write(line) - - que_script.write(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') - print(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') - """ - os.system(f'preprocessor {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') - - def submit_solver_script(self, dir_path, nb_proc): - run_solver = os.path.join(self.Edge_dir, 'edge_mpi_run') - QueScript = f'queue_edgesolver.script' - #dir_path = self.dir_path - Submitcommand = 'sbatch' - os.chdir(dir_path) - with open(self.input_que_script_path, 'r') as template_file, open(QueScript, 'w') as que_script: - for line in template_file: - if '-J jobname' in line: - line = line.replace('-J jobname', f'-J {self.jobname}solver') - que_script.write(line) - que_script.write(f'{run_solver} {self.EdgeInputFile} {nb_proc} > edge_run.log 2>&1\n') - os.system(f'{Submitcommand} {que_script}') - - - def run_edgesolver(self, dir_path, nb_proc): - run_solver = os.path.join(self.Edge_dir, 'edge_mpi_run') - os.chdir(dir_path) - 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') - ffa2engold = os.path.join(self.Edge_dir, 'ffa2engold') - grid = edge_grid - - # output file names - #walldata1 = "Edge_wall.dat" - #walldata2 = "Edge_wall.cf" - forcemoments = "Edge_force_moment.dat" - ensgoldprefix = "zzz" - solution1 = "Edge.bout" - solution2 = "Post.bout" - - # Enter the folder - os.chdir(dir_path) - - """ - # 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) - - - # Inteerpolate the soulutions - subprocess.run([ffauinterpol, solution1, 'tmp1', 'tmp11']) - subprocess.run([ffauinterpol, solution2, 'tmp1', 'tmp12']) - - # Extract tabulated data - subprocess.run([ffa2tab, 'tmp11', walldata1]) - subprocess.run([ffa2tab, 'tmp12', walldata2]) - - # Cleanup - for temp_file in ['tmp1', 'tmp11', 'tmp12']: - os.remove(temp_file) - """ - # Create ensight gold files - subprocess.run([ffa2engold, grid, solution1, ensgoldprefix]) - - - - - - - #os.system(f'{Submitcommand} {que_script}') - - - diff --git a/ceasiompy/EdgeRun/func/edge_que_script_gen.py b/ceasiompy/EdgeRun/func/edge_que_script_gen.py new file mode 100644 index 000000000..bd8b86c5f --- /dev/null +++ b/ceasiompy/EdgeRun/func/edge_que_script_gen.py @@ -0,0 +1,141 @@ +""" +CEASIOMpy: Conceptual Aircraft Design Software + +Developed for Airinnova AB, Stockholm, Sweden + +Functions to generate queuing script for Edge: queue_preprocessor.script and queue_edgesolver.script + +Python version: >=3.8 + +| Author : Mengmeng Zhang +| Creation: 2024-01-05 +""" + +# ================================================================================================= +# IMPORTS +# ================================================================================================= + +import os +import subprocess +from pathlib import Path + +# ================================================================================================= +# CLASSES +# ================================================================================================= + + +class EdgeScripts: + def __init__(self, dir_path, jobname, input_que_script_path, edge_input_file): + self.jobname = jobname + self.dir_path = dir_path + self.input_que_script_path = input_que_script_path + self.Edge_dir = "/pdc/software/22.06/other/m-edge/3.2/gnu/bin/" + self.EdgeInputFile = edge_input_file + # self.GridDir = 'grid' + # os.chdir(os.path.join(caseDir, self.GridDir)) + + def submit_preprocessor_script(self, dir_path): + preprocessor = os.path.join(self.Edge_dir, "preprocessor") + # dir_path = self.dir_path + QueScript = "queue_preprocessor.script" + Submitcommand = "sbatch" + os.chdir(dir_path) + with open(self.input_que_script_path, "r") as template_file, open( + QueScript, "w" + ) as que_script: + for line in template_file: + if "-J jobname" in line: + line = line.replace("-J jobname", f"-J {self.jobname}prepro") + que_script.write(line) + que_script.write(f"{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n") + print(f"{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n") + os.system(f"{Submitcommand} {que_script}") + + def run_preprocessor(self, dir_path): + # preprocessor = os.path.join(self.Edge_dir, 'preprocessor') + # dir_path = self.dir_path + # QueScript = f'queue_preprocessor.script' + # Submitcommand = 'sbatch' + os.chdir(dir_path) + """ + with open(self.input_que_script_path, 'r') as template_file, + open(QueScript, 'w') as que_script: + for line in template_file: + if '-J jobname' in line: + line = line.replace('-J jobname', f'-J {self.jobname}prepro') + que_script.write(line) + + que_script.write(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') + print(f'{preprocessor} {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n') + """ + os.system(f"preprocessor {self.EdgeInputFile} > edge_preprocessor.log 2>&1\n") + + def submit_solver_script(self, dir_path, nb_proc): + run_solver = os.path.join(self.Edge_dir, "edge_mpi_run") + QueScript = "queue_edgesolver.script" + # dir_path = self.dir_path + Submitcommand = "sbatch" + os.chdir(dir_path) + with open(self.input_que_script_path, "r") as template_file, open( + QueScript, "w" + ) as que_script: + for line in template_file: + if "-J jobname" in line: + line = line.replace("-J jobname", f"-J {self.jobname}solver") + que_script.write(line) + que_script.write(f"{run_solver} {self.EdgeInputFile} {nb_proc} > edge_run.log 2>&1\n") + os.system(f"{Submitcommand} {que_script}") + + def run_edgesolver(self, dir_path, nb_proc): + run_solver = os.path.join(self.Edge_dir, "edge_mpi_run") + os.chdir(dir_path) + 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') + ffa2engold = os.path.join(self.Edge_dir, "ffa2engold") + grid = edge_grid + + # output file names + # walldata1 = "Edge_wall.dat" + # walldata2 = "Edge_wall.cf" + # forcemoments = "Edge_force_moment.dat" + ensgoldprefix = "zzz" + solution1 = "Edge.bout" + # solution2 = "Post.bout" + + # Enter the folder + os.chdir(dir_path) + + """ + # 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) + + + # Inteerpolate the soulutions + subprocess.run([ffauinterpol, solution1, 'tmp1', 'tmp11']) + subprocess.run([ffauinterpol, solution2, 'tmp1', 'tmp12']) + + # Extract tabulated data + subprocess.run([ffa2tab, 'tmp11', walldata1]) + subprocess.run([ffa2tab, 'tmp12', walldata2]) + + # Cleanup + for temp_file in ['tmp1', 'tmp11', 'tmp12']: + os.remove(temp_file) + """ + # Create ensight gold files + subprocess.run([ffa2engold, grid, solution1, ensgoldprefix]) + + # os.system(f'{Submitcommand} {que_script}') + + +# ================================================================================================= +# FUNCTIONS +# ================================================================================================= diff --git a/ceasiompy/EdgeRun/func/edgeconfig.py b/ceasiompy/EdgeRun/func/edgeconfig.py index a75d89f0a..df2e1e871 100644 --- a/ceasiompy/EdgeRun/func/edgeconfig.py +++ b/ceasiompy/EdgeRun/func/edgeconfig.py @@ -20,7 +20,8 @@ # IMPORTS # ================================================================================================= -import math, os +import math +import os from pathlib import Path from shutil import copyfile @@ -58,14 +59,12 @@ # from ceasiompy.utils.configfiles import ConfigFile from ceasiompy.utils.create_ainpfile import CreateAinp from cpacspy.cpacsfunctions import ( - create_branch, - get_string_vector, get_value, get_value_or_default, ) from cpacspy.cpacspy import CPACS from ceasiompy.EdgeRun.func.edgeutils import get_edge_queScript_template -from ceasiompy.EdgeRun.func.edge_queScript_gen import EdgeScripts +from ceasiompy.EdgeRun.func.edge_que_script_gen import EdgeScripts # import cpacs diff --git a/ceasiompy/EdgeRun/func/edgeutils.py b/ceasiompy/EdgeRun/func/edgeutils.py index 3b4d67d7e..93c0fe6a9 100644 --- a/ceasiompy/EdgeRun/func/edgeutils.py +++ b/ceasiompy/EdgeRun/func/edgeutils.py @@ -23,12 +23,6 @@ import requests from ceasiompy.utils.ceasiomlogger import get_logger -from ceasiompy.utils.ceasiompyutils import get_install_path -from ceasiompy.utils.commonnames import ( - ACTUATOR_DISK_INLET_SUFFIX, - ACTUATOR_DISK_OUTLET_SUFFIX, - ENGINE_EXHAUST_SUFFIX, - ENGINE_INTAKE_SUFFIX, ) from ceasiompy.utils.moduleinterfaces import get_module_path @@ -57,7 +51,7 @@ def get_edge_ainp_template(): ) return edge_ainp_template_path -def get_edge_queScript_template(): +def get_edge_que_script_template(): """Return path of the M-Edge ainp template corresponding to the M-Edge version.""" edge_dir = get_module_path("EdgeRun") diff --git a/ceasiompy/EdgeRun/tests/test_edgerun_mpi.py b/ceasiompy/EdgeRun/tests/test_edgerun_mpi.py index 5593e6a0e..7f57660f9 100644 --- a/ceasiompy/EdgeRun/tests/test_edgerun_mpi.py +++ b/ceasiompy/EdgeRun/tests/test_edgerun_mpi.py @@ -19,7 +19,6 @@ import unittest -import sys from pathlib import Path # Add the ceasiompy module to the PYTHONPATH @@ -30,14 +29,13 @@ # import ceasiompy from ceasiompy.EdgeRun.func.edgeconfig import generate_edge_cfd_ainp import os -from ceasiompy.EdgeRun.edgerun import run_edge_multi -from ceasiompy.utils.commonxpath import EDGE_NB_CPU_XPATH -from ceasiompy.EdgeRun.func.edgeutils import get_edge_queScript_template + # from ceasiompy.utils.create_ainpfile import CreateAinp MODULE_DIR = Path(__file__).parent -input_que_script_path = get_edge_queScript_template() -nb_proc = 32 + +# input_que_script_path = get_edge_queScript_template() + # ================================================================================================= # CLASSES # ================================================================================================= @@ -47,17 +45,18 @@ class TestEdgeConfig(unittest.TestCase): """Test class for 'ceasiompy/EdgeRun/func/edgerun.py'""" def test_run_edge_cfd(self): - # cpacs_in_path = Path(MODULE_DIR / "ToolInput" / "ToolInput.xml") - cpacs_in_path = Path('/home/mengmeng/Documents/CEASIOMpy23/CEASIOMpy/WKDIR/labARstraight_toolInput.xml') + # cpacs_in_path = Path(MODULE_DIR / "ToolInput" / "ToolInput.xml") + cpacs_in_path = Path( + "/home/mengmeng/Documents/CEASIOMpy23/CEASIOMpy/WKDIR/labARstraight_toolInput.xml" + ) cpacs_out_path = MODULE_DIR / "ToolOutput.xml" wkdir = MODULE_DIR / "Results/Edge" - if not os.path.exists(wkdir): os.makedirs(wkdir) generate_edge_cfd_ainp(cpacs_in_path, cpacs_out_path, wkdir) - #run_edge_multi(wkdir,input_que_script_path ) + # run_edge_multi(wkdir,input_que_script_path ) # ================================================================================================= diff --git a/ceasiompy/EdgeRun/tests/test_edgerun_submit.py b/ceasiompy/EdgeRun/tests/test_edgerun_submit.py index 0b871e1d2..75a9d9208 100644 --- a/ceasiompy/EdgeRun/tests/test_edgerun_submit.py +++ b/ceasiompy/EdgeRun/tests/test_edgerun_submit.py @@ -17,9 +17,6 @@ # IMPORTS # ================================================================================================= -import unittest - -import sys from pathlib import Path # Add the ceasiompy module to the PYTHONPATH @@ -30,16 +27,17 @@ # import ceasiompy from ceasiompy.EdgeRun.func.edgeconfig import edge_cfd import os -from ceasiompy.EdgeRun.edgerun import run_edge_multi -from ceasiompy.utils.commonxpath import EDGE_NB_CPU_XPATH -from ceasiompy.EdgeRun.func.edgeutils import get_edge_queScript_template + +# from ceasiompy.EdgeRun.func.edgeutils import get_edge_que_script_template # from ceasiompy.utils.create_ainpfile import CreateAinp MODULE_DIR = Path(__file__).parent -input_que_script_path = get_edge_queScript_template() +# input_que_script_path = get_edge_que_script_template() - # cpacs_in_path = Path(MODULE_DIR / "ToolInput" / "ToolInput.xml") -cpacs_in_path = Path('/home/mengmeng/Documents/CEASIOMpy23/CEASIOMpy/WKDIR/CPACS_selected_from_GUI.xml') +# cpacs_in_path = Path(MODULE_DIR / "ToolInput" / "ToolInput.xml") +cpacs_in_path = Path( + "/home/mengmeng/Documents/CEASIOMpy23/CEASIOMpy/WKDIR/CPACS_selected_from_GUI.xml" +) cpacs_out_path = MODULE_DIR / "ToolOutput.xml" wkdir = MODULE_DIR / "Results"