grfsaw package¶
Submodules¶
grfsaw.autocorrelation_fft module¶
- grfsaw.autocorrelation_fft.autocorrelation_fft(binary_array)¶
autocorrelation_fft computes the (non-normalized) angular-averaged two-point correlation (autocorrelation) function. It is based on utilizing Fast Fourier Transform (FFT). According to the Wiener-Khinchin Theorem, the autocorrelation is given by the Fourier transform of the absolute square of the fourier coefficients of binary_array. Assumption: the microstructure is wrapped around its boundaries (i.e., PBC).
Arguments: binary_array: binary two- or three-dimensional numpy array denoting solid (1) and void (0) points.
Returns: numpy array of the two-point correlation function.
grfsaw.autocorrelation_xyz module¶
- grfsaw.autocorrelation_xyz.autocorrelation_xyz(binary_array, r_max, procs)¶
autocorrelation_xyz computes the (non-normalized) two-point correlation (autocorrelation) functions in the d=2 or 3 axis-aligned directions.
Arguments: binary_array: binary two- or three-dimensional numpy array denoting solid (1) and void (0) points. r_max: maximum distance as an integer number of mesh points. procs: integer number of processors available for the computation.
Returns: numpy arrays of the two-point correlation functions in x and y (and z if 3D) direction.
- grfsaw.autocorrelation_xyz.loop_2d(r, binary_array)¶
- grfsaw.autocorrelation_xyz.loop_3d(r, binary_array)¶
grfsaw.clean_structure module¶
- grfsaw.clean_structure.clean_structure(binary_array)¶
clean_structure cleans a microstructure by removing standalone clusters. More precisely, it deletes any solid point (change label from 1 to 0) that do not belong to any spanning cluster. Accomplished by applying the Burning Method from all 6 sides without the “not-at-bottom”-check. Note that there can be more than one spanning cluster, and that if no spanning cluster exists all points are deleted.
Arguments: binary_array: binary two- or three-dimensional numpy array denoting solid (1) and void (0) points.
Returns: binary two- or three-dimensional numpy array denoting solid (1) and void (0) points.
grfsaw.distributions module¶
- class grfsaw.distributions.gamma_distribution(momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None, seed=None)¶
Bases:
rv_continuous
Gamma probability distribution function used for sampling the magnitude of the wavevector.
- grfsaw.distributions.normal_distribution(mean, std, lower=0, upper=10000000000.0)¶
Gaussian probability distribution function used for sampling the magnitude of the wavevector.
grfsaw.find_shortest_path module¶
- grfsaw.find_shortest_path.find_shortest_path(binary, void_phase=False)¶
find_shortest_path find shortest path of the spanning cluster by applying the Burning Method from all 6 sides.
Arguments: binary: binary two- or three-dimensional numpy array denoting solid (1) and void (0) points. void_phase: boolean indicating wether calculating the path through the void phase (True) or solid phase (False, default).
Returns: list of 2 (if 2D) or 3 (if 3D) integers representing the shortest path through the structure in terms of number of mesh points.
- grfsaw.find_shortest_path.find_shortest_path_2d(binary_in)¶
- grfsaw.find_shortest_path.find_shortest_path_3d(binary_in)¶
grfsaw.local_wave_sums module¶
- grfsaw.local_wave_sums.local_wave_sum_2d(p, N_local, q0, xgrid, ygrid, q_hat_1, q_hat_2, phase)¶
Helper function for the (parallellized) summation of standing 2D sinusoidal waves.
- grfsaw.local_wave_sums.local_wave_sum_3d(p, N_local, q0, xgrid, ygrid, zgrid, q_hat_1, q_hat_2, q_hat_3, phase)¶
Helper function for the (parallellized) summation of standing 3D sinusoidal waves.
grfsaw.microstructure module¶
- class grfsaw.microstructure.Microstructure(shape, phi, folder='output/', single_cut=True, Nw=10000, distr='n', m_mean=3, m_std=0.001, anitype='i', a=1, seed=38683, procs=48)¶
Bases:
object
Class for the microstructure to be generated.
Attributes given by user:¶
- shapelist
list of 2 (if 2D) or 3 (if 3D) integers representing the (mesh) size of the microstructure as number of mesh points in each direction
- phifloat
desired solid volume fraction = 1 - porosity
- folderstr
name of directory to save data and plots (default: “output/”)
- single_cutboolean
generate single-cut or double-cut structure (default True)
- Nint
number of waves to use, the more the better but slower (default 10 000)
- distrchar
type of distribution to use for wavevector magnitude sampling, ‘n’ for normal or ‘g’ for gamma distribution (default ‘n’)
- m_meanfloat
average number of microstructural elements per length in the x-direction ~ a measure of the grain size of the structure (default 3)
- m_stdfloat
the standard deviation of m (default 0.001)
- anitypechar
type of preferred direction, ‘h’ for horizontal or ‘v’ for vertical, anything else is interpreted as isotropic (default isotropic)
- afloat
measure of the anisotropy level between 0 and 1 (default 1, meaning isotropic)
- seedint
seed for RNG (default np.random.randint(1, 1e5))
- procsint
number of cpus to use for the parallellized computations (default max number of cpus)
Internal attributes:¶
- q01d float numpy array
list of wave vector magnitudes
- theta1d float numpy array
list of wave vector directons
- binary_array2d or 3d boolean numpy array
the level-cut GRF
- binary_array_cleaned2d or 3d boolean numpy array
the level-cut GRF containing only the parts belonging to the spanning cluster
Methods:¶
- analytic_ssa()¶
Calculates the analytic prediction of the specific surface area per unit solid volume (SSA). Such analytic expression is only available for isotropic single-cut structures based on the gamma-distribution.
- autocorrelation(cleaned=False, one_dim=False, figsize=(13, 8), dpi=100, fontsize=22)¶
Calculates and plots the (normalized) autocorrelaton function, aka two-point correlation function. The specific surface area per unit solid volume (SSA) is also estimated from this function. If cleaned=True it uses the cleaned version of the structure (i.e., the spanning cluster only). If one_dim=True the one-dimensional autocorrelaton in all (2 or 3) directons is also calculated. The other optional parameters figsize, dpi and fontsize relates to the size and resolution of the plot.
- cleaning()¶
Cleans the microstructure by removing clusters that do not belong to any spanning clusters. Uses the so-called Burning Method, see clean_structure.py for more details.
- create()¶
Creates the microstructure with the given user parameters.
- find_shortest_path(cleaned=False)¶
Calculates the shortest path of the spanning cluster by applying the Burning Method from all sides. See find_shortest_path.py for more details. If cleaned=True it uses the cleaned version of the structure (i.e., the spanning cluster only).
- plot(slicelist=[0], cleaned=False, figsize=(13, 8), dpi=100, fontsize=22)¶
Saves plots of the structure. If 3D structure, user-defined slices are saved. The argument slicelist is only used for 3D structures and is a list of x-, y- and z-indices of slices to be plotted. If cleaned=True it uses the cleaned version of the structure (i.e., the spanning cluster only). The other optional parameters figsize, dpi and fontsize relates to the size and resolution of the plot.
- plot_distributions(figsize=(13, 8), dpi=100, fontsize=22)¶
Saves histograms of the sampling of wave lengths and directions. The optional parameters figsize, dpi and fontsize relates to the size and resolution of the plots.
- save(cleaned=False, vtk=False)¶
Saves the structure to file. If cleaned=True it uses the cleaned version of the structure (i.e., the spanning cluster only). If vtk=True the structure is saved as a VTK-file (this requires PyVista and works only for 3D structures), otherwise it is saved as a CSV-file with columns representing the x, y and z coordinates where x = 0, …, shape[0]-1, y = 0, …, shape[1]-1 and z = 0, …, shape[2]-1.
- save_parameters()¶
Saves setup parameters to folder for future reference.
- visualize_3d(cleaned=False, pyvista=True, from_file=False)¶
Visualizes the full 3D structure. If cleaned=True it uses the cleaned version of the structure (i.e., the spanning cluster only). If pyvista=True (recommended) PyVista is used for the visualization. If from_file=True the structure is read from the CSV-file in the directory. The other optional parameters figsize, dpi and fontsize relates to the size and resolution of the plot.
grfsaw.tools module¶
- grfsaw.tools.lcm(a, b)¶
Finds the lowest common multiple (lcm) of a and b
- grfsaw.tools.num2txt(dir, name, num)¶
Saves a number num to name.txt in the directory dir dir must end with “/”
- grfsaw.tools.set_axis_equal(ax)¶
Make axes have equal scale for 3D plots. Inspired by: https://stackoverflow.com/questions/13685386/matplotlib-equal-unit-length-with-equal-aspect-ratio-z-axis-is-not-equal-to/