Skip to content

Commit dd5e64d

Browse files
[FXC-743] GAI surface mesher translator (#1266)
* run test first and then fix test * Change reference case * GAI translator ready * shorten the line number * Remove print * Added the new parameters
1 parent 848ab40 commit dd5e64d

File tree

6 files changed

+845
-7
lines changed

6 files changed

+845
-7
lines changed

flow360/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
from flow360.version import __solver_version__, __version__
171171

172172
__all__ = [
173+
"GeometryRefinement",
173174
"Env",
174175
"Case",
175176
"AngleBasedRefinement",

flow360/component/simulation/framework/updater_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ def compare_values(value1, value2, atol=1e-15, rtol=1e-10, ignore_keys=None):
4545
if type(value1) != type(value2):
4646
return False
4747

48-
if isinstance(value1, Number) and isinstance(value2, Number):
49-
return np.isclose(value1, value2, rtol, atol)
5048
if isinstance(value1, dict) and isinstance(value2, dict):
5149
return compare_dicts(value1, value2, atol, rtol, ignore_keys)
5250
if isinstance(value1, list) and isinstance(value2, list):

flow360/component/simulation/translator/surface_meshing_translator.py

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

tests/simulation/translator/data/gai_geometry_entity_info/simulation.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)