Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New installation for sumo and pentagrow #299

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integrationtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Install SUMO
shell: bash -l {0}
run: installation/Ubuntu/install_sumo.sh
run: installation/Ubuntu/install_sumo_new.sh

- name: Install SU2
shell: bash -l {0}
Expand Down
5 changes: 4 additions & 1 deletion ceasiompy/CPACS2GMSH/cpacs2gmsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ def cpacs2gmsh(cpacs_path, cpacs_out_path):

else:
export_brep(cpacs, brep_dir, (intake_percent, exhaust_percent))
gmesh_path, fuselage_maxlen = generate_2d_mesh_for_pentagrow(
gmesh_path, fuselage_maxlen, model_center = generate_2d_mesh_for_pentagrow(
cpacs,
cpacs_path,
brep_dir,
results_dir,
open_gmsh=open_gmsh,
min_max_mesh_factor=min_max_mesh_factor,
fuselage_mesh_size_factor=1,
wing_mesh_size_factor=1.5,
)

if gmesh_path.exists():
Expand All @@ -169,6 +171,7 @@ def cpacs2gmsh(cpacs_path, cpacs_out_path):
growth_factor=growth_factor,
growth_ratio=growth_ratio,
feature_angle=feature_angle,
model_center=model_center,
)
if mesh_path.exists():
create_branch(cpacs.tixi, SU2MESH_XPATH)
Expand Down
225 changes: 150 additions & 75 deletions ceasiompy/CPACS2GMSH/func/RANS_mesh_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@
from pathlib import Path

