kawin.Diffusion

class kawin.DiffusionModel(self, zlim, N, elements = [‘A’, ‘B’], phases = [‘alpha’])

kawin.DiffusionModel.reset(self)

Resets model 
 
This involves clearing any caches in the Thermodynamics object and this model 
as well as resetting the composition and phase profiles 

kawin.DiffusionModel.setThermodynamics(self, thermodynamics)

Defines thermodynamics object for the diffusion model 
 
Parameters 
---------- 
thermodynamics : Thermodynamics object 
    Requires the elements in the Thermodynamics and DiffusionModel objects to have the same order 

kawin.DiffusionModel.setTemperature(self, T)

Sets iso-thermal temperature 
 
Parameters 
---------- 
T : float 
    Temperature in Kelvin 

kawin.DiffusionModel.save(self, filename, compressed = False, toCSV = False)

Saves mesh, composition and phases 
 
Parameters 
---------- 
filename : str 
    File to save to 
compressed : bool 
    Whether to compress data if saving to numpy binary format (toCSV = False) 
toCSV : bool 
    Whether to output data to a .CSV file format 

kawin.DiffusionModel.load(filename)

Loads a previously saved model 
 
filename : str 
    File name to load model from, must include file extension 

kawin.DiffusionModel.setHashSensitivity(self, s)

Sets sensitivity of the hash table by significant digits 
 
For example, if a composition set is (0.5693, 0.2937) and s = 3, then 
the hash will be stored as (0.569, 0.294) 
 
Lower s values will give faster simulation times at the expense of accuracy 
 
Parameters 
---------- 
s : int 
    Number of significant digits to keep for the hash table 

kawin.DiffusionModel._getHash(self, x)

Gets hash value for a composition set 
 
Parameters 
---------- 
x : list of floats 
    Composition set to create hash 

kawin.DiffusionModel.useCache(self, use)

Whether to use the hash table 
 
Parameters 
---------- 
use : bool 
    If True, then the hash table will be used 

kawin.DiffusionModel.clearCache(self)

Clears hash table 

kawin.DiffusionModel._getElementIndex(self, element = None)

Gets index of element in self.elements 
 
Parameters 
---------- 
element : str 
    Specified element, will return first element if None 

kawin.DiffusionModel._getPhaseIndex(self, phase = None)

Gets index of phase in self.phases 
 
Parameters 
---------- 
phase : str 
    Specified phase, will return first phase if None 

kawin.DiffusionModel.setBC(self, LBCtype = 0, LBCvalue = 0, RBCtype = 0, RBCvalue = 0, element = None)

Set boundary conditions 
 
Parameters 
---------- 
LBCtype : int 
    Left boundary condition type 
        Mesh1D.FLUX - constant flux 
        Mesh1D.COMPOSITION - constant composition 
LBCvalue : float 
    Value of left boundary condition 
RBCtype : int 
    Right boundary condition type 
        Mesh1D.FLUX - constant flux 
        Mesh1D.COMPOSITION - constant composition 
RBCvalue : float 
    Value of right boundary condition 
element : str 
    Specified element to apply boundary conditions on 

kawin.DiffusionModel.setCompositionLinear(self, Lvalue, Rvalue, element = None)

Sets composition as a linear function between ends of the mesh 
 
Parameters 
---------- 
Lvalue : float 
    Value at left boundary 
Rvalue : float 
    Value at right boundary 
element : str 
    Element to apply composition profile to 

kawin.DiffusionModel.setCompositionStep(self, Lvalue, Rvalue, z, element = None)

Sets composition as a step-wise function 
 
Parameters 
---------- 
Lvalue : float 
    Value on left side of mesh 
Rvalue : float 
    Value on right side of mesh 
z : float 
    Position on mesh where composition switches from Lvalue to Rvalue 
element : str 
    Element to apply composition profile to 

kawin.DiffusionModel.setCompositionSingle(self, value, z, element = None)

Sets single node to specified composition 
 
Parameters 
---------- 
value : float 
    Composition 
z : float 
    Position to set value to (will use closest node to z) 
element : str 
    Element to apply composition profile to 

kawin.DiffusionModel.setCompositionInBounds(self, value, Lbound, Rbound, element = None)

Sets single node to specified composition 
 
Parameters 
---------- 
value : float 
    Composition 
Lbound : float 
    Position of left bound 
Rbound : float 
    Position of right bound 
element : str 
    Element to apply composition profile to 

kawin.DiffusionModel.setCompositionFunction(self, func, element = None)

Sets composition as a function of z 
 
Parameters 
---------- 
func : function 
    Function taking in z and returning composition 
element : str 
    Element to apply composition profile to 

kawin.DiffusionModel.setCompositionProfile(self, z, x, element = None)

Sets composition profile by linear interpolation 
 
Parameters 
---------- 
z : array 
    z-coords of composition profile 
x : array 
    Composition profile 
element : str 
    Element to apply composition profile to 

kawin.DiffusionModel.setup(self)

General setup function for all diffusio models 
 
This will clear any cached values in the thermodynamics function and check if all compositions add up to 1 
 
This will also make sure that all compositions are not 0 or 1 to speed up equilibrium calculations 

kawin.DiffusionModel.getFluxes(self)

"Virtual" function to be implemented by child objects 

kawin.DiffusionModel.updateMesh(self)

"Virtual" function to be implemented by child objects 

kawin.DiffusionModel.update(self)

Updates the mesh by a given dt that is calculated for numerical stability 

kawin.DiffusionModel.solve(self, simTime, verbose=False, vIt=10)

