11"""Util functions for lucid modules."""
22import re
3+ import ansys .meshing .prime as prime
34
45
56def match_pattern (pattern : str , name : str ) -> bool :
@@ -61,3 +62,174 @@ def check_name_pattern(name_patterns: str, name: str) -> bool:
6162 return True
6263
6364 return False
65+
66+ class SummaryResults ():
67+ def __init__ (self ,
68+ summary : prime .PartSummaryResults = None ,
69+ vol_quality : prime .VolumeQualitySummaryResults = None ,
70+ surf_quality : prime .SurfaceQualitySummaryResults = None ):
71+ self ._summary = summary
72+ self ._vol_quality_result = vol_quality .quality_results_part [0 ]
73+ self ._surf_quality_result = surf_quality .quality_results [0 ]
74+
75+ class Utility ():
76+ def __init__ (self , model : prime .Model ):
77+ self ._model = model
78+
79+ def print_topology (self , part_name : str , indent = '' ):
80+ part = self ._model .get_part_by_name (part_name )
81+ if part is None :
82+ print (indent + "Invalid part - " + part_name )
83+ else :
84+ summary = part .get_summary (prime .PartSummaryParams (model = self ._model , print_id = False , print_mesh = True ))
85+ print (indent + 'Topology' )
86+ print (indent + '\t n_topo_edges : %d' % summary .n_topo_edges )
87+ print (indent + '\t n_topo_faces : %d' % summary .n_topo_faces )
88+ print (indent + '\t n_topo_volumes : %d' % summary .n_topo_volumes )
89+ print (indent + '\t n_unmeshed_topo_faces: %d' % summary .n_unmeshed_topo_faces )
90+
91+ def print_zones (self , part_name : str , indent = '' ):
92+ part = self ._model .get_part_by_name (part_name )
93+ if part is None :
94+ print (indent + "Invalid part - " + part_name )
95+ else :
96+ summary = part .get_summary (prime .PartSummaryParams (model = self ._model , print_id = False , print_mesh = True ))
97+ print (indent + 'Zones\n ' )
98+ print (indent + '\t n_edge_zones : %d' % summary .n_edge_zones )
99+ print (indent + '\t n_face_zones : %d' % summary .n_face_zones )
100+ faceZone_ids = part .get_face_zones ()
101+ for id in faceZone_ids :
102+ print (indent + '\t \t %s' % self ._model .get_zone_name (id ))
103+ print (indent + '\t n_volume_zones: %d' % summary .n_volume_zones )
104+ volZone_ids = part .get_volume_zones ()
105+ for id in volZone_ids :
106+ print (indent + '\t \t %s' % self ._model .get_zone_name (id ))
107+
108+ def print_zonelets (self , part_name : str , indent = '' ):
109+ part = self ._model .get_part_by_name (part_name )
110+ if part is None :
111+ print (indent + "Invalid part - " + part_name )
112+ else :
113+ summary = part .get_summary (prime .PartSummaryParams (model = self ._model , print_id = False , print_mesh = True ))
114+ print (indent + 'Zonelets\n ' )
115+ print (indent + '\t n_edge_zonelets: %d' % summary .n_edge_zonelets )
116+ print (indent + '\t n_face_zonelets: %d' % summary .n_face_zonelets )
117+ print (indent + '\t n_cell_zonelets: %d' % summary .n_cell_zonelets )
118+
119+ def print_mesh_summary (self , part_name : str , indent = '' ):
120+ part = self ._model .get_part_by_name (part_name )
121+ if part is None :
122+ print (indent + "Invalid part - " + part_name )
123+ else :
124+ summary = part .get_summary (prime .PartSummaryParams (model = self ._model , print_id = False , print_mesh = True ))
125+ print (indent + 'Mesh summary' )
126+ print (indent + '\t n_nodes: %d' % summary .n_nodes )
127+ print (indent + '\t n_faces: %d' % summary .n_faces )
128+ print (indent + '\t \t n_tri_faces : %d' % summary .n_tri_faces )
129+ print (indent + '\t \t n_quad_faces : %d' % summary .n_quad_faces )
130+ print (indent + '\t \t n_poly_faces : %d' % summary .n_poly_faces )
131+ print (indent + '\t n_cells: %d' % summary .n_cells )
132+ print (indent + '\t \t n_poly_cells : %d' % summary .n_poly_cells )
133+ print (indent + '\t \t n_hex_cells : %d' % summary .n_hex_cells )
134+ print (indent + '\t \t n_prism_cells: %d' % summary .n_prism_cells )
135+ print (indent + '\t \t n_pyra_cells : %d' % summary .n_pyra_cells )
136+ print (indent + '\t \t n_tet_cells : %d' % summary .n_tet_cells )
137+
138+ def get_labels (self , part_name : str ):
139+ part = self ._model .get_part_by_name (part_name )
140+ if part is None :
141+ return []
142+ else :
143+ return part .get_labels ()
144+
145+ def print_labels (self , part_name : str , indent = '' ):
146+ labels = self .get_labels (part_name )
147+ if len (labels ) > 0 :
148+ print (indent + 'Labels: %d' % len (labels ))
149+ for label in labels :
150+ print (indent + '\t %s' % label )
151+
152+ def get_summary (self , part_name : str , print_summary = True ):
153+ part = self ._model .get_part_by_name (part_name )
154+ if part is None :
155+ return None
156+ else :
157+ if print_summary is True :
158+ self .print_summary (part_name )
159+ return part .get_summary (prime .PartSummaryParams (model = self ._model , print_id = False , print_mesh = True ))
160+
161+ def get_all_parts_summary (self , printSummary = True ):
162+ parts = self ._model .parts
163+ for part in parts :
164+ if printSummary is True :
165+ self .print_summary (part .get_name ())
166+ return part .get_summary (prime .PartSummaryParams (model = self ._model , print_id = False , print_mesh = True ))
167+
168+ def print_summary (self , part_name : str ):
169+ part = self ._model .get_part_by_name (part_name )
170+ if part is None :
171+ print ("Invalid part - " + part_name )
172+ else :
173+ self .print_topology (part_name )
174+ self .print_zones (part_name )
175+ self .print_zonelets (part_name )
176+ self .print_labels (part_name )
177+ self .print_mesh_summary (part_name )
178+
179+ def get_volume_quality_summary (self , cell_quality_measure : prime .CellQualityMeasure , quality_limit : float ):
180+ vol_quality = prime .VolumeSearch (self ._model )
181+ vol_quality_summary_params = prime .VolumeQualitySummaryParams (self ._model )
182+ vol_quality_summary_params .cell_quality_measures = [cell_quality_measure ]
183+ vol_quality_summary_params .quality_limit = [quality_limit ]
184+ return vol_quality .get_volume_quality_summary (vol_quality_summary_params )
185+
186+ def get_surface_quality_summary (self , part_name : str , face_quality_measure : prime .FaceQualityMeasure , quality_limit : float ):
187+ surf_quality = prime .SurfaceSearch (self ._model )
188+ surf_quality_summary_params = prime .SurfaceQualitySummaryParams (self ._model )
189+ surf_quality_summary_params .face_quality_measures = [face_quality_measure ]
190+ surf_quality_summary_params .quality_limit = [quality_limit ]
191+ if part_name is not None :
192+ surf_quality_summary_params .scope = prime .ScopeDefinition (model = self ._model , part_expression = part_name )
193+ else :
194+ surf_quality_summary_params .scope = prime .ScopeDefinition (model = self ._model , part_expression = "*" )
195+ return surf_quality .get_surface_quality_summary (surf_quality_summary_params )
196+
197+ def get_all_summary_for_part (self ,
198+ part_name : str ,
199+ cell_quality_measure = prime .CellQualityMeasure .SKEWNESS ,
200+ cell_quality_limit = 0.6 , face_quality_measure = prime .FaceQualityMeasure .SKEWNESS ,
201+ face_quality_limit = 0.9 ,
202+ print_summary = True ) -> SummaryResults :
203+ part_summary = self .get_summary (part_name , print_summary = print_summary )
204+ vol_summary = self .get_volume_quality_summary (cell_quality_measure = cell_quality_measure , quality_limit = cell_quality_limit )
205+ surf_summary = self .get_surface_quality_summary (part_name = part_name , face_quality_measure = face_quality_measure , quality_limit = face_quality_limit )
206+ all_summary = SummaryResults (part_summary , vol_summary , surf_summary )
207+ if print_summary is True :
208+ print ('Volume quality' )
209+ if all_summary ._vol_quality_result .n_found > 0 :
210+ print ('\t n_found : %d' % all_summary ._vol_quality_result .n_found )
211+ print ('\t min_quality: %f' % all_summary ._vol_quality_result .min_quality )
212+ print ('\t max_quality: %f' % all_summary ._vol_quality_result .max_quality )
213+ print ('Surface quality' )
214+ if all_summary ._surf_quality_result .n_found > 0 :
215+ print ('\t n_found : %d' % all_summary ._surf_quality_result .n_found )
216+ print ('\t min_quality: %f' % all_summary ._surf_quality_result .min_quality )
217+ print ('\t max_quality: %f' % all_summary ._surf_quality_result .max_quality )
218+ return all_summary
219+ '''
220+ class PartValidator():
221+ def __init__(self, model: prime.Model, part_name: str):
222+ self._model = model
223+ self._part = model.get_part_by_name(part_name)
224+ self._partSummary = self._part.get_summary(prime.PartSummaryParams(model = self._model, print_id = False, print_mesh = True))
225+
226+ def ValidateTopology(self, n_topo_edges: int, n_topo_faces: int, n_topo_volumes):
227+ TestScenario.validateNumber("No. of topo edges", self._partSummary.n_topo_edges, n_topo_edges, 0)
228+ TestScenario.validateNumber("No. of topo faces", self._partSummary.n_topo_faces, n_topo_faces, 0)
229+ TestScenario.validateNumber("No. of topo volumes", self._partSummary.n_topo_volumes, n_topo_volumes, 0)
230+
231+ def ValidateMesh(self, n_nodes: int, n_faces: int, n_cells: int):
232+ TestScenario.validateNumber("No. of nodes", self._partSummary.n_nodes, n_nodes, 0)
233+ TestScenario.validateNumber("No. of faces", self._partSummary.n_faces, n_faces, 0)
234+ TestScenario.validateNumber("No. of cells", self._partSummary.n_cells, n_cells, 0)
235+ '''
0 commit comments