-
Notifications
You must be signed in to change notification settings - Fork 0
/
energy_1plate.py
executable file
·113 lines (83 loc) · 4.54 KB
/
energy_1plate.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
from packages import *
from numerical_param import *
import selfe_1plate
import selfe_bulk
# free energy from mgrf theory for 1 plate
def grandfe_mgrf_1plate(psi, n_profile, uself_profile,n_bulk, valency,rad_ions, vol_ions, vol_sol, sigma, domain, epsilon_s, epsilon_p):
grandfe = 0.5*psi[0]*sigma
N_exc = np.nonzero(n_profile[:,0])[0][0]
psi = psi[N_exc:]
n_profile = n_profile[N_exc:]
uself_profile = uself_profile[N_exc:]
nodes = len(n_profile)-1
n_bulk_profile = np.multiply(np.ones((nodes, len(valency))), n_bulk)
grandfe_bulk = grandfe_mgrf_bulk(n_bulk_profile,n_bulk, valency,rad_ions, vol_ions,vol_sol, domain, epsilon_s)
utau = np.zeros((nodes+1, len(valency)))
taus, weights = np.polynomial.legendre.leggauss(grandfe_quads)
coords = d3.CartesianCoordinates('z')
dist = d3.Distributor(coords, dtype = np.float64) # No mesh for serial / automatic parallelization
zbasis = d3.Chebyshev(coords['z'], size = len(n_profile), bounds = (0,domain))
z = np.squeeze(dist.local_grids(zbasis))
dz = np.diff(z)
n_local = 0.5 * (n_profile[:-1] + n_profile[1:])
psi_local = 0.5 * (psi[:-1] + psi[1:])
u_local = 0.5 * (uself_profile[:-1] + uself_profile[1:])
vol_local = np.sum(vol_ions * n_local, axis=1)
grandfe = grandfe - 0.5 * np.sum(psi_local * np.dot(valency, n_local.T) * dz)
grandfe = grandfe - np.sum(n_local*dz[:,np.newaxis])
grandfe = grandfe - (1 / vol_sol) * np.sum((1 - vol_local) * dz)
grandfe = grandfe + (1 / vol_sol) * np.sum(np.log(1 - vol_local) * dz)
for k in range(0, len(taus)):
utau = utau + 0.5*weights[k]*selfe_1plate.uself_complete((0.5*taus[k]+0.5)*n_profile,(0.5*taus[k]+0.5)*n_bulk,rad_ions, valency,domain, epsilon_s, epsilon_p)
utau_local = 0.5 * (utau[:-1] + utau[1:])
grandfe = grandfe + np.sum(n_local * utau_local * dz[:, np.newaxis])
grandfe = grandfe - np.sum(n_local * u_local * dz[:, np.newaxis])
return grandfe - grandfe_bulk
# free energy from mgrf theory for bulk solution
def grandfe_mgrf_bulk(n_bulk_profile,n_bulk, valency,rad_ions,vol_ions, vol_sol, domain, epsilon_s):
grandfe = 0
nodes = len(n_bulk_profile)
vol_bulk = sum([n_bulk[i] * vol_ions[i] for i in range(len(vol_ions))])
u_bulk = selfe_bulk.uselfb_numerical(n_bulk_profile, n_bulk, rad_ions, valency, domain, epsilon_s)
utau_bulk = np.zeros_like(u_bulk)
taus, weights = np.polynomial.legendre.leggauss(grandfe_quads)
coords = d3.CartesianCoordinates('z')
dist = d3.Distributor(coords, dtype = np.float64)
zbasis = d3.Chebyshev(coords['z'], size = nodes+1, bounds = (0,domain))
z = np.squeeze(dist.local_grids(zbasis))
dz =np.diff(z)
grandfe = grandfe - np.sum(n_bulk * dz[:, np.newaxis])
grandfe = grandfe - np.sum(dz*(1/vol_sol)*(1 - vol_bulk))
grandfe = grandfe + np.sum(dz*(1/vol_sol)*np.log(1-vol_bulk))
for k in range(0, len(taus)):
utau_bulk = utau_bulk + 0.5 * weights[k] * selfe_bulk.uselfb_numerical((0.5 * taus[k] + 0.5) * n_bulk_profile,(0.5*taus[k]+0.5)*n_bulk, rad_ions, valency,domain, epsilon_s)
grandfe = grandfe + np.sum(n_bulk * utau_bulk * dz[:,np.newaxis])
grandfe = grandfe - np.sum(n_bulk * u_bulk * dz[:,np.newaxis])
return grandfe
# free energy from pb theory for 1 plate
def grandfe_pb_1plate(psi, n_profile,n_bulk, valency, sigma, domain):
grandfe = 0.5*psi[0]*sigma
nodes = len(n_profile)-1
n_bulk_profile = np.multiply(np.ones((nodes, len(valency))), n_bulk)
grandfe_bulk = grandfe_pb_bulk(n_bulk_profile,n_bulk, valency, domain)
coords = d3.CartesianCoordinates('z')
dist = d3.Distributor(coords, dtype = np.float64) # No mesh for serial / automatic parallelization
zbasis = d3.Chebyshev(coords['z'], size = len(n_profile), bounds = (0,domain))
z = np.squeeze(dist.local_grids(zbasis))
dz =np.diff(z)
n_local = 0.5 * (n_profile[:-1] + n_profile[1:])
psi_local = 0.5 * (psi[:-1] + psi[1:])
grandfe = grandfe - 0.5 * np.sum(psi_local * np.dot(valency, n_local.T) * dz)
grandfe = grandfe - np.sum(n_local*dz[:,np.newaxis])
return grandfe - grandfe_bulk
# free energy from pb theory for bulk solution
def grandfe_pb_bulk(n_bulk_profile,n_bulk, valency, domain):
grandfe = 0
nodes = len(n_bulk_profile)
coords = d3.CartesianCoordinates('z')
dist = d3.Distributor(coords, dtype = np.float64)
zbasis = d3.Chebyshev(coords['z'], size = nodes+1, bounds = (0,domain))
z = np.squeeze(dist.local_grids(zbasis))
dz =np.diff(z)
grandfe = grandfe - np.sum(n_bulk[:, np.newaxis] * dz)
return grandfe