Skip to content

Commit

Permalink
Improvement of the mesh generation and control pt. 1 (#280)
Browse files Browse the repository at this point in the history
Many new features: new mesh parameters and a new way to control mesh generation; automatic aeromap, actdisk in marker monitoring
  • Loading branch information
GBenedett authored Dec 5, 2023
1 parent 7354d1f commit a11eb44
Show file tree
Hide file tree
Showing 28 changed files with 1,710 additions and 700 deletions.
68 changes: 49 additions & 19 deletions ceasiompy/CPACS2GMSH/__specs__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
GMSH_EXHAUST_PERCENT_XPATH,
GMSH_EXPORT_PROP_XPATH,
GMSH_FARFIELD_FACTOR_XPATH,
GMSH_N_POWER_FACTOR_XPATH,
GMSH_N_POWER_FIELD_XPATH,
GMSH_INTAKE_PERCENT_XPATH,
GMSH_MESH_SIZE_FARFIELD_XPATH,
GMSH_MESH_SIZE_FUSELAGE_XPATH,
Expand All @@ -16,6 +18,8 @@
GMSH_REFINE_FACTOR_XPATH,
GMSH_SYMMETRY_XPATH,
SU2MESH_XPATH,
GMSH_MESH_SIZE_FACTOR_FUSELAGE_XPATH,
GMSH_MESH_SIZE_FACTOR_WINGS_XPATH,
)
from ceasiompy.utils.moduleinterfaces import CPACSInOut

Expand Down Expand Up @@ -84,38 +88,39 @@
)

cpacs_inout.add_input(
var_name="farfield_mesh_size",
var_name="farfield_mesh_size_factor",
var_type=float,
default_value=25,
unit="[m]",
descr="Value assigned for the farfield surface mesh size",
default_value=10,
unit="[-]",
descr="""Factor proportional to the biggest cell on the plane
to obtain cell size on the farfield""",
xpath=GMSH_MESH_SIZE_FARFIELD_XPATH,
gui=True,
gui_name="Farfield",
gui_name="Farfield mesh size factor",
gui_group="Mesh size",
)

cpacs_inout.add_input(
var_name="fuselage_mesh_size",
var_name="fuselage_mesh_size_factor",
var_type=float,
default_value=0.4,
unit="[m]",
descr="Value assigned for the fuselage surfaces mesh size",
xpath=GMSH_MESH_SIZE_FUSELAGE_XPATH,
default_value=1,
unit="[-]",
descr="Factor proportional to fuselage radius of curvature to obtain cell size on it",
xpath=GMSH_MESH_SIZE_FACTOR_FUSELAGE_XPATH,
gui=True,
gui_name="Fuselage",
gui_name="Fuselage mesh size factor",
gui_group="Mesh size",
)

cpacs_inout.add_input(
var_name="wing_mesh_size",
var_name="wing_mesh_size_factor",
var_type=float,
default_value=0.23,
unit="[m]",
descr="Value assigned for the wings surfaces mesh size",
xpath=GMSH_MESH_SIZE_WINGS_XPATH,
default_value=1.5,
unit="[-]",
descr="Factor proportional to wing radius of curvature to obtain cell size on it",
xpath=GMSH_MESH_SIZE_FACTOR_WINGS_XPATH,
gui=True,
gui_name="Wings",
gui_name="Wings mesh size factor",
gui_group="Mesh size",
)

Expand All @@ -130,6 +135,7 @@
gui_name="Engines",
gui_group="Mesh size",
)

cpacs_inout.add_input(
var_name="propeller_mesh_size",
var_type=float,
Expand All @@ -142,10 +148,34 @@
gui_group="Mesh size",
)

cpacs_inout.add_input(
var_name="n_power_factor",
var_type=float,
default_value=2,
unit="1",
descr="Value that changes the number of cells near the aircraft parts",
xpath=GMSH_N_POWER_FACTOR_XPATH,
gui=True,
gui_name="n power factor",
gui_group="Advanced mesh parameters",
)

