Skip to content

Commit

Permalink
hole position and minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
GBenedett committed Oct 23, 2024
1 parent f1f46b6 commit 7b27419
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 27 deletions.
43 changes: 28 additions & 15 deletions ceasiompy/CPACS2GMSH/__specs__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
GMSH_MAX_THICKNESS_LAYER_XPATH,
GMSH_GROWTH_FACTOR_XPATH,
GMSH_GROWTH_RATIO_XPATH,
GMSH_SURFACE_MESH_SIZE_XPATH,
MIN_GMSH_SURFACE_MESH_SIZE_XPATH,
MAX_GMSH_SURFACE_MESH_SIZE_XPATH,
GMSH_FEATURE_ANGLE_XPATH,
)
from ceasiompy.utils.moduleinterfaces import CPACSInOut
Expand Down Expand Up @@ -217,10 +218,34 @@
gui_group="Advanced Euler mesh parameters",
)

cpacs_inout.add_input(
var_name="max_surface_mesh_factor",
var_type=float,
default_value=0.1,
unit="[10^-3]",
descr="Maximum surface mesh size factor",
xpath=MAX_GMSH_SURFACE_MESH_SIZE_XPATH,
gui=True,
gui_name="Max surface mesh size",
gui_group="RANS options",
)

cpacs_inout.add_input(
var_name="min_surface_mesh_factor",
var_type=float,
default_value=0.01,
unit="[10^-3]",
descr="Minimum surface mesh size factor",
xpath=MIN_GMSH_SURFACE_MESH_SIZE_XPATH,
gui=True,
gui_name="Min surface mesh size",
gui_group="RANS options",
)

cpacs_inout.add_input(
var_name="n_layer",
var_type=int,
default_value=20,
default_value=35,
unit="[-]",
descr="Number of prismatic element layers.",
xpath=GMSH_NUMBER_LAYER_XPATH,
Expand Down Expand Up @@ -280,7 +305,7 @@
cpacs_inout.add_input(
var_name="feature_angle",
var_type=float,
default_value=40,
default_value=45,
unit="[grad]",
descr="Larger angles are treated as resulting from approximation of curved surfaces",
xpath=GMSH_FEATURE_ANGLE_XPATH,
Expand All @@ -289,18 +314,6 @@
gui_group="RANS options",
)

cpacs_inout.add_input(
var_name="surface_mesh_factor",
var_type=float,
default_value=5,
unit="[10^-3]",
descr="Surface mesh size factor compared to aircraft largest dimension (omogeneus everywhere)",
xpath=GMSH_SURFACE_MESH_SIZE_XPATH,
gui=True,
gui_name="Surface mesh size",
gui_group="RANS options",
)

cpacs_inout.add_input(
var_name="export_propellers",
var_type=bool,
Expand Down
12 changes: 8 additions & 4 deletions ceasiompy/CPACS2GMSH/cpacs2gmsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
GMSH_MAX_THICKNESS_LAYER_XPATH,
GMSH_GROWTH_FACTOR_XPATH,
GMSH_GROWTH_RATIO_XPATH,
GMSH_SURFACE_MESH_SIZE_XPATH,
MIN_GMSH_SURFACE_MESH_SIZE_XPATH,
MAX_GMSH_SURFACE_MESH_SIZE_XPATH,
GMSH_FEATURE_ANGLE_XPATH,
)
from cpacspy.cpacsfunctions import create_branch, get_value_or_default
Expand Down Expand Up @@ -115,7 +116,8 @@ def cpacs2gmsh(cpacs_path, cpacs_out_path):
max_layer_thickness = get_value_or_default(cpacs.tixi, GMSH_MAX_THICKNESS_LAYER_XPATH, 10)
growth_factor = get_value_or_default(cpacs.tixi, GMSH_GROWTH_FACTOR_XPATH, 1.4)
growth_ratio = get_value_or_default(cpacs.tixi, GMSH_GROWTH_RATIO_XPATH, 1.2)
min_max_mesh_factor = get_value_or_default(cpacs.tixi, GMSH_SURFACE_MESH_SIZE_XPATH, 5)
min_mesh_factor = get_value_or_default(cpacs.tixi, MIN_GMSH_SURFACE_MESH_SIZE_XPATH, 0.01)
max_mesh_factor = get_value_or_default(cpacs.tixi, MAX_GMSH_SURFACE_MESH_SIZE_XPATH, 0.1)
feature_angle = get_value_or_default(cpacs.tixi, GMSH_FEATURE_ANGLE_XPATH, 40)

# Run mesh generation
Expand Down Expand Up @@ -148,13 +150,14 @@ 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,
min_mesh_factor=min_mesh_factor,
max_mesh_factor=max_mesh_factor,
)

