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
38 changes: 0 additions & 38 deletions examples/geometry_to_surface_mesh_V2.py

This file was deleted.

49 changes: 49 additions & 0 deletions examples/project_from_cloud_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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")

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_case(params=params, name="Case of Simple Airplane from Python")
37 changes: 37 additions & 0 deletions examples/project_from_cloud_volume_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from matplotlib.pyplot import show

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.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-b8eb4cc7-4fb8-4baa-9bcd-f1cf6d73163d")

volume_mesh = project.volume_mesh

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

project.run_case(params=params)

residuals = project.case.results.nonlinear_residuals
residuals.as_dataframe().plot(x="pseudo_step", logy=True)
show()
50 changes: 50 additions & 0 deletions examples/project_from_file_geometry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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()

project = Project.from_file(Airplane.geometry, name="Python Project (Geometry, from file)")

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"])
],
)

project.run_case(params=params, name="Case of Simple Airplane from Python")
83 changes: 83 additions & 0 deletions examples/project_from_file_geometry_multiple_runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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,
UniformRefinement,
)
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 Box, 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()

project = Project.from_file(
Airplane.geometry, name="Python Project (Geometry, from file, multiple runs)"
)

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()],
refinements=[
UniformRefinement(
entities=[
Box.from_principal_axes(
name="MyBox",
center=(0, 1, 2),
size=(4, 5, 6),
axes=((2, 2, 0), (-2, 2, 0)),
),
],
spacing=1.5,
),
],
),
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"])
],
)

# Run the mesher once
project.generate_surface_mesh(params=params, name="Surface mesh 1")
surface_mesh_1 = project.surface_mesh

# Tweak some parameter in the params
params.meshing.defaults.surface_max_edge_length = 2 * u.m

# Run the mesher again
project.generate_surface_mesh(params=params, name="Surface mesh 2")
surface_mesh_2 = project.surface_mesh

assert surface_mesh_1.id != surface_mesh_2.id

# Check available surface mesh IDs in the project
ids = project.get_cached_surface_meshes()
print(ids)
42 changes: 42 additions & 0 deletions examples/project_from_file_volume_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from matplotlib.pyplot import show

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.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", tags=["python"]
)

volume_mesh = project.volume_mesh

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

project.run_case(params=params)

residuals = project.case.results.nonlinear_residuals
residuals.as_dataframe().plot(x="pseudo_step", logy=True)
show()
3 changes: 2 additions & 1 deletion flow360/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
from .environment import Env
from .flags import Flags
from .user_config import UserConfig
from .version import __version__
from .version import __solver_version__, __version__

__all__ = [
"Accounts",
Expand Down Expand Up @@ -262,6 +262,7 @@
"ZeroFreestream",
"ZeroFreestreamFromVelocity",
"__version__",
"__solver_version__",
"air",
"flow360",
"flow360_unit_system",
Expand Down
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