Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
GBenedett committed Jan 11, 2024
1 parent d1ff01b commit 73c9bed
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 43 deletions.
18 changes: 9 additions & 9 deletions ceasiompy/EdgeRun/func/edgeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TODO:
*
*
"""

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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")

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ceasiompy/EdgeRun/func/edgeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
88 changes: 55 additions & 33 deletions ceasiompy/utils/create_ainpfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 73c9bed

Please sign in to comment.