Skip to content

Commit

Permalink
Merge branch 'medge_integration' of https://github.com/cfsengineering…
Browse files Browse the repository at this point in the history
…/CEASIOMpy into medge_integration
  • Loading branch information
GBenedett committed Jan 29, 2024
2 parents 673bcef + a9c837c commit 7681e30
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 76 deletions.
71 changes: 3 additions & 68 deletions ceasiompy/EdgeRun/edgerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,70 +55,6 @@
# =================================================================================================
input_que_script_path = get_edge_queScript_template()


def run_edge_multi(wkdir, input_que_script_path, nb_proc=2):
"""Function to run a multiple Edge calculation.
Function 'run_edge_multi' will run in the given working directory Edge calculations.
The working directory must have a folder structure created by 'SU2Config'/ 'EdgeConfig' module.
Args:
wkdir (Path): Path to the working directory
nb_proc (int): Number of processor that should be used to run the calculation in parallel
"""
cpacs = CPACS(cpacs_path)

edge_mesh = Path(get_value(cpacs.tixi, EDGE_MESH_XPATH))

if not wkdir.exists():
raise OSError(f"The working directory : {wkdir} does not exist!")

case_dir_name = (
f"Case{str(case_nb).zfill(2)}_alt{alt}_mach{round(mach, 2)}"
f"_aoa{round(aoa, 1)}_aos{round(aos, 1)}"
)

case_dir_path = Path(wkdir, case_dir_name)
if not case_dir_path.exists():
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}")

for config_dir in sorted(case_dir_list):
current_dir = Path(case_dir_path, config_dir)

config_cfd = [c for c in config_dir.iterdir() if c.name == AINP_CFD_NAME]

if not config_cfd:
raise ValueError(f"No '{AINP_CFD_NAME}' file has been found in this directory!")

if len(config_cfd) > 1:
raise ValueError(f"More than one '{AINP_CFD_NAME}' file in this directory!")

# run / submit edge commands
edge_scripts_instance = EdgeScripts(current_dir, input_que_script_path, AINP_CFD_NAME)
# check if preprocessor is already run
bedg_files_exist = True
for i in range(1, nb_proc + 1):
bedg_file_path = Path(case_dir_path, grid_folder, f"Edge.bedg_p{i}")
if not bedg_file_path.exists():
bedg_files_exist = False
break
if not bedg_files_exist:
# edge_scripts_instance.submit_preprocessor_script(case_dir_path)
edge_scripts_instance.run_preprocessor(case_dir_path)
print("bedg files are generated")

# edge_scripts_instance.submit_solver_script(nb_proc)
edge_scripts_instance.run_solver(nb_proc)

# 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 = [
Expand Down Expand Up @@ -185,8 +121,7 @@ def extract_edge_forces(results_dir):
def main(cpacs_path, cpacs_out_path):
log.info("----- Start of " + MODULE_NAME + " -----")

# tixi = open_tixi(cpacs_path)
# nb_proc = get_value_or_default(tixi, EDGE_NB_CPU_XPATH, get_reasonable_nb_cpu())
cpacs = CPACS(cpacs_path)

results_dir = get_results_directory("EdgeRun")

Expand All @@ -198,9 +133,9 @@ def main(cpacs_path, cpacs_out_path):
log.info("Edge postprocessing started")
extract_edge_forces(results_dir)
log.info("Edge postprocessing finished")
# run_edge_multi(results_dir, nb_proc)
# get_su2_results(cpacs_tmp_cfg, cpacs_out_path, results_dir)

cpacs.save_cpacs(cpacs_out_path, overwrite=True)

log.info("----- End of " + MODULE_NAME + " -----")


Expand Down
11 changes: 7 additions & 4 deletions ceasiompy/EdgeRun/func/edgeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def edge_cfd(cpacs_path, cpacs_out_path, wkdir):
raise FileNotFoundError(f"M-Edge mesh file {edge_mesh} not found")
# copy edge_mesh and edge_aboc file to the Working directory

grid_folder = Path(wkdir, "grid")
grid_folder = Path(wkdir, "grid")
#grid_folder = Path(wkdir) # Added by Mengmeng Zhang
to_grid = grid_folder / edge_mesh.name
to_aboc = grid_folder / edge_aboc.name

Expand Down Expand Up @@ -314,12 +315,14 @@ def edge_cfd(cpacs_path, cpacs_out_path, wkdir):


# edge_scripts_instance.submit_solver_script(case_dir_path,NPART)
log.info("Running Edge solver for " + 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 )
log.info("Edge solver is done." )

# postprocess for results
#edge_scripts_instance.postprocess_script(case_dir_path, edge_mesh)
log.info("Running Edge postprocessor...for " + case_dir_name )
edge_scripts_instance.postprocess_script(case_dir_path, edge_mesh)
log.info("Edge postprocessor is done." )
# wait until the results are generated

cpacs.save_cpacs(cpacs_out_path, overwrite=True)
Expand Down
10 changes: 6 additions & 4 deletions ceasiompy/SUMOAutoMesh/sumoautomesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,17 @@ def create_mesh(cpacs_path, cpacs_out_path):
tixi.updateTextElement(SU2MESH_XPATH, str(mesh_out_path))
mesh_path.unlink()

else:
elif output == "edge":
create_branch(tixi, EDGE_MESH_XPATH)
tixi.updateTextElement(EDGE_MESH_XPATH, str(mesh_out_path))

edge_aboc_path = Path(sumo_results_dir, "ToolOutput.aboc")
shutil.copyfile(mesh_path, edge_aboc_path)
edge_aboc_path = Path(sumo_results_dir, "ToolOutput.aboc") # commented by Mengmeng
edge_aboc_name = aircraft_name(tixi) + f"_baseline.aboc"
aboc_out_path = Path(sumo_results_dir, edge_aboc_name)
shutil.copyfile(edge_aboc_path, aboc_out_path)

create_branch(tixi, EDGE_ABOC_XPATH)
tixi.updateTextElement(EDGE_ABOC_XPATH, str(edge_aboc_path))
tixi.updateTextElement(EDGE_ABOC_XPATH, str(aboc_out_path))

mesh_path.unlink()

Expand Down
2 changes: 2 additions & 0 deletions ceasiompy/utils/commonxpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
SMFILE_XPATH = CEASIOMPY_XPATH + "/filesPath/SMpath"
SU2MESH_XPATH = CEASIOMPY_XPATH + "/filesPath/su2Mesh"
EDGE_MESH_XPATH = CEASIOMPY_XPATH + "/filesPath/edgeMesh"

SUMOFILE_XPATH = CEASIOMPY_XPATH + "/filesPath/sumoFilePath"
WKDIR_XPATH = CEASIOMPY_XPATH + "/filesPath/wkdirPath"

Expand Down Expand Up @@ -151,6 +152,7 @@
EDGE_CFL_NB_XPATH = EDGE_XPATH + "/settings/cflNumber/value"
EDGE_MG_LEVEL_XPATH = EDGE_XPATH + "/settings/multigridLevel"
EDGE_FIXED_CL_XPATH = EDGE_XPATH + "/fixedCL"
EDGE_SOLVER = EDGE_XPATH + "/solver"
EDGE_ABOC_XPATH = EDGE_XPATH + "/boundary_condition"

# RANGE
Expand Down

0 comments on commit 7681e30

Please sign in to comment.