Skip to content

Commit 5f9296a

Browse files
committed
Merge pull request #691 from bobmyhill/refactor_solver
refactor nonlinear solver
2 parents c54a6ff + facb920 commit 5f9296a

File tree

8 files changed

+578
-431
lines changed

8 files changed

+578
-431
lines changed

burnman/classes/solutionmodel.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
import importlib
88
import numpy as np
9+
from ..constants import logish_eps
910
from ..utils.chemistry import process_solution_chemistry
1011
from .. import constants
1112
import warnings
1213
from .material import material_property, cached_property
1314
from dataclasses import make_dataclass
1415

15-
np_eps = np.finfo(float).eps
16-
1716
Interaction = make_dataclass(
1817
"Interaction", ["inds", "expts", "f_r", "m_jr", "f_rs", "m_jrs"]
1918
)
@@ -106,26 +105,26 @@ def _non_ideal_interactions_subreg(p, n_endmembers, Wijk):
106105
return Wint
107106

108107

109-
def logish(x, eps=np_eps):
108+
def logish(x, eps=logish_eps):
110109
"""
111110
2nd order series expansion of log(x) about eps:
112111
log(eps) - sum_k=1^infty (f_eps)^k / k
113112
Prevents infinities at x=0
114113
"""
115-
f_eps = 1.0 - x / eps
116-
mask = x > eps
117-
ln = np.where(x <= eps, np.log(eps) - f_eps - f_eps * f_eps / 2.0, 0.0)
114+
f_eps = 1.0 - x / eps[0]
115+
mask = x > eps[0]
116+
ln = np.where(x <= eps[0], np.log(eps[0]) - f_eps - f_eps * f_eps / 2.0, 0.0)
118117
ln[mask] = np.log(x[mask])
119118
return ln
120119

121120

122-
def inverseish(x, eps=np_eps):
121+
def inverseish(x, eps=logish_eps):
123122
"""
124123
1st order series expansion of 1/x about eps: 2/eps - x/eps/eps
125124
Prevents infinities at x=0
126125
"""
127-
mask = x > eps
128-
oneoverx = np.where(x <= eps, 2.0 / eps - x / eps / eps, 0.0)
126+
mask = x > eps[0]
127+
oneoverx = np.where(x <= eps[0], 2.0 / eps[0] - x / eps[0] / eps[0], 0.0)
129128
oneoverx[mask] = 1.0 / x[mask]
130129
return oneoverx
131130

burnman/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# GPL v2 or later.
44

55
import scipy.constants
6+
import numpy as np
67

78
"""
89
molar gas constant (R) in J mol^-1 K^-1
@@ -42,3 +43,10 @@
4243
1 cm^-1 in J/mol
4344
"""
4445
invcm = 11.9627
46+
47+
48+
"""
49+
Small number for numerical stability
50+
Kept in list form for mutability
51+
"""
52+
logish_eps = [np.finfo(float).eps]

0 commit comments

Comments
 (0)