{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cold-Started Alpha Sweep\n",
    "\n",
    "This notebook demonstrates how to perform an angle of attack (alpha) sweep using the Flow360 Python API. The process involves creating a project, defining simulation parameters, launching a series of cases with varying alpha values, and finally generating a comprehensive report summarizing the results.\n",
    "\n",
    "**Note:** The settings in this example are by no means a validation setup; they are crafted to showcase the capabilities of Flow360 and we have intentionally reduced node count and example FC cost. For rigorous validation, modify the settings as needed."
   ],
   "id": "a94961e7"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Setup and Imports\n",
    "\n",
    "The following cell imports the necessary libraries and modules. `flow360` is the main package for interacting with the Flow360 platform. Specific modules for defining simulation parameters, creating reports, and handling units are also imported.\n"
   ],
   "id": "a1ceab36"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "import flow360 as fl\n",
    "from flow360.examples import EVTOL"
   ],
   "execution_count": 1,
   "outputs": [],
   "id": "8963fd17"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. Project Creation\n",
    "\n",
    "A Flow360 `Project` is a container for simulations and their associated assets, such as geometries and meshes. A project can be initiated either from an existing volume mesh or from a CAD geometry file. When starting from a geometry, meshing parameters must be defined to instruct the platform on how to generate the volume mesh.\n"
   ],
   "id": "9a939d59"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "EVTOL.get_files()\n",
    "\n",
    "project = fl.Project.from_geometry(EVTOL.geometry, name=\"sweep_evtol_from_geometry\")\n",
    "\n",
    "geometry = project.geometry\n",
    "geometry.group_faces_by_tag(\"faceName\")"
   ],
   "execution_count": 2,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:04:13] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Geometry successfully submitted:                                                                  \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Geometry                                                                               \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = sweep_evtol_from_geometry                                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = geo-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">b66e23df-1030-4070-89e7-3d2e9b86e46d</span>                                               \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = uploaded                                                                               \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:04:13]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Geometry successfully submitted:                                                                  \n",
       "\u001b[2;36m           \u001b[0m        type   = Geometry                                                                               \n",
       "\u001b[2;36m           \u001b[0m        name   = sweep_evtol_from_geometry                                                              \n",
       "\u001b[2;36m           \u001b[0m        id     = geo-\u001b[93mb66e23df-1030-4070-89e7-3d2e9b86e46d\u001b[0m                                               \n",
       "\u001b[2;36m           \u001b[0m        status = uploaded                                                                               \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Waiting for geometry to be processed.                                                             \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m          \u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Waiting for geometry to be processed.                                                             \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:06:07] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Regrouping face entities under `faceName` tag <span style=\"font-weight: bold\">(</span>previous `_color`<span style=\"font-weight: bold\">)</span>.                                \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:06:07]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Regrouping face entities under `faceName` tag \u001b[1m(\u001b[0mprevious `_color`\u001b[1m)\u001b[0m.                                \n"
      ]
     },
     "metadata": {}
    }
   ],
   "id": "15b1576a"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3. Meshing parameters\n",
    "\n",
    "We define some simple meshing parameters to achieve appropriate resolution for this example. The use of `AngleBasedRefinement` will allow us to better model the flow at the leading edge."
   ],
   "id": "771faa53"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "with fl.SI_unit_system:\n",
    "    meshing_params = fl.MeshingParams(\n",
    "        defaults=fl.MeshingDefaults(\n",
    "            boundary_layer_first_layer_thickness=1e-5, surface_max_edge_length=1\n",
    "        ),\n",
    "        volume_zones=[fl.AutomatedFarfield()],\n",
    "        refinements=[\n",
    "            fl.SurfaceEdgeRefinement(\n",
    "                name=\"leading_edges\",\n",
    "                edges=[geometry[\"leadingEdge\"]],\n",
    "                method=fl.AngleBasedRefinement(value=2 * fl.u.deg),\n",
    "            )\n",
    "        ],\n",
    "    )"
   ],
   "execution_count": 3,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m          \u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    }
   ],
   "id": "3442bfbf"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. Boundary Conditions\n",
    "\n",
    "Boundary conditions define the physical behavior at the boundaries of the computational domain. We need to apply appropriate `Wall` and `Freestream` conditions to different surfaces of the geometry.\n",
    "\n",
    "Surface selection can be done using exact names or with wildcards, for example:\n",
    "- geometry[\"*\"] will select all geometry boundaries\n",
    "- geometry[\"*pylon\"] will select all geometry boundaries that end with `pylon`"
   ],
   "id": "09e801b5"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "models = [\n",
    "    fl.Wall(surfaces=[geometry[\"*\"]]),\n",
    "    fl.Freestream(surfaces=fl.AutomatedFarfield().farfield),\n",
    "]"
   ],
   "execution_count": 4,
   "outputs": [],
   "id": "f291cb44"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5. Simulation Parameters\n",
    "\n",
    "The `SimulationParams` object encapsulates all settings for a simulation run. This includes meshing parameters, reference geometry, operating conditions, time-stepping scheme, physical models, and output specifications."
   ],
   "id": "37c99350"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "with fl.SI_unit_system:\n",
    "    params = fl.SimulationParams(\n",
    "        meshing=meshing_params,\n",
    "        reference_geometry=fl.ReferenceGeometry(moment_center=(0, 0, 0), moment_length=1, area=1),\n",
    "        operating_condition=fl.AerospaceCondition(velocity_magnitude=100, alpha=0 * fl.u.deg),\n",
    "        time_stepping=fl.Steady(max_steps=5000, CFL=fl.AdaptiveCFL()),\n",
    "        models=[\n",
    "            *models,\n",
    "            fl.Fluid(\n",
    "                navier_stokes_solver=fl.NavierStokesSolver(),\n",
    "                turbulence_model_solver=fl.SpalartAllmaras(),\n",
    "            ),\n",
    "        ],\n",
    "        outputs=[\n",
    "            fl.VolumeOutput(\n",
    "                output_format=[\"tecplot\"],\n",
    "                output_fields=[\n",
    "                    \"Mach\",\n",
    "                    \"Cp\",\n",
    "                    \"mut\",\n",
    "                    \"mutRatio\",\n",
    "                    \"primitiveVars\",\n",
    "                    \"qcriterion\",\n",
    "                ],\n",
    "            ),\n",
    "            fl.SurfaceOutput(\n",
    "                surfaces=[\n",
    "                    geometry[\"fuselage\"],\n",
    "                    geometry[\"*pylon\"],\n",
    "                    geometry[\"*wing\"],\n",
    "                    geometry[\"*tail\"],\n",
    "                ],\n",
    "                output_fields=[\n",
    "                    \"Cp\",\n",
    "                    \"yPlus\",\n",
    "                    \"Cf\",\n",
    "                    \"CfVec\",\n",
    "                    \"primitiveVars\",\n",
    "                    \"wallDistance\",\n",
    "                ],\n",
    "                output_format=[\"tecplot\"],\n",
    "            ),\n",
    "        ],\n",
    "    )"
   ],
   "execution_count": 5,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m          \u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    }
   ],
   "id": "dbddb634"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6. Executing an Alpha Sweep\n",
    "\n",
    "A sweep is performed by iterating through a list of alpha values. In each iteration, the `operating_condition` in `SimulationParams` is updated with a new alpha, and new `Case` is run using `project.run_case()`. The returned `Case` objects are collected in a list for later analysis and report generation. The cases will be running in parallel on the cloud. We then wait for all cases to complete before proceeding.\n",
    "\n",
    "To not recreate the entire `SimulationParams` every time, we can modify existing one's alpha angle by doing `params.operating_condition.alpha = alpha_angle`.\n"
   ],
   "id": "068fa8cb"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "case_list = []\n",
    "\n",
    "alphas = [-10, -5, 0, 5, 10, 12, 14] * fl.u.deg\n",
    "\n",
    "for alpha_angle in alphas:\n",
    "    params.operating_condition.alpha = alpha_angle\n",
    "\n",
    "    case = project.run_case(params=params, name=f\"alpha_{alpha_angle.value}_case\")\n",
    "\n",
    "    print(f\"The case ID is: {case.id} with {alpha_angle=} \")\n",
    "    case_list.append(case)\n",
    "\n",
    "print(\"Waiting for cases to complete...\")\n",
    "for case in case_list:\n",
    "    case.wait()\n",
    "print(\"All cases completed.\")"
   ],
   "execution_count": 6,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:25] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:25]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:29] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_-10_case                                                                         \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">420f149b-69b1-41f1-a8b5-20ee88f153d2</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:29]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_-10_case                                                                         \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93m420f149b-69b1-41f1-a8b5-20ee88f153d2\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-420f149b-69b1-41f1-a8b5-20ee88f153d2 with alpha_angle=unyt_quantity(-10, 'degree') \n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m          \u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:31] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_-5_case                                                                          \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">d9f7acb8-7c1a-44b1-8672-b0bbef43859a</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:31]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_-5_case                                                                          \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93md9f7acb8-7c1a-44b1-8672-b0bbef43859a\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-d9f7acb8-7c1a-44b1-8672-b0bbef43859a with alpha_angle=unyt_quantity(-5, 'degree') \n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:32] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:32]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:34] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_0_case                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">3cc6f5d3-d7fe-4b9e-a639-0560111ca309</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:34]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_0_case                                                                           \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93m3cc6f5d3-d7fe-4b9e-a639-0560111ca309\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-3cc6f5d3-d7fe-4b9e-a639-0560111ca309 with alpha_angle=unyt_quantity(0, 'degree') \n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:35] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:35]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:37] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_5_case                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">aac5be66-37ae-452d-ac30-0f7f69d301f5</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:37]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_5_case                                                                           \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93maac5be66-37ae-452d-ac30-0f7f69d301f5\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-aac5be66-37ae-452d-ac30-0f7f69d301f5 with alpha_angle=unyt_quantity(5, 'degree') \n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:38] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:38]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:40] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_10_case                                                                          \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">dca4c09b-fce6-4e7e-a653-106efec6512d</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:40]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_10_case                                                                          \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93mdca4c09b-fce6-4e7e-a653-106efec6512d\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-dca4c09b-fce6-4e7e-a653-106efec6512d with alpha_angle=unyt_quantity(10, 'degree') \n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:41] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:41]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:43] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_12_case                                                                          \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">e55b6e47-3a45-42f8-854c-0b0d629c250a</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:43]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_12_case                                                                          \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93me55b6e47-3a45-42f8-854c-0b0d629c250a\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-e55b6e47-3a45-42f8-854c-0b0d629c250a with alpha_angle=unyt_quantity(12, 'degree') \n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: using: SI unit system for unit inference.                                                         \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m          \u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: using: SI unit system for unit inference.                                                         \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:26:46] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Successfully submitted:                                                                           \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        type   = Case                                                                                   \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        name   = alpha_14_case                                                                          \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        id     = case-<span style=\"color: #ffff00; text-decoration-color: #ffff00\">fa4f47df-9363-4e34-ac66-178c41a0c30b</span>                                              \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>        status = pending                                                                                \n",
       "<span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">           </span>                                                                                                        \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:26:46]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Successfully submitted:                                                                           \n",
       "\u001b[2;36m           \u001b[0m        type   = Case                                                                                   \n",
       "\u001b[2;36m           \u001b[0m        name   = alpha_14_case                                                                          \n",
       "\u001b[2;36m           \u001b[0m        id     = case-\u001b[93mfa4f47df-9363-4e34-ac66-178c41a0c30b\u001b[0m                                              \n",
       "\u001b[2;36m           \u001b[0m        status = pending                                                                                \n",
       "\u001b[2;36m           \u001b[0m                                                                                                        \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "The case ID is: case-fa4f47df-9363-4e34-ac66-178c41a0c30b with alpha_angle=unyt_quantity(14, 'degree') \n",
      "Waiting for cases to complete...\n"
     ],
     "name": "stdout"
    },
    {
     "output_type": "stream",
     "text": [
      "All cases completed.\n"
     ],
     "name": "stdout"
    }
   ],
   "id": "d545556e"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7. Report Generation\n",
    "\n",
    "Flow360 provides a reporting feature to automatically generate documents summarizing simulation results. A report is defined by a `ReportTemplate` which is populated with various items like tables, charts, and 3D scenes. The following cells will walk through the process of setting up the components of the report.\n",
    "\n",
    "For convenience sake, we will assign `fl.report` namespace to `rep` and mark farfield as a surface we want to exclude from our report as it would skew the results.\n"
   ],
   "id": "821fd3ed"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "from flow360.plugins.report.report_items import Summary, Inputs\n",
    "\n",
    "rep = fl.report\n",
    "\n",
    "exclude_surfaces = [\"fluid/farfield\"]"
   ],
   "execution_count": 7,
   "outputs": [],
   "id": "bee3847e"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Camera and View Setup\n",
    "\n",
    "For 3D visualizations within the report, such as surface contours or isosurfaces, specific camera views must be defined. The following code sets up a series of standard camera positions (top, bottom, front, etc.) that will be used to generate consistent imagery for each case in the sweep."
   ],
   "id": "4997664e"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "top_camera = rep.TopCamera(pan_target=(3.5, 0, -0.5), dimension=15, dimension_dir=\"height\")\n",
    "bottom_camera = rep.BottomCamera(pan_target=(3.5, 0, -0.5), dimension=15, dimension_dir=\"height\")\n",
    "front_camera = rep.FrontCamera(pan_target=(3.5, 0, -0.5), dimension=15, dimension_dir=\"width\")\n",
    "rear_camera = rep.RearCamera(pan_target=(3.5, 0, -0.5), dimension=15, dimension_dir=\"width\")\n",
    "left_camera = rep.LeftCamera(pan_target=(3.5, 0, -0.5), dimension=10, dimension_dir=\"width\")\n",
    "right_camera = rep.Camera(\n",
    "    pan_target=(3.5, 0, -0.5),\n",
    "    position=(0.0, -1.0, 0.0),\n",
    "    look_at=(0.0, 0.0, 0.0),\n",
    "    up=(0.0, 0.0, 1.0),\n",
    "    dimension=10,\n",
    "    dimension_dir=\"width\",\n",
    ")\n",
    "front_left_top_camera = rep.FrontLeftTopCamera(\n",
    "    pan_target=(3.5, 0, -0.5), dimension=15, dimension_dir=\"width\"\n",
    ")\n",
    "rear_right_bottom_camera = rep.RearRightBottomCamera(\n",
    "    pan_target=(3.5, 0, -0.5), dimension=15, dimension_dir=\"width\"\n",
    ")\n",
    "\n",
    "geo_cameras = [\n",
    "    top_camera,\n",
    "    bottom_camera,\n",
    "    front_camera,\n",
    "    rear_camera,\n",
    "    left_camera,\n",
    "    right_camera,\n",
    "    front_left_top_camera,\n",
    "    rear_right_bottom_camera,\n",
    "]\n",
    "\n",
    "geo_camera_names = [\n",
    "    \"top_camera\",\n",
    "    \"bottom_camera\",\n",
    "    \"front_camera\",\n",
    "    \"rear_camera\",\n",
    "    \"left_camera\",\n",
    "    \"right_camera\",\n",
    "    \"front_left_top_camera\",\n",
    "    \"rear_right_bottom_camera\",\n",
    "]"
   ],
   "execution_count": 8,
   "outputs": [],
   "id": "a802dc38"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Items and Averaging\n",
    "\n",
    "`DataItem` objects are used to specify which results to extract for tables and charts. They can be combined with operations, such as `Average`, to perform post-processing. Here, we define `DataItem`s for aerodynamic coefficients and apply a time-averaging operation over the last 10% of the simulation steps."
   ],
   "id": "19ec4716"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "avg = rep.Average(fraction=0.1)\n",
    "\n",
    "force_list = [\n",
    "    \"CD\",\n",
    "    \"CL\",\n",
    "    \"CFx\",\n",
    "    \"CFy\",\n",
    "    \"CFz\",\n",
    "    \"CMx\",\n",
    "    \"CMy\",\n",
    "    \"CMz\",\n",
    "]\n",
    "\n",
    "CD = rep.DataItem(\n",
    "    data=\"surface_forces/totalCD\", exclude=exclude_surfaces, title=\"CD\", operations=avg\n",
    ")\n",
    "CL = rep.DataItem(\n",
    "    data=\"surface_forces/totalCL\", exclude=exclude_surfaces, title=\"CL\", operations=avg\n",
    ")\n",
    "CFX = rep.DataItem(\n",
    "    data=\"surface_forces/totalCFx\",\n",
    "    exclude=exclude_surfaces,\n",
    "    title=\"CFx\",\n",
    "    operations=avg,\n",
    ")\n",
    "CFY = rep.DataItem(\n",
    "    data=\"surface_forces/totalCFy\",\n",
    "    exclude=exclude_surfaces,\n",
    "    title=\"CFy\",\n",
    "    operations=avg,\n",
    ")\n",
    "CFZ = rep.DataItem(\n",
    "    data=\"surface_forces/totalCFz\",\n",
    "    exclude=exclude_surfaces,\n",
    "    title=\"CFz\",\n",
    "    operations=avg,\n",
    ")\n",
    "CMX = rep.DataItem(\n",
    "    data=\"surface_forces/totalCMx\",\n",
    "    exclude=exclude_surfaces,\n",
    "    title=\"CMx\",\n",
    "    operations=avg,\n",
    ")\n",
    "CMY = rep.DataItem(\n",
    "    data=\"surface_forces/totalCMy\",\n",
    "    exclude=exclude_surfaces,\n",
    "    title=\"CMy\",\n",
    "    operations=avg,\n",
    ")\n",
    "CMZ = rep.DataItem(\n",
    "    data=\"surface_forces/totalCMz\",\n",
    "    exclude=exclude_surfaces,\n",
    "    title=\"CMz\",\n",
    "    operations=avg,\n",
    ")\n",
    "\n",
    "table_data = [\n",
    "    CD,\n",
    "    CL,\n",
    "    CFX,\n",
    "    CFY,\n",
    "    CFZ,\n",
    "    CMX,\n",
    "    CMY,\n",
    "    CMZ,\n",
    "]"
   ],
   "execution_count": 9,
   "outputs": [],
   "id": "03da53bf"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Assembling the Report Items\n",
    "\n",
    "With the cameras and data items defined, the individual components of the report can be assembled. We will create `generate_report_items` function that creates a list of report items based on the provided boolean flags. This modular approach allows for easy customization of the report content.\n"
   ],
   "id": "fd9048d2"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "def generate_report_items(\n",
    "    params,\n",
    "    table_data,\n",
    "    force_list,\n",
    "    geo_cameras,\n",
    "    geo_camera_names,\n",
    "    front_left_top_camera,\n",
    "    exclude_surfaces,\n",
    "    include_geometry: bool,\n",
    "    include_general_tables: bool,\n",
    "    include_residuals: bool,\n",
    "    include_cfl: bool,\n",
    "    include_forces_moments_table: bool,\n",
    "    include_forces_moments_charts: bool,\n",
    "    include_forces_moments_alpha_charts: bool,\n",
    "    include_forces_moments_beta_charts: bool,\n",
    "    include_cf_vec: bool,\n",
    "    include_cp: bool,\n",
    "    include_yplus: bool,\n",
    "    include_qcriterion: bool,\n",
    "):\n",
    "    items = []\n",
    "\n",
    "    if params.time_stepping.type_name == \"Unsteady\":\n",
    "        step_type = \"physical_step\"\n",
    "    else:\n",
    "        step_type = \"pseudo_step\"\n",
    "\n",
    "    for model in params.models:\n",
    "        if model.type == \"Fluid\":\n",
    "            turbulence_solver = model.turbulence_model_solver.type_name\n",
    "\n",
    "    if include_geometry:\n",
    "        geometry_screenshots = [\n",
    "            rep.Chart3D(\n",
    "                section_title=\"Geometry\",\n",
    "                items_in_row=2,\n",
    "                force_new_page=True,\n",
    "                show=\"boundaries\",\n",
    "                camera=front_left_top_camera,\n",
    "                exclude=exclude_surfaces,\n",
    "                fig_name=\"Geometry_view\",\n",
    "            )\n",
    "        ]\n",
    "        items.extend(geometry_screenshots)\n",
    "\n",
    "    if include_general_tables:\n",
    "        items.append(Summary())\n",
    "        items.append(Inputs())\n",
    "\n",
    "    if include_forces_moments_table:\n",
    "        table = rep.Table(\n",
    "            data=table_data,\n",
    "            section_title=\"Quantities of interest\",\n",
    "        )\n",
    "        items.append(table)\n",
    "\n",
    "    if include_residuals:\n",
    "        residual_chart = rep.NonlinearResiduals(\n",
    "            force_new_page=True,\n",
    "            section_title=\"Nonlinear residuals\",\n",
    "            fig_name=f\"nonlin-res_fig\",\n",
    "        )\n",
    "        items.append(residual_chart)\n",
    "\n",
    "    if include_cfl and params.time_stepping.CFL.type == \"adaptive\":\n",
    "        cfl_chart = rep.Chart2D(\n",
    "            x=f\"cfl/{step_type}\",\n",
    "            y=[\"cfl/0_NavierStokes_cfl\", f\"cfl/1_{turbulence_solver}_cfl\"],\n",
    "            force_new_page=True,\n",
    "            section_title=\"CFL\",\n",
    "            fig_name=\"cfl_fig\",\n",
    "            y_log=True,\n",
    "        )\n",
    "        items.append(cfl_chart)\n",
    "\n",
    "    if include_forces_moments_charts:\n",
    "        force_charts = [\n",
    "            rep.Chart2D(\n",
    "                x=f\"surface_forces/{step_type}\",\n",
    "                y=f\"surface_forces/total{force}\",\n",
    "                force_new_page=True,\n",
    "                section_title=\"Forces/Moments\",\n",
    "                fig_name=f\"{force}_fig\",\n",
    "                exclude=exclude_surfaces,\n",
    "                ylim=rep.SubsetLimit(subset=(0.5, 1), offset=0.25),\n",
    "            )\n",
    "            for force in force_list\n",
    "        ]\n",
    "        items.extend(force_charts)\n",
    "\n",
    "    if include_forces_moments_alpha_charts:\n",
    "        force_alpha_charts = [\n",
    "            rep.Chart2D(\n",
    "                x=f\"params/operating_condition/alpha\",\n",
    "                y=f\"total_forces/averages/{force}\",\n",
    "                force_new_page=True,\n",
    "                section_title=\"Averaged Forces/Moments against alpha\",\n",
    "                fig_name=f\"{force}_alpha_fig\",\n",
    "            )\n",
    "            for force in force_list\n",
    "        ]\n",
    "        items.extend(force_alpha_charts)\n",
    "\n",
    "    if include_forces_moments_beta_charts:\n",
    "        force_beta_charts = [\n",
    "            rep.Chart2D(\n",
    "                x=f\"params/operating_condition/beta\",\n",
    "                y=f\"total_forces/averages/{force}\",\n",
    "                force_new_page=True,\n",
    "                section_title=\"Averaged Forces/Moments against beta\",\n",
    "                fig_name=f\"{force}_beta_fig\",\n",
    "            )\n",
    "            for force in force_list\n",
    "        ]\n",
    "        items.extend(force_beta_charts)\n",
    "\n",
    "    if include_yplus:\n",
    "        y_plus_screenshots = [\n",
    "            rep.Chart3D(\n",
    "                caption=rep.PatternCaption(pattern=f\"y+_{camera_name}_[case.name]\"),\n",
    "                show=\"boundaries\",\n",
    "                field=\"yPlus\",\n",
    "                exclude=exclude_surfaces,\n",
    "                limits=(0, 5),\n",
    "                camera=camera,\n",
    "                fig_name=f\"yplus_{camera_name}_fig\",\n",
    "                fig_size=1,\n",
    "            )\n",
    "            for camera_name, camera in zip(geo_camera_names, geo_cameras)\n",
    "        ]\n",
    "        items.extend(y_plus_screenshots)\n",
    "\n",
    "    if include_cp:\n",
    "        cp_screenshots = [\n",
    "            rep.Chart3D(\n",
    "                caption=rep.PatternCaption(pattern=f\"Cp_{camera_name}_[case.name]\"),\n",
    "                show=\"boundaries\",\n",
    "                field=\"Cp\",\n",
    "                exclude=exclude_surfaces,\n",
    "                limits=(-1, 1),\n",
    "                camera=camera,\n",
    "                fig_name=f\"cp_{camera_name}_fig\",\n",
    "                fig_size=1,\n",
    "            )\n",
    "            for camera_name, camera in zip(geo_camera_names, geo_cameras)\n",
    "        ]\n",
    "        items.extend(cp_screenshots)\n",
    "\n",
    "    if include_cf_vec:\n",
    "        cfvec_screenshots = [\n",
    "            rep.Chart3D(\n",
    "                caption=rep.PatternCaption(pattern=f\"Cf_vec_{camera_name}_[case.name]\"),\n",
    "                show=\"boundaries\",\n",
    "                field=\"CfVec\",\n",
    "                mode=\"lic\",\n",
    "                exclude=exclude_surfaces,\n",
    "                limits=(0, 0.025),\n",
    "                camera=camera,\n",
    "                fig_name=f\"cfvec_{camera_name}_fig\",\n",
    "                fig_size=1,\n",
    "            )\n",
    "            for camera_name, camera in zip(geo_camera_names, geo_cameras)\n",
    "        ]\n",
    "        items.extend(cfvec_screenshots)\n",
    "\n",
    "    if include_qcriterion:\n",
    "        qcriterion_screenshots = [\n",
    "            rep.Chart3D(\n",
    "                caption=rep.PatternCaption(\n",
    "                    pattern=f\"Isosurface_q_criterion_{camera_name}_[case.name]\"\n",
    "                ),\n",
    "                show=\"isosurface\",\n",
    "                iso_field=\"qcriterion\",\n",
    "                exclude=exclude_surfaces,\n",
    "                limits=(0, 0.8),\n",
    "                camera=camera,\n",
    "                fig_name=f\"qcriterion_{camera_name}_fig\",\n",
    "                fig_size=1,\n",
    "            )\n",
    "            for camera_name, camera in zip(geo_camera_names, geo_cameras)\n",
    "        ]\n",
    "        items.extend(qcriterion_screenshots)\n",
    "\n",
    "    return items"
   ],
   "execution_count": 10,
   "outputs": [],
   "id": "32dbc7b9"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can easily choose which items to include in our report."
   ],
   "id": "2522778a"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "items = generate_report_items(\n",
    "    params,\n",
    "    table_data,\n",
    "    force_list,\n",
    "    geo_cameras,\n",
    "    geo_camera_names,\n",
    "    front_left_top_camera,\n",
    "    exclude_surfaces,\n",
    "    include_geometry=True,\n",
    "    include_general_tables=True,\n",
    "    include_residuals=True,\n",
    "    include_cfl=True,\n",
    "    include_forces_moments_table=True,\n",
    "    include_forces_moments_charts=True,\n",
    "    include_forces_moments_alpha_charts=True,\n",
    "    include_forces_moments_beta_charts=True,\n",
    "    include_cf_vec=True,\n",
    "    include_cp=True,\n",
    "    include_yplus=True,\n",
    "    include_qcriterion=True,\n",
    ")"
   ],
   "execution_count": 11,
   "outputs": [],
   "id": "4e1d67fd"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Creating and Downloading the Report\n",
    "\n",
    "Finally, the `ReportTemplate` is instantiated with the list of items. The `create_in_cloud` method initiates the report generation process on the Flow360 platform. The script then waits for the report to be completed and downloads it as a PDF file.\n"
   ],
   "id": "f421780d"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": [
    "report = rep.ReportTemplate(\n",
    "    title=\"Sweep Template Report\",\n",
    "    items=items,\n",
    "    settings=rep.Settings(dpi=150),\n",
    ")\n",
    "\n",
    "report = report.create_in_cloud(\n",
    "    \"sweep-script-report\",\n",
    "    case_list,\n",
    ")\n",
    "\n",
    "report.wait()\n",
    "report.download(\"report.pdf\")\n",
    "print(\"Report downloaded as report.pdf\")"
   ],
   "execution_count": 12,
   "outputs": [
    {
     "output_type": "display_data",
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7fbfbf; text-decoration-color: #7fbfbf\">[12:34:55] </span><span style=\"color: #008080; text-decoration-color: #008080\">INFO</span>: Saved to report.pdf                                                                               \n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2;36m[12:34:55]\u001b[0m\u001b[2;36m \u001b[0m\u001b[36mINFO\u001b[0m: Saved to report.pdf                                                                               \n"
      ]
     },
     "metadata": {}
    },
    {
     "output_type": "stream",
     "text": [
      "Report downloaded as report.pdf\n"
     ],
     "name": "stdout"
    }
   ],
   "id": "5bf06cce"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "flow360-m20sMBMn-py3.11",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
