##  [PyFluent Cheat Sheet](/blog/pyfluent-cheat-sheet) 

This is a quick-reference guide for [PyFluent](https://fluent.docs.pyansys.com/version/stable/). You can jump to a section of your choosing by using these links:

[Launching Fluent](#launch) | [Import Mesh in Launched Session](#importmesh) | [Enable Heat Transfer Physics](#heattransfer) | [Accessing the Object State Using pprint](#pprint) | [Define materials](#materials) | [Define Boundary Conditions](#boundary) | [Modify Cell Zone Conditions](#cellzone) | [Apply Solution Settings](#solutionsettings)

# <a name="launch"></a>Launching Fluent Locally

The following method is used to start Fluent from Python in gRPC mode. This code starts Fluent in the background so that commands can be sent to Fluent from the Python interpreter.

```Python
import ansys.fluent.core as pyfluent 
solver=pyfluent.launch_fluent(mode="solver", show_gui=True) 

```

The solver object contains attributes such as **file**, **setup**, **solution**, and **results**, which are also instances of settings objects.

# <a name="importmesh"></a>Import Mesh in Launched Session

The following examples show how to read the available mesh file in Fluent Session.

```Python
import_filename='example_file.msh.h5'
solver.file.read(file_type="case", file_name= import_filename) 

```

There are other specific Client Libraries available for reading case files and reading case-datafiles.

```Python
# e.g., read_case(), read_case_data() 

import_filename = 'example_file.cas.h5' 
solver.file.read_case(file_type="case", file_name=import_filename)

```

# <a name="heattransfer"></a>Enable heat transfer physics

The following examples show how to enable heat transfer by activating the energy equation.

```Python
solver.setup.models.energy.enabled = True

```

# <a name="pprint"></a>Accessing the Object State Using pprint

```IPython
&gt;&gt;&gt; from pprint import pprint
&gt;&gt;&gt; pprint(solver.setup.models.energy())
    {'enabled':True,
    'inlet_diffusion': True,
    'kinetic_energy': False,
    'pressure_work': False,
    'viscous_dissipation': False}

```

# <a name="materials"></a>Define materials

This example shows how to use solver settings objects to define materials.

```Python
solver.setup.materials.copy_database_material_by_name(type="fluid", name="water-liquid")
solver.setup.cell_zone_conditions.fluid["elbow-fluid" ].material = "water-liquid" 

```

# <a name="boundary"></a>Define Boundary Conditions

The examples in this section show how you use solver settings objects to define boundary conditions.

```Python
solver.setup.boundary_conditions.velocity_inlet["coldinlet"].vmag = {
    "option": "constantorexpression",
    "constant": 0.4,
} 

solver.setup.boundary_conditions.velocity_inlet["cold-inlet"].ke_spec = "IntensityandHydraulicDiameter" 
solver.setup.boundary_conditions.velocity_inlet["coldinlet"].turb_intensity = 5 
solver.setup.boundary_conditions.velocity_inlet[ "cold-inlet" ].turb_hydraulic_diam = "4[in]" 
solver.setup.boundary_conditions.velocity_inlet["coldinlet"].t = { "option": "constantorexpression", "constant": 293.15} 

```

# <a name="cellzone"></a>Modify Cell Zone Conditions

The examples in this section show how you use solver settings objects to modify cell zone conditions.

```Python
# Enabling Laminar Zone 

solver.setup.cell_zone_conditions.fluid["elbow-fluid"] = {"laminar": True} 

```

# <a name="solutionsettings"></a>Apply Solution Settings

PyFluent allows you to use solver settings objects to apply solution settings, initialize, and solve.

```Python
solver.solution.initialization.hybrid_initialize()
solver.solution.run_calculation.iterate(number_of_iterations=150)

```

# <a name="post"></a>Post-Processing

PyFluent allows you to post-process data with the results object. The following example shows you how to create and display contours on a plane.

```Python
solver.results.graphics.contour["contour"] = {} 
solver.results.graphics.contour["contour"].print_state() 
solver.results.graphics.contour["contour"].field = " temperature" 
solver.results.graphics.contour["contour"]. surfaces_list = [ "symmetry-xyplane"] 

```

# Temperature Contour

![Temperature Contour](/sites/default/files/inline-images/img_pyfluent_cheat_sheet.png)

# References from PyAnsys Documentation

- [Getting Started](https://fluent.docs.pyansys.com/version/stable/)
- [PyFluent Solver Settings Objects](https://fluent.docs.pyansys.com/version/stable/api/solver/settings.html#solver-settings-objects)
- [PyFluent Examples](https://fluent.docs.pyansys.com/version/stable/examples/index.html)