Skip to content

Commit b3e537c

Browse files
committed
cleaned comments RANS
1 parent e1ff100 commit b3e537c

File tree

2 files changed

+102
-26
lines changed

2 files changed

+102
-26
lines changed

ceasiompy/CPACS2GMSH/func/advancemeshing.py

+72-17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
88
| Author: Tony Govoni
99
| Creation: 2022-04-07
10+
| Modified: Cassandre Renaud
11+
| Date: 2025-May-9
1012
1113
TODO:
1214
-Add a parameter to let the user tune the powerlaw for the wing surface mesh
@@ -577,7 +579,7 @@ def refine_other_lines(
577579

578580
# foundbigangle = False
579581
# # Get the adjacent surface, and the nodes
580-
# surfs, _ = gmsh.model.getAdjacencies(dim, line)
582+
# surface_tags, _ = gmsh.model.getAdjacencies(dim, line)
581583
# tags, coord, param = gmsh.model.mesh.getNodes(1, line)
582584
# nbpoints = len(coord) // 3
583585
# # Select at most 40 nodes (but 20 evenly spaces if too big)
@@ -592,11 +594,11 @@ def refine_other_lines(
592594

593595
# # Now test for every 2 surfaces along line (usually always one or two surfaces total)
594596
# # And if one, can't be a weird angle
595-
# for k in range(len(surfs)):
596-
# i = surfs[k]
597+
# for k in range(len(surface_tags)):
598+
# i = surface_tags[k]
597599
# params_i = gmsh.model.getParametrization(2, i, coord_small)
598-
# for l in range(k + 1, len(surfs)):
599-
# j = surfs[l]
600+
# for l in range(k + 1, len(surface_tags)):
601+
# j = surface_tags[l]
600602
# params_j = gmsh.model.getParametrization(2, j, coord_small)
601603
# for a in range(len(coord_small) // 3):
602604
# # For each point, get the normal to the surface
@@ -622,14 +624,14 @@ def refine_other_lines(
622624
for (dim, line) in lines:
623625
if line % step_lines == 0:
624626
log.info(f"{math.floor(line/total*100)}% done")
625-
surfs, _ = gmsh.model.getAdjacencies(dim, line)
627+
surface_tags, _ = gmsh.model.getAdjacencies(dim, line)
626628
tags_coords_params = {-1: "yay"}
627629
# For each adjacent surface, get all the nodes
628-
for i in surfs:
630+
for i in surface_tags:
629631
tags, coord, param = gmsh.model.mesh.getNodes(2, i, True)
630632
tags_coords_params[i] = {'tags': tags, 'coord': coord, 'param': param}
631633
# Now see the surfaces two by two, to see their intersection
632-
big_angle = compute_angle_surfaces(surfs, tags_coords_params)
634+
big_angle = compute_angle_surfaces(surface_tags, tags_coords_params)
633635
if big_angle:
634636
lines_with_angles_tag.append(line)
635637

@@ -650,17 +652,49 @@ def refine_other_lines(
650652
# Get all the lines that are adjacent and need refinement
651653
[_, adjacent_lines] = gmsh.model.getAdjacencies(2, s)
652654
lines_to_refine = list(set(adjacent_lines) & set(lines_with_angles_tag))
653-
refine_surface(part.uid, lines_to_refine, s, mesh_fields,
654-
m, n_power, refine, mesh_size)
655+
mesh_fields = refine_surface(part.uid, lines_to_refine, s, mesh_fields,
656+
m, n_power, refine, mesh_size)
655657

656658
return mesh_fields
657659

658660

659661
def refine_surface(
660-
part_uid, lines_to_refine, s, mesh_fields, m, n_power, refine, mesh_size
662+
part_uid, lines_to_refine, surface_tag, mesh_fields, m, n_power, refine, mesh_size
661663
):
664+
"""
665+
Function to refine the surfaces on a specific part along some given lines by creating Fields
666+
667+
Args:
668+
----------
669+
part_uid : string
670+
name of the part the surface is on
671+
lines_to_refine : list of int
672+
list of the tags of the lines we need to refine
673+
surface_tag : int
674+
tag of the surface we are refining
675+
mesh_fields : dict
676+
mesh_fields["nbfields"] : number of existing mesh field in the model,
677+
each field must be created with a different index !!!
678+
mesh_fields["restrict_fields"] : list of the restrict fields,
679+
this is the list to be use for the final "Min" background field
680+
m : float
681+
length of the refinement (from the line, if more than distance m then
682+
has "normal" mesh size)
683+
n_power : float
684+
power of the power law for the refinement
685+
refine : float
686+
refinement factor
687+
mesh_size : float
688+
mesh size depending of the part
689+
...
690+
Returns:
691+
----------
692+
mesh_fields : dict
693+
mesh_fields["nbfields"] : number of existing mesh field in the model
694+
695+
"""
662696
for line in lines_to_refine:
663-
log.info(f"Refining line {line} in surface {s} in part {part_uid}")
697+
log.info(f"Refining line {line} in surface {surface_tag} in part {part_uid}")
664698

665699
# 1 : Math eval field
666700
mesh_fields["nbfields"] += 1
@@ -685,21 +719,42 @@ def refine_surface(
685719
mesh_fields["nbfields"] += 1
686720
gmsh.model.mesh.field.add("Restrict", mesh_fields["nbfields"])
687721
gmsh.model.mesh.field.setNumbers(
688-
mesh_fields["nbfields"], "SurfacesList", [s])
722+
mesh_fields["nbfields"], "SurfacesList", [surface_tag])
689723
gmsh.model.mesh.field.setNumber(
690724
mesh_fields["nbfields"], "InField", mesh_fields["nbfields"] - 1)
691725
mesh_fields["restrict_fields"].append(mesh_fields["nbfields"])
692726
gmsh.model.mesh.field.setAsBackgroundMesh(mesh_fields["nbfields"])
693727
gmsh.model.occ.synchronize()
694728

729+
return mesh_fields
730+
695731

696732
def compute_angle_surfaces(
697-
surfs, tags_coords_params
733+
surface_tags, tags_coords_params
698734
):
699-
for k, i in enumerate(surfs):
700-
# i is surface nb, k in index in surfs
735+
"""
736+
Function to compute the angle between some surfaces
737+
738+
Args:
739+
----------
740+
surface_tags : list of int
741+
list of the tags of the surfaces we wnat to compute the angle (usually two or one)
742+
tags_coords_params : dictionary of dictionaries
743+
for each surface i, tags_coords_params[i] gives 3 elements:
744+
params: list of the parameters of the nodes ([p1u,p1v,p2u,p2v,...])
745+
coord: list of the xyz coordinates of the nodes ([n1x,n1y,n1z,n2x,n2y,n2z,...])
746+
tag: list of tags of the nodes
747+
...
748+
Returns:
749+
----------
750+
big_angle : bool
751+
True if we found a "big_angle", i.e. a sharp edge
752+
753+
"""
754+
for k, i in enumerate(surface_tags):
755+
# i is surface nb, k in index in surface_tags
701756
coordi = tags_coords_params[i]['coord']
702-
for _ , j in enumerate(surfs, k + 1):
757+
for _ , j in enumerate(surface_tags, k + 1):
703758
coordj = tags_coords_params[j]['coord']
704759
# Now search for nodes that are in both surfaces
705760
for a in range(len(coordi) // 3):

ceasiompy/CPACS2GMSH/func/rans_mesh_generator.py

+30-9
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def sort_surfaces_and_create_physical_groups(
535535
all_surfaces_tag = [s[1] for s in all_surfaces]
536536

537537
# First reimport all the shapes, get their new tags and names
538-
newaircraft_parts = []
538+
new_aircraft_parts = []
539539
for brep_file in brep_files:
540540
# Import the part and create the aircraft part object (and translate them as the
541541
# original were translated)
@@ -554,15 +554,15 @@ def sort_surfaces_and_create_physical_groups(
554554
part_obj.volume = part_entities[0]
555555
part_obj.volume_tag = part_entities[0][1]
556556

557-
newaircraft_parts.append(part_obj)
557+
new_aircraft_parts.append(part_obj)
558558

559559
# Reorder the imported shape so that it is in same order than our previous ones
560560
# (i.e. vectors surfaces by part and newpart name tag type have save brep name at same index)
561561
for i, old_part in enumerate(aircraft_parts):
562-
for j, new_part in enumerate(newaircraft_parts):
562+
for j, new_part in enumerate(new_aircraft_parts):
563563
if old_part.uid == new_part.uid:
564-
newaircraft_parts[i], newaircraft_parts[j] = newaircraft_parts[j], \
565-
newaircraft_parts[i]
564+
new_aircraft_parts[i], new_aircraft_parts[j] = new_aircraft_parts[j], \
565+
new_aircraft_parts[i]
566566
break
567567

568568
# Now for each surface count in how many different part it is
@@ -576,11 +576,11 @@ def sort_surfaces_and_create_physical_groups(
576576

577577
# Now deal with it if in more than one part
578578
if len(parts_in) > 1:
579-
choose_correct_part(parts_in, surf, aircraft_parts, newaircraft_parts)
579+
choose_correct_part(parts_in, surf, aircraft_parts, new_aircraft_parts)
580580

581581
# Remove the parts we re-imported, to get a clean result (we won't need them anymore)
582582
gmsh.model.occ.remove(
583-
[model_part.volume for model_part in newaircraft_parts], recursive=True)
583+
[model_part.volume for model_part in new_aircraft_parts], recursive=True)
584584
gmsh.model.occ.synchronize()
585585

586586
# Now add the physical group to each part and the surfaces that are now sorted
@@ -598,7 +598,28 @@ def sort_surfaces_and_create_physical_groups(
598598
model_part.lines_tags = [li[1] for li in model_part.lines]
599599

600600

601-
def choose_correct_part(parts_in, surf, aircraft_parts, newaircraft_parts):
601+
def choose_correct_part(
602+
parts_in, surf, aircraft_parts, new_aircraft_parts
603+
):
604+
"""
605+
Function to chose the correct part for a surface still in multiple bounding boxes
606+
607+
Args:
608+
----------
609+
parts_in : list of int
610+
List of the parts such that the surface is in the bounding box
611+
surf : int
612+
tag of the surface
613+
aircraft_parts : list of ModelPart
614+
List of all the parts in the airplane
615+
new_aircraft_parts : list of ModelPart
616+
List of all the parts in the airplane but the reimported new ones.
617+
The numerotation is the same as in aircraft_parts
618+
...
619+
Returns:
620+
----------
621+
nothing
622+
"""
602623
for i in parts_in:
603624
# This is maybe overcomplicated, but gmsh doesn't keep the tags of surfaces when
604625
# fused so we have to find a way to rematch them to their original part
@@ -610,7 +631,7 @@ def choose_correct_part(parts_in, surf, aircraft_parts, newaircraft_parts):
610631
# We only get intersection if the surface is really along/inside the volume,
611632
# which only happens if it is the volume it comes from.)
612633
intersection = gmsh.model.occ.intersect(
613-
[(2, surf)], [newaircraft_parts[i].volume],
634+
[(2, surf)], [new_aircraft_parts[i].volume],
614635
removeObject=False, removeTool=False)[0]
615636
# Remove intersection to have a clean result
616637
gmsh.model.occ.remove(intersection, recursive=True)

0 commit comments

Comments
 (0)