Skip to content

Commit 91cdefd

Browse files
Added a redunet test.. (#1318) (#1323)
1 parent 17d930b commit 91cdefd

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

flow360/component/project.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,12 @@ def get_surface_mesh(self, asset_id: str = None) -> SurfaceMeshV2:
472472
return SurfaceMeshV2.from_cloud(id=asset_id)
473473

474474
@property
475-
def surface_mesh(self):
475+
def surface_mesh(self) -> SurfaceMeshV2:
476476
"""
477477
Returns the last used surface mesh asset of the project.
478478
479+
If the project is initialized from surface mesh, the surface mesh asset is the root asset.
480+
479481
Raises
480482
------
481483
Flow360ValueError
@@ -486,6 +488,12 @@ def surface_mesh(self):
486488
SurfaceMeshV2
487489
The surface mesh asset.
488490
"""
491+
if self.metadata.root_item_type is RootType.SURFACE_MESH:
492+
return self._root_asset
493+
log.warning(
494+
f"Accessing surface mesh from a project initialized from {self.metadata.root_item_type.name}. "
495+
"Please use the root asset for assigning entities to SimulationParams."
496+
)
489497
return self.get_surface_mesh()
490498

491499
def get_volume_mesh(self, asset_id: str = None) -> VolumeMeshV2:
@@ -515,7 +523,7 @@ def get_volume_mesh(self, asset_id: str = None) -> VolumeMeshV2:
515523
return VolumeMeshV2.from_cloud(id=asset_id)
516524

517525
@property
518-
def volume_mesh(self):
526+
def volume_mesh(self) -> VolumeMeshV2:
519527
"""
520528
Returns the last used volume mesh asset of the project.
521529
@@ -529,6 +537,12 @@ def volume_mesh(self):
529537
VolumeMeshV2
530538
The volume mesh asset.
531539
"""
540+
if self.metadata.root_item_type is RootType.VOLUME_MESH:
541+
return self._root_asset
542+
log.warning(
543+
f"Accessing volume mesh from a project initialized from {self.metadata.root_item_type.name}. "
544+
"Please use the root asset for assigning entities to SimulationParams."
545+
)
532546
return self.get_volume_mesh()
533547

534548
def get_case(self, asset_id: str = None) -> Case:

flow360/component/project_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def set_up_params_for_uploading(
260260
params: SimulationParams,
261261
use_beta_mesher: bool,
262262
use_geometry_AI: bool, # pylint: disable=invalid-name
263-
):
263+
) -> SimulationParams:
264264
"""
265265
Set up params before submitting the draft.
266266
"""

flow360/component/simulation/primitives.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,6 @@ class Surface(_SurfaceEntityBase):
531531
# TODO: With the amount of private_attribute prefixes we have
532532
# TODO: here maybe it makes more sense to lump them together to save space?
533533

534-
private_attribute_color: Optional[str] = pd.Field(
535-
None, description="Front end storage for the color selected for this `Surface` entity."
536-
)
537-
538-
# pylint: disable=fixme
539534
# TODO: Should inherit from `ReferenceGeometry` but we do not support this from solver side.
540535

541536
def _will_be_deleted_by_mesher(self, farfield_method: Literal["auto", "quasi-3d"]) -> bool:

tests/simulation/test_project.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import flow360 as fl
77
from flow360 import log
8+
from flow360.component.project_utils import set_up_params_for_uploading
89
from flow360.exceptions import Flow360ValueError
910

1011
log.set_logging_level("DEBUG")
@@ -46,6 +47,31 @@ def test_from_cloud(mock_id, mock_response):
4647
project.get_case(asset_id=current_case_id)
4748

4849

50+
def test_root_asset_entity_change_reflection(mock_id, mock_response):
51+
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
52+
geo = project.geometry
53+
geo["wing"].private_attribute_color = "red"
54+
55+
with fl.SI_unit_system:
56+
params = fl.SimulationParams(
57+
outputs=[fl.SurfaceOutput(surfaces=geo["*"], output_fields=["Cp"])],
58+
)
59+
params = set_up_params_for_uploading(
60+
params=params,
61+
root_asset=project._root_asset,
62+
length_unit=project.length_unit,
63+
use_beta_mesher=False,
64+
use_geometry_AI=False,
65+
)
66+
67+
assert (
68+
params.private_attribute_asset_cache.project_entity_info.grouped_faces[0][
69+
0
70+
].private_attribute_color
71+
== "red"
72+
)
73+
74+
4975
def test_get_asset_with_id(mock_id, mock_response):
5076
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
5177
print(f"The correct asset_id: {project.case.id}")

0 commit comments

Comments
 (0)