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

# PyPrimeMesh Cheat Sheet

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

[Launching PyPrimeMesh](#launch) | [Read and Write Files](#readwrite) | [Defining Size Controls](#sizecontrols) | [Generate Wrapper Surface Mesh](#wrapper) | [Generate Surface Mesh](#surfacemesh) | [Surface Mesh Analysis](#meshanalysis) | [Generate Volume Mesh](#volumemesh) | [Part Summary](#partsummary)

### Launch PyPrimeMesh Client

To launch and exit a PyPrimeMesh server from Python in gRPC mode.

```python theme={null}
# Launch PyPrimeMesh Server
from ansys.meshing import prime


with prime.launch_prime(timeout=20) as prime_client:
    # The Client class gets the model parameter
    model = prime_client.model
    # Define Script Here

    # Disconnect from server
    prime_client.exit()
```

To launch an instance of PyPrimeMesh at IP127.0.0.1 and port 50055 with number of processes = 4.

```python theme={null}
with prime.launch_prime(ip="127.0.0.1", port= 50055, n_procs=4) as prime_client:
    model = prime_client.model
```

### Read and Write Files

Read or write files of different formats based on file extension. An example for the same can be seen below.

```python theme={null}
# Import lucid class
from ansys.meshing.prime import lucid


# Define mesher object
mesher=lucid.Mesh(model)

# Read Mesh (*.msh) file
mesh_file_name = r"sample1_mesh.msh"
mesher.read(mesh_file_name, append=False)

# Import CAD (*.step) file
cad_file_name = r"sample2_CAD.stp"
mesher.read(cad_file_name, append=False)

# Write Mesh (*.cdb) file
cdb_file_name = r"sample3_case.cdb"
mesher.write(cdb_file_name)
```

### Defining Size Controls

Sets the global sizing parameters

```python theme={null}
# Define Global Size Controls
model.set_global_sizing_params(prime.GlobalSizingParams(min=0.5, max=16.0, growth_rate=1.2))
```

Curvature size control definition.

```python theme={null}
# Create Curvature Size Control
curvature_control = model.control_data.create_size_control(prime.SizingType.CURVATURE)
control_name = "Curvature_Size_Control"
curvature_control.set_suggested_name(control_name)

# Define Scope
scope = prime.ScopeDefinition(model, evaluation_type=prime.ScopeEvaluationType.LABELS, label_expression="*")
curvature_control.set_scope(scope)

# Define Curvature Control Parameter
curvature_control.set_curvature_sizing_params(prime.CurvatureSizingParams(model, normal_angle=18))
```

### Generate Wrapper Surface Mesh

Generate Wrapper Surface Mesh.

```python theme={null}
mesher.wrap(
    min_size = 0.5,
    max_size = 16,
    input_parts = "flange,pipe",
    use_existing_features = True,
    recompute_remesh_sizes = True,
    remesh_size_controls = [curvature_control]
)
```

### Generate Surface Mesh

Generate Surface Mesh based on min, max size.

```python theme={null}
mesher.surface_mesh(min_size = 0.5, max_size = 16, generate_quads = True)
```

Generate Surface Mesh based on size controls.

```python theme={null}
control_name = "Curvature_Size_Control"
mesher.surface_mesh_with_size_controls(control_name)
```

### Surface Mesh Analysis

Surface Mesh Diagnostics.

```python theme={null}
diag = prime.SurfaceSearch(model)
diag_params = prime.SurfaceDiagnosticSummaryParams(
    model,
    scope = surface_scope,
    compute_free_edges = True,
)
diag_res = diag.get_surface_diagnostic_summary(diag_params)
print("Number of free faces: ", diag_res.n_free_edges)
```

Surface Mesh Quality Metrics.

```python theme={null}
face_quality_measures = prime.FaceQualityMeasure.SKEWNESS
quality = prime.SurfaceSearch(model)
quality_params = prime.SurfaceQualitySummaryParams(
    model = model,
    scope = surface_scope,
    face_quality_measures = [face_quality_measures],
    quality_limit = [0.9],
)
print("Maximum surface skewness: ", qual_summary_res.quality_results[0].max_quality)
```

### Generate Volume Mesh

Generate Volume Mesh.

```python theme={null}
vol_scope = prime.ScopeDefinition(model, part_expression = "*")
mesher.volume_mesh(volume_fill_type = prime.VolumeFillType.HEXCOREPOLY, scope = vol_scope)
```

### Part Summary

Query for Part Summary.

```python theme={null}
part = model.get_part_by_name("sample_part")
summary = part.get_summary(prime.PartSummaryParams(model))
print("Total number of cells: ", summary.n_cells)
```

### References from PyAnsys Documentation

* [PyPrimeMesh - GettingStarted](https://prime.docs.pyansys.com/version/stable/getting_started/index.html)
* [PyPrimeMesh - User guide](https://prime.docs.pyansys.com/version/stable/user_guide/index.html)
* [PyPrimeMesh - Examples](https://prime.docs.pyansys.com/version/stable/examples/index.html)