if gmesh_path.exists():
Expand All @@ -169,6 +172,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
35 changes: 28 additions & 7 deletions ceasiompy/CPACS2GMSH/func/RANS_mesh_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@


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_mesh_factor,
max_mesh_factor,
symmetry=False,
):
"""
Function to generate a mesh from brep files forming an airplane
Expand Down Expand Up @@ -170,7 +177,6 @@ def bounding_box_distance(bbox1, bbox2):
gmsh.model.occ.synchronize()

log.info(f"Part : {part_obj.uid} imported")
log.info(f"Importing part from {brep_file}: {part_entities}")

while len(parts_parent_dimtag) > 1:
fused = False
Expand Down Expand Up @@ -227,10 +233,24 @@ def bounding_box_distance(bbox1, bbox2):
fuselage_maxlen, _ = fuselage_size(cpacs_path)
log.info("Fusion process ended")

# maybe can be removed
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] / 4,
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] / 4,
]
print(f"model_center {model_center}")

aircraft = ModelPart("aircraft")

for part in aircraft_parts:
log.info(f"Part: {part.uid}, Points: {part.points}, Type: {part.part_type}")
aircraft.points.extend(part.points)
aircraft.lines.extend(part.lines)
aircraft.surfaces.extend(part.surfaces)
Expand All @@ -240,6 +260,8 @@ def bounding_box_distance(bbox1, bbox2):
aircraft.surfaces_tags.extend(part.surfaces_tags)
aircraft.volume_tag.extend(part.volume_tag)

log.info(f"Part: {part.uid}, Points: {part.points}, Type: {part.part_type}")

# Set surface BC for each part of the aircraft
# if part.part_type == "engine":
# define_engine_bc(part, brep_dir)
Expand Down Expand Up @@ -303,7 +325,7 @@ def bounding_box_distance(bbox1, bbox2):

process_gmsh_log(gmsh.logger.get())

return gmsh_path, fuselage_maxlen
return gmsh_path, fuselage_maxlen, model_center


def pentagrow_3d_mesh(
Expand All @@ -316,6 +338,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 @@ -327,9 +350,8 @@ 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"
OutputFormat = "su2"
HolePosition = "0.0 0.0 0.0"
HolePosition = model_center
TetgenOptions = "-pq1.3VY"
TetGrowthFactor = growth_factor
HeightIterations = 8
Expand All @@ -348,7 +370,6 @@ def pentagrow_3d_mesh(
file.write(f"FarfieldRadius = {FarfieldRadius}\n")
file.write(f"OutputFormat = {OutputFormat}\n")
file.write(f"HolePosition = {HolePosition}\n")
file.write(f"FarfieldCenter = {FarfieldCenter}\n")
file.write(f"TetgenOptions = {TetgenOptions}\n")
file.write(f"TetGrowthFactor = {TetGrowthFactor}\n")
file.write(f"HeightIterations = {HeightIterations}\n")
Expand Down
3 changes: 2 additions & 1 deletion ceasiompy/utils/commonxpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
GMSH_MAX_THICKNESS_LAYER_XPATH = GMSH_XPATH + "/max_thickness_layer"
GMSH_GROWTH_FACTOR_XPATH = GMSH_XPATH + "/growth_factor"
GMSH_GROWTH_RATIO_XPATH = GMSH_XPATH + "/growth_ratio"
GMSH_SURFACE_MESH_SIZE_XPATH = GMSH_XPATH + "min_max_mesh_factor"
MIN_GMSH_SURFACE_MESH_SIZE_XPATH = GMSH_XPATH + "max_mesh_factor"
MAX_GMSH_SURFACE_MESH_SIZE_XPATH = GMSH_XPATH + "max_mesh_factor"
GMSH_FEATURE_ANGLE_XPATH = GMSH_XPATH + "/feature_angle"

# SU2
Expand Down

0 comments on commit 7b27419

Please sign in to comment.