
from matplotlib.pyplot import show

import flow360 as fl
from flow360.examples import EVTOL

EVTOL.get_files()

project = fl.Project.from_geometry(
    EVTOL.geometry,
    name="Python Project (Geometry, from file)",
)
geo = project.geometry

geo.group_faces_by_tag("groupName")

with fl.SI_unit_system:
    far_field_zone = fl.AutomatedFarfield()

    params = fl.SimulationParams(
        meshing=fl.MeshingParams(
            defaults=fl.MeshingDefaults(
                boundary_layer_first_layer_thickness=0.001,
                surface_max_edge_length=1,
            ),
            volume_zones=[far_field_zone],
        ),
        operating_condition=fl.AerospaceCondition(
            velocity_magnitude=100,
            alpha=5 * fl.u.deg,
        ),
        time_stepping=fl.Steady(max_steps=1000),
        models=[
            fl.Wall(surfaces=[geo["*"]]),
            fl.Freestream(surfaces=[far_field_zone.farfield]),
        ],
        outputs=[
            fl.SurfaceOutput(
                surfaces=geo["*"],
                output_fields=["Cp", "Cf", "yPlus", "CfVec"],
            )
        ],
    )

case = project.run_case(params=params, name="Case of EVTOL from Python")

case = project.case
case.wait()

total_forces = case.results.total_forces.as_dataframe()
total_forces.plot("pseudo_step", ["CL", "CD"], ylim=[-5, 15])
show()
