> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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)

## 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 theme={null}
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.

## Import Mesh in Launched Session

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

```python theme={null}
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 theme={null}
# e.g., read_case(), read_case_data()

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

## Enable heat transfer physics

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

```python theme={null}
solver.setup.models.energy.enabled = True
```

## Accessing the Object State Using pprint

```python theme={null}
>>> from pprint import pprint
>>> pprint(solver.setup.models.energy())
    {'enabled':True,
    'inlet_diffusion': True,
    'kinetic_energy': False,
    'pressure_work': False,
    'viscous_dissipation': False}
```

## Define materials

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

```python theme={null}
solver.setup.materials.copy_database_material_by_name(type="fluid", name="water-liquid")
solver.setup.cell_zone_conditions.fluid["elbow-fluid" ].material = "water-liquid"
```

## Define Boundary Conditions

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

```python theme={null}
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}
```

## Modify Cell Zone Conditions

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

```python theme={null}
# Enabling Laminar Zone

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

## Apply Solution Settings

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

```python theme={null}
solver.solution.initialization.hybrid_initialize()
solver.solution.run_calculation.iterate(number_of_iterations=150)
```

## 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 theme={null}
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](https://developer.synopsys.com/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)
