Skip to content

Commit

Permalink
add medge as output mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
GBenedett committed Dec 6, 2023
1 parent a11eb44 commit f8eb3bf
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 24 deletions.
19 changes: 18 additions & 1 deletion ceasiompy/SUMOAutoMesh/__specs__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from pathlib import Path

from ceasiompy.utils.commonxpath import SU2MESH_XPATH, SUMO_REFINE_LEVEL_XPATH, SUMOFILE_XPATH
from ceasiompy.utils.commonxpath import (
SU2MESH_XPATH,
SUMO_REFINE_LEVEL_XPATH,
SUMOFILE_XPATH,
SUMO_OUTPUT_MESH_FORMAT_XPATH,
)
from ceasiompy.utils.moduleinterfaces import CPACSInOut

# ===== Module Status =====
Expand Down Expand Up @@ -43,6 +48,18 @@
gui_group="SUMO options",
)

cpacs_inout.add_input(
var_name="output_format",
var_type=list,
default_value=["SU2", "M-Edge"],
unit="1",
descr="chose the output mesh format",
xpath=SUMO_OUTPUT_MESH_FORMAT_XPATH,
gui=True,
gui_name="Output mesh format",
gui_group="SUMO options",
)


# ----- Output -----

Expand Down
38 changes: 22 additions & 16 deletions ceasiompy/SUMOAutoMesh/sumoautomesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def add_mesh_parameters(sumo_file_path, refine_level=0.0):

REFINE_RATIO = 0.6 # to get approx. double mesh cell when +1 on "refine_level"
refine_factor = REFINE_RATIO**refine_level
log.info("Refinement factor is {}".format(refine_factor))
log.info(f"Refinement factor is {refine_factor:.3f}")

# Open SUMO (.smx) with tixi library
sumo = open_tixi(sumo_file_path)
Expand Down Expand Up @@ -209,7 +209,7 @@ def add_mesh_parameters(sumo_file_path, refine_level=0.0):
sumo.save(str(sumo_file_path))


def create_SU2_mesh(cpacs_path, cpacs_out_path):
def create_mesh(cpacs_path, cpacs_out_path, output):
"""Function to create a simple SU2 mesh form an SUMO file (.smx)
Function 'create_mesh' is used to generate an unstructured mesh with SUMO
Expand All @@ -228,8 +228,15 @@ def create_SU2_mesh(cpacs_path, cpacs_out_path):

tixi = open_tixi(cpacs_path)

if output == "su2":
file_extension = "su2"
elif output == "edge":
file_extension = "bmsh"
else:
raise ValueError("Unsupported output format. Use 'su2' or 'edge'")

sumo_results_dir = get_results_directory("SUMOAutoMesh")
su2_mesh_path = Path(sumo_results_dir, "ToolOutput.su2")
mesh_path = Path(sumo_results_dir, f"ToolOutput.{file_extension}")

sumo_file_path = Path(get_value_or_default(tixi, SUMOFILE_XPATH, ""))
if not sumo_file_path.exists():
Expand All @@ -241,7 +248,7 @@ def create_SU2_mesh(cpacs_path, cpacs_out_path):
add_mesh_parameters(sumo_file_path, refine_level)

# Tetgen option, see the help for more options
output = "su2"
# output = "su2"
options = "pq1.16VY"
arguments = [
"-batch",
Expand Down Expand Up @@ -284,17 +291,17 @@ def create_SU2_mesh(cpacs_path, cpacs_out_path):
raise OSError("OS not recognize!")

# Copy the mesh in the MESH directory
su2_mesh_name = aircraft_name(tixi) + "_baseline.su2"
su2_mesh_out_path = Path(sumo_results_dir, su2_mesh_name)
shutil.copyfile(su2_mesh_path, su2_mesh_out_path)
mesh_name = aircraft_name(tixi) + f"_baseline.{file_extension}"
mesh_out_path = Path(sumo_results_dir, mesh_name)
shutil.copyfile(mesh_path, mesh_out_path)

if not su2_mesh_out_path.exists():
raise ValueError("No SU2 Mesh file has been generated!")
if not mesh_out_path.exists():
raise ValueError("No mesh file has been generated!")

log.info("An SU2 Mesh has been correctly generated.")
log.info(f"A {output} mesh has been correctly generated.")
create_branch(tixi, SU2MESH_XPATH)
tixi.updateTextElement(SU2MESH_XPATH, str(su2_mesh_out_path))
su2_mesh_path.unlink()
tixi.updateTextElement(SU2MESH_XPATH, str(mesh_out_path))
mesh_path.unlink()

tixi.save(str(cpacs_out_path))

Expand All @@ -304,17 +311,16 @@ def create_SU2_mesh(cpacs_path, cpacs_out_path):
# =================================================================================================


def main(cpacs_path, cpacs_out_path):

def main(cpacs_path, cpacs_out_path, output_format="edge"):
log.info("----- Start of " + MODULE_NAME + " -----")

create_SU2_mesh(cpacs_path, cpacs_out_path)
# Call create_mesh with the desired output format
create_mesh(cpacs_path, cpacs_out_path, output=output_format)

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
1 change: 1 addition & 0 deletions ceasiompy/utils/commonxpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
TURBOPROP_XPATH = PROP_XPATH + "/turboprop"

# SUMO
SUMO_OUTPUT_MESH_FORMAT_XPATH = MESH_XPATH + "sumoOptions/format"
SUMO_REFINE_LEVEL_XPATH = MESH_XPATH + "/sumoOptions/refinementLevel"
SUMO_INCLUDE_PYLON_XPATH = CEASIOMPY_XPATH + "/engine/includePylon"
SUMO_INCLUDE_ENGINE_XPATH = CEASIOMPY_XPATH + "/engine/includeEngine"
Expand Down
25 changes: 18 additions & 7 deletions src/bin/ceasiompy_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def run_testcase(testcase_nb):
"""Run a test case."""

if testcase_nb == 1:

testcase_message(1)

test_case_1_path = Path(TEST_CASES_PATH, "test_case_1")
Expand Down Expand Up @@ -174,13 +173,18 @@ def run_gui():
os.system(f"cd {STREAMLIT_PATH} && streamlit run CEASIOMpy.py")


def run_output(format):
"""Chose the format for the output mesh"""

log.info()


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


def main():

parser = argparse.ArgumentParser(
description="CEASIOMpy: Conceptual Aircraft Design Environment",
usage=argparse.SUPPRESS,
Expand Down Expand Up @@ -215,34 +219,41 @@ def main():
metavar="NB",
help="run a test case [1, 2, or 3]",
)
parser.add_argument(
"-o",
"--output",
type=str,
metavar="",
default="su2",
help="chose to generate a mesh for SU2 or m-Edge [su2, edge]",
)

args = parser.parse_args()

if args.testcase:

run_testcase(args.testcase)
return

if args.modules:

run_modules_list(args.modules)
return

if args.cfg:

run_config_file(args.cfg)

return

if args.gui:

run_gui()
return

if args.output:
run_output(args.output)
return

# If no argument is given, print the help
parser.print_help()


if __name__ == "__main__":

main()

0 comments on commit f8eb3bf

Please sign in to comment.