Skip to content

Commit

Permalink
replace calls to equilibrium with Workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Ury committed Jul 25, 2024
1 parent d030474 commit b3a992c
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 481 deletions.
12 changes: 6 additions & 6 deletions examples/01_Binary_Precipitation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -45,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -78,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -122,7 +122,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {
"tags": []
},
Expand All @@ -146,7 +146,7 @@
"\tbeta\t0.000e+00\t\t0.0000\t\t0.0000e+00\t5.7737e+03\n",
"\n",
"N\tTime (s)\tSim Time (s)\tTemperature (K)\tMatrix Comp\n",
"3675\t1.8e+06\t\t36.6\t\t723\t\t0.0126\n",
"3675\t1.8e+06\t\t14.3\t\t723\t\t0.0126\n",
"\n",
"\tPhase\tPrec Density (#/m3)\tVolume Frac\tAvg Radius (m)\tDriving Force (J/mol)\n",
"\tbeta\t1.374e+22\t\t1.5504\t\t6.1126e-09\t3.2902e+02\n",
Expand All @@ -171,7 +171,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down
16 changes: 8 additions & 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"\tCU4TI\t0.000e+00\t\t0.0000\t\t0.0000e+00\t1.9660e+03\n",
"\n",
"N\tTime (s)\tSim Time (s)\tTemperature (K)\tMatrix Comp\n",
"4571\t1.0e+05\t\t78.2\t\t623\t\t0.1757\n",
"4571\t1.0e+05\t\t29.3\t\t623\t\t0.1757\n",
"\n",
"\tPhase\tPrec Density (#/m3)\tVolume Frac\tAvg Radius (m)\tDriving Force (J/mol)\n",
"\tCU4TI\t1.455e+23\t\t9.3695\t\t5.1198e-09\t1.2258e+02\n",
Expand All @@ -154,7 +154,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down
22 changes: 11 additions & 11 deletions examples/05_Strength_Modeling.ipynb

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/06_Single_Phase_Diffusion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@
"text": [
"Iteration\tSim Time (h)\tRun time (s)\n",
"0\t\t0.0e+00\t\t0.0\n",
"100\t\t2.9e+01\t\t5.2\n",
"200\t\t5.7e+01\t\t9.8\n",
"300\t\t8.6e+01\t\t13.1\n",
"349\t\t1.0e+02\t\t14.1\n"
"100\t\t2.9e+01\t\t2.8\n",
"200\t\t5.7e+01\t\t5.3\n",
"300\t\t8.6e+01\t\t7.1\n",
"349\t\t1.0e+02\t\t7.6\n"
]
}
],
Expand All @@ -138,7 +138,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand Down
20 changes: 10 additions & 10 deletions examples/07_Homogenization_Model.ipynb

Large diffs are not rendered by default.

38 changes: 11 additions & 27 deletions examples/08_Model_Coupling.ipynb

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/09_Thermodynamics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x2bf515a4ac0>"
"<matplotlib.legend.Legend at 0x1d70c1b50a0>"
]
},
"execution_count": 5,
Expand Down Expand Up @@ -226,7 +226,7 @@
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x2bf55cfadf0>"
"<matplotlib.legend.Legend at 0x1d7104ff880>"
]
},
"execution_count": 6,
Expand Down Expand Up @@ -312,7 +312,7 @@
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x2bf581c5c70>"
"<matplotlib.legend.Legend at 0x1d712e1dc40>"
]
},
"execution_count": 7,
Expand Down Expand Up @@ -403,7 +403,7 @@
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x2bf58482610>"
"<matplotlib.legend.Legend at 0x1d712e1de80>"
]
},
"execution_count": 8,
Expand Down
10 changes: 5 additions & 5 deletions examples/10_Surrogates.ipynb

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions examples/12_Custom_Iterators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"\tbeta\t0.000e+00\t\t0.0000\t\t0.0000e+00\t5.7737e+03\n",
"\n",
"N\tTime (s)\tSim Time (s)\tTemperature (K)\tMatrix Comp\n",
"3831\t1.8e+06\t\t25.9\t\t723\t\t0.0126\n",
"3831\t1.8e+06\t\t5.4\t\t723\t\t0.0126\n",
"\n",
"\tPhase\tPrec Density (#/m3)\tVolume Frac\tAvg Radius (m)\tDriving Force (J/mol)\n",
"\tbeta\t1.395e+22\t\t1.5504\t\t6.0887e-09\t3.2954e+02\n",
Expand Down Expand Up @@ -140,14 +140,6 @@
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\ury3\\OneDrive - LLNL\\Documents\\Projects\\U-C Modeling\\kawin-development\\kawin\\kawin\\precipitation\\KWNBase.py:1162: RuntimeWarning: divide by zero encountered in scalar divide\n",
" return np.exp(-tau / t)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
Expand All @@ -159,7 +151,7 @@
"\tbeta\t0.000e+00\t\t0.0000\t\t0.0000e+00\t5.7737e+03\n",
"\n",
"N\tTime (s)\tSim Time (s)\tTemperature (K)\tMatrix Comp\n",
"3751\t1.8e+06\t\t39.0\t\t723\t\t0.0126\n",
"3751\t1.8e+06\t\t9.1\t\t723\t\t0.0126\n",
"\n",
"\tPhase\tPrec Density (#/m3)\tVolume Frac\tAvg Radius (m)\tDriving Force (J/mol)\n",
"\tbeta\t1.386e+22\t\t1.5505\t\t6.0962e-09\t3.2700e+02\n",
Expand Down Expand Up @@ -188,7 +180,7 @@
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x243f92e8400>"
"<matplotlib.legend.Legend at 0x12d50fdbc10>"
]
},
"execution_count": 5,
Expand Down
35 changes: 10 additions & 25 deletions kawin/diffusion/Homogenization.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,10 @@ def _newEqCalc(self, x, T):
'''
Calculates equilibrium and returns a CompositionSet
'''
eq = self.therm.getEq(x, T, 0, self.phases)
state_variables = np.array([0, 1, 101325, T], dtype=np.float64)
stable_phases = eq.Phase.values.ravel()
phase_amounts = eq.NP.values.ravel()
comp = []
for p in stable_phases:
if p != '':
idx = np.where(stable_phases == p)[0]
cs, misc = self.therm._createCompositionSet(eq, state_variables, p, phase_amounts, idx)
comp.append(cs)