cpacs_inout.add_input(
var_name="n_power_field",
var_type=float,
default_value=0.9,
unit="1",
descr="Value that changes the measure of fist cells near aircraft parts",
xpath=GMSH_N_POWER_FIELD_XPATH,
gui=True,
gui_name="n power field",
gui_group="Advanced mesh parameters",
)

cpacs_inout.add_input(
var_name="refine_factor",
var_type=float,
default_value=7.0,
default_value=2.0,
unit="1",
descr="Refinement factor of wing leading/trailing edge mesh",
xpath=GMSH_REFINE_FACTOR_XPATH,
Expand All @@ -168,7 +198,7 @@
cpacs_inout.add_input(
var_name="auto_refine",
var_type=bool,
default_value=True,
default_value=False,
unit="1",
descr="Automatically refine the mesh on surfaces that are small compare to the chosen mesh"
"size, this option increase the mesh generation time",
Expand Down
30 changes: 19 additions & 11 deletions ceasiompy/CPACS2GMSH/cpacs2gmsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
GMSH_AUTO_REFINE_XPATH,
GMSH_EXHAUST_PERCENT_XPATH,
GMSH_FARFIELD_FACTOR_XPATH,
GMSH_N_POWER_FACTOR_XPATH,
GMSH_N_POWER_FIELD_XPATH,
GMSH_INTAKE_PERCENT_XPATH,
GMSH_MESH_SIZE_FARFIELD_XPATH,
GMSH_MESH_SIZE_FUSELAGE_XPATH,
GMSH_MESH_SIZE_WINGS_XPATH,
GMSH_MESH_SIZE_FACTOR_FUSELAGE_XPATH,
GMSH_MESH_SIZE_FACTOR_WINGS_XPATH,
GMSH_MESH_SIZE_ENGINES_XPATH,
GMSH_MESH_SIZE_PROPELLERS_XPATH,
GMSH_OPEN_GUI_XPATH,
Expand Down Expand Up @@ -65,7 +67,6 @@


def cpacs2gmsh(cpacs_path, cpacs_out_path):

# Get option from the CPACS file
cpacs = CPACS(cpacs_path)

Expand All @@ -78,9 +79,15 @@ def cpacs2gmsh(cpacs_path, cpacs_out_path):
open_gmsh = get_value_or_default(cpacs.tixi, GMSH_OPEN_GUI_XPATH, False)
farfield_factor = get_value_or_default(cpacs.tixi, GMSH_FARFIELD_FACTOR_XPATH, 6)
symmetry = get_value_or_default(cpacs.tixi, GMSH_SYMMETRY_XPATH, False)
mesh_size_farfield = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_FARFIELD_XPATH, 25)
mesh_size_fuselage = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_FUSELAGE_XPATH, 0.4)
mesh_size_wings = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_WINGS_XPATH, 0.23)
farfield_size_factor = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_FARFIELD_XPATH, 17)
n_power_factor = get_value_or_default(cpacs.tixi, GMSH_N_POWER_FACTOR_XPATH, 2)
n_power_field = get_value_or_default(cpacs.tixi, GMSH_N_POWER_FIELD_XPATH, 0.9)
fuselage_mesh_size_factor = get_value_or_default(
cpacs.tixi,
GMSH_MESH_SIZE_FACTOR_FUSELAGE_XPATH,
1,
)
wing_mesh_size_factor = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_FACTOR_WINGS_XPATH, 1)
mesh_size_engines = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_ENGINES_XPATH, 0.23)
mesh_size_propellers = get_value_or_default(cpacs.tixi, GMSH_MESH_SIZE_PROPELLERS_XPATH, 0.23)
refine_factor = get_value_or_default(cpacs.tixi, GMSH_REFINE_FACTOR_XPATH, 7.0)
Expand All @@ -93,14 +100,17 @@ def cpacs2gmsh(cpacs_path, cpacs_out_path):
export_brep(cpacs, brep_dir, (intake_percent, exhaust_percent))
mesh_path, _ = generate_gmsh(
cpacs,
cpacs_path,
brep_dir,
results_dir,
open_gmsh=open_gmsh,
farfield_factor=farfield_factor,
symmetry=symmetry,
mesh_size_farfield=mesh_size_farfield,
mesh_size_fuselage=mesh_size_fuselage,
mesh_size_wings=mesh_size_wings,
farfield_size_factor=farfield_size_factor,
n_power_factor=n_power_factor,
n_power_field=n_power_field,
fuselage_mesh_size_factor=fuselage_mesh_size_factor,
wing_mesh_size_factor=wing_mesh_size_factor,
mesh_size_engines=mesh_size_engines,
mesh_size_propellers=mesh_size_propellers,
refine_factor=refine_factor,
Expand All @@ -124,7 +134,6 @@ def cpacs2gmsh(cpacs_path, cpacs_out_path):


def main(cpacs_path, cpacs_out_path):

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

check_cpacs_input_requirements(cpacs_path)
Expand All @@ -135,7 +144,6 @@ def main(cpacs_path, cpacs_out_path):


if __name__ == "__main__":

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

Expand Down
17 changes: 7 additions & 10 deletions ceasiompy/CPACS2GMSH/func/advancemeshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
TODO:
-Add a parameter to let the user tune the powerlaw governing the mesh
in the fluid domaine and the powerlaw for the wing surface mesh
-Add a parameter to let the user tune the powerlaw for the wing surface mesh
"""

Expand Down Expand Up @@ -253,14 +252,12 @@ def refine_wing_section(

# For each wing section get the mean chord and le/te lines
for wing_section in wing_part.wing_sections:

chord_mean = wing_section["mean_chord"]
x_chord = chord_mean * chord_percent
lines_to_refine = wing_section["lines_tags"]

# If the wing is truncated:
if len(lines_to_refine) == 3:

# Find the trailing edge thickness
x1, y1, z1 = gmsh.model.occ.getCenterOfMass(1, lines_to_refine[0])
x2, y2, z2 = gmsh.model.occ.getCenterOfMass(1, lines_to_refine[1])
Expand All @@ -274,7 +271,6 @@ def refine_wing_section(

# Overwrite the trailing edge refinement
if (mesh_size_wings / te_thickness > refine) and refine_truncated:

refine = mesh_size_wings / te_thickness

# 1 : Math eval field
Expand Down Expand Up @@ -331,7 +327,8 @@ def set_domain_mesh(
mesh_size_farfield,
aircraft_charact_length,
final_domain_volume_tag,
n_power=1.5,
n_power_factor,
n_power_field,
):
"""
Function to define the domain mesh between the farfield and the aircraft
Expand Down Expand Up @@ -375,7 +372,6 @@ def set_domain_mesh(
log.info("Set mesh refinement of fluid domain")

for part in aircraft_parts:

# 1 : Math eval field between the part surface and the farfield

mesh_fields = distance_field(mesh_fields, 2, part.surfaces_tags)
Expand All @@ -388,7 +384,7 @@ def set_domain_mesh(
mesh_fields["nbfields"],
"F",
f"{part.mesh_size} + ({mesh_size_farfield} - {part.mesh_size})*"
f"(F{distance_field_tag}/{aircraft_charact_length})^{n_power}",
f"(F{distance_field_tag}/{aircraft_charact_length})^{n_power_factor}",
)
mesh_fields = restrict_fields(mesh_fields, 3, final_domain_volume_tag)

Expand All @@ -399,7 +395,9 @@ def set_domain_mesh(
gmsh.model.mesh.field.add("Threshold", mesh_fields["nbfields"])
gmsh.model.mesh.field.setNumber(mesh_fields["nbfields"], "InField", distance_field_tag)
gmsh.model.mesh.field.setNumber(mesh_fields["nbfields"], "SizeMax", part.mesh_size)
gmsh.model.mesh.field.setNumber(mesh_fields["nbfields"], "SizeMin", part.mesh_size * 0.9)
gmsh.model.mesh.field.setNumber(
mesh_fields["nbfields"], "SizeMin", part.mesh_size * n_power_field
)

mesh_fields = restrict_fields(mesh_fields, 2, part.surfaces_tags)

Expand Down Expand Up @@ -519,5 +517,4 @@ def refine_small_surfaces(
# =================================================================================================

if __name__ == "__main__":

print("Nothing to execute!")
Loading

0 comments on commit a11eb44

Please sign in to comment.