Skip to content

Commit cc94e63

Browse files
authored
Added radius and crinkling options to MeshSliceOutput (#1611)
* Added radius and crinkling options to MeshSliceOutput * PR comments * Camelcased cutoffRadius in json * Change variable name
1 parent 0f2b053 commit cc94e63

File tree

5 files changed

+102
-24
lines changed

5 files changed

+102
-24
lines changed

flow360/component/simulation/meshing_param/volume_params.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ class MeshSliceOutput(Flow360BaseModel):
532532
alias="slices",
533533
description="List of output :class:`~flow360.Slice` entities.",
534534
)
535+
include_crinkled_slices: bool = pd.Field(
536+
default=False, description="Generate crinkled slices in addition to flat slices."
537+
)
538+
cutoff_radius: Optional[pd.PositiveFloat] = pd.Field(
539+
default=None,
540+
description="Cutoff radius of the slice output. If not specified, "
541+
"the slice extends to the boundaries of the volume mesh.",
542+
)
535543
output_type: Literal["MeshSliceOutput"] = pd.Field("MeshSliceOutput", frozen=True)
536544

537545

flow360/component/simulation/translator/volume_meshing_translator.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ def _get_custom_volumes(volume_zones: list):
252252
return custom_volumes
253253

254254

255+
def translate_mesh_slice_fields(
256+
model: MeshSliceOutput,
257+
):
258+
"""Translate mesh slice type and radius fields."""
259+
mesh_slice_fields = {}
260+
mesh_slice_fields["crinkled"] = model.include_crinkled_slices
261+
if model.cutoff_radius is not None:
262+
mesh_slice_fields["cutoffRadius"] = model.cutoff_radius
263+
return mesh_slice_fields
264+
265+
255266
# def _get_seedpoint_zones(volume_zones: list):
256267
# """
257268
# Get translated seedpoint volumes from volume zones.
@@ -274,15 +285,15 @@ def _get_custom_volumes(volume_zones: list):
274285

275286
def translate_mesh_slice_output(
276287
output_params: list,
277-
output_class: Union[MeshSliceOutput],
288+
output_class: MeshSliceOutput,
278289
injection_function,
279290
):
280-
"""Translate slice or isosurface output settings."""
291+
"""Translate mesh slice output settings."""
281292
translated_output = {}
282293
translated_output["slices"] = translate_setting_and_apply_to_all_entities(
283294
output_params,
284295
output_class,
285-
translation_func=lambda x: {},
296+
translation_func=translate_mesh_slice_fields,
286297
to_list=False,
287298
entity_injection_func=injection_function,
288299
)

tests/simulation/translator/ref/volume_meshing/ref_param_to_json_inhouse.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@
2121
"slices": {
2222
"test_slice_y_normal": {
2323
"sliceOrigin": [0.1, 0.2, 0.3],
24-
"sliceNormal": [0.0, 1.0, 0.0]
24+
"sliceNormal": [0.0, 1.0, 0.0],
25+
"crinkled": false
2526
},
2627
"test_slice_z_normal": {
2728
"sliceOrigin": [0.6, 0.1, 0.4],
28-
"sliceNormal": [0.0, 0.0, 1.0]
29+
"sliceNormal": [0.0, 0.0, 1.0],
30+
"crinkled": false
31+
},
32+
"crinkled_slice_with_cutoff": {
33+
"sliceOrigin": [0.1, 0.2, 0.3],
34+
"sliceNormal": [0.0, 0.7071067811865475, 0.7071067811865475],
35+
"crinkled": true,
36+
"cutoffRadius": 10.0
37+
},
38+
"crinkled_slice_without_cutoff": {
39+
"sliceOrigin": [0.5, 0.6, 0.7],
40+
"sliceNormal": [-1.0, 0.0, 0.0],
41+
"crinkled": true
2942
}
3043
}
3144
},

tests/simulation/translator/ref/volume_meshing/ref_param_to_json_legacy.json

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@
1818
"slices": {
1919
"test_slice_y_normal": {
2020
"sliceOrigin": [0.1, 0.2, 0.3],
21-
"sliceNormal": [0.0, 1.0, 0.0]
21+
"sliceNormal": [0.0, 1.0, 0.0],
22+
"crinkled": false
2223
},
2324
"test_slice_z_normal": {
2425
"sliceOrigin": [0.6, 0.1, 0.4],
25-
"sliceNormal": [0.0, 0.0, 1.0]
26+
"sliceNormal": [0.0, 0.0, 1.0],
27+
"crinkled": false
28+
},
29+
"crinkled_slice_with_cutoff": {
30+
"sliceOrigin": [0.1, 0.2, 0.3],
31+
"sliceNormal": [0.0, 0.7071067811865475, 0.7071067811865475],
32+
"crinkled": true,
33+
"cutoffRadius": 10.0
34+
},
35+
"crinkled_slice_without_cutoff": {
36+
"sliceOrigin": [0.5, 0.6, 0.7],
37+
"sliceNormal": [-1.0, 0.0, 0.0],
38+
"crinkled": true
2639
}
2740
}
2841
},

tests/simulation/translator/test_volume_meshing_translator.py

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,55 @@ def _make(beta_mesher: bool = True):
288288
)
289289
)
290290

291+
# Build mesh slice outputs
292+
meshSliceOutputs = []
293+
meshSliceOutputs.append(
294+
MeshSliceOutput(
295+
name="slice_output",
296+
entities=[
297+
Slice(
298+
name=f"test_slice_y_normal",
299+
origin=(0.1, 0.2, 0.3),
300+
normal=(0, 1, 0),
301+
),
302+
Slice(
303+
name=f"test_slice_z_normal",
304+
origin=(0.6, 0.1, 0.4),
305+
normal=(0, 0, 1),
306+
),
307+
],
308+
)
309+
)
310+
311+
meshSliceOutputs.append(
312+
MeshSliceOutput(
313+
name="slice_output_2",
314+
entities=[
315+
Slice(
316+
name=f"crinkled_slice_with_cutoff",
317+
origin=(0.1, 0.2, 0.3),
318+
normal=(0, 1, 1),
319+
),
320+
],
321+
include_crinkled_slices=True,
322+
cutoff_radius=10.0,
323+
)
324+
)
325+
326+
meshSliceOutputs.append(
327+
MeshSliceOutput(
328+
name="slice_output_3",
329+
entities=[
330+
Slice(
331+
name=f"crinkled_slice_without_cutoff",
332+
origin=(0.5, 0.6, 0.7),
333+
normal=(-1, 0, 0),
334+
),
335+
],
336+
include_crinkled_slices=True,
337+
)
338+
)
339+
291340
param = SimulationParams(
292341
meshing=MeshingParams(
293342
refinement_factor=1.45,
@@ -297,23 +346,7 @@ def _make(beta_mesher: bool = True):
297346
),
298347
refinements=refinements,
299348
volume_zones=volume_zones,
300-
outputs=[
301-
MeshSliceOutput(
302-
name="slice_output",
303-
entities=[
304-
Slice(
305-
name=f"test_slice_y_normal",
306-
origin=(0.1, 0.2, 0.3),
307-
normal=(0, 1, 0),
308-
),
309-
Slice(
310-
name=f"test_slice_z_normal",
311-
origin=(0.6, 0.1, 0.4),
312-
normal=(0, 0, 1),
313-
),
314-
],
315-
),
316-
],
349+
outputs=meshSliceOutputs,
317350
),
318351
private_attribute_asset_cache=AssetCache(use_inhouse_mesher=beta_mesher),
319352
)

0 commit comments

Comments
 (0)