/
reciprocal_kprime.py
320 lines (273 loc) · 10.7 KB
/
reciprocal_kprime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
from __future__ import absolute_import
# This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for the Earth and Planetary Sciences
# Copyright (C) 2012 - 2017 by the BurnMan team, released under the GNU
# GPL v2 or later.
import scipy.optimize as opt
from scipy.special import gamma, gammainc
from . import equation_of_state as eos
from ..utils.math import bracket
import warnings
import numpy as np
# Try to import the jit from numba. If it is
# not available, just go with the standard
# python interpreter
try:
from numba import jit
except ImportError:
def jit(fn):
return fn
@jit(nopython=True)
def _delta_PoverK_from_P(PoverK, pressure, K_0, Kprime_0, Kprime_inf):
return PoverK - (pressure / K_0) * np.power(
(1.0 - Kprime_inf * PoverK), Kprime_0 / Kprime_inf
) # eq. 58
@jit(nopython=True)
def _delta_PoverK_from_V(PoverK, V, V_0, K_0, Kprime_0, Kprime_inf):
Kprime_ratio = Kprime_0 / Kprime_inf
return (
np.log(V_0 / V)
+ Kprime_ratio / Kprime_inf * np.log(1.0 - Kprime_inf * PoverK)
+ (Kprime_ratio - 1.0) * PoverK
) # eq. 61
def _upper_incomplete_gamma(z, a):
"""
An implementation of the non-regularised upper incomplete gamma
function. Computed using the relationship with the regularised
lower incomplete gamma function (scipy.special.gammainc).
Uses the recurrence relation wherever z<0.
"""
n = int(-np.floor(z))
if n > 0:
z = z + n
u_gamma = (1.0 - gammainc(z, a)) * gamma(z)
for i in range(n):
z = z - 1.0
u_gamma = (u_gamma - np.power(a, z) * np.exp(-a)) / z
return u_gamma
else:
return (1.0 - gammainc(z, a)) * gamma(z)
def _PoverK_from_P(pressure, params):
"""
Calculates the pressure:bulk modulus ratio
from a given pressure using brentq optimization
"""
args = (
(pressure - params["P_0"]),
params["K_0"],
params["Kprime_0"],
params["Kprime_inf"],
)
return opt.brentq(
_delta_PoverK_from_P,
1.0 / (params["Kprime_inf"] - params["Kprime_0"]) + np.finfo(float).eps,
1.0 / params["Kprime_inf"] - np.finfo(float).eps,
args=args,
)
def _PoverK_from_V(volume, params):
"""
Calculates the pressure:bulk modulus ratio
from a given volume using brentq optimization
"""
args = (
volume,
params["V_0"],
params["K_0"],
params["Kprime_0"],
params["Kprime_inf"],
)
return opt.brentq(
_delta_PoverK_from_V,
1.0 / (params["Kprime_inf"] - params["Kprime_0"]) + np.finfo(float).eps,
1.0 / params["Kprime_inf"] - np.finfo(float).eps,
args=args,
)
def bulk_modulus(pressure, params):
"""
Returns the bulk modulus at a given pressure
"""
PoverK = _PoverK_from_P(pressure, params)
K = params["K_0"] * np.power(
(1.0 - params["Kprime_inf"] * PoverK),
-params["Kprime_0"] / params["Kprime_inf"],
)
return K
def shear_modulus(pressure, params):
"""
Returns the shear modulus at a given pressure
"""
G = (
params["G_0"] / params["K_0"] * bulk_modulus(pressure, params)
- (params["G_0"] / params["K_0"] * params["Kprime_inf"] - params["Gprime_inf"])
* pressure
)
return G # eq. 78
class RKprime(eos.EquationOfState):
"""
Class for the isothermal reciprocal K-prime equation of state
detailed in :cite:`StaceyDavis2004`. This equation of state is
a development of work by :cite:`Keane1954` and :cite:`Stacey2000`,
making use of the fact that :math:`K'` typically varies smoothly
as a function of :math:`P/K`, and is thermodynamically required to
exceed 5/3 at infinite pressure.
It is worth noting that this equation of state rapidly becomes
unstable at negative pressures, so should not be trusted to provide
a good *HT-LP* equation of state using a thermal pressure
formulation. The negative root of :math:`dP/dK`
can be found at :math:`K/P = K'_{\infty} - K'_0`,
which corresponds to a bulk modulus of
:math:`K = K_0 ( 1 - K'_{\infty}/K'_0 )^{K'_0/K'_{\infty}}`
and a volume of
:math:`V = V_0 ( K'_0 / (K'_0 - K'_{\infty}) )^{K'_0/{K'}^2_{\infty}} \exp{(-1/K'_{\infty})}`.
This equation of state has no temperature dependence.
"""
def volume(self, pressure, temperature, params):
"""
Returns volume :math:`[m^3]` as a function of pressure :math:`[Pa]`.
"""
Kprime_ratio = params["Kprime_0"] / params["Kprime_inf"]
PoverK = _PoverK_from_P(pressure, params)
V = params["V_0"] * np.exp(
Kprime_ratio
/ params["Kprime_inf"]
* np.log(1.0 - params["Kprime_inf"] * PoverK)
+ (Kprime_ratio - 1.0) * PoverK
) # Eq. 61
return V
def pressure(self, temperature, volume, params):
"""
Returns pressure :math:`[Pa]` as a function of volume :math:`[m^3]`.
"""
PoverK = _PoverK_from_V(volume, params)
return params["P_0"] + (
params["K_0"]
* PoverK
* np.power(
1.0 - params["Kprime_inf"] * PoverK,
-params["Kprime_0"] / params["Kprime_inf"],
)
)
def isothermal_bulk_modulus(self, pressure, temperature, volume, params):
"""
Returns isothermal bulk modulus :math:`K_T` :math:`[Pa]` as a function of pressure :math:`[Pa]`,
temperature :math:`[K]` and volume :math:`[m^3]`.
"""
return bulk_modulus(pressure, params)
def adiabatic_bulk_modulus(self, pressure, temperature, volume, params):
"""
Returns adiabatic bulk modulus :math:`K_s` of the mineral. :math:`[Pa]`.
"""
return bulk_modulus(pressure, params)
def shear_modulus(self, pressure, temperature, volume, params):
"""
Returns shear modulus :math:`G` of the mineral. :math:`[Pa]`
"""
return shear_modulus(pressure, params)
def entropy(self, pressure, temperature, volume, params):
"""
Returns the molar entropy :math:`\mathcal{S}` of the mineral. :math:`[J/K/mol]`
"""
return 0.0
def _intVdP(self, xi, params):
a = params["Kprime_inf"]
b = (
params["Kprime_0"] / params["Kprime_inf"] / params["Kprime_inf"]
- params["Kprime_0"] / params["Kprime_inf"]
- 1.0
)
c = params["Kprime_0"] - params["Kprime_inf"]
f = params["Kprime_0"] / params["Kprime_inf"] - 1.0
i1 = float(
params["V_0"]
* params["K_0"]
* np.exp(f / a)
* np.power(a, b - 1.0)
/ np.power(f, b + 2.0)
* (
f
* params["Kprime_0"]
* _upper_incomplete_gamma(b + 1.0, f * (1.0 / a - xi))
- a * c * _upper_incomplete_gamma(b + 2.0, f * (1.0 / a - xi))
)
)
return i1
def gibbs_free_energy(self, pressure, temperature, volume, params):
"""
Returns the Gibbs free energy :math:`\mathcal{G}` of the mineral. :math:`[J/mol]`
"""
# G = E0 + int VdP (when S = 0)
K = self.isothermal_bulk_modulus(pressure, temperature, volume, params)
return (
params["E_0"]
+ params["P_0"] * params["V_0"]
+ self._intVdP((pressure - params["P_0"]) / K, params)
- self._intVdP(0.0, params)
)
def molar_internal_energy(self, pressure, temperature, volume, params):
"""
Returns the internal energy :math:`\mathcal{E}` of the mineral. :math:`[J/mol]`
"""
# E = G - PV (+ TS)
return (
self.gibbs_free_energy(pressure, temperature, volume, params)
- pressure * volume
)
def molar_heat_capacity_v(self, pressure, temperature, volume, params):
"""
Since this equation of state does not contain temperature effects, simply return a very large number. :math:`[J/K/mol]`
"""
return 1.0e99
def molar_heat_capacity_p(self, pressure, temperature, volume, params):
"""
Since this equation of state does not contain temperature effects, simply return a very large number. :math:`[J/K/mol]`
"""
return 1.0e99
def thermal_expansivity(self, pressure, temperature, volume, params):
"""
Since this equation of state does not contain temperature effects, simply return zero. :math:`[1/K]`
"""
return 0.0
def grueneisen_parameter(self, pressure, temperature, volume, params):
"""
Since this equation of state does not contain temperature effects, simply return zero. :math:`[unitless]`
"""
return 0.0
def validate_parameters(self, params):
"""
Check for existence and validity of the parameters.
The value for :math:`K'_{\infty}` is thermodynamically bounded
between 5/3 and :math:`K'_0` :cite:`StaceyDavis2004`.
"""
if "E_0" not in params:
params["E_0"] = 0.0
if "P_0" not in params:
params["P_0"] = 0.0
# If G and Gprime_inf are not included this is presumably deliberate,
# as we can model density and bulk modulus just fine without them,
# so just add them to the dictionary as nans
if "G_0" not in params:
params["G_0"] = float("nan")
if "Gprime_inf" not in params:
params["Gprime_inf"] = float("nan")
# Check that all the required keys are in the dictionary
expected_keys = ["V_0", "K_0", "Kprime_0", "Kprime_inf", "G_0", "Gprime_inf"]
for k in expected_keys:
if k not in params:
raise KeyError("params object missing parameter : " + k)
# Finally, check that the values are reasonable.
if params["P_0"] < 0.0:
warnings.warn("Unusual value for P_0", stacklevel=2)
if params["V_0"] < 1.0e-7 or params["V_0"] > 1.0e-3:
warnings.warn("Unusual value for V_0", stacklevel=2)
if params["K_0"] < 1.0e9 or params["K_0"] > 1.0e13:
warnings.warn("Unusual value for K_0", stacklevel=2)
if params["Kprime_0"] < 0.0 or params["Kprime_0"] > 10.0:
warnings.warn("Unusual value for Kprime_0", stacklevel=2)
if (
params["Kprime_inf"] < 5.0 / 3.0
or params["Kprime_inf"] > params["Kprime_0"]
):
warnings.warn("Unusual value for Kprime_inf", stacklevel=2) # eq. 17
if params["G_0"] < 0.0 or params["G_0"] > 1.0e13:
warnings.warn("Unusual value for G_0", stacklevel=2)
if params["Gprime_inf"] < -5.0 or params["Gprime_inf"] > 10.0:
warnings.warn("Unusual value for Gprime_inf", stacklevel=2)