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
18 changes: 16 additions & 2 deletions flow360/component/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,12 @@ def get_surface_mesh(self, asset_id: str = None) -> SurfaceMeshV2:
return SurfaceMeshV2.from_cloud(id=asset_id)

@property
def surface_mesh(self):
def surface_mesh(self) -> SurfaceMeshV2:
"""
Returns the last used surface mesh asset of the project.

If the project is initialized from surface mesh, the surface mesh asset is the root asset.

Raises
------
Flow360ValueError
Expand All @@ -486,6 +488,12 @@ def surface_mesh(self):
SurfaceMeshV2
The surface mesh asset.
"""
if self.metadata.root_item_type is RootType.SURFACE_MESH:
return self._root_asset
log.warning(
f"Accessing surface mesh from a project initialized from {self.metadata.root_item_type.name}. "
"Please use the root asset for assigning entities to SimulationParams."
)
return self.get_surface_mesh()

def get_volume_mesh(self, asset_id: str = None) -> VolumeMeshV2:
Expand Down Expand Up @@ -515,7 +523,7 @@ def get_volume_mesh(self, asset_id: str = None) -> VolumeMeshV2:
return VolumeMeshV2.from_cloud(id=asset_id)

@property
def volume_mesh(self):
def volume_mesh(self) -> VolumeMeshV2:
"""
Returns the last used volume mesh asset of the project.

Expand All @@ -529,6 +537,12 @@ def volume_mesh(self):
VolumeMeshV2
The volume mesh asset.
"""
if self.metadata.root_item_type is RootType.VOLUME_MESH:
return self._root_asset
log.warning(
f"Accessing volume mesh from a project initialized from {self.metadata.root_item_type.name}. "
"Please use the root asset for assigning entities to SimulationParams."
)
return self.get_volume_mesh()

def get_case(self, asset_id: str = None) -> Case:
Expand Down
2 changes: 1 addition & 1 deletion flow360/component/project_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def set_up_params_for_uploading(
params: SimulationParams,
use_beta_mesher: bool,
use_geometry_AI: bool, # pylint: disable=invalid-name
):
) -> SimulationParams:
"""
Set up params before submitting the draft.
"""
Expand Down
5 changes: 0 additions & 5 deletions flow360/component/simulation/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,6 @@ class Surface(_SurfaceEntityBase):
# TODO: With the amount of private_attribute prefixes we have
# TODO: here maybe it makes more sense to lump them together to save space?

private_attribute_color: Optional[str] = pd.Field(
None, description="Front end storage for the color selected for this `Surface` entity."
)

# pylint: disable=fixme
# TODO: Should inherit from `ReferenceGeometry` but we do not support this from solver side.

def _will_be_deleted_by_mesher(self, farfield_method: Literal["auto", "quasi-3d"]) -> bool:
Expand Down
26 changes: 26 additions & 0 deletions tests/simulation/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import flow360 as fl
from flow360 import log
from flow360.component.project_utils import set_up_params_for_uploading
from flow360.exceptions import Flow360ValueError

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


def test_root_asset_entity_change_reflection(mock_id, mock_response):
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
geo = project.geometry
geo["wing"].private_attribute_color = "red"

with fl.SI_unit_system:
params = fl.SimulationParams(
outputs=[fl.SurfaceOutput(surfaces=geo["*"], output_fields=["Cp"])],
)
params = set_up_params_for_uploading(
params=params,
root_asset=project._root_asset,
length_unit=project.length_unit,
use_beta_mesher=False,
use_geometry_AI=False,
)

assert (
params.private_attribute_asset_cache.project_entity_info.grouped_faces[0][
0
].private_attribute_color
== "red"
)


def test_get_asset_with_id(mock_id, mock_response):
project = fl.Project.from_cloud(project_id="prj-41d2333b-85fd-4bed-ae13-15dcb6da519e")
print(f"The correct asset_id: {project.case.id}")
Expand Down
Loading