-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6f3563
commit d1d5e6a
Showing
27 changed files
with
1,550 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Support class and functions for project interface. | ||
""" | ||
|
||
from flow360.component.simulation.framework.base_model import Flow360BaseModel | ||
from flow360.component.simulation.framework.entity_base import EntityList | ||
from flow360.component.simulation.primitives import GhostSurface | ||
from flow360.component.simulation.simulation_params import SimulationParams | ||
from flow360.exceptions import Flow360ConfigurationError | ||
|
||
|
||
def replace_ghost_surfaces(params: SimulationParams): | ||
""" | ||
When the `SimulationParam` is constructed with python script on the Python side, the ghost boundaries | ||
will be obtained by for example `automated_farfield.farfield` which returns :class:`GhostSurface` | ||
not :class:`GhostSphere`. This will not be recognized by the webUI causing the assigned farfield being | ||
removed by front end. | ||
""" | ||
|
||
def _replace_the_ghost_surface(*, ghost_surface, ghost_entities_from_metadata): | ||
for item in ghost_entities_from_metadata: | ||
if item.name == ghost_surface.name: | ||
return item | ||
raise Flow360ConfigurationError( | ||
f"Unknown ghost surface with name `{ghost_surface.name}` found." | ||
"Please double check the use of ghost surfaces." | ||
) | ||
|
||
def _find_ghost_surfaces(*, model, ghost_entities_from_metadata): | ||
for field in model.__dict__.values(): | ||
if isinstance(field, GhostSurface): | ||
# pylint: disable=protected-access | ||
field = _replace_the_ghost_surface( | ||
ghost_surface=field, ghost_entities_from_metadata=ghost_entities_from_metadata | ||
) | ||
|
||
if isinstance(field, EntityList): | ||
if field.stored_entities: | ||
for entity_index, _ in enumerate(field.stored_entities): | ||
if isinstance(field.stored_entities[entity_index], GhostSurface): | ||
field.stored_entities[entity_index] = _replace_the_ghost_surface( | ||
ghost_surface=field.stored_entities[entity_index], | ||
ghost_entities_from_metadata=ghost_entities_from_metadata, | ||
) | ||
|
||
elif isinstance(field, list): | ||
for item in field: | ||
if isinstance(item, Flow360BaseModel): | ||
_find_ghost_surfaces( | ||
model=item, ghost_entities_from_metadata=ghost_entities_from_metadata | ||
) | ||
|
||
elif isinstance(field, Flow360BaseModel): | ||
_find_ghost_surfaces( | ||
model=field, ghost_entities_from_metadata=ghost_entities_from_metadata | ||
) | ||
|
||
ghost_entities_from_metadata = ( | ||
params.private_attribute_asset_cache.project_entity_info.ghost_entities | ||
) | ||
_find_ghost_surfaces(model=params, ghost_entities_from_metadata=ghost_entities_from_metadata) | ||
|
||
return params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
flow360/component/simulation/framework/updater_functions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Implementation of the updater functions. The updated.py should just import functions from here.""" | ||
|
||
|
||
def fix_ghost_sphere_schema(*, params_as_dict: dict): | ||
""" | ||
The previous ghost farfield has wrong schema (bug) and therefore needs data alternation. | ||
""" | ||
|
||
def i_am_outdated_ghost_sphere(*, data: dict): | ||
"""Identify if the current dict is a outdated ghost sphere.""" | ||
if "type_name" in data.keys() and data["type_name"] == "GhostSphere": | ||
return True | ||
return False | ||
|
||
def recursive_fix_ghost_surface(*, data): | ||
if isinstance(data, dict): | ||
# 1. Check if this is a ghost sphere instance | ||
if i_am_outdated_ghost_sphere(data=data): | ||
data.pop("type_name") | ||
data["private_attribute_entity_type_name"] = "GhostSphere" | ||
|
||
# 2. Otherwise, recurse into each item in the dictionary | ||
for _, val in data.items(): | ||
recursive_fix_ghost_surface( | ||
data=val, | ||
) | ||
|
||
elif isinstance(data, list): | ||
# Recurse into each item in the list | ||
for _, item in enumerate(data): | ||
recursive_fix_ghost_surface(data=item) | ||
|
||
recursive_fix_ghost_surface(data=params_as_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.