Skip to content

Class pypfc_pre

pyPFC logo

Bases: setup_base

Functions

__init__

__init__(
    domain_size: Union[List[float], ndarray],
    ndiv: Union[List[int], ndarray],
    config: Dict[str, Any],
) -> None

Initialize the class.

Parameters:

Name Type Description Default
domain_size array_like of int, shape (3,)

Number of grid divisions along each coordinate axis [nx, ny, nz].

required
ndiv array_like of int, shape (3,)

Number of grid divisions along each coordinate axis [nx, ny, nz].

required
config dict

Configuration parameters as key-value pairs. See the pyPFC overview for a complete list of the configuration parameters.

required

do_bicrystal

do_bicrystal(
    xtal_rot: ndarray,
    params: Optional[List[float]] = None,
    liq_width: float = 0.0,
    model: int = 0,
) -> np.ndarray

Define a bicrystal with two different crystal orientations.

Bicrystal Example

Parameters:

Name Type Description Default
xtal_rot ndarray of float, shape (3,3,2)

Crystal orientations (rotation matrices) for the two grains.

required
params list

List containing parameters for the bicrystal model.

  • model=0: [r] - cylindrical crystal radius
  • model=1: [r] - spherical crystal radius
  • model=2: [gb_x1, gb_x2] - grain boundary positions along x
None
liq_width float

Width of the liquid band along the grain boundary.

0.0
model int

Density field layout.

  • 0: Cylindrical crystal, extending through z
  • 1: Spherical crystal
  • 2: Bicrystal with two planar grain boundaries, normal to x
0

Returns:

Name Type Description
density ndarray of float, shape (nx,ny,nz)

Density field.

Raises:

Type Description
ValueError

If the value of model is not supported (should be 0, 1 or 2).

do_polycrystal

do_polycrystal(
    xtal_rot: ndarray,
    params: Optional[List[float]] = None,
    liq_width: float = 0.0,
    model: int = 0,
) -> np.ndarray

Define a polycrystal in a periodic 3D domain.

Polycrystal Example

Parameters:

Name Type Description Default
xtal_rot ndarray of float, shape (3,3,n_xtal)

Crystal orientations (rotation matrices) for n_xtal crystals.

required
params list

List containing parameters for the polycrystal model.

  • model=0: No parameter needed. The number of crystal seeds is determined from the number of provided orientations.
None
liq_width float

Width of the liquid band along the grain boundaries.

0.0
model int

Density field layout.

  • 0: A row of cylindrical seeds along y, with cylinders extending through z
0

Returns:

Name Type Description
density ndarray of float, shape (nx,ny,nz)

Polycrystal density field.

Raises:

Type Description
ValueError

If the value of model is not supported (should be 0).

do_single_crystal

do_single_crystal(
    xtal_rot: Optional[ndarray] = None,
    params: Optional[List[float]] = None,
    model: int = 0,
) -> np.ndarray

Define a single crystal in a periodic 3D domain.

Single Crystal Example

Parameters:

Name Type Description Default
xtal_rot ndarray of float, shape (3,3)

Crystal orientation (rotation matrix). Default is an identity matrix.

None
params list

List containing parameters for the single crystal model:

  • model=0: [r] - spherical crystal radius
  • model=1: [x1, x2] - crystal extent in x direction
  • model=2: [r] - cylindrical crystal radius
None
model (int, optional)

Density field layout.

  • 0: Spherical crystal
  • 1: Crystal extending throughout y and z, covering interval in x
  • 2: Cylindrical crystal, extending through z
0

Returns:

Name Type Description
density ndarray of float, shape (nx,ny,nz)

Density field.

Raises:

Type Description
ValueError

If the value of model is not supported (should be 0 or 1).

evaluate_ampl_dens

evaluate_ampl_dens() -> Tuple[np.ndarray, np.ndarray]

Get density field amplitudes and phase densities for PFC simulations.

Amplitude and Density Example

Returns:

Name Type Description
ampl ndarray of float, shape (npeaks,)

Density field amplitudes for the specified crystal structure and number of peaks.

nLnS ndarray of float, shape (2,)

Densities in the liquid (nL) and solid (nS) phases.

Raises:

Type Description
ValueError

If npeaks is not supported for the current crystal structure.

