Skip to content

Commit

Permalink
remove unnecessary lines and update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Ury committed Jul 24, 2024
1 parent aaac02d commit f61e4fa
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 172 deletions.
14 changes: 7 additions & 7 deletions examples/01_Binary_Precipitation.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions examples/02_Multicomponent_Precipitation.ipynb

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions examples/03_Multiphase_Precipitation.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/04_Precipitation_with_Elastic_Energy.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/05_Strength_Modeling.ipynb

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions examples/06_Single_Phase_Diffusion.ipynb

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions examples/07_Homogenization_Model.ipynb

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions examples/08_Model_Coupling.ipynb

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions examples/09_Thermodynamics.ipynb

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions examples/10_Surrogates.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/11_Extra_Factors.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/12_Custom_Iterators.ipynb

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions kawin/thermo/BinTherm.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ def _interfacialCompositionFromEq(self, T, gExtra = 0, precPhase = None):

#Compute equilibrium at guess composition
cond = {v.X(self.elements[1]): self._guessComposition[precPhase], v.T: T, v.P: 101325, v.GE: gExtra}
#eq = equilibrium(self.db, self.elements, [self.phases[0], precPhase], cond, model=self.models,
# phase_records={self.phases[0]: self.phase_records[self.phases[0]], precPhase: self.phase_records[precPhase]},
# calc_opts = {'pdens': self.pDens})
eq = equilibrium(self.db, self.elements, [self.phases[0], precPhase], cond, model=self.models,
phase_records=self.phase_records,
calc_opts = {'pdens': self.pDens})
Expand Down Expand Up @@ -240,9 +237,6 @@ def _interfacialCompositionFromCurvature(self, T, gExtra = 0, precPhase = None):

#Compute equilibrium at guess composition
cond = {v.X(self.elements[1]): self._guessComposition[precPhase], v.T: T, v.P: 101325, v.GE: self.gOffset, v.N: 1}
#eq = equilibrium(self.db, self.elements, [self.phases[0], precPhase], cond, model=self.models,
# phase_records={self.phases[0]: self.phase_records[self.phases[0]], precPhase: self.phase_records[precPhase]},
# calc_opts = {'pdens': self.pDens})
eq = equilibrium(self.db, self.elements, [self.phases[0], precPhase], cond, model=self.models,
phase_records=self.phase_records,
calc_opts = {'pdens': self.pDens})
Expand Down
4 changes: 0 additions & 4 deletions kawin/thermo/FreeEnergyHessian.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import numpy as np
from pycalphad import Model, variables as v
#from pycalphad.codegen.callables import build_callables

setattr(v, 'GE', v.StateVariable('GE'))

def hessian(chemical_potentials, composition_set):
'''
Expand Down
1 change: 0 additions & 1 deletion kawin/thermo/LocalEquilibrium.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pycalphad.core.solver import Solver
from pycalphad.core.composition_set import CompositionSet
from pycalphad.codegen.callables import build_phase_records
from pycalphad import calculate, variables as v
import numpy as np

Expand Down
2 changes: 0 additions & 2 deletions kawin/thermo/Mobility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from symengine import exp, Symbol, Add
from kawin.thermo.FreeEnergyHessian import partialdMudX, dMudX

setattr(v, 'GE', v.StateVariable('GE'))

#List of interstitial elements
# When calculating interdiffusivity, we do not require reference element
# When calculating the mobility factor, we have an additional vacancy term to multiply by
Expand Down
70 changes: 1 addition & 69 deletions kawin/thermo/Thermodynamics.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import numpy as np
from pycalphad import Model, Database, calculate, equilibrium, variables as v
#from pycalphad.codegen.callables import build_callables, build_phase_records
#from pycalphad.codegen.callables import build_phase_records
from pycalphad.codegen.phase_record_factory import PhaseRecordFactory
from pycalphad.core.composition_set import CompositionSet
from pycalphad.core.utils import extract_parameters
from kawin.thermo.Mobility import MobilityModel, inverseMobility, inverseMobility_from_diffusivity, tracer_diffusivity, tracer_diffusivity_from_diff
from kawin.thermo.FreeEnergyHessian import dMudX
from kawin.thermo.LocalEquilibrium import local_equilibrium
import matplotlib.pyplot as plt
import copy
from tinydb import where

#setattr(v, 'GE', v.StateVariable('GE'))
class ExtraFreeEnergyType(v.IndependentPotential):
implementation_units = 'joules'
display_units = 'joules'
Expand Down Expand Up @@ -143,11 +139,6 @@ def _buildThermoModels(self):
self.models[self.phases[0]].state_variables,
self.models, parameters=self._parameters)

#self.phase_records = build_phase_records(self.db, self.elements, self.phases,
# self.models[self.phases[0]].state_variables,
# self.models, build_gradients=True, build_hessians=True,
# parameters=self._parameters)

self.OCMphase_records = {}
for i in range(1, len(self.phases)):
if self.orderedPhase[self.phases[i]]:
Expand All @@ -156,12 +147,6 @@ def _buildThermoModels(self):
include_grad=False,
include_hess=False)

#self.OCMphase_records[self.phases[i]] = build_phase_records(self.db, self.elements, [self.phases[i]],
# self.models[self.phases[0]].state_variables,
# {self.phases[i]: self.models[self.phases[i]]},
# output='OCM', build_gradients=False, build_hessians=False,
# parameters=self._parameters)

def _buildMobilityModels(self):
'''
Builds mobility models for phases that have model parameters
Expand Down Expand Up @@ -205,45 +190,6 @@ def _buildMobilityModels(self):
if len(phase_diff_params[p]) > 0:
self.diffCallables[p] = {c: self.mob_phase_records.get_phase_property(p, 'DIFF_'+c, include_grad=False, include_hess=False).func for c in self.phase_records[p].nonvacant_elements}

