Skip to content
This repository was archived by the owner on Jul 3, 2025. It is now read-only.

Commit 37e4e6e

Browse files
authored
Merge pull request #34 from sandialabs/2d
2d
2 parents a68f9e6 + 98cbac8 commit 37e4e6e

File tree

12 files changed

+1585
-6
lines changed

12 files changed

+1585
-6
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
**.pyc
44
*dist/
55
*build/
6-
*statmechcrack.egg-info/
6+
**.egg-info/
77
**.coverage
88
*.vscode/

MiscPlotting/silica.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
import matplotlib.pyplot as pl
3+
4+
5+
wn = 1050*100 #1/m, si-o-si stretching frequency, measured from FTIR
6+
b = 5e-10 # approximate lattice spacing
7+
l = 1.55e-10 # Si-O bond length
8+
ws = 7520 # m/s, elastic wave speed
9+
E = 87e9 # modulus C11
10+
udd = 8e-19 #J, Si-O bond energy in water
11+
12+
# set xdd to be a scaling of equilibrium bond length, if xdd=0 there is no Bell term acting
13+
xdd = 0.0*l
14+
k = 1.38e-23 #J/K
15+
T = 293 # K
16+
17+
18+
def velSM(K):
19+
R = K**2/E
20+
f = np.sqrt(R*E*b**3)
21+
22+
omega = ws*wn
23+
24+
v = b*omega/np.pi
25+
v *= np.exp( (f*xdd-udd)/(k*T) )
26+
v *= np.sinh( 0.5*(R*b**2)/(k*T) )
27+
return v
28+
29+
npt = 100
30+
kr = np.linspace(0.1,1.0,npt)
31+
vr = np.zeros(npt)
32+
for i in range(npt):
33+
vr[i] = velSM(kr[i]*1e6)
34+
35+
pl.semilogy(kr,vr,'k-')
36+
pl.show()

