7
7
8
8
| Author: Tony Govoni
9
9
| Creation: 2022-04-07
10
+ | Modified: Cassandre Renaud
11
+ | Date: 2025-May-9
10
12
11
13
TODO:
12
14
-Add a parameter to let the user tune the powerlaw for the wing surface mesh
@@ -577,7 +579,7 @@ def refine_other_lines(
577
579
578
580
# foundbigangle = False
579
581
# # Get the adjacent surface, and the nodes
580
- # surfs , _ = gmsh.model.getAdjacencies(dim, line)
582
+ # surface_tags , _ = gmsh.model.getAdjacencies(dim, line)
581
583
# tags, coord, param = gmsh.model.mesh.getNodes(1, line)
582
584
# nbpoints = len(coord) // 3
583
585
# # Select at most 40 nodes (but 20 evenly spaces if too big)
@@ -592,11 +594,11 @@ def refine_other_lines(
592
594
593
595
# # Now test for every 2 surfaces along line (usually always one or two surfaces total)
594
596
# # 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]
597
599
# 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]
600
602
# params_j = gmsh.model.getParametrization(2, j, coord_small)
601
603
# for a in range(len(coord_small) // 3):
602
604
# # For each point, get the normal to the surface
@@ -622,14 +624,14 @@ def refine_other_lines(
622
624
for (dim , line ) in lines :
623
625
if line % step_lines == 0 :
624
626
log .info (f"{ math .floor (line / total * 100 )} % done" )
625
- surfs , _ = gmsh .model .getAdjacencies (dim , line )
627
+ surface_tags , _ = gmsh .model .getAdjacencies (dim , line )
626
628
tags_coords_params = {- 1 : "yay" }
627
629
# For each adjacent surface, get all the nodes
628
- for i in surfs :
630
+ for i in surface_tags :
629
631
tags , coord , param = gmsh .model .mesh .getNodes (2 , i , True )
630
632
tags_coords_params [i ] = {'tags' : tags , 'coord' : coord , 'param' : param }
631
633
# 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 )
633
635
if big_angle :
634
636
lines_with_angles_tag .append (line )
635
637
@@ -650,17 +652,49 @@ def refine_other_lines(
650
652
# Get all the lines that are adjacent and need refinement
651
653
[_ , adjacent_lines ] = gmsh .model .getAdjacencies (2 , s )
652
654
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 )
655
657
656
658
return mesh_fields
657
659
658
660
659
661
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
661
663
):
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
+ """
662
696
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 } " )
664
698
665
699
# 1 : Math eval field
666
700
mesh_fields ["nbfields" ] += 1
@@ -685,21 +719,42 @@ def refine_surface(
685
719
mesh_fields ["nbfields" ] += 1
686
720
gmsh .model .mesh .field .add ("Restrict" , mesh_fields ["nbfields" ])
687
721
gmsh .model .mesh .field .setNumbers (
688
- mesh_fields ["nbfields" ], "SurfacesList" , [s ])
722
+ mesh_fields ["nbfields" ], "SurfacesList" , [surface_tag ])
689
723
gmsh .model .mesh .field .setNumber (
690
724
mesh_fields ["nbfields" ], "InField" , mesh_fields ["nbfields" ] - 1 )
691
725
mesh_fields ["restrict_fields" ].append (mesh_fields ["nbfields" ])
692
726
gmsh .model .mesh .field .setAsBackgroundMesh (mesh_fields ["nbfields" ])
693
727
gmsh .model .occ .synchronize ()
694
728
729
+ return mesh_fields
730
+
695
731
696
732
def compute_angle_surfaces (
697
- surfs , tags_coords_params
733
+ surface_tags , tags_coords_params
698
734
):
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
701
756
coordi = tags_coords_params [i ]['coord' ]
702
- for _ , j in enumerate (surfs , k + 1 ):
757
+ for _ , j in enumerate (surface_tags , k + 1 ):
703
758
coordj = tags_coords_params [j ]['coord' ]
704
759
# Now search for nodes that are in both surfaces
705
760
for a in range (len (coordi ) // 3 ):
0 commit comments