Solves the model by updated the mesh until the final simulation time is met 

kawin.DiffusionModel.getX(self, element)

Gets composition profile of element 
 
Parameters 
---------- 
element : str 
    Element to get profile of 

kawin.DiffusionModel.getP(self, phase)

Gets phase profile 
 
Parameters 
---------- 
phase : str 
    Phase to get profile of 

kawin.DiffusionModel.plot(self, ax, plotReference = True, plotElement = None, zScale = 1, *args, **kwargs)

Plots composition profile 
 
Parameters 
---------- 
ax : matplotlib Axes object 
    Axis to plot on 
plotReference : bool 
    Whether to plot reference element (composition = 1 - sum(composition of rest of elements)) 
plotElement : None or str 
    Plots single element if it is defined, otherwise, all elements are plotted 
zScale : float 
    Scale factor for z-coordinates 

kawin.DiffusionModel.plotTwoAxis(self, axL, Lelements, Relements, zScale = 1, *args, **kwargs)

Plots composition profile with two y-axes 
 
Parameters 
---------- 
axL : matplotlib Axes object 
    Left axis to plot on 
Lelements : list of str 
    Elements to plot on left axis 
Relements : list of str 
    Elements to plot on right axis 
zScale : float 
    Scale factor for z-coordinates 

kawin.DiffusionModel.plotPhases(self, ax, plotPhase = None, zScale = 1, *args, **kwargs)

Plots phase fractions over z 
 
Parameters 
---------- 
ax : matplotlib Axes object 
    Axis to plot on 
plotPhase : None or str 
    Plots single phase if it is defined, otherwise, all phases are plotted 
zScale : float 
    Scale factor for z-coordinates 

class kawin.SinglePhaseModel

kawin.SinglePhaseModel.getFluxes(self)

Gets fluxes at the boundary of each nodes 
 
Returns 
------- 
fluxes : (e-1, n+1) array of floats 
    e - number of elements including reference element 
    n - number of nodes 
dt : float 
    Maximum calculated time interval for numerical stability 

kawin.SinglePhaseModel.updateMesh(self, fluxes, dt)

Updates mesh using fluxes by time increment dt 
 
Parameters 
---------- 
fluxes : 2D array 
    Fluxes for each element between each node. Size must be (E, N-1) 
        E - number of elements (NOT including reference element) 
        N - number of nodes 
    Boundary conditions will automatically be applied 
dt : float 
    Time increment 

class kawin.HomogenizationModel(self, zlim, N, elements = [‘A’, ‘B’], phases = [‘alpha’])

kawin.HomogenizationModel.reset(self)

Resets model 
 
This also includes chemical potential and pycalphad CompositionSets for each node 

kawin.HomogenizationModel.setMobilityFunction(self, function)

Sets averaging function to use for mobility 
 
Default mobility value should be that a phase of unknown mobility will be ignored for average mobility calcs 
 
Parameters 
---------- 
function : str 
    Options - 'upper wiener', 'lower wiener', 'upper hashin-shtrikman', 'lower hashin-strikman', 'labyrinth' 

kawin.HomogenizationModel.setLabyrinthFactor(self, n)

Labyrinth factor 
 
Parameters 
---------- 
n : int 
    Either 1 or 2 
    Note: n = 1 will the same as the weiner upper bounds 

kawin.HomogenizationModel.setup(self)

Sets up model 
 
This also includes getting the CompositionSets for each node 

kawin.HomogenizationModel._newEqCalc(self, x)

Calculates equilibrium and returns a CompositionSet 

kawin.HomogenizationModel.updateCompSets(self, xarray)

Updates the array of CompositionSets 
 
If an equilibrium calculation is already done for a given composition,  
the CompositionSet will be taken out of the hash table 
 
Otherwise, a new equilibrium calculation will be performed 
 
Parameters 
---------- 
xarray : (e-1, N) array 
    Composition for each node 
    e is number of elements 
    N is number of nodes 
 
Returns 
------- 
parray : (p, N) array 
    Phase fractions for each node 
    p is number of phases 

kawin.HomogenizationModel.getMobility(self, xarray)

Gets mobility of all phases 
 
Returns 
------- 
(p, e+1, N) array - p is number of phases, e is number of elements, N is number of nodes 

kawin.HomogenizationModel.wienerUpper(self, xarray)

Upper wiener bounds for average mobility 
 
Returns 
------- 
(e+1, N) mobility array - e is number of elements, N is number of nodes 

kawin.HomogenizationModel.wienerLower(self, xarray)

Lower wiener bounds for average mobility 
 
Returns 
------- 
(e+1, N) mobility array - e is number of elements, N is number of nodes 

kawin.HomogenizationModel.labyrinth(self, xarray)

Labyrinth mobility 
 
Returns 
------- 
(e+1, N) mobility array - e is number of elements, N is number of nodes 

kawin.HomogenizationModel.hashin_shtrikmanUpper(self, xarray)

Upper hashin shtrikman bounds for average mobility 
 
Returns 
------- 
(e+1, N) mobility array - e is number of elements, N is number of nodes 

kawin.HomogenizationModel.hashin_shtrikmanLower(self, xarray)

Lower hashin shtrikman bounds for average mobility 
 
Returns 
------- 
(e, N) mobility array - e is number of elements, N is number of nodes 

kawin.HomogenizationModel.getFluxes(self)

Return fluxes and time interval for the current iteration 

kawin.HomogenizationModel.updateMesh(self, fluxes, dt)

Updates the mesh based off the fluxes and time interval