Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
GBenedett committed Feb 7, 2024
1 parent 912b4df commit 3abf780
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 187 deletions.
24 changes: 5 additions & 19 deletions ceasiompy/EdgeRun/edgerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 = [
Expand Down Expand Up @@ -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 + " -----")


Expand Down
138 changes: 0 additions & 138 deletions ceasiompy/EdgeRun/func/edge_queScript_gen.py

This file was deleted.

141 changes: 141 additions & 0 deletions ceasiompy/EdgeRun/func/edge_que_script_gen.py
Original file line number Diff line number Diff line change
@@ -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
# =================================================================================================
7 changes: 3 additions & 4 deletions ceasiompy/EdgeRun/func/edgeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# IMPORTS
# =================================================================================================

import math, os
import math
import os

from pathlib import Path
from shutil import copyfile
Expand Down Expand Up @@ -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

Expand Down
8 changes: 1 addition & 7 deletions ceasiompy/EdgeRun/func/edgeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 3abf780

Please sign in to comment.