Skip to content

schiedung/PhaseField

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PhaseField

A collection of phase-field simulation codes for modeling pure melt solidification using both CPU and GPU implementations.

Overview

This repository contains four phase-field simulation applications:

  • Kobayashi Model - Implementation of the Kobayashi phase-field model for dendritic solidification
  • Physical Model - Physically-based phase-field model with realistic material parameters

Each model is available in both CPU (OpenMP) and GPU (CUDA) implementations.

Features

  • 3D phase-field simulations
  • CPU implementations with OpenMP parallelization
  • GPU implementations using CUDA
  • VTK output for visualization
  • Modern C++17/CUDA standards
  • CMake and Makefile build systems

Requirements

For CPU Applications

  • C++ compiler with C++17 support (GCC 7+, Clang 5+, MSVC 2017+)
  • OpenMP support (optional, for parallel execution)
  • CMake 3.18+ (for CMake builds) or GNU Make

For GPU Applications

  • NVIDIA CUDA Toolkit 11.0+
  • GPU with Compute Capability 7.0+ (Volta architecture or newer)
  • C++ compiler compatible with your CUDA version

Build Instructions

Using CMake (Recommended)

CMake provides a unified build system for all applications:

# Create build directory
mkdir build && cd build

# Configure (CPU and GPU if CUDA is available)
cmake ..

# Build all applications
cmake --build .

# Or build specific applications
cmake --build . --target KobayashiCPU
cmake --build . --target KobayashiGPU
cmake --build . --target PhaseFieldCPU
cmake --build . --target PhaseField  # GPU version

CMake Options

# Specify build type
cmake -DCMAKE_BUILD_TYPE=Release ..  # or Debug

# Specify CUDA architectures (if needed)
cmake -DCMAKE_CUDA_ARCHITECTURES="80;86" ..

# Build with verbose output
cmake --build . --verbose

Using Make

Each application can be built independently using Make:

# Kobayashi CPU
cd apps/kobayashi-cpu
make          # Release build
make debug    # Debug build
make clean    # Clean build artifacts

# Kobayashi GPU
cd apps/kobayashi-gpu
make          # Release build
make debug    # Debug build
make clean    # Clean build artifacts

# Physical CPU
cd apps/physical-cpu
make          # Release build
make debug    # Debug build
make clean    # Clean build artifacts

# Physical GPU
cd apps/physical-gpu
make          # Release build
make debug    # Debug build
make clean    # Clean build artifacts

Makefile Customization

For GPU builds, you can customize the target architectures:

# Build for specific GPU architectures
make SMS="70 80 86"

# Specify CUDA path if not in default location
make CUDA_PATH=/opt/cuda

Running Simulations

After building, executables are created in their respective directories:

# Run CPU simulations
./apps/kobayashi-cpu/KobayashiCPU
./apps/physical-cpu/PhaseFieldCPU

# Run GPU simulations
./apps/kobayashi-gpu/KobayashiGPU
./apps/physical-gpu/PhaseField

Output Files

Simulations generate VTK files for visualization:

  • Out_PhaseField_*.vtk - Phase field data
  • Out_Temperature_*.vtk - Temperature field data

These files can be visualized using ParaView, VisIt, or similar tools.

Application Details

Kobayashi Model

  • Domain Size: 128³ (CPU) / 128³ (GPU)
  • Parameters: Based on Kobayashi's dimensionless model
  • Features: Dendritic growth with anisotropy

Physical Model

  • Domain Size: 128³
  • Parameters: Realistic material properties (Aluminum)
  • Features: Physical units with temperature-dependent properties

Code Structure

PhaseField/
├── CMakeLists.txt           # Root CMake configuration
├── README.md                # This file
├── LICENSE                  # License information
├── .gitignore              # Git ignore patterns
└── apps/
    ├── kobayashi-cpu/      # Kobayashi CPU implementation
    │   ├── CMakeLists.txt
    │   ├── Makefile
    │   └── KobayashiCPU.cpp
    ├── kobayashi-gpu/      # Kobayashi GPU implementation
    │   ├── CMakeLists.txt
    │   ├── Makefile
    │   ├── KobayashiGPU.cu
    │   ├── wrapper.h
    │   └── vtk.h
    ├── physical-cpu/       # Physical CPU implementation
    │   ├── CMakeLists.txt
    │   ├── Makefile
    │   └── PhaseFieldCPU.cpp
    └── physical-gpu/       # Physical GPU implementation
        ├── CMakeLists.txt
        ├── Makefile
        └── PhaseField.cu

Performance Tips

CPU Applications

  • Ensure OpenMP is enabled for parallel execution
  • Adjust OMP_NUM_THREADS environment variable to control thread count
  • Use Release build for best performance

GPU Applications

  • Build for your specific GPU architecture for optimal performance
  • Ensure sufficient GPU memory is available
  • Monitor GPU utilization using nvidia-smi

Troubleshooting

CMake cannot find CUDA

# Set CUDA path explicitly
cmake -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc ..

OpenMP not found

# Install OpenMP development package
# Ubuntu/Debian: sudo apt-get install libomp-dev
# macOS: brew install libomp

CUDA compilation errors

  • Ensure your GPU supports the target compute capability
  • Update to the latest CUDA toolkit
  • Check compiler compatibility with your CUDA version

Development

Code Standards

  • C++17 standard for modern C++ features
  • CUDA C++17 for GPU code
  • OpenMP for CPU parallelization
  • Modern CMake practices (3.18+)

Building with Debug Symbols

# CMake
cmake -DCMAKE_BUILD_TYPE=Debug ..

# Make
make debug

Continuous Integration

The repository includes automated CI/CD for CPU applications:

  • Runs on every push and pull request
  • Tests compilation with Make
  • Uses standard GitHub Actions runners
  • See .github/workflows/cpp.yml for workflow configuration

Contributing

Contributions are welcome! Please ensure:

  • Code follows modern C++17 standards
  • GPU code supports compute capability 7.0+
  • Documentation is updated as needed
  • Code is tested before submission

License

See LICENSE file for details.

References

  1. Kobayashi, R. (1993). "Modeling and numerical simulations of dendritic crystal growth." Physica D: Nonlinear Phenomena.
  2. Wheeler, A. A., Boettinger, W. J., & McFadden, G. B. (1992). "Phase-field model for isothermal phase transitions in binary alloys." Physical Review A.

Contact

Acknowledgments

This project uses phase-field methods for simulating solidification phenomena in materials science.

About

Educative Phase Field Simulation Examples

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •