Skip to content

Commit 6723299

Browse files
committed
fix2 RANS tests
1 parent f8d36e5 commit 6723299

File tree

2 files changed

+59
-29
lines changed

2 files changed

+59
-29
lines changed

ceasiompy/CPACS2GMSH/func/advancemeshing.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,22 @@ def refine_lines_with_acute_angles(
641641
# Now search for nodes that are in both surfaces
642642
for a in range(len(coordi) // 3):
643643
for b in range(len(coordj) // 3):
644-
if coordi[3 * a] == coordj[3 * b] and coordi[3 * a + 1] == coordj[3 * b + 1] and coordi[3 * a + 2] == coordj[3 * b + 2]:
645-
# if here, we have found a node that is in both. Get the normal at this node of the two surfaces
644+
if coordi[3 * a] == coordj[3 * b] and\
645+
coordi[3 * a + 1] == coordj[3 * b + 1] and\
646+
coordi[3 * a + 2] == coordj[3 * b + 2]:
647+
# if here, we have found a node that is in both. Get the normal at
648+
# this node of the two surfaces
646649
normal_i = gmsh.model.getNormal(
647-
i, [tags_coords_params[i]['param'][2 * a], tags_coords_params[i]['param'][2 * a + 1]])
650+
i,
651+
[tags_coords_params[i]['param'][2 * a],
652+
tags_coords_params[i]['param'][2 * a + 1]])
648653
normal_j = gmsh.model.getNormal(
649-
j, [tags_coords_params[j]['param'][2 * b], tags_coords_params[j]['param'][2 * b + 1]])
650-
# Compute cosinus which is the scalar product as the normals are of norm 1
654+
j,
655+
[tags_coords_params[j]['param'][2 * b],
656+
tags_coords_params[j]['param'][2 * b + 1]]
657+
)
658+
# Compute cosinus which is the scalar product as the normals
659+
# are of norm 1
651660
cosalpha = (normal_i[0] * normal_j[0] + normal_i[1]
652661
* normal_j[1] + normal_i[2] * normal_j[2])
653662
if cosalpha < -0.7: # (more than 45 degrees from being flat)
@@ -671,20 +680,21 @@ def refine_lines_with_acute_angles(
671680
bb = part.bounding_box
672681
size = [abs(bb[3] - bb[0]), abs(bb[4] - bb[1]), abs(bb[5] - bb[2])]
673682
size.sort()
674-
# Choose refinement to go on 1/4 of the length of the second smallest size (somehow usually the correct length)
683+
# Choose refinement to go on 1/4 of the length of the second smallest size
684+
# (somehow usually the correct length)
675685
m = size[1] / 4
676686
for s in surfaces_tags:
677687
# Get all the lines that are adjacent and need refinement
678688
[_, adjacent_lines] = gmsh.model.getAdjacencies(2, s)
679689
lines_to_refine = list(set(adjacent_lines) & set(lines_with_angles_tag))
680-
for l in lines_to_refine:
681-
log.info(f"Refining line {l} in surface {s} in part {part.uid}")
690+
for line in lines_to_refine:
691+
log.info(f"Refining line {line} in surface {s} in part {part.uid}")
682692

683693
# 1 : Math eval field
684694
mesh_fields["nbfields"] += 1
685695
gmsh.model.mesh.field.add("Distance", mesh_fields["nbfields"])
686696
gmsh.model.mesh.field.setNumbers(
687-
mesh_fields["nbfields"], "CurvesList", [l])
697+
mesh_fields["nbfields"], "CurvesList", [line])
688698
gmsh.model.mesh.field.setNumber(
689699
mesh_fields["nbfields"], "Sampling", 200)
690700

ceasiompy/CPACS2GMSH/func/rans_mesh_generator.py

+40-20
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,21 @@ def generate_2d_mesh_for_pentagrow(
106106
refine_factor : float
107107
Factor of refinement along le and te of wings
108108
refine_truncated : bool
109-
If set to true, the refinement can change to match the truncated te thickness
109+
If set to true, the refinement can change to match the truncated
110+
te thickness
110111
refine_factor_sharp_edges :float
111112
Factor of refinement along the edges that are sharp but not le and te
112113
n_power_factor : float
113-
Power of how much refinement on the le and te (and for now in the "refine acute angle" as well)
114+
Power of how much refinement on the le and te (and for now in the
115+
"refine acute angle" as well)
114116
n_power_field: float
115117
Coefficient ?? (Idk but not used here)
116118
fuselage_mesh_size_factor : float
117-
Factor of the fuselage mesh size : the mesh size will be the mean fuselage width divided by this factor
119+
Factor of the fuselage mesh size : the mesh size will be the mean
120+
fuselage width divided by this factor
118121
wing_mesh_size_factor : float
119-
Factor of the wing mesh size : the mesh size will be the mean fuselage width divided by this factor
122+
Factor of the wing mesh size : the mesh size will be the mean
123+
fuselage width divided by this factor
120124
mesh_size_engines : float
121125
Size of the engines mesh
122126
mesh_size_propellers : float
@@ -246,8 +250,10 @@ def generate_2d_mesh_for_pentagrow(
246250
mesh_fields = {"nbfields": 0, "restrict_fields": []}
247251
# Now fix the mesh size for every part
248252
for model_part in aircraft_parts:
249-
# Take the right mesh size (name physical group should be wing or fuselage or engine or propeller or rotor or pylon or vort)
250-
if "vort" in model_part.uid: # TODO, has been here bc of one airplane where it needs to be smaller
253+
# Take the right mesh size (name physical group should be wing or fuselage
254+
# or engine or propeller or rotor or pylon or vort)
255+
if "vort" in model_part.uid: # TODO, has been here bc of one airplane
256+
# where it needs to be smaller
251257
lc = mesh_size_by_group["vort"]
252258
else:
253259
lc = mesh_size_by_group[model_part.part_type]
@@ -267,7 +273,7 @@ def generate_2d_mesh_for_pentagrow(
267273
# Now do the refinement on the le and te
268274
if refine_factor != 1:
269275
log.info("Start refinement of leading and trailing edge")
270-
# We want the lines already refined so we don't refined them afgain in the second function
276+
# We want the lines already refined so we don't refined them again in the second function
271277
mesh_fields, te_le_already_refined = refine_le_te(
272278
aircraft_parts, mesh_size_by_group["wing"], mesh_fields, refine_factor, refine_truncated=refine_truncated, n_power_factor=n_power_factor)
273279
log.info("Finished refinement of leading and trailing edge")
@@ -386,7 +392,8 @@ def intersecting_entities_for_fusing(
386392
intersect = gmsh.model.occ.intersect(
387393
entities1, entities2, removeObject=False, removeTool=False)[0]
388394
gmsh.model.occ.synchronize()
389-
# What's missing is that he sadly doesn't recognize the intersection by a face (only volume) (but rarely a problem)
395+
# What's missing is that he sadly doesn't recognize the intersection by a face (only
396+
# volume) (but rarely a problem)
390397

391398
# Check if there is an intersection (i.e. there will be a dimtag in intersect)
392399
if len(intersect):
@@ -426,7 +433,8 @@ def fusing_parts(
426433

427434
# Secondly we take care of the fusion to create the airfoil
428435

429-
# Keep count of how many times it didn't work (if error or some seperate part, could loop forever)
436+
# Keep count of how many times it didn't work (if error or some seperate part,
437+
# could loop forever)
430438
counter = 0
431439
while len(parts_dimtag) > 1:
432440
# Choose two entities to fuse
@@ -507,7 +515,8 @@ def sort_surfaces_and_create_physical_groups(
507515
"""
508516
# Now we sort the surfaces by part (to name them & set mesh size)
509517

510-
# Get all the surfaces, classified by part with bounding boxes (might take too many, will be dealt with after)
518+
# Get all the surfaces, classified by part with bounding boxes (might take too many,
519+
# will be dealt with after)
511520

512521
log.info("Start the classification of surfaces by parts")
513522
for model_part in aircraft_parts:
@@ -526,7 +535,8 @@ def sort_surfaces_and_create_physical_groups(
526535
# First reimport all the shapes, get their new tags and names
527536
newaircraft_parts = []
528537
for brep_file in brep_files:
529-
# Import the part and create the aircraft part object (and translate them as the original were translated)
538+
# Import the part and create the aircraft part object (and translate them as the
539+
# original were translated)
530540
part_entities = gmsh.model.occ.importShapes(
531541
str(brep_file), highestDimOnly=False)
532542
gmsh.model.occ.translate(
@@ -544,7 +554,8 @@ def sort_surfaces_and_create_physical_groups(
544554

545555
newaircraft_parts.append(part_obj)
546556

547-
# Reorder the imported shape so that it is in same order than our previous ones (i.e. vectors surfaces by part and newpart name tag type have save brep name at same index)
557+
# Reorder the imported shape so that it is in same order than our previous ones
558+
# (i.e. vectors surfaces by part and newpart name tag type have save brep name at same index)
548559
for i in range(len(aircraft_parts)):
549560
old_part = aircraft_parts[i]
550561
for j in range(len(newaircraft_parts)):
@@ -566,16 +577,22 @@ def sort_surfaces_and_create_physical_groups(
566577
# Now deal with it if in more than one part
567578
if len(parts_in) > 1:
568579
for i in parts_in:
569-
# This is maybe overcomplicated, but gmsh doesn't keep the tags of surfaces when fused so we have to find a way to rematch them to their original part
570-
# Compute intersection (which is a surface) of surface with the original shape/part. If there is an intersection, it means that it is the shape that the surface was on.
571-
# (Precision : gmsh doesn't compute curves (or in general entity of smaller dim) at intersection for some reason, which is why it works.
572-
# We only get intersection if the surface is really along/inside the volume, which only happens if it is the volume it comes from.)
580+
# This is maybe overcomplicated, but gmsh doesn't keep the tags of surfaces when
581+
# fused so we have to find a way to rematch them to their original part
582+
# Compute intersection (which is a surface) of surface with the original
583+
# shape/part. If there is an intersection, it means that it is the shape
584+
# that the surface was on.
585+
# (Precision : gmsh doesn't compute curves (or in general entity of smaller dim)
586+
# at intersection for some reason, which is why it works.
587+
# We only get intersection if the surface is really along/inside the volume,
588+
# which only happens if it is the volume it comes from.)
573589
intersection = gmsh.model.occ.intersect(
574590
[(2, surf)], [newaircraft_parts[i].volume], removeObject=False, removeTool=False)[0]
575591
# Remove intersection to have a clean result
576592
gmsh.model.occ.remove(intersection, recursive=True)
577593
if len(intersection) > 0:
578-
# If found, remove the tag from the others parts, and we have finished for this surface
594+
# If found, remove the tag from the others parts, and we have finished
595+
# for this surface
579596
log.info(
580597
f"Surface {surf} was in multiple volumes and is classified into part {aircraft_parts[i].uid}")
581598
for j in parts_in:
@@ -584,7 +601,8 @@ def sort_surfaces_and_create_physical_groups(
584601
aircraft_parts[j].surfaces_tags.remove(surf)
585602
break
586603
elif i == parts_in[-1]:
587-
# If we are here, we have found no part st the part is in, so there is a problem. We choose a part and hope for the best
604+
# If we are here, we have found no part st the part is in, so there
605+
# is a problem. We choose a part and hope for the best
588606
log.info(
589607
f"Surface {surf} still in parts {[aircraft_parts[i].uid for i in parts_in]}, take off randomly")
590608
for k in range(len(parts_in) - 1):
@@ -597,12 +615,14 @@ def sort_surfaces_and_create_physical_groups(
597615

598616
# Now add the physical group to each part and the surfaces that are now sorted
599617
for model_part in aircraft_parts:
600-
# Just add group and name (which is the brep file without ".brep") to the surfaces of the part computed before
618+
# Just add group and name (which is the brep file without ".brep") to the surfaces
619+
# of the part computed before
601620
part_group = gmsh.model.addPhysicalGroup(2, model_part.surfaces_tags)
602621
name_group = model_part.uid
603622
gmsh.model.setPhysicalName(2, part_group, name_group)
604623

605-
# Compute the lines in each part by taking the boundary of surfaces (need them later for wing refinement)
624+
# Compute the lines in each part by taking the boundary of surfaces (need them later
625+
# for wing refinement)
606626
model_part.lines = gmsh.model.getBoundary(
607627
model_part.surfaces, combined=False, oriented=False)
608628
model_part.lines_tags = [li[1] for li in model_part.lines]

0 commit comments

Comments
 (0)