import gmsh
from ceasiompy.CPACS2GMSH.func.generategmesh import (
# duplicate_disk_actuator_surfaces,
# control_disk_actuator_normal,
# get_entities_from_volume,
from ceasiompy.CPACS2GMSH.func.generategmesh import ( # duplicate_disk_actuator_surfaces,; control_disk_actuator_normal,; get_entities_from_volume,
ModelPart,
add_disk_actuator,
fuselage_size,
process_gmsh_log,
)
from ceasiompy.CPACS2GMSH.func.gmsh_utils import MESH_COLORS
from ceasiompy.utils.ceasiomlogger import get_logger

# from ceasiompy.utils.commonnames import (
Expand All @@ -53,9 +50,12 @@
# GMSH_ENGINE_CONFIG_NAME,
# )
from ceasiompy.utils.ceasiompyutils import get_part_type

# from ceasiompy.utils.commonxpath import GMSH_MESH_SIZE_WINGS_XPATH
from ceasiompy.utils.commonxpath import GMSH_MESH_SIZE_FUSELAGE_XPATH, GMSH_MESH_SIZE_WINGS_XPATH
from ceasiompy.utils.configfiles import ConfigFile
from cpacspy.cpacsfunctions import create_branch

from ceasiompy.CPACS2GMSH.func.mesh_sizing import fuselage_size, wings_size


log = get_logger()

Expand All @@ -66,7 +66,15 @@


def generate_2d_mesh_for_pentagrow(
cpacs, cpacs_path, brep_dir, results_dir, open_gmsh, min_max_mesh_factor, symmetry=False
cpacs,
cpacs_path,
brep_dir,
results_dir,
open_gmsh,
min_max_mesh_factor,
symmetry=False,
fuselage_mesh_size_factor=1,
wing_mesh_size_factor=1.5,
):
"""
Function to generate a mesh from brep files forming an airplane
Expand Down Expand Up @@ -133,15 +141,22 @@ def generate_2d_mesh_for_pentagrow(
gmsh.option.setNumber("General.Terminal", 0)
# Log complexity
gmsh.option.setNumber("General.Verbosity", 5)
# Tollerance for boolean
gmsh.option.setNumber("Geometry.ToleranceBoolean", 1e-5)

# Import each aircraft original parts / parent parts
fuselage_volume_dimtags = []
wings_volume_dimtags = []
enginePylons_enginePylon_volume_dimtags = []
engine_nacelle_fanCowl_volume_dimtags = []
engine_nacelle_coreCowl_volume_dimtags = []
vehicles_engines_engine_volume_dimtags = []
vehicles_rotorcraft_model_rotors_rotor_volume_dimtags = []
# fuselage_volume_dimtags = []
# wings_volume_dimtags = []
# enginePylons_enginePylon_volume_dimtags = []
# engine_nacelle_fanCowl_volume_dimtags = []
# engine_nacelle_coreCowl_volume_dimtags = []
# vehicles_engines_engine_volume_dimtags = []
# vehicles_rotorcraft_model_rotors_rotor_volume_dimtags = []

# fuselage_surface = []
# wing_surface = []
aircraft_parts = []
parts_parent_dimtag = []

log.info(f"Importing files from {brep_dir}")

Expand All @@ -150,87 +165,146 @@ def generate_2d_mesh_for_pentagrow(
part_entities = gmsh.model.occ.importShapes(str(brep_file), highestDimOnly=False)
gmsh.model.occ.synchronize()

# Create the aircraft part object
part_obj = ModelPart(uid=brep_file.stem)
# maybe to cut off -->
part_obj.part_type = get_part_type(cpacs.tixi, part_obj.uid)

if part_obj.part_type == "fuselage":
fuselage_volume_dimtags.append(part_entities[0])
model_bb = gmsh.model.get_bounding_box(
fuselage_volume_dimtags[0][0], fuselage_volume_dimtags[0][1]
)

elif part_obj.part_type == "wing":
wings_volume_dimtags.append(part_entities[0])
# return wings_volume_dimtags

elif part_obj.part_type == "enginePylons/enginePylon":
enginePylons_enginePylon_volume_dimtags.append(part_entities[0])
# return enginePylons_enginePylon_volume_dimtags

elif part_obj.part_type == "engine/nacelle/fanCowl":
engine_nacelle_fanCowl_volume_dimtags.append(part_entities[0])
part_surfaces = [e for e in part_entities if e[0] == 2]
part_obj.surfaces_tags = [tag for dim, tag in part_surfaces]

elif part_obj.part_type == "engine/nacelle/coreCowl":
engine_nacelle_coreCowl_volume_dimtags.append(part_entities[0])

elif part_obj.part_type == "vehicles/engines/engine":
vehicles_engines_engine_volume_dimtags.append(part_entities[0])

elif part_obj.part_type == "vehicles/rotorcraft/model/rotors/rotor":
vehicles_rotorcraft_model_rotors_rotor_volume_dimtags.append(part_entities[0])
else:
log.warning(f"'{brep_file}' cannot be categorized!")
return None
gmsh.model.occ.synchronize()
log.info("Start manipulation to obtain a watertight volume")
# we have to obtain a wathertight volume
gmsh.model.occ.cut(wings_volume_dimtags, fuselage_volume_dimtags, -1, True, False)

gmsh.model.occ.synchronize()
# Add to the list of aircraft parts
aircraft_parts.append(part_obj)
parts_parent_dimtag.append(part_entities[0])

gmsh.model.occ.fuse(wings_volume_dimtags, fuselage_volume_dimtags, -1, True, True)
log.info(f"Part : {part_obj.uid} imported")

gmsh.model.occ.synchronize()

# Create external domain for the farfield
model_bb = gmsh.model.getBoundingBox(-1, -1)
model_dimensions = [
abs(model_bb[0] - model_bb[3]),
abs(model_bb[1] - model_bb[4]),
abs(model_bb[2] - model_bb[5]),
]
model_center = [
model_bb[0] + model_dimensions[0] / 2,
0, # the y coordinate is set to zero because sometimes (when act disk
# actuator is present) the coordinate of the model is not exact
model_bb[2] + model_dimensions[2] / 2,
]

log.info("Start manipulation to obtain a watertight volume")
log.info("Fusing parts...")

# Ciclo di fusione
while len(parts_parent_dimtag) > 1:
fused_entities, mapping = gmsh.model.occ.fuse(
[parts_parent_dimtag[0]], [parts_parent_dimtag[1]]
)

gmsh.model.occ.synchronize()

fuselage_maxlen, _ = fuselage_size(cpacs_path)
# Aggiorna la lista delle entità fuse
new_fused = fused_entities[0]
parts_parent_dimtag = [new_fused] + parts_parent_dimtag[2:]

gmsh.model.occ.translate(
[(3, 1)],
-((model_bb[0]) + (model_dimensions[0] / 2)),
-((model_bb[1]) + (model_dimensions[1] / 2)),
-((model_bb[2]) + (model_dimensions[2] / 2)),
)
# Verifica le entità nel modello
final_volume_numbers = gmsh.model.getEntities(3)

if len(final_volume_numbers) != 1 or final_volume_numbers[0][1] != 1:
log.error(f"There are {len(final_volume_numbers)}, fusion not successful")
log.error("You should have just one volume")

gmsh.model.occ.synchronize()

aircraft = ModelPart("aircraft")

for part in aircraft_parts:
aircraft.points.extend(part.points)
aircraft.lines.extend(part.lines)
aircraft.surfaces.extend(part.surfaces)
aircraft.volume.extend(part.volume)
aircraft.points_tags.extend(part.points_tags)
aircraft.lines_tags.extend(part.lines_tags)
aircraft.surfaces_tags.extend(part.surfaces_tags)
aircraft.volume_tag.extend(part.volume_tag)

print(part.surfaces_tags)

surfaces_group = gmsh.model.addPhysicalGroup(2, part.surfaces_tags)
print(f"surfaces_group ={surfaces_group}")
gmsh.model.setPhysicalName(2, surfaces_group, f"{part.uid}")
part.physical_groups.append(surfaces_group)

# Set surface BC for each part of the aircraft
# if part.part_type == "engine":
# define_engine_bc(part, brep_dir)
# else:
# surfaces_group = gmsh.model.addPhysicalGroup(2, part.surfaces_tags)
# if part.part_type == "rotor":
# gmsh.model.setPhysicalName(
# 2, surfaces_group, f"{part.uid}{ACTUATOR_DISK_INLET_SUFFIX}"
# )
# else:
# gmsh.model.setPhysicalName(2, surfaces_group, f"{part.uid}")
# part.physical_groups.append(surfaces_group)
gmsh.model.occ.synchronize()
log.info("Manipulation finished")

aircraft_surface_dimtags = gmsh.model.get_entities(2)
len_aircraft_surface = len(aircraft_surface_dimtags)
surface = []
# gmsh.fltk.run()

for i in range(len_aircraft_surface):
tags = aircraft_surface_dimtags[i][1]
surface.append(tags)
fuselage_maxlen, fuselage_minlen = fuselage_size(cpacs_path)

gmsh.model.add_physical_group(2, surface, -1, name="aircraft_surface")
# gmsh.model.occ.translate(
# [(3, 1)],
# -((model_bb[0]) + (model_dimensions[0] / 2)),
# -((model_bb[1]) + (model_dimensions[1] / 2)),
# -((model_bb[2]) + (model_dimensions[2] / 2)),
# )

gmsh.model.occ.synchronize()
log.info("Geometry has been fused")

mesh_size_fuselage = ((fuselage_maxlen + fuselage_minlen) / 2) / fuselage_mesh_size_factor
log.info(f"Mesh size fuselage={mesh_size_fuselage:.3f} m")

create_branch(cpacs.tixi, GMSH_MESH_SIZE_FUSELAGE_XPATH)
cpacs.tixi.updateDoubleElement(GMSH_MESH_SIZE_FUSELAGE_XPATH, mesh_size_fuselage, "%.3f")

wing_maxlen, wing_minlen = wings_size(cpacs_path)
mesh_size_wing = ((wing_maxlen * 0.8 + wing_minlen) / 2) / wing_mesh_size_factor
log.info(f"Mesh size wing={mesh_size_wing:.3f} m")

create_branch(cpacs.tixi, GMSH_MESH_SIZE_WINGS_XPATH)
cpacs.tixi.updateDoubleElement(GMSH_MESH_SIZE_WINGS_XPATH, mesh_size_wing, "%.3f")

for part in aircraft_parts:
print(part.part_type)
if part.part_type == "fuselage":
part.mesh_size = mesh_size_fuselage
gmsh.model.mesh.setSize(part.points, part.mesh_size)
gmsh.model.setColor(part.surfaces, *MESH_COLORS[part.part_type], recursive=False)
elif part.part_type in ["wing", "pylon"]:
part.mesh_size = mesh_size_wing
gmsh.model.mesh.setSize(part.points, part.mesh_size)
gmsh.model.setColor(part.surfaces, *MESH_COLORS[part.part_type], recursive=False)
# elif part.part_type == "engine":
# part.mesh_size = mesh_size_engines
# gmsh.model.mesh.setSize(part.points, part.mesh_size)
# gmsh.model.setColor(part.surfaces, *MESH_COLORS[part.part_type], recursive=False)
# elif part.part_type == "rotor":
# part.mesh_size = mesh_size_propellers
# gmsh.model.mesh.setSize(part.points, part.mesh_size)
# gmsh.model.setColor(part.surfaces, *MESH_COLORS[part.part_type], recursive=False)

# mesh_size = model_dimensions[0] * float(min_max_mesh_factor) * (10**-3)
# gmsh.option.set_number("Mesh.MeshSizeMin", mesh_size)
# gmsh.option.set_number("Mesh.MeshSizeMax", mesh_size)
# gmsh.option.setNumber("Mesh.StlOneSolidPerSurface", 2)

# Mesh generation
log.info("Start of gmsh 2D surface meshing process")

gmsh.option.setNumber("Mesh.Algorithm", 6)
gmsh.option.setNumber("Mesh.LcIntegrationPrecision", 1e-6)
mesh_size = model_dimensions[0] * float(min_max_mesh_factor) * (10**-3)
gmsh.option.set_number("Mesh.MeshSizeMin", mesh_size)
gmsh.option.set_number("Mesh.MeshSizeMax", mesh_size)
gmsh.option.setNumber("Mesh.StlOneSolidPerSurface", 2)

gmsh.model.occ.synchronize()
gmsh.logger.start()
Expand All @@ -243,12 +317,12 @@ def generate_2d_mesh_for_pentagrow(

gmsh.model.occ.synchronize()

gmesh_path = Path(results_dir, "mesh_2d.stl")
gmsh.write(str(gmesh_path))
gmsh_path = Path(results_dir, "mesh_2d.stl")
gmsh.write(str(gmsh_path))

process_gmsh_log(gmsh.logger.get())

return gmesh_path, fuselage_maxlen
return gmsh_path, fuselage_maxlen, model_center


def pentagrow_3d_mesh(
Expand All @@ -261,6 +335,7 @@ def pentagrow_3d_mesh(
growth_factor,
growth_ratio,
feature_angle,
model_center,
) -> None:
# create the config file for pentagrow
config_penta_path = Path(result_dir, "config.cfg")
Expand All @@ -272,7 +347,7 @@ def pentagrow_3d_mesh(
MaxGrowthRatio = growth_ratio
MaxLayerThickness = max_layer_thickness / 10
FarfieldRadius = fuselage_maxlen * farfield_factor * 100
FarfieldCenter = "0.0 0.0 0.0"
FarfieldCenter = model_center
OutputFormat = "su2"
HolePosition = "0.0 0.0 0.0"
TetgenOptions = "-pq1.3VY"
Expand Down
Loading
Loading