ValueError

If sigma value is not supported for the current configuration.

ValueError

If struct is not 'SC', 'BCC' or 'FCC' or if amplitudes and densities are not available for the specified structure.

Notes

This method provides pre-calculated density field amplitudes and phase densities for different crystal structures (SC, BCC, FCC) and numbers of Fourier peaks in the two-point correlation function. The values depend on the temperature-like parameter sigma.

Fore efficiency, the method uses lookup tables of pre-computed values.

Supported configurations:

struct npeaks sigma range
SC 1 [0.0, 0.25]
2 [0.0, 0.22]
3 [0.0, 0.22]
BCC 1 [0.0, 0.33]
2 [0.0, 0.30]
3 [0.0, 0.25]
FCC 1 [0.0, 0.25]
2 [0.0, 0.25]
3 [0.0, 0.25]

generate_density_field

generate_density_field(
    crd: ndarray, g: ndarray
) -> np.ndarray

Define a 3D density field for (X)PFC modeling.

Parameters:

Name Type Description Default
crd ndarray of float, shape (3,...)

Grid point coordinates [x,y,z].

required
g ndarray of float, shape (3,3)

Rotation matrix for crystal orientation.

required

Returns:

Name Type Description
density ndarray of float

Density field for the specified crystal structure with appropriate Fourier modes and amplitudes.

Raises:

Type Description
ValueError

If struct is not one of the supported crystal structures ('SC', 'BCC', 'FCC', 'DC').

Notes

The density field is generated based on the current crystal structure (struct) and density field amplitudes (ampl) settings.

get_ampl

get_ampl() -> np.ndarray

Get the amplitudes in the density approximation.

Returns:

Name Type Description
ampl ndarray of float, shape (N,)

Amplitudes.

get_density

get_density() -> np.ndarray

Get the density field.

Returns:

Name Type Description
den ndarray of float, shape (nx,ny,nz)

Density field.

get_nlns

get_nlns() -> np.ndarray

Get the liquid and solid phase densities.

Returns:

Name Type Description
nlns ndarray of float, shape (2,)

\([n_{l},n_{s}]\) where \(n_{l}\) is liquid phase density and \(n_{s}\) is solid phase density.

get_npeaks

get_npeaks() -> int

Get the number of peaks in the density field approximation.

Returns:

Name Type Description
npeaks int

Number of peaks in the density field approximation.

get_sigma

get_sigma() -> float

Get the temperature-like parameter sigma.

Returns:

Name Type Description
sigma float

Temperature-like parameter sigma

get_struct

get_struct() -> str

Get the crystal structure.

Returns:

Name Type Description
struct str

Crystal structure type: 'FCC', 'BCC'.

set_ampl

set_ampl(ampl: Union[List[float], ndarray]) -> None

Set the amplitudes in the density approximation.

Parameters:

Name Type Description Default
ampl array_like of float, shape (N,)

Amplitudes.

required

set_density

set_density(den: ndarray) -> None

Set the density field.

Parameters:

Name Type Description Default
den ndarray of float, shape (nx,ny,nz)

Density field.

required

set_energy

set_energy(ene: ndarray) -> None

Set the PFC energy field.

Parameters:

Name Type Description Default
ene ndarray of float, shape (nx,ny,nz)

PFC energy field.

required

set_nlns

set_nlns(nlns: Union[List[float], ndarray]) -> None

Set the liquid and solid phase densities.

Parameters:

Name Type Description Default
nlns array_like of float, shape (2,)

\([n_{l},n_{s}]\) where \(n_{l}\) is liquid phase density and \(n_{s}\) is solid phase density.

required

set_npeaks

set_npeaks(npeaks: int) -> None

Set the number of peaks in the density field approximation.

Parameters:

Name Type Description Default
npeaks int

Number of peaks in the density field approximation.

required

set_sigma

set_sigma(sigma: float) -> None

Set the temperature-like parameter sigma.

Parameters:

Name Type Description Default
sigma float

Temperature-like parameter sigma.

required

set_struct

set_struct(struct: str) -> None

Set the crystal structure.

Parameters:

Name Type Description Default
struct (FCC, BCC)

Crystal structure type: 'FCC', 'BCC'.

'FCC'