Skip to content

pyPFC logo

Examples

This page provides an overview of examples included with pyPFC. The examples demonstrates different aspects of the simulation framework. Additional useful information is also provided:

Running Examples

# Navigate to examples directory
cd examples/

# Run specific example
python ex04_quick_start.py

Example 0

Source Code: ex00_density_field.py

Description: Investigate solid/liquid coexistence, interpolation of density field maxima and phase field evaluation. Output is written to VTK files and saved in pickle format for subsequent post-processing, for example, using Matplotlib.

Example 1

Source Code: ex01_grain_growth.py

Description: Growth/solidification from a spherical nucleus. Data is saved to VTK and pickle formats. The example is suitable for performance benchmarking of different pyPFC parameter settings and of alternative hardware configurations.

Example 2

Source Code: ex02_grain_boundary_migration.py

Description: Simulation of selective grain growth in a bicrystal under an artificial driving pressure, controlled via a directional convolution kernel. Field averages are evluated and data is written to VTK and pickle files.

Example 3

Source Code: ex03_polycrystal_solidification.py

Description: A polycrystal is seeded in a large liquid domain and the simulation shows the subsequent polycrystal solidification process. Grain boundaries are formed and evolve during the process. Data is written to Extended XYZ format for post-processing.

Example 4

Source code: ex04_quick_start.py

Description: Basic single crystal simulation, output is written in VTK format. The example is also found in the Quick Start Guide.

Example 5

Source code: ex05_structure_analysis.py

Description: This is an example to illustrate the use of structure analysis by the centro-symmetry parameter (CSP) method in the pyPFC package and use of the class pypfc_ovito. The example demonstrates how to set up a simulation, generate an initial density field, evolve the density field over time, and perform structure analysis to identify defects in the crystal structure. The results are saved to VTK files for visualization.

Example 6

Source code: ex06_hdf5_file_io.py

Description: Demonstrates HDF5 file I/O with pypfc.save_hdf5() and pypfc.load_hdf5(). The example shows how to map a typical legacy pickle-style payload list to the newer HDF5 group structure.

Field arrays are supplied as a label-to-array mapping and stored in /fields/field_data with matching /fields/field_labels. Discrete data is supplied through one atoms mapping containing coords, atom_data, and atom_data_labels, stored under /atoms.


File Formats

pyPFC works with different file formats for data I/O:

Extension Description Viewer
.h5 Binary HDF5 format Custom analysis using pypfc.save_hdf5() and pypfc.load_hdf5()
.pickle Binary Python pickle format Custom analysis using pypfc.save_pickle() and pypfc.load_pickle()
.txt Standard ASCII text files Text editor
.vtp VTK point data, binary XML format Can be opened in, for example, ParaView
.vts VTK structured grid data, binary XML format Can be opened in, for example, ParaView
.xyz Extended XYZ format Can be opened in, for example, OVITO

Performance Notes

Indicative GPU Memory Requirements Depending on Floating-Point Precision

Grid Size Memory (Single) Memory (Double)
64³ ~1 GB ~2 GB
128³ ~8 GB ~16 GB
256³ ~64 GB ~128 GB

For Testing (fast execution):

config = {
    'device_type': 'GPU',
    'dtype_gpu': 'single',
}

For Production (high accuracy):

config = {
    'device_type': 'GPU',
    'dtype_gpu': 'double',
}

Customization

All examples can be customized by modifying parameters:

# Modify any example
domain_size = [custom_x, custom_y, custom_z]
ndiv        = [custom_nx, custom_ny, custom_nz]
params['your_parameter'] = your_value

For more advanced customization, see the API documentation.