markovChain.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from multiprocessing import Pool
2+
import numpy as np
3+
from statmechcrack import CrackQ2D
4+
5+
def Nn(L,W,Nnom,n=0,verbose=False):
6+
if n==0:
7+
return Nnom * np.ones(W, dtype=int)
8+
elif n==1:
9+
pass
10+
11+
12+
def gen_N(L,W,Nnom,verbose=False):
13+
N0 = Nnom * np.ones(W, dtype=int)
14+
N = [N0]
15+
if verbose:
16+
print(N[-1])
17+
for i in range(W):
18+
N1 = Nnom * np.ones(W, dtype=int)
19+
N1[i] = Nnom+1
20+
N.append(N1)
21+
if verbose:
22+
print(N[-1])
23+
24+
for i in range(W):
25+
N1 = Nnom * np.ones(W, dtype=int)
26+
N1[i] = Nnom+2
27+
N.append(N1)
28+
if verbose:
29+
print(N[-1])
30+
31+
for i in range(W-1):
32+
N1 = Nnom * np.ones(W, dtype=int)
33+
N1[i] = Nnom+1
34+
N1[i+1] = Nnom+1
35+
N.append(N1)
36+
if verbose:
37+
print(N[-1])
38+
39+
for i in range(W-2):
40+
N1 = Nnom * np.ones(W, dtype=int)
41+
N1[i] = Nnom+1
42+
N1[i+1] = Nnom+1
43+
N1[i+2] = Nnom+1
44+
N.append(N1)
45+
if verbose:
46+
print(N[-1])
47+
48+
for i in range(W-1):
49+
N1 = Nnom * np.ones(W, dtype=int)
50+
N1[i] = Nnom+1
51+
N1[i+1] = Nnom+2
52+
N.append(N1)
53+
if verbose:
54+
print(N[-1])
55+
56+
for i in range(W-2):
57+
N1 = Nnom * np.ones(W, dtype=int)
58+
N1[i] = Nnom+2
59+
N1[i+1] = Nnom+1
60+
N1[i+2] = Nnom+1
61+
N.append(N1)
62+
if verbose:
63+
print(N[-1])
64+
65+
for i in range(W-2):
66+
N1 = Nnom * np.ones(W, dtype=int)
67+
N1[i] = Nnom+1
68+
N1[i+1] = Nnom+2
69+
N1[i+2] = Nnom+1
70+
N.append(N1)
71+
if verbose:
72+
print(N[-1])
73+
74+
return N
75+
76+
def calc_rates(L,W,N,verbose=False):
77+
model = CrackQ2D(L=L,W=W,N=N)
78+
rates = np.zeros(model.W)
79+
for k in range(model.W):
80+
rates[k] = model.k_isometric(2*np.ones(model.W),k)
81+
if verbose:
82+
print(N)
83+
print(rates)
84+
return [N,rates]
85+
86+
def saveRates(N,rates,fname):
87+
ofile = open(fname,'w')
88+
nN = len(N)
89+
for i in range(nN):
90+
for n in N[i]:
91+
ofile.write('{}\t'.format(n))
92+
ofile.write('\n')
93+
for r in rates[i]:
94+
ofile.write('{}\t'.format(r))
95+
ofile.write('\n')
96+
ofile.close()
97+
98+
if __name__=="__main__":
99+
L = 25
100+
W = 11
101+
Nnom = 7
102+
103+
NAll = gen_N(L,W,Nnom,verbose=True)
104+
nN = len(NAll)
105+
print(nN)
106+
107+
Nout = [[] for i in range(nN)]
108+
rates = [[] for i in range(nN)]
109+
110+
def mapFun(N):
111+
rates = calc_rates(L,W,N,verbose=True)
112+
return rates
113+
114+
nproc = 30
115+
#pool = Pool(processes=nproc)
116+
pool = Pool()
117+
for ind, res in enumerate(pool.imap(mapFun, NAll, chunksize=3)):
118+
Nout[ind] = res[0]
119+
rates[ind] = res[1]
120+
121+
fname = 'L{}W{}.rates'.format(L,W)
122+
saveRates(NAll,rates,fname)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_version():
3636
keywords=['fracture mechanics',
3737
'statistical mechanics',
3838
'thermodynamics'],
39-
install_requires=['matplotlib', 'numpy', 'scipy'],
39+
install_requires=['matplotlib', 'numpy', 'scipy', 'sympy'],
4040
extras_require={
4141
'docs': ['docutils>=0.14,<0.21', 'ipykernel', 'ipython',
4242
'jinja2>=3.0', 'nbsphinx', 'pycodestyle',

statmechcrack/mechanical.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def beta_U_0(self, v, s):
112112
113113
.. math::
114114
\beta U_0(v, \mathbf{s}) =
115-
\sum_{i=1}^{L-1} \frac{\kappa}{2} \left(
116-
s_{i-1} - 2s_i + s_{i+1}
115+
\sum_{i=2}^{L} \frac{\kappa}{2} \left(
116+
s_{i-2} - 2s_{i-1} + s_i
117117
\right)^2,
118118
119119
where :math:`s_0\equiv v`.
@@ -746,7 +746,7 @@ def minimize_beta_U_00(self, v, lambda_):
746746
- (*numpy.ndarray*) -
747747
The minimized nondimensional potential energy.
748748
- (*numpy.ndarray*) -
749-
The corresponding nondimensional end separation.
749+
The corresponding nondimensional end force.
750750
- (*numpy.ndarray*) -
751751
The corresponding nondimensional positions.
752752
@@ -807,6 +807,8 @@ def minimize_beta_U(self, v, transition_state=False):
807807
808808
- (*numpy.ndarray*) -
809809
The minimized nondimensional potential energy.
810+
- (*numpy.ndarray*) -
811+
The corresponding nondimensional force.
810812
- (*numpy.ndarray*) -
811813
The corresponding nondimensional positions.
812814

statmechcrack/q2d/isometric.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
"""
55

6+
import numpy as np
7+
from numpy.linalg import det, inv
8+
69
from .mechanical import CrackQ2DMechanical
710

811

@@ -19,3 +22,35 @@ def __init__(self, **kwargs):
1922
2023
"""
2124
CrackQ2DMechanical.__init__(self, **kwargs)
25+
26+
def k_isometric(self, v, transition_state):
27+
r"""The nondimensional forward reaction rate coefficient
28+
as a function of the nondimensional end separations
29+
in the isometric ensemble.
30+
31+
Args:
32+
v (array_like): The nondimensional end separations.
33+
transition_state (int): The kth transition state.
34+
35+
Returns:
36+
numpy.ndarray: The nondimensional forward reaction rate.
37+
38+
"""
39+
v_ref = np.ones(self.W)
40+
beta_U, _, _, hess = self.minimize_beta_U(v)
41+
beta_U_ref, _, _, hess_ref = self.minimize_beta_U(v_ref)
42+
beta_U_TS, _, _, hess_TS = self.minimize_beta_U(
43+
v, transition_state=transition_state
44+
)
45+
beta_U_TS_ref, _, _, hess_TS_ref = self.minimize_beta_U(
46+
v_ref, transition_state=transition_state
47+
)
48+
scale = self.varepsilon*(self.W*self.L)**(1/3)
49+
return np.exp(
50+
beta_U - beta_U_ref - beta_U_TS + beta_U_TS_ref
51+
)*np.sqrt(
52+
det(hess/scale) /
53+
det(hess_ref/scale) *
54+
det(hess_TS_ref/scale) /
55+
det(hess_TS/scale)
56+
)

statmechcrack/q2d/isotensional.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
"""
55

6+
import numpy as np
7+
from numpy.linalg import det, inv
8+
69
from .isometric import CrackQ2DIsometric
710

811

@@ -19,3 +22,35 @@ def __init__(self, **kwargs):
1922
2023
"""
2124
CrackQ2DIsometric.__init__(self, **kwargs)
25+
26+
def k_isotensional(self, p, transition_state):
27+
r"""The nondimensional forward reaction rate coefficient
28+
as a function of the nondimensional end forces
29+
in the isotensional ensemble.
30+
31+
Args:
32+
p (array_like): The nondimensional end forces.
33+
transition_state (int): The kth transition state.
34+
35+
Returns:
36+
numpy.ndarray: The nondimensional forward reaction rate.
37+
38+
"""
39+
p_ref = np.zeros(self.W)
40+
beta_Pi, _, _, hess = self.minimize_beta_Pi(p)
41+
beta_Pi_ref, _, _, hess_ref = self.minimize_beta_Pi(p_ref)
42+
beta_Pi_TS, _, _, hess_TS = self.minimize_beta_Pi(
43+
p, transition_state=transition_state
44+
)
45+
beta_Pi_TS_ref, _, _, hess_TS_ref = self.minimize_beta_Pi(
46+
p_ref, transition_state=transition_state
47+
)
48+
scale = self.varepsilon*(self.W*self.L)**(1/3)
49+
return np.exp(
50+
beta_Pi - beta_Pi_ref - beta_Pi_TS + beta_Pi_TS_ref
51+
)*np.sqrt(
52+
det(hess/scale) /
53+
det(hess_ref/scale) *
54+
det(hess_TS_ref/scale) /
55+
det(hess_TS/scale)
56+
)

0 commit comments

Comments
 (0)