Skip to content

Commit

Permalink
edgerun
Browse files Browse the repository at this point in the history
  • Loading branch information
GBenedett committed Jan 24, 2024
1 parent f8fd12a commit 0257ecc
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions ceasiompy/EdgeRun/edgerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ 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}")
Expand Down Expand Up @@ -119,35 +118,41 @@ 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")]
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}")
# 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)
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}")
# 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:
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)
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]
Expand All @@ -161,14 +166,17 @@ def extract_edge_forces(results_dir):
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:
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")
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
# =================================================================================================
Expand All @@ -177,17 +185,19 @@ 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())
# tixi = open_tixi(cpacs_path)
# nb_proc = get_value_or_default(tixi, EDGE_NB_CPU_XPATH, get_reasonable_nb_cpu())

results_dir = get_results_directory("EdgeRun")

# Temporary CPACS to be stored after "generate_edge_cfd_ainp"
cpacs_tmp_cfg = Path(cpacs_out_path.parent, "ConfigTMP.xml")

edge_cfd(cpacs_path, cpacs_tmp_cfg, results_dir)

log.info("Edge postprocessing started")
extract_edge_forces(results_dir)
log.info("Edge Postprocess finished")
log.info("Edge postprocessing finished")
# run_edge_multi(results_dir, nb_proc)
# get_su2_results(cpacs_tmp_cfg, cpacs_out_path, results_dir)

Expand Down

0 comments on commit 0257ecc

Please sign in to comment.