Skip to content

[Hotfix 25.5]: Complete sweep launching template #1047

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
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
58 changes: 58 additions & 0 deletions examples/post_processing/report/sweep_launch_report.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""This script is used by sweep_launch_template.py to create a report."""

import pandas as pd

import flow360 as fl
from flow360.plugins.report.report import ReportTemplate
from flow360.plugins.report.report_items import (
BottomCamera,
Expand All @@ -24,6 +27,43 @@
from flow360.version import __solver_version__


def main():

csv_path = "PATH/TO/CSV/FILE.csv" # Replace with the actual path to your CSV file generated by sweep_launch_template.py

generate_report(
*csv_reader(csv_path),
include_geometry=True,
include_general_tables=True,
include_residuals=True,
include_cfl=True,
include_forces_moments_table=True,
include_forces_moments_charts=True,
include_forces_moments_alpha_charts=True,
include_forces_moments_beta_charts=True,
include_cf_vec=True,
include_cp=True,
include_yplus=True,
include_qcriterion=True,
)


def csv_reader(
file_path,
):
csv_case_specific = pd.read_csv(file_path, sep=",", skiprows=2)

case_list = []

for case_id in csv_case_specific["case_id"]:
case = fl.Case(case_id)
case_list.append(case)

params = case_list[0].params

return case_list, params


def generate_report(
cases,
params,
Expand All @@ -34,6 +74,7 @@ def generate_report(
include_forces_moments_table: bool = False,
include_forces_moments_charts: bool = False,
include_forces_moments_alpha_charts: bool = False,
include_forces_moments_beta_charts: bool = False,
include_cf_vec: bool = False,
include_cp: bool = False,
include_yplus: bool = False,
Expand Down Expand Up @@ -199,6 +240,19 @@ def generate_report(
]
items.extend(force_alpha_charts)

if include_forces_moments_beta_charts:
force_beta_charts = [
Chart2D(
x=f"params/operating_condition/beta",
y=f"total_forces/averages/{force}",
force_new_page=True,
section_title="Averaged Forces/Moments against beta",
fig_name=f"{force}_beta_fig",
)
for force in force_list
]
items.extend(force_beta_charts)

if include_yplus:
y_plus_screenshots = [
Chart3D(
Expand Down Expand Up @@ -278,3 +332,7 @@ def generate_report(

report.wait()
report.download("report.pdf")


if __name__ == "__main__":
main()
18 changes: 11 additions & 7 deletions examples/post_processing/report/sweep_launch_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import os

import pandas as pd
from sweep_launch_report import generate_report
from sweep_launch_report import csv_reader, generate_report

import flow360 as fl
from flow360 import u
Expand Down Expand Up @@ -94,14 +94,14 @@ def launch_sweep(params, project, mesh_object, dir_path):
df.to_csv(csv_path, index=False)

# For example let's vary alpha:
alphas = [-10, 12] * u.deg
alphas = [-10, -5, 0, 5, 10, 12, 14] * u.deg

cases_params = []
for i, alpha_angle in enumerate(alphas):
# modify the alpha
params.operating_condition.alpha = alpha_angle

case = project.run_case(params=params, name=f"{alpha_angle}_case ")
case = project.run_case(params=params, name=f"alpha_{alpha_angle.value}_case")
data = {
"case_id": case.id,
"alpha(deg)": params.operating_condition.alpha.value,
Expand Down Expand Up @@ -137,7 +137,7 @@ def launch_sweep(params, project, mesh_object, dir_path):
df = df_data.join(df_forces)
df.to_csv(csv_path, index=False, mode="a")

return case_list
return csv_path


######################################################################################################################
Expand Down Expand Up @@ -247,6 +247,10 @@ def main():
# Option 1b: If you want to upload a CAD geometry and create a new project.
# project = project_from_geometry()

# Option 1c: if you want to run from an existing project.
# project = fl.Project.from_cloud(
# 'prj-XXXXXXXXXXX') # where prj-XXXXXXXXXX is an ID that can be saved from a previously created project or read off the WEBUI

vm = project.volume_mesh
# If the project has more then one mesh then use hte line below to choose a specific mesh instead.
# vm = project.get_volume_mesh(asset_id='vm-XXXXXXXXXXXXXXX')
Expand All @@ -261,18 +265,18 @@ def main():
# Step3: Launch the cases and save the relevant data.
models = assign_boundary_conditions(project)
params = make_run_params(vm, models)
cases = launch_sweep(params, project, vm, dir_name)
csv_path = launch_sweep(params, project, vm, dir_name)

generate_report(
cases,
params,
*csv_reader(csv_path),
include_geometry=True,
include_general_tables=True,
include_residuals=True,
include_cfl=True,
include_forces_moments_table=True,
include_forces_moments_charts=True,
include_forces_moments_alpha_charts=True,
include_forces_moments_beta_charts=True,
include_cf_vec=True,
include_cp=True,
include_yplus=True,
Expand Down
Loading