Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions flow360/component/simulation/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
get_validation_info,
)
from flow360.component.types import Axis
from flow360.exceptions import Flow360BoundaryMissingError

BOUNDARY_FULL_NAME_WHEN_NOT_FOUND = "This boundary does not exist!!!"


def _get_boundary_full_name(surface_name: str, volume_mesh_meta: dict[str, dict]) -> str:
Expand All @@ -52,16 +53,9 @@ def _get_boundary_full_name(surface_name: str, volume_mesh_meta: dict[str, dict]
match is not None and match.group(1) == surface_name
) or existing_boundary_name == surface_name:
return existing_boundary_name
if surface_name == "symmetric":
# Provides more info when the symmetric boundary is not auto generated.
raise Flow360BoundaryMissingError(
f"Parent zone not found for boundary: {surface_name}. "
"It is likely that it was never auto generated because the condition is not met."
)
raise Flow360BoundaryMissingError(
f"Parent zone not found for surface {surface_name}. "
"It may have been deleted due to overlapping with generated symmetry plane."
)

# Not found
return BOUNDARY_FULL_NAME_WHEN_NOT_FOUND


def _check_axis_is_orthogonal(axis_pair: Tuple[Axis, Axis]) -> Tuple[Axis, Axis]:
Expand Down
37 changes: 31 additions & 6 deletions flow360/component/simulation/translator/solver_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,12 @@
UserDefinedField,
VolumeOutput,
)
from flow360.component.simulation.primitives import Box, ImportedSurface, SurfacePair
from flow360.component.simulation.primitives import (
BOUNDARY_FULL_NAME_WHEN_NOT_FOUND,
Box,
ImportedSurface,
SurfacePair,
)
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.simulation.time_stepping.time_stepping import Steady, Unsteady
from flow360.component.simulation.translator.user_expression_utils import (
Expand Down Expand Up @@ -279,7 +284,9 @@ def surface_probe_setting_translation_func(entity: Union[SurfaceProbeOutput, Sur
"""Translate non-entities part of SurfaceProbeOutput"""
dict_with_merged_output_fields = monitor_translator(entity)
dict_with_merged_output_fields["surfacePatches"] = [
surface.full_name for surface in entity.target_surfaces.stored_entities
surface.full_name
for surface in entity.target_surfaces.stored_entities
if surface.full_name != BOUNDARY_FULL_NAME_WHEN_NOT_FOUND
]
return dict_with_merged_output_fields

Expand Down Expand Up @@ -396,7 +403,11 @@ def inject_surface_probe_info(entity: EntityList):
def inject_surface_list_info(entity: EntityList):
"""inject entity info"""
return {
"surfaces": [surface.full_name for surface in entity.stored_entities],
"surfaces": [
surface.full_name
for surface in entity.stored_entities
if surface.full_name != BOUNDARY_FULL_NAME_WHEN_NOT_FOUND
],
"type": "surfaceIntegral",
}

Expand Down Expand Up @@ -615,7 +626,9 @@ def translate_acoustic_output(output_params: list):
aeroacoustic_output["patchType"] = output.patch_type
if output.permeable_surfaces is not None:
aeroacoustic_output["permeableSurfaces"] = [
item.full_name for item in output.permeable_surfaces.stored_entities
item.full_name
for item in output.permeable_surfaces.stored_entities
if item.full_name != BOUNDARY_FULL_NAME_WHEN_NOT_FOUND
]
return aeroacoustic_output
return None
Expand Down Expand Up @@ -1100,10 +1113,14 @@ def boundary_entity_info_serializer(entity, translated_setting, solid_zone_bound
if isinstance(entity, SurfacePair):
key1 = _get_key_name(entity.pair[0])
key2 = _get_key_name(entity.pair[1])
if BOUNDARY_FULL_NAME_WHEN_NOT_FOUND in (key1, key2):
return None
output[key1] = {**translated_setting, "pairedPatchName": key2}
output[key2] = translated_setting
else:
key_name = _get_key_name(entity)
if key_name == BOUNDARY_FULL_NAME_WHEN_NOT_FOUND:
return None
output = {key_name: {**translated_setting}}
if key_name in solid_zone_boundaries:
if "temperature" in translated_setting:
Expand Down Expand Up @@ -1726,10 +1743,18 @@ def get_solver_json(
if udd.input_boundary_patches is not None:
udd_dict_translated["inputBoundaryPatches"] = []
for surface in udd.input_boundary_patches.stored_entities:
udd_dict_translated["inputBoundaryPatches"].append(_get_key_name(surface))
full_name = _get_key_name(surface)
if full_name != BOUNDARY_FULL_NAME_WHEN_NOT_FOUND:
udd_dict_translated["inputBoundaryPatches"].append(full_name)
udd_dict_translated["inputBoundaryPatches"].sort()
if udd.output_target is not None:
udd_dict_translated["outputTargetName"] = udd.output_target.full_name
full_name = udd.output_target.full_name
if full_name == BOUNDARY_FULL_NAME_WHEN_NOT_FOUND:
raise Flow360TranslationError(
f"The output target {udd.output_target.name} is not found in the generated volume mesh.",
input_value=udd.output_target,
)
udd_dict_translated["outputTargetName"] = full_name
translated["userDefinedDynamics"].append(udd_dict_translated)

translated["userDefinedDynamics"].sort(key=lambda udd: udd["dynamicsName"])
Expand Down
14 changes: 10 additions & 4 deletions flow360/component/simulation/translator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ def translate_setting_and_apply_to_all_entities(
if not to_list:
# Generate a $name:{$value} dict
if custom_output_dict_entries:
output.update(entity_injection_func(entity, **entity_injection_kwargs))
setting = entity_injection_func(entity, **entity_injection_kwargs)
if setting is None:
continue
output.update(setting)
else:
if use_instance_name_as_key is True and lump_list_of_entities is False:
raise NotImplementedError(
Expand All @@ -413,14 +416,17 @@ def translate_setting_and_apply_to_all_entities(
]
for key_name in key_names:
if output.get(key_name) is None:
output[key_name] = entity_injection_func(
entity, **entity_injection_kwargs
)
setting = entity_injection_func(entity, **entity_injection_kwargs)
if setting is None:
continue
output[key_name] = setting
update_dict_recursively(output[key_name], translated_setting)
else:
# Generate a list with $name being an item
# Note: Surface/Boundary logic should be handeled in the entity_injection_func
setting = entity_injection_func(entity, **entity_injection_kwargs)
if setting is None:
continue
setting.update(translated_setting)
output.append(setting)
return output
Expand Down
Loading
Loading