kawin.PopulationBalance
class kawin.PopulationBalanceModel(self, cMin = 1e-10, cMax = 1e-9, bins = 150, minBins = 100, maxBins = 200)
Class for handling particle size distributions (PSD)
This include time evolution, moments and graphing
NOTE: more formally, the PSD is defined such that the number of particles of size R in a volume
is the integral of the PSD from R-1/2 to R+1/2
For the discrete PSD, n_i = PSD_i * (R+1/2 - R-1/2)
Here, we just store the PSD as the number of particles (n_i), but the formulation for
growth rates and moments are the same since the factor (R+1/2 - R-1/2) cancels out
Parameters
----------
cMin : float (optional)
Lower bound of PSD (defaults at 1e-10)
cMax : float (optional)
Upper bound of PSD (defaults at 1e-9)
bins : int (optional)
Initial number of bins (defaults at 150)
minBins : int (optional)
Minimum number of bins over an order of magnitude (defaults at 100)
maxBins : int (optional)
Maximum number of bins over an order of magnitude (defaults at 200)
Attributes
----------
originalMin : float
Minimum bin size initially set
min : float
Current minimum bin size (this will almost always be equal to originalMin)
originalMax : float
Maximum bin size initially set
max : float
Current maximum bin size
bins : int
Default number of bins
minBins : int
Minimum number of allowed bins
maxBins : int
Maximum number of allowed bins
PSD : array
Particle size distribution
PSDsize : array
Average radius of each PSD size class
PSDbounds : array
Radius at the bounds of each size class - length of array is len(PSD)+1
kawin.PopulationBalanceModel.setAdaptiveBinSize(self, adaptive)
For Euler implementation, sets whether to change the bin size when
the number of filled bins > maxBins or < minBins
If False, the bins will still change if nucleated particles are greater than the max bin size
and bins will still be added when the last bins starts to fill (although this will not change the bin size)
kawin.PopulationBalanceModel.setBinConstraints(self, bins = 150, minBins = 100, maxBins = 200)
Sets constraints for minimum and maxinum number of bins over an order of magnitude
All bins will be overridden to an even number
Minimum number of bins will be overridden to be at most half of maximum bins
Default bins will be overridden to be halfway between min and max bins if out of range
kawin.PopulationBalanceModel.LoadDistribution(self, data)
Creates a particle size distribution from a set of data
Parameters
----------
data : array of floats
Array of data to be inserted into PSD
kawin.PopulationBalanceModel.LoadDistributionFunction(self, function)
Creates a particle size distribution from a function
Parameters
----------
function : function
Takes in R and returns density
kawin.PopulationBalanceModel.createBackup(self)
Stores current PSD and PSDbounds
kawin.PopulationBalanceModel.revert(self)
Reverts to previous PSD and PSDbounds
kawin.PopulationBalanceModel.reset(self, resetBounds = True)
Resets the PSD to 0
This will remove any size classes that were added since initialization
kawin.PopulationBalanceModel.changeSizeClasses(self, cMin, cMax, bins = None, resetPSD = False)
Changes the size classes and resets the PSD
Parameters
----------
cMin : float
Lower bound of PSD
cMax : float
Upper bound of PSD
bins : int
Number of bins
resetPSD : bool (optional)
Whether to reset the PSD (defaults to False)
kawin.PopulationBalanceModel.addSizeClasses(self, bins = 1)
Adds an additional size class to end of distribution
Parameters
----------
bins : int
Number of bins to add
kawin.PopulationBalanceModel.getDTEuler(self, currDT, growth, maxDissolution, startIndex)
Calculates time interval for Euler implementation
dt < dR / (2 * growth rate)
This ensures that at most, only half of particles in one size class can go to another
Parameters
----------
currDT : float
Current time interval, will be returned if it's smaller than what's given by the contraint
growth : array of floats
Growth rate, must have lenth of bins+1 (or length of PSDbounds)
maxDissolution : float
Maximum volume allowed to dissolve
startIndex : int
First index to look at for growth rate, all indices below startIndex will be ignored
kawin.PopulationBalanceModel.adjustSizeClassesEuler(self, checkDissolution = False)
Adds a size class if last class in PBM is filled
Changes length of size classes based off number of allowed bins
kawin.PopulationBalanceModel.Normalize(self)
Normalizes the PSD to 1
kawin.PopulationBalanceModel.NormalizeToMoment(self, order = 0)
Normalizes the PSD with so that the moment of specified order will be 1
Parameters
----------
order : int (optional)
Order of moment that PSD will be normalized to (defaults to 0)
Using zeroth order will normalize the PSD so the sum of PSD will be 1
kawin.PopulationBalanceModel.Nucleate(self, amount, radius)
Adds nucleated particles to PSD given radius and amount of particles
Parameters
----------
amount : float
Amount of nucleated particles
radius : float
Radius of nucleated particles
kawin.PopulationBalanceModel.UpdateEuler(self, dt, flux)
Updates PSD given the flux and any external contributions
Change in the amount of particles in a given size class = d(G*n)/dx
Where G is flux of size class, n is number of particles in size class and dx is range of size class
Parameters
----------
dt : float
Time increment
flux : array
Growth rate of each particle size class
Array size must be (bins + 1) since this operates on bounds of size classes
kawin.PopulationBalanceModel.UpdateLagrange(self, dt, flux)
Updates bounds of size classes with given growth rate
Fluxes of particles between size classes is d(Gn)/dx,
however, keeping the number of particles in each size class the same,
the bounds of the size classes can be updated by r_i = v_i * dt
Parameters
----------
dt : float
Time increment
flux : array
Growth rate of each particle size class
Array size must be (bins + 1) since this operates on bounds of size classes
kawin.PopulationBalanceModel.Moment(self, order)
Moment of specified order
Parameters
----------
order : int
Order of moment
kawin.PopulationBalanceModel.CumulativeMoment(self, order)
Cumulative distribution using moment of specified order
Parameters
----------
order : int
Order of moment
kawin.PopulationBalanceModel.WeightedMoment(self, order, weights)
Weighted moment of specified order
Parameters
----------
order : int
Order of moment
weights : array
Weights to apply to each size class
Array size of (bins)
kawin.PopulationBalanceModel.CumulativeWeightedMoment(self, order, weights)
Weighted moment of specified order
Parameters
----------
order : int
Order of moment
weights : array
Weights to apply to each size class
Array size of (bins)
kawin.PopulationBalanceModel.ZeroMoment(self)
Sum of the PSD
kawin.PopulationBalanceModel.FirstMoment(self)
Length weighted moment
kawin.PopulationBalanceModel.SecondMoment(self)
Area weighted moment
kawin.PopulationBalanceModel.ThirdMoment(self)
Volume weighted moment
kawin.PopulationBalanceModel.PlotCurve(self, axes, fill = False, logX = False, logY = False, scale = 1, *args, **kwargs)
Plots the PSD as a curve
Parameters
----------
axes : Axes
Axis to plot on
fill : bool (optional)
Will fill area between PSD curve and x-axis (defaults to False)
logX : bool (optional)
Whether to set x-axis on log scale (defaults to False)
logY : bool (optional)
Whether to set y-axis on log scale (defaults to False)
scale : float (optional)
Scale factor for x-axis (defaults to 1)
Note: this is for grain boundary nucleation where the
reported precipitate radius differs from the radius
determined by precipitate curvature
*args, **kwargs - extra arguments for plotting
kawin.PopulationBalanceModel.PlotDistributionDensity(self, axes, fill = False, logX = False, logY = False, scale = 1, *args, **kwargs)
Plots the distribution density as a curve
Defined as N_i / (R_i+1/2 - R_i-1/2)
Parameters
----------
axes : Axes
Axis to plot on
fill : bool (optional)
Will fill area between PSD curve and x-axis (defaults to False)
logX : bool (optional)
Whether to set x-axis on log scale (defaults to False)
logY : bool (optional)
Whether to set y-axis on log scale (defaults to False)
scale : float (optional)
Scale factor for x-axis (defaults to 1)
Note: this is for grain boundary nucleation where the
reported precipitate radius differs from the radius
determined by precipitate curvature
*args, **kwargs - extra arguments for plotting
kawin.PopulationBalanceModel.PlotKDE(self, axes, bw_method = None, fill = False, logX = False, logY = False, scale = 1, *args, **kwargs)
Plots the kernel density estimation (KDE)
Parameters
----------
axes : Axes
Axis to plot on
bw_method : str (optional)
Method to estimate bandwidth ('scott', 'silverman' or a scalar)
Defaults to scipy's default for KDE
fill : bool (optional)
Will fill area between PSD curve and x-axis (defaults to False)
logX : bool (optional)
Whether to set x-axis on log scale (defaults to False)
logY : bool (optional)
Whether to set y-axis on log scale (defaults to False)
scale : float (optional)
Scale factor for x-axis (defaults to 1)
Note: this is for grain boundary nucleation where the
reported precipitate radius differs from the radius
determined by precipitate curvature
*args, **kwargs - extra arguments for plotting
kawin.PopulationBalanceModel.PlotHistogram(self, axes, outline = ‘outline bins’, fill = True, logX = False, logY = False, scale = 1, *args, **kwargs)
Plots the PSD as a histogram
Parameters
----------
axes : Axes
Axis to plot on
outline : str (optional)
How to outline the bins ('no outline', 'outline bins', 'outline top')
Defaults to 'outline bins'
fill : bool (optional)
Will fill area between PSD curve and x-axis (defaults to False)
logX : bool (optional)
Whether to set x-axis on log scale (defaults to False)
logY : bool (optional)
Whether to set y-axis on log scale (defaults to False)
scale : float (optional)
Scale factor for x-axis (defaults to 1)
Note: this is for grain boundary nucleation where the
reported precipitate radius differs from the radius
determined by precipitate curvature
*args, **kwargs - extra arguments for plotting
kawin.PopulationBalanceModel.PlotCDF(self, axes, logX = False, scale = 1, order = 0, *args, **kwargs)
Plots cumulative size distribution
Parameters
----------
axes : Axes
Axis to plot on
logX : bool (optional)
Whether to set x-axis on log scale (defaults to False)
scale : float (optional)
Scale factor for x-axis (defaults to 1)
Note: this is for grain boundary nucleation where the
reported precipitate radius differs from the radius
determined by precipitate curvature
order : int (optional)
Moment of specified order
*args, **kwargs - extra arguments for plotting
kawin.PopulationBalanceModel.setAxes(self, axes, scale = 1, logX = False, logY = False)
Sets x- and y-axis to linear or log scale
Parameters
----------
axes : Axis
Axis to plot on
logX : bool (optional)
Whether to set x-axis on log scale (defaults to False)
logY : bool (optional)
Whether to set y-axis on log scale (defaults to False)