# for p in self.phases:
# #Get mobility/diffusivity of phase p if exists
# param_search = self.db.search
# param_query_mob = (
# (where('phase_name') == p) & \
# (where('parameter_type') == 'MQ') | \
# (where('parameter_type') == 'MF')
# )

# param_query_diff = (
# (where('phase_name') == p) & \
# (where('parameter_type') == 'DQ') | \
# (where('parameter_type') == 'DF')
# )

# pMob = param_search(param_query_mob)
# pDiff = param_search(param_query_diff)

# if len(pMob) > 0 or len(pDiff) > 0:
# self.mobModels[p] = MobilityModel(self.db, self.elements, p, parameters=param_keys)
# if len(pMob) > 0:
# self.mobCallables[p] = {}
# for c in self.phase_records[p].nonvacant_elements:
# #bcp = build_callables(self.db, self.elements, [p], {p: self.mobModels[p]},
# # parameter_symbols=self._parameters, output='MOB_'+c, build_gradients=False, build_hessians=False,
# # additional_statevars=[v.T, v.P, v.N, v.GE])
# #self.mobCallables[p][c] = bcp['MOB_'+c]['callables'][p]

# self.mobCallables[p][c] = self.phase_records.get_phase_property(p, 'MOB_'+c, include_grad=False, include_hess=False)
# else:
# self.diffCallables[p] = {}
# for c in self.phase_records[p].nonvacant_elements:
# #bcp = build_callables(self.db, self.elements, [p], {p: self.mobModels[p]},
# # parameter_symbols=self._parameters, output='DIFF_'+c, build_gradients=False, build_hessians=False,
# # additional_statevars=[v.T, v.P, v.N, v.GE])
# #self.diffCallables[p][c] = bcp['DIFF_'+c]['callables'][p]

# self.diffCallables[p][c] = self.phase_records.get_phase_property(p, 'DIFF_'+c, include_grad=False, include_hess=False)

#This applies to all phases since this is typically reflective of quenched-in vacancies
self.mobility_correction = {A: 1 for A in self.elements}

Expand Down Expand Up @@ -477,7 +423,6 @@ def getEq(self, x, T, gExtra = 0, precPhase = None):
phases.append(precPhase)
else:
phases = [p for p in precPhase]
phaseRec = {p: self.phase_records[p] for p in phases}

if not hasattr(x, '__len__'):
x = [x]
Expand All @@ -487,23 +432,10 @@ def getEq(self, x, T, gExtra = 0, precPhase = None):
x = x[1:]

cond = self._getConditions(x, T, gExtra+self.gOffset)

#eq = equilibrium(self.db, self.elements, phases, cond, model=self.models,
# phase_records=phaseRec,
# calc_opts={'pdens': self.pDens})

#print(phases, {p: self.models[p] for p in phases})
#sub_models = {p: self.models[p] for p in phases}
#sub_phase_records = PhaseRecordFactory(self.db, self.elements,
# sub_models[phases[0]].state_variables,
# sub_models, parameters=self._parameters)
#eq = equilibrium(self.db, self.elements, phases, cond, model=sub_models,
# phase_records=sub_phase_records,
# calc_opts={'pdens': self.pDens})

# Phases, models and phase records should match in the list of phases
# Here, I create a model dictionary of the relevant phases
# Then, I hijack the models in the phase records with this sublist
# Then, I replace the models in the phase records with this sublist
# After equilibrium, restore the original model list
sub_models = {p: self.models[p] for p in phases}
self.phase_records.models = sub_models
Expand Down

0 comments on commit f61e4fa

Please sign in to comment.