@@ -59,9 +59,7 @@ def SurfaceRefinement_to_faces(obj: SurfaceRefinement, global_max_edge_length):
5959 }
6060
6161
62- @preprocess_input
63- # pylint: disable=unused-argument
64- def get_surface_meshing_json (input_params : SimulationParams , mesh_units ):
62+ def legacy_mesher_json (input_params : SimulationParams ):
6563 """
6664 Get JSON for surface meshing.
6765
@@ -135,3 +133,97 @@ def get_surface_meshing_json(input_params: SimulationParams, mesh_units):
135133 translated ["boundaries" ][face_id ] = {"boundaryName" : surface .name }
136134
137135 return translated
136+
137+
138+ def _get_surface_refinements (refinement_list : list [dict ]):
139+ """
140+ Get the surface refinements from the input_params.
141+ """
142+ return [
143+ item
144+ for item in refinement_list
145+ if item ["refinement_type" ]
146+ in ("SurfaceRefinement" , "UniformRefinement" , "GeometryRefinement" )
147+ ]
148+
149+
150+ GAI_SETTING_WHITELIST = {
151+ "meshing" : {
152+ "defaults" : {
153+ "surface_max_edge_length" : None ,
154+ "curvature_resolution_angle" : None ,
155+ "surface_edge_growth_rate" : None ,
156+ "geometry_accuracy" : None ,
157+ "surface_max_aspect_ratio" : None ,
158+ "surface_max_adaptation_iterations" : None ,
159+ },
160+ "refinements" : _get_surface_refinements ,
161+ },
162+ "private_attribute_asset_cache" : {
163+ "project_entity_info" : {
164+ "face_group_tag" : None ,
165+ "face_attribute_names" : None ,
166+ "grouped_faces" : None ,
167+ "body_group_tag" : None ,
168+ "body_attribute_names" : None ,
169+ "grouped_bodies" : None ,
170+ }
171+ },
172+ }
173+
174+
175+ def _traverse_and_filter (data , whitelist ):
176+ """
177+ Recursively traverse data and whitelist to extract matching values.
178+
179+ Args:
180+ data: The data to traverse
181+ whitelist: The whitelist structure defining what to extract
182+
183+ Returns:
184+ Filtered data matching the whitelist structure
185+ """
186+ if isinstance (whitelist , dict ):
187+ result = {}
188+ for key , value in whitelist .items ():
189+ if key in data :
190+ if value is None :
191+ # Copy as is
192+ result [key ] = data [key ]
193+ elif callable (value ):
194+ # Run the function
195+ result [key ] = value (data [key ])
196+ else :
197+ # Recursively traverse
198+ result [key ] = _traverse_and_filter (data [key ], value )
199+ return result
200+ return data
201+
202+
203+ def filter_simulation_json (input_params : SimulationParams ):
204+ """
205+ Filter the simulation JSON to only include the GAI surface meshing parameters.
206+ """
207+
208+ # Get the JSON from the input_params
209+ json_data = input_params .model_dump (mode = "json" , exclude_none = True )
210+
211+ # Filter the JSON to only include the GAI surface meshing parameters
212+ filtered_json = _traverse_and_filter (json_data , GAI_SETTING_WHITELIST )
213+
214+ return filtered_json
215+
216+
217+ @preprocess_input
218+ # pylint: disable=unused-argument
219+ def get_surface_meshing_json (input_params : SimulationParams , mesh_units ):
220+ """
221+ Get JSON for surface meshing.
222+ """
223+ if not input_params .private_attribute_asset_cache .use_geometry_AI :
224+ return legacy_mesher_json (input_params )
225+
226+ # === GAI mode ===
227+ input_params .private_attribute_asset_cache .project_entity_info .compute_transformation_matrices ()
228+ # Just do a filtering of the input_params's JSON
229+ return filter_simulation_json (input_params )
0 commit comments