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

	ceasiompy/EdgeRun/func/edgeutils.py
  • Loading branch information
mengmengzhang2019 committed Jan 11, 2024
2 parents f340306 + 11ccb81 commit 727bcf3
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 675 deletions.
33 changes: 20 additions & 13 deletions ceasiompy/EdgeRun/edgerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
get_results_directory,
run_software,
)
#from ceasiompy.utils.commonnames import AINP_CFD_NAME, SU2_FORCES_BREAKDOWN_NAME

# from ceasiompy.utils.commonnames import AINP_CFD_NAME, SU2_FORCES_BREAKDOWN_NAME
from ceasiompy.utils.commonnames import AINP_CFD_NAME
from ceasiompy.utils.commonxpath import Edge_NB_CPU_XPATH
from ceasiompy.utils.commonxpath import EDGE_NB_CPU_XPATH
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
Expand All @@ -49,11 +50,11 @@
# =================================================================================================
input_que_script_path = get_edge_queScript_template()

def run_Edge_multi(wkdir, nb_proc=2):
def run_edge_multi(wkdir, 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.
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
Expand All @@ -68,7 +69,6 @@ def run_Edge_multi(wkdir, nb_proc=2):
raise OSError(f"No Case directory has been found in the working directory: {wkdir}")

for config_dir in sorted(case_dir_list):

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

if not config_cfd:
Expand All @@ -84,16 +84,25 @@ def run_Edge_multi(wkdir, nb_proc=2):
software_name="edge_mpi_run",
arguments=[config_cfd[0], str(nb_proc)],
wkdir=config_dir,
<<<<<<< HEAD
with_mpi=True,
# nb_proc
)
"""

#forces_breakdown_file = Path(config_dir, SU2_FORCES_BREAKDOWN_NAME)
#if not forces_breakdown_file.exists():
=======
with_mpi=False,
# nb_proc
)

# forces_breakdown_file = Path(config_dir, SU2_FORCES_BREAKDOWN_NAME)
# if not forces_breakdown_file.exists():
>>>>>>> 11ccb81e114b69bf4ab99efd08c252c4ab3ecd0f
# raise ValueError(
# "The SU2_CFD calculation has not ended correctly,"
# f"{SU2_FORCES_BREAKDOWN_NAME} is missing!"
# "The SU2_CFD calculation has not ended correctly,"
# f"{SU2_FORCES_BREAKDOWN_NAME} is missing!"
# )


Expand All @@ -103,26 +112,24 @@ def run_Edge_multi(wkdir, nb_proc=2):


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())
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")

generate_edge_cfd_ainp(cpacs_path, cpacs_tmp_cfg, results_dir)
run_Edge_multi(results_dir, nb_proc)
#get_su2_results(cpacs_tmp_cfg, cpacs_out_path, results_dir)
run_edge_multi(results_dir, nb_proc)
# get_su2_results(cpacs_tmp_cfg, cpacs_out_path, results_dir)

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


if __name__ == "__main__":

cpacs_path = get_toolinput_file_path(MODULE_NAME)
cpacs_out_path = get_tooloutput_file_path(MODULE_NAME)

Expand Down
39 changes: 20 additions & 19 deletions ceasiompy/EdgeRun/func/edgeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TODO:
*
*
"""

Expand All @@ -35,6 +35,7 @@
# write_actuator_disk_data,
# write_header,
# )

from ceasiompy.EdgeRun.func.edgeutils import get_edge_ainp_template
from ceasiompy.utils.ceasiomlogger import get_logger
from ceasiompy.utils.commonnames import (
Expand All @@ -44,13 +45,13 @@
GMSH_SYMMETRY_XPATH,
PROP_XPATH,
RANGE_XPATH,
EdgeMESH_XPATH,
Edge_AEROMAP_UID_XPATH,
Edge_CFL_NB_XPATH,
Edge_MAX_ITER_XPATH,
Edge_MG_LEVEL_XPATH,
Edge_NB_CPU_XPATH,
Edge_FIXED_CL_XPATH,
EDGE_MESH_XPATH,
EDGE_AEROMAP_UID_XPATH,
EDGE_CFL_NB_XPATH,
EDGE_MAX_ITER_XPATH,
EDGE_MG_LEVEL_XPATH,
EDGE_NB_CPU_XPATH,
EDGE_FIXED_CL_XPATH,
)

# from ceasiompy.utils.configfiles import ConfigFile
Expand Down Expand Up @@ -99,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 @@ -113,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 @@ -137,15 +138,15 @@ 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")

else: # if fixed_cl == 'YES':
log.info("Configuration file for fixed CL calculation will be created.")

fixed_cl_aeromap = cpacs.create_aeromap("aeroMap_fixedCL_SU2")
fixed_cl_aeromap.description = f"AeroMap created for SU2 fixed CL value of {target_cl}"
# fixed_cl_aeromap.description = f"AeroMap created for SU2 fixed CL value of {target_cl}"

mach = get_value_or_default(cpacs.tixi, RANGE_XPATH + "/cruiseMach", 0.78)
alt = get_value_or_default(cpacs.tixi, RANGE_XPATH + "/cruiseAltitude", 12000)
Expand Down Expand Up @@ -175,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 All @@ -197,8 +198,8 @@ def generate_edge_cfd_ainp(cpacs_path, cpacs_out_path, wkdir):
speedofsound = Atm.speed_of_sound[0]
airspeed = mach * speedofsound

aoa_rad = math.radians(aoa)
aos_rad = math.radians(aos)
# aoa_rad = math.radians(aoa)
# aos_rad = math.radians(aos)

UFREE = airspeed * math.cos(aos) * math.cos(aoa)
WFREE = airspeed * math.cos(aos) * math.sin(aoa)
Expand Down
11 changes: 3 additions & 8 deletions ceasiompy/EdgeRun/func/edgeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
# FUNCTIONS
# =================================================================================================


def get_edge_ainp_template():
"""Return path of the M-Edge ainp template corresponding to the M-Edge version."""

# su2_version = get_su2_version()
# 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 Expand Up @@ -102,17 +103,11 @@ def get_su2_aerocoefs(force_file):
velocity = float(line.split(" ")[7])

return cl, cd, cs, cmd, cms, cml, velocity
""""""






# =================================================================================================
# MAIN
# =================================================================================================

if __name__ == "__main__":

print("Nothing to execute!")
Loading

0 comments on commit 727bcf3

Please sign in to comment.