if len(comp) == 0:
comp = None

return self.therm.getLocalEq(x, T, 0, self.phases, comp)
wks = self.therm.getEq(x, T, 0, self.phases)
chemical_potentials = np.squeeze(wks.eq.MU)
composition_sets = wks.get_composition_sets()
return chemical_potentials, composition_sets

def updateCompSets(self, xarray):
'''
Expand Down Expand Up @@ -127,18 +116,14 @@ def updateCompSets(self, xarray):
if self.cache:
hashValue = self._getHash(xarray[:,i], self.T[i])
if hashValue not in self.hashTable:
result, comp = self._newEqCalc(xarray[:,i], self.T[i])
#result, comp = self.therm.getLocalEq(xarray[:,i], self.T, 0, self.phases, self.compSets[i])
self.hashTable[hashValue] = (result, comp, None)
chemical_potentials, comp = self._newEqCalc(xarray[:,i], self.T[i])
self.hashTable[hashValue] = (chemical_potentials, comp, None)
else:
result, comp, _ = self.hashTable[hashValue]
results, self.compSets[i] = copy.copy(result), copy.copy(comp)
chemical_potentials, comp, _ = self.hashTable[hashValue]
chemical_potentials, self.compSets[i] = copy.copy(chemical_potentials), copy.copy(comp)
else:
if self.compSets[i] is None:
results, self.compSets[i] = self._newEqCalc(xarray[:,i], self.T[i])
else:
results, self.compSets[i] = self.therm.getLocalEq(xarray[:,i], self.T[i], 0, self.phases, self.compSets[i])
self.mu[:,i] = results.chemical_potentials[self.unsortIndices]
chemical_potentials, self.compSets[i] = self._newEqCalc(xarray[:,i], self.T[i])
self.mu[:,i] = chemical_potentials[self.unsortIndices]
cs_phases = [cs.phase_record.phase_name for cs in self.compSets[i]]
for p in range(len(cs_phases)):
parray[self._getPhaseIndex(cs_phases[p]), i] = self.compSets[i][p].NP
Expand Down
8 changes: 4 additions & 4 deletions kawin/tests/test_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,18 @@ def test_homogenization_dxdt():
dt = m.getDt(dxdt)

#Index 5
ind5, vals5 = 5, np.array([-1.592463e-9, 1.211067e-9])
ind5, vals5 = 5, np.array([-1.581478e-9, 1.212876e-9])

#Index 10
ind10, vals10 = 10, np.array([-9.751858e-10, 1.702190e-9])
ind10, vals10 = 10, np.array([-9.722631e-10, 1.703447e-9])

#Index 15
ind15, vals15 = 15, np.array([-4.728854e-10, 8.590127e-10])
ind15, vals15 = 15, np.array([-4.720562e-10, 8.600518e-10])

assert_allclose(dxdt[0][:,ind5], vals5, atol=0, rtol=1e-3)
assert_allclose(dxdt[0][:,ind10], vals10, atol=0, rtol=1e-3)
assert_allclose(dxdt[0][:,ind15], vals15, atol=0, rtol=1e-3)
assert_allclose(dt, 61865.352193, rtol=1e-3)
assert_allclose(dt, 62271.050081, rtol=1e-3)



Loading

0 comments on commit b3a992c

Please sign in to comment.