Skip to content

Project class interface #511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 29, 2024
Merged
50 changes: 50 additions & 0 deletions examples/project_from_cloud_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from flow360.component.project import Project
from flow360.component.simulation.meshing_param.params import (
MeshingDefaults,
MeshingParams,
)
from flow360.component.simulation.meshing_param.volume_params import AutomatedFarfield
from flow360.component.simulation.models.surface_models import Freestream, Wall
from flow360.component.simulation.operating_condition.operating_condition import (
AerospaceCondition,
)
from flow360.component.simulation.outputs.outputs import SurfaceOutput
from flow360.component.simulation.primitives import ReferenceGeometry
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.simulation.time_stepping.time_stepping import Steady
from flow360.component.simulation.unit_system import SI_unit_system, u
from flow360.environment import dev

dev.active()

project = Project.from_cloud("prj-f3569ba5-16a3-4e41-bfd2-b8840df79835")
print(project.get_simulation_json())

geometry = project.geometry
geometry.show_available_groupings(verbose_mode=True)
geometry.group_faces_by_tag("faceId")

with SI_unit_system:
params = SimulationParams(
meshing=MeshingParams(
defaults=MeshingDefaults(
boundary_layer_first_layer_thickness=0.001, surface_max_edge_length=1
),
volume_zones=[AutomatedFarfield()],
),
reference_geometry=ReferenceGeometry(),
operating_condition=AerospaceCondition(velocity_magnitude=100, alpha=5 * u.deg),
time_stepping=Steady(max_steps=1000),
models=[
Wall(
surfaces=[geometry["*"]],
name="Wall",
),
Freestream(surfaces=[AutomatedFarfield().farfield], name="Freestream"),
],
outputs=[
SurfaceOutput(surfaces=geometry["*"], output_fields=["Cp", "Cf", "yPlus", "CfVec"])
],
)

project.run_surface_mesher(params=params, draft_name="Case of Simple Airplane from Python")
29 changes: 29 additions & 0 deletions examples/project_from_cloud_volume_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import flow360.component.simulation.units as u
from flow360.component.project import Project
from flow360.component.simulation.models.surface_models import Freestream, Wall
from flow360.component.simulation.models.volume_models import Fluid
from flow360.component.simulation.operating_condition.operating_condition import (
AerospaceCondition,
)
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.simulation.unit_system import SI_unit_system
from flow360.environment import dev

dev.active()

project = Project.from_cloud("prj-e8c6c7eb-c18b-4c15-bac8-edf5aaf9b155")
print(project.get_simulation_json())

volume_mesh = project.volume_mesh

