From 73c9bed98e4439ae54d8d7d9c4d9e63284256cbe Mon Sep 17 00:00:00 2001 From: GBenedett Date: Thu, 11 Jan 2024 10:27:10 +0100 Subject: [PATCH] formatting --- ceasiompy/EdgeRun/func/edgeconfig.py | 18 +++--- ceasiompy/EdgeRun/func/edgeutils.py | 2 +- ceasiompy/utils/create_ainpfile.py | 88 +++++++++++++++++----------- 3 files changed, 65 insertions(+), 43 deletions(-) diff --git a/ceasiompy/EdgeRun/func/edgeconfig.py b/ceasiompy/EdgeRun/func/edgeconfig.py index 17673ca2e..3e78a7819 100644 --- a/ceasiompy/EdgeRun/func/edgeconfig.py +++ b/ceasiompy/EdgeRun/func/edgeconfig.py @@ -12,7 +12,7 @@ TODO: - * + * """ @@ -100,12 +100,12 @@ def generate_edge_cfd_ainp(cpacs_path, cpacs_out_path, wkdir): cpacs = CPACS(cpacs_path) - edge_mesh = Path(get_value(cpacs.tixi, EdgeMESH_XPATH)) + edge_mesh = Path(get_value(cpacs.tixi, EDGE_MESH_XPATH)) if not edge_mesh.is_file(): raise FileNotFoundError(f"M-Edge mesh file {edge_mesh} not found") # Get the fixedCL value from CPACS - fixed_cl = get_value_or_default(cpacs.tixi, Edge_FIXED_CL_XPATH, "NO") + fixed_cl = get_value_or_default(cpacs.tixi, EDGE_FIXED_CL_XPATH, "NO") if fixed_cl == "NO": # Get the first aeroMap as default one or create automatically one aeromap_list = cpacs.get_aeromap_uid_list() @@ -114,7 +114,7 @@ def generate_edge_cfd_ainp(cpacs_path, cpacs_out_path, wkdir): aeromap_default = aeromap_list[0] log.info(f"The aeromap is {aeromap_default}") - aeromap_uid = get_value_or_default(cpacs.tixi, Edge_AEROMAP_UID_XPATH, aeromap_default) + aeromap_uid = get_value_or_default(cpacs.tixi, EDGE_AEROMAP_UID_XPATH, aeromap_default) activate_aeromap = cpacs.get_aeromap_by_uid(aeromap_uid) alt_list = activate_aeromap.get("altitude").tolist() @@ -138,7 +138,7 @@ def generate_edge_cfd_ainp(cpacs_path, cpacs_out_path, wkdir): aos_list = [0.0] aeromap_uid = get_value_or_default( - cpacs.tixi, Edge_AEROMAP_UID_XPATH, "DefaultAeromap" + cpacs.tixi, EDGE_AEROMAP_UID_XPATH, "DefaultAeromap" ) log.info(f"{aeromap_uid} has been created") @@ -176,10 +176,10 @@ def generate_edge_cfd_ainp(cpacs_path, cpacs_out_path, wkdir): # Settings - ITMAX = int(get_value_or_default(cpacs.tixi, Edge_MAX_ITER_XPATH, 200)) - CFL = get_value_or_default(cpacs.tixi, Edge_CFL_NB_XPATH, 1.5) - NGRID = int(get_value_or_default(cpacs.tixi, Edge_MG_LEVEL_XPATH, 3)) - NPART = int(get_value_or_default(cpacs.tixi, Edge_NB_CPU_XPATH, 32)) + ITMAX = int(get_value_or_default(cpacs.tixi, EDGE_MAX_ITER_XPATH, 200)) + CFL = get_value_or_default(cpacs.tixi, EDGE_CFL_NB_XPATH, 1.5) + NGRID = int(get_value_or_default(cpacs.tixi, EDGE_MG_LEVEL_XPATH, 3)) + NPART = int(get_value_or_default(cpacs.tixi, EDGE_NB_CPU_XPATH, 32)) INSEUL = 0 # Parameters which will vary for the different cases (alt,mach,aoa,aos) diff --git a/ceasiompy/EdgeRun/func/edgeutils.py b/ceasiompy/EdgeRun/func/edgeutils.py index fc9d46896..cf65a51c3 100644 --- a/ceasiompy/EdgeRun/func/edgeutils.py +++ b/ceasiompy/EdgeRun/func/edgeutils.py @@ -50,7 +50,7 @@ def get_edge_ainp_template(): # su2_version = get_su2_version() edge_dir = get_module_path("EdgeRun") - edge_ainp_template_path = Path(edge_dir, "files", f"default.ainp.tmp") + edge_ainp_template_path = Path(edge_dir, "files", "default.ainp.tmp") if not edge_ainp_template_path.is_file(): raise FileNotFoundError( f"The M-Edge ainp template '{edge_ainp_template_path}' has not been found!" diff --git a/ceasiompy/utils/create_ainpfile.py b/ceasiompy/utils/create_ainpfile.py index 1d26a8df6..5f6900295 100644 --- a/ceasiompy/utils/create_ainpfile.py +++ b/ceasiompy/utils/create_ainpfile.py @@ -32,45 +32,67 @@ class CreateAinp: def __init__(self): self.template_file = get_edge_ainp_template() - - def _write_file(self,content,output_file_path): - #output_file_path = os.path.join(output_folder, 'Edge.ainp') - with open(output_file_path,'w') as f: - f.write(content) + def _write_file(self, content, output_file_path): + # output_file_path = os.path.join(output_folder, 'Edge.ainp') + with open(output_file_path, "w") as f: + f.write(content) - def create_ainp(self,UFREE, VFREE, WFREE, TFREE, PFREE, SREF, CREF, BREF, IXMP, IDCLP, IDCDP, IDCCP, IDCMP, IDCNP, IDCRP, NPART, ITMAX, INSEUL, NGRID, CFL,output_folder): - #template_file_path = get_edge_ainp_template() - with open(self.template_file,'r') as f: + def create_ainp( + self, + UFREE, + VFREE, + WFREE, + TFREE, + PFREE, + SREF, + CREF, + BREF, + IXMP, + IDCLP, + IDCDP, + IDCCP, + IDCMP, + IDCNP, + IDCRP, + NPART, + ITMAX, + INSEUL, + NGRID, + CFL, + output_folder, + ): + # template_file_path = get_edge_ainp_template() + with open(self.template_file, "r") as f: template_content = f.read() - - # Define a dictionary for keyword-value pairs + + # Define a dictionary for keyword-value pairs replacements = { - '__UFREE__': str(UFREE), - '__VFREE__': str(VFREE), - '__WFREE__': str(WFREE), - '__TFREE__': str(TFREE), - '__PFREE__': str(PFREE), - '__SREF__': str(SREF), - '__CREF__': str(CREF), - '__BREF__': str(BREF), - '__IXMP__': f"{IXMP[0]} {IXMP[1]} {IXMP[2]}", - '__IDCLP__': IDCLP, - '__IDCDP__': IDCDP, - '__IDCCP__': IDCCP, - '__IDCMP__': IDCMP, - '__IDCNP__': IDCNP, - '__IDCRP__': IDCRP, - '__NPART__': str(NPART), - '__ITMAX__': str(ITMAX), - '__INSEUL__': str(INSEUL), - '__NGRID__': str(NGRID), - '__CFL__': str(CFL) + "__UFREE__": str(UFREE), + "__VFREE__": str(VFREE), + "__WFREE__": str(WFREE), + "__TFREE__": str(TFREE), + "__PFREE__": str(PFREE), + "__SREF__": str(SREF), + "__CREF__": str(CREF), + "__BREF__": str(BREF), + "__IXMP__": f"{IXMP[0]} {IXMP[1]} {IXMP[2]}", + "__IDCLP__": IDCLP, + "__IDCDP__": IDCDP, + "__IDCCP__": IDCCP, + "__IDCMP__": IDCMP, + "__IDCNP__": IDCNP, + "__IDCRP__": IDCRP, + "__NPART__": str(NPART), + "__ITMAX__": str(ITMAX), + "__INSEUL__": str(INSEUL), + "__NGRID__": str(NGRID), + "__CFL__": str(CFL), } - - # Use regular expression to replace keywords with their corresponding values + + # Use regular expression to replace keywords with their corresponding values edge_content = template_content for keyword, value in replacements.items(): edge_content = re.sub(re.escape(keyword), value, edge_content) - + self._write_file(edge_content, output_folder)