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
52 changes: 52 additions & 0 deletions examples/case_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from pylab import *

from flow360.component.case import CaseList


my_cases = CaseList()
case = my_cases[0].to_case()

print(case)

# get residuals:
residuals = case.results.residuals

# print residuals as a table:
print(residuals.raw)

# print other results as tables:
print(case.results.cfl.raw)
print(case.results.total_forces.raw)
print(case.results.linear_residuals.raw)
print(case.results.minmax_state.raw)

# download all result files of the case:
case.results.download_manager(all=True)

# download specific result files of the case:
case.results.download_manager(bet_forces=True, actuator_disk_output=True)

# alternative way of downloading using dedicated functions:
case.results.download_surface()
case.results.download_volumetric()


try:
case.results.total_forces.plot()
except NotImplementedError as e:
print(e)

# plot some results manually, code will not re-download data, it is already stored in memory
plot(case.results.total_forces.raw["pseudo_step"], case.results.total_forces.raw["CL"])
xlabel("pseudo step")
ylabel("CL")
show()

# alterantive way of plotting using pre-defined plot setup
case.results.plot.total_forces()


try:
case.results.total_forces.to_csv()
except NotImplementedError as e:
print(e)
31 changes: 31 additions & 0 deletions examples/list_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from flow360.component.case import CaseList
from flow360.component.volume_mesh import VolumeMeshList


# get all cases:
my_cases = CaseList(include_deleted=True)

# print metadata for the latest case:
print(my_cases[0])

for case in my_cases:
print(f"id: {case.id}, status: {case.status}, is case deleted: {case.deleted}")

# get parameters for the latest case:
case0 = my_cases[0].to_case()
print(case0.params)
print(case0.params.time_stepping.max_pseudo_steps)


# get all meshes:
meshes = VolumeMeshList()
for mesh in meshes:
print(f"mesh id: {mesh.id}, status: {mesh.status}, is mesh deleted: {mesh.deleted}")

mesh = meshes[0]
print(mesh.to_volume_mesh())

# list of cases for a given mesh
mesh_cases = CaseList(mesh_id=mesh.id, include_deleted=True)
for case in mesh_cases:
print(f"id: {case.id}, status: {case.status}, is case deleted: {case.deleted}")
16 changes: 16 additions & 0 deletions examples/mesh_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from flow360.component.volume_mesh import VolumeMeshList

meshes = VolumeMeshList()
mesh = meshes[0].to_volume_mesh()

for item in meshes:
mesh = item.to_volume_mesh()
print(
mesh.id,
"status:",
mesh.status,
"| all boundaries:",
mesh.all_boundaries,
"| no slip walls:",
mesh.no_slip_walls,
)
3 changes: 1 addition & 2 deletions flow360/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"""
from .cli import flow360
from .environment import Env

__version__ = "0.1.0"
from .version import __version__

from .component.volume_mesh import VolumeMesh
from .component.case import Case
Expand Down
12 changes: 8 additions & 4 deletions flow360/cloud/http_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import requests

from flow360 import Env, __version__
from flow360.cloud.security import api_key
from ..environment import Env
from ..version import __version__

from .security import api_key


def api_key_auth(request):
Expand Down Expand Up @@ -61,14 +63,16 @@ def __init__(self, session: requests.Session):
self.session = session

@http_interceptor
def get(self, path: str, json=None):
def get(self, path: str, json=None, params=None):
"""
Get the resource.
:param path:
:param json:
:return:
"""
return self.session.get(url=Env.current.get_real_url(path), auth=api_key_auth, json=json)
return self.session.get(
url=Env.current.get_real_url(path), auth=api_key_auth, json=json, params=params
)

@http_interceptor
def post(self, path: str, json=None):
Expand Down
4 changes: 2 additions & 2 deletions flow360/cloud/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def init_id(self, id):
else:
raise RuntimeError('"id" already set, change of "id" is not allowed.')

def get(self, path=None, method=None, json=None):
def get(self, path=None, method=None, json=None, params=None):
"""
Resource get
"""
return http.get(path or self._url(method), json=json)
return http.get(path or self._url(method), json=json, params=params)

def post(self, json, path=None, method=None):
"""
Expand Down
15 changes: 14 additions & 1 deletion flow360/cloud/s3_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import boto3
from boto3.s3.transfer import TransferConfig

# pylint: disable=unused-import
from botocore.exceptions import ClientError as CloudFileNotFoundError
from pydantic import BaseModel, Field
from rich.progress import (
BarColumn,
Expand Down Expand Up @@ -186,8 +189,14 @@ def _call_back(bytes_in_chunk):
Config=_s3_config,
)

# pylint: disable=too-many-arguments
def download_file(
self, resource_id: str, remote_file_name: str, to_file: str, keep_folder: bool = True
self,
resource_id: str,
remote_file_name: str,
to_file: str,
keep_folder: bool = True,
overwrite: bool = True,
):
"""
Download a file from s3.
Expand All @@ -196,9 +205,13 @@ def download_file(
:param to_file: local file name or local folder name.
:param keep_folder: If true, the downloaded file will be put
in the same folder as the file on cloud. Only works when to_file is a folder name.
:param overwrite: if True overwrite if file exists, otherwise don't download
:return:
"""
to_file = create_base_folder(resource_id, remote_file_name, to_file, keep_folder)
if os.path.exists(to_file) and not overwrite:
print(f"Skipping {remote_file_name}, file exists.")
return
token = self._get_s3_sts_token(resource_id, remote_file_name)
client = token.get_client()
meta_data = client.head_object(Bucket=token.get_bucket(), Key=token.get_s3_key())
Expand Down
Loading