with SI_unit_system:
params = SimulationParams(
operating_condition=AerospaceCondition(velocity_magnitude=100 * u.m / u.s),
models=[
Fluid(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fluid will be added automatically, remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587

Wall(entities=[volume_mesh["fluid/wall"]]),
Freestream(entities=[volume_mesh["fluid/farfield"]]),
],
)

project.run_case(params=params)
54 changes: 54 additions & 0 deletions examples/project_from_file_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import flow360 as fl
from flow360.component.project import Project
from flow360.component.simulation.meshing_param.params import (
MeshingDefaults,
MeshingParams,
)
from flow360.component.simulation.meshing_param.volume_params import AutomatedFarfield
from flow360.component.simulation.models.surface_models import Freestream, Wall
from flow360.component.simulation.operating_condition.operating_condition import (
AerospaceCondition,
)
from flow360.component.simulation.outputs.outputs import SurfaceOutput
from flow360.component.simulation.primitives import ReferenceGeometry
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.simulation.time_stepping.time_stepping import Steady
from flow360.component.simulation.unit_system import SI_unit_system, u
from flow360.examples import Airplane

fl.Env.dev.active()

SOLVER_VERSION = "workbench-24.9.3"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's be consistent with solver version. Let's always use release-24.11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587


project = Project.from_file(
Airplane.geometry, name="airplane-geometry-python-upload", solver_version=SOLVER_VERSION
)

geometry = project.geometry
geometry.show_available_groupings(verbose_mode=True)
geometry.group_faces_by_tag("groupName")

with SI_unit_system:
params = SimulationParams(
meshing=MeshingParams(
defaults=MeshingDefaults(
boundary_layer_first_layer_thickness=0.001, surface_max_edge_length=1
),
volume_zones=[AutomatedFarfield()],
),
reference_geometry=ReferenceGeometry(),
operating_condition=AerospaceCondition(velocity_magnitude=100, alpha=5 * u.deg),
time_stepping=Steady(max_steps=1000),
models=[
Wall(
surfaces=[geometry["*"]],
name="Wall",
),
Freestream(surfaces=[AutomatedFarfield().farfield], name="Freestream"),
],
outputs=[
SurfaceOutput(surfaces=geometry["*"], output_fields=["Cp", "Cf", "yPlus", "CfVec"])
],
)

case = project.run_surface_mesher(params=params, draft_name="Case of Simple Airplane from Python")
41 changes: 41 additions & 0 deletions examples/project_from_file_volume_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import flow360 as fl
import flow360.component.simulation.units as u
from flow360.component.project import Project
from flow360.component.simulation.models.surface_models import (
Freestream,
SymmetryPlane,
Wall,
)
from flow360.component.simulation.models.volume_models import Fluid
from flow360.component.simulation.operating_condition.operating_condition import (
AerospaceCondition,
)
from flow360.component.simulation.simulation_params import SimulationParams
from flow360.component.simulation.unit_system import SI_unit_system
from flow360.examples import OM6wing

fl.Env.dev.active()

OM6wing.get_files()
# Creating and uploading a volume mesh from file
project = Project.from_file(
OM6wing.mesh_filename,
name="wing-volume-mesh-python-upload",
solver_version="workbench-24.9.3",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add repository-level default solver version

Copy link
Contributor Author

@andrzej-krupka andrzej-krupka Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9ba5587, added __solver_version__ to version.py

tags=["python"],
)

volume_mesh = project.volume_mesh

with SI_unit_system:
params = SimulationParams(
operating_condition=AerospaceCondition(velocity_magnitude=100 * u.m / u.s),
models=[
Fluid(),
Wall(entities=[volume_mesh["1"]]),
Freestream(entities=[volume_mesh["3"]]),
SymmetryPlane(entities=[volume_mesh["2"]]),
],
)

project.run_case(params=params)
18 changes: 0 additions & 18 deletions flow360/component/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import json
import tempfile
import time
from typing import Any, Iterator, List, Union

import pydantic.v1 as pd
Expand Down Expand Up @@ -524,12 +523,6 @@ def has_user_defined_dynamics(self):
"""
return self.params.user_defined_dynamics is not None

def is_finished(self):
"""
returns False when case is in running or preprocessing state
"""
return self.status.is_final()

def move_to_folder(self, folder: Folder):
"""
Move the current case to the specified folder.
Expand Down Expand Up @@ -626,17 +619,6 @@ def create(
)
return new_case

def wait(self, timeout_minutes=60):
"""Wait until the Case finishes processing, refresh periodically"""

start_time = time.time()
while self.is_finished() is False:
if time.time() - start_time > timeout_minutes * 60:
raise TimeoutError(
"Timeout: Process did not finish within the specified timeout period"
)
time.sleep(2)


# pylint: disable=unnecessary-lambda
class CaseResultsModel(pd.BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions flow360/component/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from flow360.component.simulation.entity_info import GeometryEntityInfo
from flow360.component.simulation.framework.entity_registry import EntityRegistry
from flow360.component.simulation.primitives import Edge, Surface
from flow360.component.simulation.utils import _model_attribute_unlock
from flow360.component.simulation.utils import model_attribute_unlock
from flow360.component.simulation.web.asset_base import AssetBase
from flow360.component.utils import (
SUPPORTED_GEOMETRY_FILE_PATTERNS,
Expand Down Expand Up @@ -223,7 +223,7 @@ def face_group_tag(self):

@face_group_tag.setter
def face_group_tag(self, new_value: str):
with _model_attribute_unlock(self._entity_info, "face_group_tag"):
with model_attribute_unlock(self._entity_info, "face_group_tag"):
self._entity_info.face_group_tag = new_value

@property
Expand All @@ -233,7 +233,7 @@ def edge_group_tag(self):

@edge_group_tag.setter
def edge_group_tag(self, new_value: str):
with _model_attribute_unlock(self._entity_info, "edge_group_tag"):
with model_attribute_unlock(self._entity_info, "edge_group_tag"):
self._entity_info.edge_group_tag = new_value

@classmethod
Expand Down
Loading
Loading