.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/00-released_examples/00-ahmed_body_workflow.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_00-released_examples_00-ahmed_body_workflow.py: .. _ahmed_body_simulation: Ahmed Body External Aerodynamics Simulation ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 9-30 Objective ===================================================================================== Ahmed body is a simplified car model used for studying the flow around it and to predict the drag and lift forces. The model consists of a slanted back and a blunt front. In this example, PyFluent API is used to perform Ahmed Body external aerodynamics simulation. which includes typical workflow of CFD Simulation as follows: * Importing the geometry/CAD model. * Meshing the geometry. * Setting up the solver. * Running the solver. * Post-processing the results. .. image:: ../../_static/ahmed_body_model.png :align: center :alt: Ahmed Body Model .. GENERATED FROM PYTHON SOURCE LINES 33-35 Import required libraries/modules ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 35-48 .. code-block:: default from pathlib import Path import ansys.fluent.core as pyfluent from ansys.fluent.core import examples try: import ansys.fluent.visualization.pyvista as pv except ImportError: import ansys.fluent.post.pyvista as pv from ansys.fluent.visualization import set_config .. GENERATED FROM PYTHON SOURCE LINES 49-54 Specifying save path ===================================================================================== save_path can be specified as Path("E:/", "pyfluent-examples-tests") or Path("E:/pyfluent-examples-tests") in a Windows machine for example, or Path("~/pyfluent-examples-tests") in Linux. .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. code-block:: default save_path = Path(pyfluent.EXAMPLES_PATH) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Configure specific settings for this example ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 59-61 .. code-block:: default set_config(blocking=True, set_view_on_display="isometric") .. GENERATED FROM PYTHON SOURCE LINES 62-64 Launch Fluent session with meshing mode ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 64-67 .. code-block:: default session = pyfluent.launch_fluent(mode="meshing", cleanup_on_exit=True) session.check_health() .. GENERATED FROM PYTHON SOURCE LINES 68-70 Meshing Workflow ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 72-74 Initialize the Meshing Workflow ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 74-86 .. code-block:: default workflow = session.workflow geometry_filename = examples.download_file( "ahmed_body_20_0degree_boi_half.scdoc", "pyfluent/examples/Ahmed-Body-Simulation", save_path=save_path, ) workflow.InitializeWorkflow(WorkflowType="Watertight Geometry") workflow.TaskObject["Import Geometry"].Arguments = dict(FileName=geometry_filename) workflow.TaskObject["Import Geometry"].Execute() .. GENERATED FROM PYTHON SOURCE LINES 87-89 Add Local Face Sizing ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 89-129 .. code-block:: default add_local_sizing = workflow.TaskObject["Add Local Sizing"] add_local_sizing.Arguments = dict( { "AddChild": "yes", "BOIControlName": "facesize_front", "BOIFaceLabelList": ["wall_ahmed_body_front"], "BOIGrowthRate": 1.15, "BOISize": 8, } ) add_local_sizing.Execute() add_local_sizing.InsertCompoundChildTask() workflow.TaskObject["Add Local Sizing"].Execute() add_local_sizing = workflow.TaskObject["Add Local Sizing"] add_local_sizing.Arguments = dict( { "AddChild": "yes", "BOIControlName": "facesize_rear", "BOIFaceLabelList": ["wall_ahmed_body_rear"], "BOIGrowthRate": 1.15, "BOISize": 5, } ) add_local_sizing.Execute() add_local_sizing.InsertCompoundChildTask() workflow.TaskObject["Add Local Sizing"].Execute() add_local_sizing = workflow.TaskObject["Add Local Sizing"] add_local_sizing.Arguments = dict( { "AddChild": "yes", "BOIControlName": "facesize_main", "BOIFaceLabelList": ["wall_ahmed_body_main"], "BOIGrowthRate": 1.15, "BOISize": 12, } ) add_local_sizing.Execute() .. GENERATED FROM PYTHON SOURCE LINES 130-132 Add BOI (Body of Influence) Sizing ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 132-147 .. code-block:: default add_boi_sizing = workflow.TaskObject["Add Local Sizing"] add_boi_sizing.InsertCompoundChildTask() add_boi_sizing.Arguments = dict( { "AddChild": "yes", "BOIControlName": "boi_1", "BOIExecution": "Body Of Influence", "BOIFaceLabelList": ["ahmed_body_20_0degree_boi_half-boi"], "BOISize": 20, } ) add_boi_sizing.Execute() add_boi_sizing.InsertCompoundChildTask() .. GENERATED FROM PYTHON SOURCE LINES 148-150 Add Surface Mesh Sizing ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 150-169 .. code-block:: default generate_surface_mesh = workflow.TaskObject["Generate the Surface Mesh"] generate_surface_mesh.Arguments = dict( { "CFDSurfaceMeshControls": { "CurvatureNormalAngle": 12, "GrowthRate": 1.15, "MaxSize": 50, "MinSize": 1, "SizeFunctions": "Curvature", } } ) generate_surface_mesh.Execute() generate_surface_mesh.InsertNextTask(CommandName="ImproveSurfaceMesh") improve_surface_mesh = workflow.TaskObject["Improve Surface Mesh"] improve_surface_mesh.Arguments.update_dict({"FaceQualityLimit": 0.4}) improve_surface_mesh.Execute() .. GENERATED FROM PYTHON SOURCE LINES 170-172 Describe Geometry, Update Boundaries, Update Regions ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 172-180 .. code-block:: default workflow.TaskObject["Describe Geometry"].Arguments = dict( CappingRequired="Yes", SetupType="The geometry consists of only fluid regions with no voids", ) workflow.TaskObject["Describe Geometry"].Execute() workflow.TaskObject["Update Boundaries"].Execute() workflow.TaskObject["Update Regions"].Execute() .. GENERATED FROM PYTHON SOURCE LINES 181-183 Add Boundary Layers ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 183-197 .. code-block:: default add_boundary_layers = workflow.TaskObject["Add Boundary Layers"] add_boundary_layers.AddChildToTask() add_boundary_layers.InsertCompoundChildTask() workflow.TaskObject["smooth-transition_1"].Arguments.update_dict( { "BLControlName": "smooth-transition_1", "NumberOfLayers": 14, "Rate": 1.15, "TransitionRatio": 0.5, } ) add_boundary_layers.Execute() .. GENERATED FROM PYTHON SOURCE LINES 198-200 Generate the Volume Mesh ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 200-204 .. code-block:: default generate_volume_mesh = workflow.TaskObject["Generate the Volume Mesh"] generate_volume_mesh.Arguments.update_dict({"VolumeFill": "poly-hexcore"}) generate_volume_mesh.Execute() .. GENERATED FROM PYTHON SOURCE LINES 205-207 Switch to the Solver Mode ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 207-209 .. code-block:: default session = session.switch_to_solver() .. GENERATED FROM PYTHON SOURCE LINES 210-212 Mesh Visualization ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 214-217 .. image:: ../../_static/ahmed_body_mesh_1.png :align: center :alt: Ahmed Body Mesh .. GENERATED FROM PYTHON SOURCE LINES 219-222 .. image:: ../../_static/ahmed_body_mesh_2.png :align: center :alt: Ahmed Body Mesh .. GENERATED FROM PYTHON SOURCE LINES 224-226 Solver Setup and Solve Workflow ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 228-230 Define Constants ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 230-234 .. code-block:: default density = 1.225 inlet_velocity = 30 inlet_area = 0.11203202 .. GENERATED FROM PYTHON SOURCE LINES 235-237 Define Materials ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 237-241 .. code-block:: default session.tui.define.materials.change_create("air", "air", "yes", "constant", density) session.tui.define.models.viscous.ke_realizable("yes") session.tui.define.models.viscous.curvature_correction("yes") .. GENERATED FROM PYTHON SOURCE LINES 242-244 Define Boundary Conditions ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 244-252 .. code-block:: default inlet = session.setup.boundary_conditions.velocity_inlet["inlet"] inlet.turb_intensity = 0.05 inlet.vmag = inlet_velocity inlet.turb_viscosity_ratio = 5 outlet = session.setup.boundary_conditions.pressure_outlet["outlet"] outlet.turb_intensity = 0.05 .. GENERATED FROM PYTHON SOURCE LINES 253-255 Define Reference Values ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 255-259 .. code-block:: default session.tui.report.reference_values.area(inlet_area) session.tui.report.reference_values.density(density) session.tui.report.reference_values.velocity(inlet_velocity) .. GENERATED FROM PYTHON SOURCE LINES 260-262 Define Solver Settings ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 262-273 .. code-block:: default session.tui.solve.set.p_v_coupling(24) session.tui.solve.set.discretization_scheme("pressure", 12) session.tui.solve.set.discretization_scheme("k", 1) session.tui.solve.set.discretization_scheme("epsilon", 1) session.tui.solve.initialize.set_defaults("k", 0.000001) session.tui.solve.monitors.residual.convergence_criteria( 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001 ) .. GENERATED FROM PYTHON SOURCE LINES 274-276 Define Report Definitions ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 276-292 .. code-block:: default session.tui.solve.report_definitions.add( "cd-mon1", "drag", "thread-names", "*ahmed*", "()", "scaled?", "yes", "force-vector", "0 0 1", "q", ) session.tui.define.parameters.output_parameters.create("report-definition", "cd-mon1") session.tui.solve.report_plots.add("cd-mon1", "report-defs", "cd-mon1", "()", "q") .. GENERATED FROM PYTHON SOURCE LINES 293-295 Initialize and Run Solver ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 295-300 .. code-block:: default session.tui.solve.set.number_of_iterations(5) session.tui.solve.initialize.initialize_flow() session.tui.solve.iterate() .. GENERATED FROM PYTHON SOURCE LINES 301-303 Post-Processing Workflow ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 303-316 .. code-block:: default session.tui.surface.iso_surface("x-coordinate", "xmid", "()", "()", 0, "()") graphics_session1 = pv.Graphics(session) contour1 = graphics_session1.Contours["contour-1"] contour1.field = "velocity-magnitude" contour1.surfaces_list = ["xmid"] contour1.display("window-1") contour2 = graphics_session1.Contours["contour-2"] contour2.field.allowed_values contour2.field = "pressure-coefficient" contour2.surfaces_list = ["xmid"] contour2.display("window-2") .. GENERATED FROM PYTHON SOURCE LINES 317-319 Simulation Results Visualization ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 321-324 .. image:: ../../_static/ahmed_body_model_velocity_mag.png :align: center :alt: Velocity Magnitude .. GENERATED FROM PYTHON SOURCE LINES 326-327 Velocity Magnitude Contour .. GENERATED FROM PYTHON SOURCE LINES 329-332 .. image:: ../../_static/ahmed_body_model_pressure_coeff.png :align: center :alt: Peressure Coefficient .. GENERATED FROM PYTHON SOURCE LINES 334-335 Pressure Coefficient Contour .. GENERATED FROM PYTHON SOURCE LINES 337-339 Save the case file ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 339-343 .. code-block:: default save_case_data_as = Path(save_path) / "ahmed_body_final.cas.h5" session.tui.file.write_case_data(save_case_data_as) .. GENERATED FROM PYTHON SOURCE LINES 344-346 Close the session ===================================================================================== .. GENERATED FROM PYTHON SOURCE LINES 346-349 .. code-block:: default session.exit() .. GENERATED FROM PYTHON SOURCE LINES 350-355 References ===================================================================================== [1] S.R. Ahmed, G. Ramm, Some Salient Features of the Time-Averaged Ground Vehicle Wake,SAE-Paper 840300,1984 .. GENERATED FROM PYTHON SOURCE LINES 355-357 .. code-block:: default # sphinx_gallery_thumbnail_path = '_static/ahmed_body_model_pressure_coeff.png' .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_examples_00-released_examples_00-ahmed_body_workflow.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 00-ahmed_body_workflow.py <00-ahmed_body_workflow.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 00-ahmed_body_workflow.ipynb <00-ahmed_body_workflow.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_