Skip to content

Commit

Permalink
added copy mesh from example (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-flexcompute committed Mar 7, 2024
1 parent 9e980b7 commit eb5ba61
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
9 changes: 9 additions & 0 deletions examples/run_case_from_example_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import flow360 as fl
from flow360.examples import OM6wing

vm = fl.VolumeMesh.copy_from_example("2ad77a88-1676-4f89-8652-13bd7e34f257")

params = fl.Flow360Params(OM6wing.case_json)
case = fl.Case.create("OM6wing", params, vm.id, solver_version="release-24.2")
case = case.submit()
print(case)
7 changes: 7 additions & 0 deletions flow360/cloud/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ def set_mesh_params(cls, value: Union[Flow360MeshParams, None]):
return value


class CopyExampleVolumeMeshRequest(Flow360Requests):
"""request for new volume mesh"""

name: str = pd.Field()
example_id: str = pd.Field(alias="meshId")


class NewFolderRequest(Flow360Requests):
"""request for new folder"""

Expand Down
40 changes: 39 additions & 1 deletion flow360/component/volume_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from flow360.component.compress_upload import compress_and_upload_chunks

from ..cloud.requests import NewVolumeMeshRequest
from ..cloud.requests import CopyExampleVolumeMeshRequest, NewVolumeMeshRequest
from ..cloud.rest_api import RestApi
from ..exceptions import (
Flow360CloudFileError,
Expand Down Expand Up @@ -720,6 +720,44 @@ def from_file(
isascii=isascii,
)

@classmethod
def copy_from_example(
cls,
example_id: str,
name: str = None,
) -> VolumeMesh:
"""
Create a new volume mesh by copying from an example mesh identified by `example_id`.
Parameters
----------
example_id : str
The unique identifier of the example volume mesh to copy from.
name : str, optional
The name to assign to the new volume mesh. If not provided, the name
of the example volume mesh will be used.
Returns
-------
VolumeMesh
A new instance of VolumeMesh copied from the example mesh if successful.
Examples
--------
>>> new_mesh = VolumeMesh.copy_from_example('example_id_123', name='New Mesh')
"""

if name is None:
eg_vm = cls(example_id)
name = eg_vm.name
req = CopyExampleVolumeMeshRequest(example_id=example_id, name=name)
resp = RestApi(f"{VolumeMeshInterface.endpoint}/examples/copy").post(req.dict())
if not resp:
raise RuntimeError("Something went wrong when accessing example mesh.")

info = VolumeMeshMeta(**resp)
return cls(info.id)

@classmethod
def create(
cls,
Expand Down

0 comments on commit eb5ba61

Please sign in to comment.