|
| 1 | +--- |
| 2 | +jupytext: |
| 3 | + text_representation: |
| 4 | + extension: .mystnb |
| 5 | + format_name: myst |
| 6 | + format_version: 0.13 |
| 7 | + jupytext_version: 1.14.1 |
| 8 | +kernelspec: |
| 9 | + display_name: Python 3 (ipykernel) |
| 10 | + language: python |
| 11 | + name: python3 |
| 12 | +--- |
| 13 | +# Applied: Prepare a NACA airfoil for a Fluent simulation |
| 14 | + |
| 15 | +Once a NACA airfoil is designed, it is necessary to prepare the geometry for a CFD simulation. This notebook demonstrates |
| 16 | +how to prepare a NACA 6412 airfoil for a Fluent simulation. The starting point of this example is the previously designed |
| 17 | +NACA 6412 airfoil. The airfoil was saved in an SCDOCX file, which is now imported into the notebook. The geometry is then |
| 18 | +prepared for the simulation. |
| 19 | + |
| 20 | +In case you want to run this notebook, make sure that you have run the previous notebook to design the NACA 6412 airfoil. |
| 21 | + |
| 22 | +## Import the NACA 6412 airfoil |
| 23 | + |
| 24 | +The following code starts up the Geometry Service and imports the NACA 6412 airfoil. The airfoil is then displayed in the |
| 25 | +notebook. |
| 26 | + |
| 27 | +```{code-cell} ipython3 |
| 28 | +import os |
| 29 | + |
| 30 | +from ansys.geometry.core import launch_modeler |
| 31 | + |
| 32 | +# Launch the modeler |
| 33 | +modeler = launch_modeler() |
| 34 | + |
| 35 | +# Import the NACA 6412 airfoil |
| 36 | +design = modeler.open_file(os.path.join(os.getcwd(), f"NACA_Airfoil_6412.scdocx")) |
| 37 | + |
| 38 | +# Retrieve the airfoil body |
| 39 | +airfoil = design.bodies[0] |
| 40 | + |
| 41 | +# Display the airfoil |
| 42 | +design.plot() |
| 43 | +``` |
| 44 | + |
| 45 | +## Prepare the geometry for the simulation |
| 46 | + |
| 47 | +The current design is only composed of the airfoil. To prepare the geometry for the simulation, |
| 48 | +you must define the domain around the airfoil. The following code creates a rectangular |
| 49 | +fluid domain around the airfoil. |
| 50 | + |
| 51 | +The airfoil has the following dimensions: |
| 52 | + |
| 53 | +* Chord length: 1 (X-axis) |
| 54 | +* Thickness: Depends on NACA value (Y-axis) |
| 55 | + |
| 56 | +Define the fluid domain as a large box with these dimensions: |
| 57 | + |
| 58 | +* Length (X-axis) - 10 times the chord length |
| 59 | +* Width (Z-axis) - 5 times the chord length |
| 60 | +* Height (Y-axis) - 4 times the chord length |
| 61 | + |
| 62 | +Place the airfoil at the center of the fluid domain. |
| 63 | + |
| 64 | +```{code-cell} ipython3 |
| 65 | +from ansys.geometry.core.math import Point2D, Plane, Point3D |
| 66 | +from ansys.geometry.core.sketch import Sketch |
| 67 | + |
| 68 | +BOX_LENGTH = 10 # X-Axis |
| 69 | +BOX_WIDTH = 5 # Z-Axis |
| 70 | +BOX_HEIGHT = 4 # Y-Axis |
| 71 | + |
| 72 | +# Create the sketch |
| 73 | +fluid_sketch = Sketch( |
| 74 | + plane=Plane(origin=Point3D([0, 0, 0.5 - (BOX_WIDTH / 2)])) |
| 75 | +) |
| 76 | +fluid_sketch.box( |
| 77 | + center=Point2D([0.5, 0]), |
| 78 | + height=BOX_HEIGHT, |
| 79 | + width=BOX_LENGTH, |
| 80 | +) |
| 81 | + |
| 82 | +# Extrude the fluid domain |
| 83 | +fluid = design.extrude_sketch("Fluid", fluid_sketch, BOX_WIDTH) |
| 84 | +``` |
| 85 | + |
| 86 | +## Create named selections |
| 87 | + |
| 88 | +Named selections are used to define boundary conditions in Fluent. The following code creates named selections for the |
| 89 | +inlet, outlet, and walls of the fluid domain. The airfoil is also assigned a named selection. |
| 90 | + |
| 91 | +The airfoil is aligned with the X axis. The inlet is located at the left side of the airfoil, the outlet is located at the |
| 92 | +right side of the airfoil, and the walls are located at the top and bottom of the airfoil. The inlet face has therefore |
| 93 | +a negative X-axis normal vector, and the outlet face has a positive X-axis normal vector. The rest of the faces, therefore, |
| 94 | +constitute the walls. |
| 95 | + |
| 96 | +```{code-cell} ipython3 |
| 97 | +# Create named selections in the fluid domain (inlet, outlet, and surrounding faces) |
| 98 | +# Add also the airfoil as a named selection |
| 99 | +fluid_faces = fluid.faces |
| 100 | +surrounding_faces = [] |
| 101 | +inlet_faces = [] |
| 102 | +outlet_faces = [] |
| 103 | +for face in fluid_faces: |
| 104 | + if face.normal().x == 1: |
| 105 | + outlet_faces.append(face) |
| 106 | + elif face.normal().x == -1: |
| 107 | + inlet_faces.append(face) |
| 108 | + else: |
| 109 | + surrounding_faces.append(face) |
| 110 | + |
| 111 | +design.create_named_selection("Outlet Fluid", faces=outlet_faces) |
| 112 | +design.create_named_selection("Inlet Fluid", faces=inlet_faces) |
| 113 | +design.create_named_selection("Surrounding Faces", faces=surrounding_faces) |
| 114 | +design.create_named_selection("Airfoil Faces", faces=airfoil.faces) |
| 115 | +``` |
| 116 | + |
| 117 | +## Display the geometry |
| 118 | + |
| 119 | +The geometry is now ready for the simulation. The following code displays the geometry in the notebook. |
| 120 | +This example uses the ``PlotterHelper`` class to display the geometry for |
| 121 | +the airfoil and fluid domain in different colors with a specified opacity level. |
| 122 | + |
| 123 | +The airfoil is displayed in green, and the fluid domain is displayed in blue with an opacity of 0.25. |
| 124 | + |
| 125 | +```{code-cell} ipython3 |
| 126 | +from ansys.geometry.core.plotting import PlotterHelper |
| 127 | + |
| 128 | +plotter_helper = PlotterHelper() |
| 129 | +plotter_helper.add(airfoil, color="green") |
| 130 | +plotter_helper.add(fluid, color="blue", opacity=0.15) |
| 131 | +plotter_helper.show_plotter() |
| 132 | +``` |
| 133 | + |
| 134 | +## Export the geometry |
| 135 | + |
| 136 | +Export the geometry into a Fluent-compatible format. The following code exports the geometry |
| 137 | +into a PMDB file, which retains the named selections. |
| 138 | + |
| 139 | +```{code-cell} ipython3 |
| 140 | +# Save the design |
| 141 | +file = design.export_to_pmdb() |
| 142 | +print(f"Design saved to {file}.") |
| 143 | +``` |
| 144 | + |
| 145 | +You can import the exported PMDB file into Fluent to set up the mesh and perform the simulation. |
| 146 | +For an example of how to set up the mesh and boundary conditions in Fluent, see the [Modeling External Compressible Flow](https://fluent.docs.pyansys.com/version/stable/examples/00-fluent/external_compressible_flow.html) example in the Fluent documentation. |
| 147 | + |
| 148 | +The main difference between the Fluent example and this geometry is the coordinate system. The Fluent example |
| 149 | +defines the airfoil in the XY plane, while this geometry defines the airfoil in the XZ plane. |
0 commit comments