-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhs_oneoff.py
More file actions
executable file
·140 lines (92 loc) · 4.71 KB
/
hs_oneoff.py
File metadata and controls
executable file
·140 lines (92 loc) · 4.71 KB
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
#!/usr/bin/env python3
# This file is part of SunlightDPD - a home for open source software
# related to the dissipative particle dynamics (DPD) simulation
# method.
# Copyright (c) 2009-2017 Unilever UK Central Resources Ltd
# (Registered in England & Wales, Company No 29140; Registered
# Office: Unilever House, Blackfriars, London, EC4P 4BQ, UK).
# SunlightDPD is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# SunlightDPD is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with SunlightDPD. If not, see <http://www.gnu.org/licenses/>.
import argparse
from oz import wizard as w
parser = argparse.ArgumentParser(description='hard spheres one off calculator')
parser.add_argument('--ncomp', action='store', default=1, type=int, help='number of components (species) (default 1)')
parser.add_argument('--ng', action='store', default='65536', help='number of grid points (default 65536)')
parser.add_argument('--deltar', action='store', default=1e-3, type=float, help='grid spacing (default 1e-3)')
parser.add_argument('--alpha', action='store', default=0.2, type=float, help='Picard mixing fraction (default 0.2)')
parser.add_argument('--npic', action='store', default=6, type=int, help='number of Picard steps (default 6)')
parser.add_argument('--nps', action='store', default=6, type=int, help='length of history array (default 6)')
parser.add_argument('--maxsteps', action='store', default=100, type=int, help='number of iterations (default 100)')
parser.add_argument('--sigma', action='store', default=1.0, type=float, help='hard core diameter (default 1.0)')
parser.add_argument('--eta', action='store', default=0.3, type=float, help='packing fraction (default 0.3)')
parser.add_argument('--grcut', action='store', default=15.0, type=float, help='r cut off for g(r) plots (default 15.0)')
parser.add_argument('--skcut', action='store', default=15.0, type=float, help='k cut off for S(k) plots (default 15.0)')
parser.add_argument('--msa', action='store_true', help='use MSA (default HNC)')
parser.add_argument('--dump', action='store_true', help='write out g(r)')
parser.add_argument('--show', action='store_true', help='plot results')
parser.add_argument('--eps', action='store', default=1e-20, type=float, help='floor for log tails (default 1e-20)')
parser.add_argument('--tail', action='store_true', help='plot showing tails of pair functions')
parser.add_argument('--verbose', action='store_true', help='more output')
args = parser.parse_args()
w.ncomp = args.ncomp
w.ng = eval(args.ng.replace('^', '**')) # catch 2^10 etc
w.deltar = args.deltar
w.alpha = args.alpha
w.npic = args.npic
w.nps = args.nps
w.maxsteps = args.maxsteps
w.initialise()
w.sigma = args.sigma
w.hs_potential()
rho = 6.0 * args.eta / (w.pi * w.sigma**3)
for i in range(args.ncomp): w.rho[i] = rho / args.ncomp
eps = 1e-20
if args.verbose:
w.write_params()
w.verbose = True
if args.msa: w.msa_solve()
else: w.hnc_solve()
if w.return_code: exit()
if not args.dump: w.write_thermodynamics()
if args.dump:
for i in range(w.ng-1):
print("%g\t%g\tC" % (w.r[i], w.c[i, 0, 0]))
for i in range(w.ng-1):
print("%g\t%g\tH" % (w.r[i], w.hr[i, 0, 0]))
for i in range(w.ng-1):
print("%g\t%g\tS" % (w.k[i], w.sk[i, 0, 0]))
elif args.show:
import math as m
import matplotlib.pyplot as plt
plt.figure(1)
plt.subplot(2, 2, 1)
plt.title('%s solution, error = %0.1g' % (str(w.closure_name, 'utf-8'), w.error))
imax = int(args.grcut / w.deltar)
plt.plot(w.r[0:imax], 1.0 + w.hr[0:imax, 0, 0], label="$g(r)$")
plt.legend(loc='lower right')
plt.subplot(2, 2, 2)
jmax = int(args.skcut / w.deltak)
plt.plot(w.k[:jmax], w.sk[:jmax, 0, 0], label='$S(k)$')
plt.legend(loc='lower right')
plt.subplot(2, 2, 3)
plt.plot(w.r[0:imax], w.c[0:imax, 0, 0], label="$c(r)$")
plt.legend(loc='lower right')
plt.subplot(2, 2, 4)
if args.tail: # plot log10(r h(r)) versus r
plt.plot(w.r[:],
list(map(lambda x, y: m.log10(args.eps + m.fabs(x*y)), w.hr[:, 0, 0], w.r[:])),
label="$r|h_{11}|$")
plt.legend(loc='upper right')
else:
jmax = int(args.skcut*3 / w.deltak)
plt.plot(w.k[0:jmax], w.ek[0:jmax, 0]+w.ck[0:jmax, 0], label="${\\tilde h}(k)$")
plt.legend(loc='lower right')
plt.show()