thalfshear-darcy-strain.py - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
(HTM) git clone git://src.adamsgaard.dk/sphere
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
thalfshear-darcy-strain.py (7005B)
---
1 #!/usr/bin/env python
2 import matplotlib
3 matplotlib.use('Agg')
4 matplotlib.rcParams.update({'font.size': 18, 'font.family': 'serif'})
5 matplotlib.rc('text', usetex=True)
6 matplotlib.rcParams['text.latex.preamble']=[r"\usepackage{amsmath}"]
7 import shutil
8
9 import os
10 import numpy
11 import sphere
12 from permeabilitycalculator import *
13 import matplotlib.pyplot as plt
14 from matplotlib.ticker import MaxNLocator
15
16 import seaborn as sns
17 #sns.set(style='ticks', palette='Set2')
18 #sns.set(style='ticks', palette='colorblind')
19 sns.set(style='ticks', palette='Set2')
20 sns.despine() # remove chartjunk
21
22 sigma0_list = [20000.0, 80000.0]
23 #cvals = ['dry', 1.0, 0.1, 0.01]
24 #cvals = ['dry', 3.5e-13, 3.5e-15]
25 cvals = ['dry', 3.5e-13, 3.5e-14, 3.5e-15]
26 #cvals = ['dry', 1.0]
27 #step = 1999
28
29 for sigma0 in sigma0_list:
30
31 sim = sphere.sim('halfshear-sigma0=' + str(sigma0) + '-shear')
32 sim.readfirst(verbose=False)
33
34
35 # particle z positions
36 zpos_p = [[], [], [], []]
37
38 # cell midpoint cell positions
39 zpos_c = [[], [], [], []]
40
41 # particle x displacements
42 xdisp = [[], [], [], []]
43 xdisp_mean = [[], [], [], []]
44
45 s = 0
46 for c in cvals:
47
48 if c == 'dry':
49 fluid = False
50 sid = 'halfshear-sigma0=' + str(sigma0) + '-shear'
51 else:
52 fluid = True
53 sid = 'halfshear-darcy-sigma0=' + str(sigma0) + '-k_c=' + str(c) + \
54 '-mu=1.797e-06-velfac=1.0-shear'
55
56 sim = sphere.sim(sid, fluid=fluid)
57
58 if os.path.isfile('../output/' + sid + '.status.dat'):
59
60 sim.readlast(verbose=False)
61
62 zpos_c[s] = numpy.zeros(sim.num[2]*2)
63 dz = sim.L[2]/(sim.num[2]*2)
64 for i in numpy.arange(sim.num[2]*2):
65 zpos_c[s][i] = i*dz + 0.5*dz
66
67 xdisp[s] = numpy.zeros(sim.np)
68 xdisp_mean[s] = numpy.zeros(sim.num[2]*2)
69
70
71 zpos_p[s][:] = sim.x[:,2]
72
73 xdisp[s][:] = sim.xyzsum[:,0]
74
75 #shear_strain[s] += sim.shearStrain()/nsteps_avg
76
77 # calculate mean values of xdisp and f_pf
78 for iz in numpy.arange(sim.num[2]*2):
79 z_bot = iz*dz
80 z_top = (iz+1)*dz
81 I = numpy.nonzero((zpos_p[s][:] >= z_bot) & (zpos_p[s][:] < z_top))
82 if len(I) > 0:
83 xdisp_mean[s][iz] = numpy.mean(xdisp[s][I])
84
85 # normalize distance
86 max_dist = numpy.nanmax(xdisp_mean[s])
87 xdisp_mean[s] /= max_dist
88
89 else:
90 print(sid + ' not found')
91 s += 1
92
93
94 #fig = plt.figure(figsize=(8,4*(len(steps))+1))
95 #fig = plt.figure(figsize=(8,5*(len(steps))+1))
96 #fig = plt.figure(figsize=(8/2,6/2))
97 fig = plt.figure(figsize=(3.74,3.47)) # 3.14 inch = 80 mm, 3.74 = 95 mm
98 #fig = plt.figure(figsize=(8,6))
99
100 ax = []
101 #linetype = ['-', '--', '-.']
102 #linetype = ['-', '-', '-', '-']
103 linetype = ['-', '--', '-.', ':']
104 #color = ['b','g','c','y']
105 #color = ['k','g','c','y']
106 color = ['y','g','c','k']
107 #color = ['c','m','y','k']
108 for s in numpy.arange(len(cvals)):
109 #for s in numpy.arange(len(cvals)-1, -1, -1):
110
111 ax.append(plt.subplot(111))
112 #ax.append(plt.subplot(len(steps)*100 + 31 + s*3))
113 #ax.append(plt.subplot(len(steps)*100 + 32 + s*3, sharey=ax[s*4+0]))
114 #ax.append(plt.subplot(len(steps)*100 + 33 + s*3, sharey=ax[s*4+0]))
115 #ax.append(ax[s*4+2].twiny())
116
117 if cvals[s] == 'dry':
118 legend = 'dry'
119 elif cvals[s] == 3.5e-13:
120 legend = 'wet, high permeability'
121 elif cvals[s] == 3.5e-14:
122 legend = 'wet, interm.\\ permeability'
123 elif cvals[s] == 3.5e-15:
124 legend = 'wet, low permeability'
125 else:
126 legend = 'wet, $k_c$ = ' + str(cvals[s]) + ' m$^2$'
127
128 #ax[0].plot(xdisp[s], zpos_p[s], ',', color = '#888888')
129 #ax[0].plot(xdisp[s], zpos_p[s], ',', color=color[s], alpha=0.5)
130 ax[0].plot(xdisp_mean[s], zpos_c[s], linetype[s],
131 label=legend)#,
132 #color=color[s],
133 #linewidth=2.0)
134
135 ax[0].set_ylabel('Vertical position $z$ [m]')
136 #ax[0].set_xlabel('$\\boldsymbol{x}^x_\\text{p}$ [m]')
137 ax[0].set_xlabel('Normalized horizontal movement')
138
139 #ax[s*4+0].get_xaxis().set_major_locator(MaxNLocator(nbins=5))
140 #ax[s*4+1].get_xaxis().set_major_locator(MaxNLocator(nbins=5))
141 #ax[s*4+2].get_xaxis().set_major_locator(MaxNLocator(nbins=5))
142
143 #plt.setp(ax[s*4+0].xaxis.get_majorticklabels(), rotation=90)
144 #plt.setp(ax[s*4+1].xaxis.get_majorticklabels(), rotation=90)
145 #plt.setp(ax[s*4+2].xaxis.get_majorticklabels(), rotation=90)
146 #plt.setp(ax[s*4+3].xaxis.get_majorticklabels(), rotation=90)
147
148 #if s == 0:
149 #y = 0.95
150 #if s == 1:
151 #y = 0.55
152
153 #strain_str = 'Shear strain $\\gamma = %.3f$' % (shear_strain[s])
154 #fig.text(0.1, y, strain_str, horizontalalignment='left', fontsize=22)
155 #ax[s*4+0].annotate(strain_str, xytext=(0,1.1), textcoords='figure fraction',
156 #horizontalalignment='left', fontsize=22)
157 #plt.text(0.05, 1.06, strain_str, horizontalalignment='left', fontsize=22,
158 #transform=ax[s*4+0].transAxes)
159 #ax[s*4+0].set_title(strain_str)
160
161 #ax[s*4+0].grid()
162 #ax[s*4+1].grid()
163 #ax[s*4+2].grid()
164 #ax1.legend(loc='lower right', prop={'size':18})
165 #ax2.legend(loc='lower right', prop={'size':18})
166
167 # remove box at top and right
168 ax[0].spines['top'].set_visible(False)
169 ax[0].spines['right'].set_visible(False)
170 # remove ticks at top and right
171 ax[0].get_xaxis().tick_bottom()
172 ax[0].get_yaxis().tick_left()
173 ax[0].get_xaxis().grid(False) # horizontal grid lines
174 #ax[0].get_yaxis().grid(True, linestyle='--', linewidth=0.5) # vertical grid lines
175 ax[0].get_xaxis().grid(True, linestyle=':', linewidth=0.5) # vertical grid lines
176 ax[0].get_yaxis().grid(True, linestyle=':', linewidth=0.5) # vertical grid lines
177
178 # reverse legend order
179 handles, labels = ax[0].get_legend_handles_labels()
180 ax[0].legend(handles[::-1], labels[::-1], loc='best')
181
182 #legend_alpha=0.5
183 #ax[0].legend(loc='lower right', prop={'size':18}, fancybox=True, framealpha=legend_alpha)
184 #ax[0].legend(loc='best', prop={'size':18}, fancybox=True, framealpha=legend_alpha)
185 #ax[0].legend(loc='best')
186 #ax[0].grid()
187 #ax[0].set_xlim([-0.05, 1.01])
188 ax[0].set_xlim([-0.05, 1.05])
189 #ax[0].set_ylim([0.0, 0.47])
190 ax[0].set_ylim([0.20, 0.47])
191 plt.tight_layout()
192 plt.subplots_adjust(wspace = .05)
193 plt.MaxNLocator(nbins=4)
194
195 filename = 'halfshear-darcy-strain.pdf'
196 if sigma0 == 80000.0:
197 filename = 'halfshear-darcy-strain-N80.pdf'
198 plt.savefig(filename)
199 #shutil.copyfile(filename, '/Users/adc/articles/own/2/graphics/' + filename)
200 shutil.copyfile(filename, '/home/adc/articles/own/2/graphics/' + filename)
201 print(filename)