def print_strengths(sid, fluid=False, c=0.0): sim = sphere.sim(sid, fluid=fluid) sim.readfirst(verbose=False) sim.visualize('shear') friction = sim.tau[1:] / sim.sigma_eff[1:] tau_peak = numpy.max(friction) tau_ultimate = numpy.average(friction[-500:-1]) if fluid: print('%.2f \t %.2f \t %.2f' % (c, tau_peak, tau_ultimate)) else: print('dry \t %.2f \t %.2f' % (tau_peak, tau_ultimate)) return friction
def print_strengths(sid, fluid=False, c=0.0): sim = sphere.sim(sid, fluid=fluid) sim.readfirst(verbose=False) sim.visualize('shear') friction = sim.tau[1:]/sim.sigma_eff[1:] tau_peak = numpy.max(friction) tau_ultimate = numpy.average(friction[-500:-1]) if fluid: print('%.2f \t %.2f \t %.2f' % (c, tau_peak, tau_ultimate)) else: print('dry \t %.2f \t %.2f' % (tau_peak, tau_ultimate)) return friction
#!/usr/bin/env python import sphere import numpy for sigma0 in [80.0e3, 120.0e3]: sim = sphere.sim('diffusivity-relax') sim.readlast() sim.sid = 'diffusivity-sigma0=' + str(sigma0) # Checkerboard colors x_min = numpy.min(sim.x[:, 0]) x_max = numpy.max(sim.x[:, 0]) y_min = numpy.min(sim.x[:, 1]) y_max = numpy.max(sim.x[:, 1]) z_min = numpy.min(sim.x[:, 2]) z_max = numpy.max(sim.x[:, 2]) color_nx = 6 color_ny = 6 color_nz = 6 for i in range(sim.np): ix = numpy.floor((sim.x[i, 0] - x_min) / (x_max / color_nx)) iy = numpy.floor((sim.x[i, 1] - y_min) / (y_max / color_ny)) iz = numpy.floor((sim.x[i, 2] - z_min) / (z_max / color_nz)) sim.color[i] = (-1)**ix + (-1)**iy + (-1)**iz sim.cleanup() sim.adjustUpperWall() sim.zeroKinematics() sim.consolidate(normal_stress=sigma0)
#!/usr/bin/env python from pytestutils import * import sphere import sys import numpy import matplotlib.pyplot as plt print('### DEM/CFD tests - Dirichlet/Neumann BCs and a single particle ###') print('# No gravity') orig = sphere.sim('dem_cfd', fluid = True) cleanup(orig) orig.defaultParams(mu_s = 0.4, mu_d = 0.4) orig.addParticle([0.2, 0.2, 0.6], 0.05) orig.defineWorldBoundaries([0.4, 0.4, 1.0], dx = 0.1) orig.initFluid(mu = 8.9e-4) orig.initTemporal(total = 0.5, file_dt = 0.05, dt = 1.0e-4) py = sphere.sim(sid = orig.sid, fluid = True) orig.bc_bot[0] = 1 # No-flow BC at bottom (Neumann) #orig.run(dry=True) orig.run(verbose=False) #orig.writeVTKall() py.readlast(verbose = False) ones = numpy.ones((orig.num)) zeros = numpy.zeros((orig.num[0], orig.num[1], orig.num[2], 3)) compareNumpyArraysClose(ones, py.p_f, 'Conservation of pressure:', tolerance = 1.0e-1) compareNumpyArraysClose([0,0,0], py.vel[0], 'Particle velocity:\t', tolerance = 1.0e-5) compareNumpyArraysClose(zeros, py.v_f, 'Fluid velocities:\t',
#!/usr/bin/env python import sphere import numpy for dp in [1.0e3, 2.0e3]: # Read initial configuration sim = sphere.sim('diffusivity-relax') sim.readlast() sim.sid = 'permeability-dp=' + str(dp) sim.cleanup() sim.g[2] = 0.0 sim.nw[0] = 0 sim.initGrid() sim.zeroKinematics() sim.initFluid(mu = 17.87e-4, p = 1.0e5, hydrostatic=True) # Initialize to linear hydraulic gradient p_bottom = 10.0 p_top = p_bottom + dp dz = sim.L[2]/sim.num[2] for iz in range(sim.num[2]-1): #z = dz*iz + 0.5*dz # cell-center z-coordinate z = dz*iz sim.p_f[:,:,iz] = p_bottom + dp/sim.L[2] * z sim.setFluidTopFixedPressure() sim.setFluidBottomFixedPressure() sim.p_f[:,:,-1] = p_top
for c in numpy.arange(0, len(k_c_vals)): k_c = k_c_vals[c] if k_c == 'dry': sid = 'halfshear-sigma0=' + str(sigma0) + '-shear' fluid = False else: sid = 'halfshear-darcy-sigma0=' + str(sigma0) + '-k_c=' + str(k_c) + \ '-mu=' + str(mu_f) + '-velfac=' + str(velfac) + '-shear' fluid = True #sid = 'halfshear-sigma0=' + str(sigma0) + '-c_v=' + str(c_v) +\ #'-c_a=0.0-velfac=1.0-shear' if os.path.isfile('../output/' + sid + '.status.dat'): sim = sphere.sim(sid, fluid=fluid) n = sim.status() #n = 20 shear_strain[c] = numpy.zeros(n) friction[c] = numpy.zeros_like(shear_strain[c]) dilation[c] = numpy.zeros_like(shear_strain[c]) # fluid pressures and particle forces if fluid: p_mean[c] = numpy.zeros_like(shear_strain[c]) p_min[c] = numpy.zeros_like(shear_strain[c]) p_max[c] = numpy.zeros_like(shear_strain[c]) if contact_forces: f_n_mean[c] = numpy.zeros_like(shear_strain[c]) f_n_max[c] = numpy.zeros_like(shear_strain[c])
i = 0 for sid in sids: if os.path.isfile('../output/' + sid + '.status.dat'): pc = PermeabilityCalc(sid, plot_evolution=False, print_results=False, verbose=False) K[c][i] = pc.conductivity() pc.findPressureGradient() pc.findCrossSectionalFlux() dpdz[c][i] = pc.dPdL[2] Q[c][i] = pc.Q[2] pc.findMeanPorosity() #pc.plotEvolution() phi_bar[c][i] = pc.phi_bar sim = sphere.sim(sid, fluid=True) sim.readlast(verbose=False) Re[c][i] = numpy.mean(sim.ReynoldsNumber()) #sim.writeVTKall() # find magnitude of fluid pressure force and total interaction force ''' fp_magn = numpy.empty(sim.np) fsum_magn = numpy.empty(sim.np) for i in numpy.arange(sim.np): fp_magn[i] = sim.f_p[i,:].dot(sim.f_p[i,:]) fsum_magn[i] = sim.f_sum[i,:].dot(sim.f_sum[i,:]) fp_fsum[c][i] = numpy.mean(fp_magn/fsum_magn) # interaction forces not written in these old output files!
sns.set(style='ticks', palette='Set2') sns.despine() # remove chartjunk sigma0_list = [20000.0, 80000.0] #cvals = ['dry', 1.0, 0.1, 0.01] #cvals = ['dry', 3.5e-13, 3.5e-15] #cvals = ['dry', 3.5e-13, 3.5e-14, 3.5e-15] #cvals = ['dry', 3.5e-13, 3.5e-14, 3.5e-15] #cvals = ['dry', 1.0] c = 3.5e-15 muvals = ['dry', 1.797e-08, 1.797e-07, 1.797e-06] #step = 1999 for sigma0 in sigma0_list: sim = sphere.sim('halfshear-sigma0=' + str(sigma0) + '-shear') sim.readfirst(verbose=False) # particle z positions zpos_p = [[], [], [], []] # cell midpoint cell positions zpos_c = [[], [], [], []] # particle x displacements xdisp = [[], [], [], []] xdisp_mean = [[], [], [], []] s = 0 for mu in muvals:
# Fluid density rho_f = 1000.0 # Gravitational acceleration g = 10.0 # Number of particles np = 1e4 ### INITIALIZATION ### # New class # init = sphere.sim(np = np, nd = 3, nw = 0, sid = sim_id + "-init") init = sphere.sim(np=np, nd=3, nw=0, sid="creep1-init") # Uniform radii from 0.8 cm to 1.2 cm init.generateRadii(psd="uni", mean=0.005, variance=0.001) # Use default params init.defaultParams(gamma_n=100.0, mu_s=0.6, mu_d=0.6) init.setYoungsModulus(1e8) # Add gravity init.g[2] = -g # Periodic x and y boundaries init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size)
#!/usr/bin/env python from pytestutils import * import sphere import sys import numpy import matplotlib.pyplot as plt print('### CFD tests - Dirichlet/Neumann BCs ###') print('''# Neumann bottom, Dirichlet top BC. # No gravity, no pressure gradients => no flow''') orig = sphere.sim("neumann", fluid = True) cleanup(orig) orig.defaultParams(mu_s = 0.4, mu_d = 0.4) orig.defineWorldBoundaries([0.4, 0.4, 1], dx = 0.1) orig.initFluid(mu = 8.9e-4) #orig.initFluid(mu = 0.0) orig.initTemporal(total = 0.05, file_dt = 0.005, dt = 1.0e-4) orig.c_v[0] = 0.1 #orig.c_phi[0] = 0.1 py = sphere.sim(sid = orig.sid, fluid = True) orig.bc_bot[0] = 1 # No-flow BC at bottom (Neumann) #orig.run(dry=True) orig.run(verbose=False) #orig.run(device=2) #orig.writeVTKall() py.readlast(verbose = False) zeros = numpy.zeros((orig.num)) py.readlast(verbose = False) compareNumpyArraysClose(zeros, py.p_f, "Conservation of pressure:",
# Import sphere functionality import sphere initialization = True plots = True # CUDA device to use device = 0 # Number of particles np = 1e4 # Common simulation id sim_id = 'init-1e4' init = sphere.sim(np=np, nd=3, nw=0, sid=sim_id) # Save radii init.generateRadii(mean=0.01) # Use default params init.defaultParams(gamma_n=100.0, mu_s=0.6, mu_d=0.6) init.setStiffnessNormal(1.16e7) init.setStiffnessTangential(1.16e7) # Add gravity init.g[2] = -9.81 # Periodic x and y boundaries init.periodicBoundariesXY()
#!/usr/bin/env python from pytestutils import * import sphere #### Input/output tests #### print("### Fluid input/output tests ###") # Generate data in python orig = sphere.sim(np=100, sid="test-initgrid-fluid", fluid=True) orig.generateRadii(histogram=False, radius_mean=1.0) orig.defaultParams() orig.initRandomGridPos() orig.initFluid() orig.initTemporal(current=0.0, total=0.0) orig.time_total=2.0*orig.time_dt orig.time_file_dt = orig.time_dt orig.writebin(verbose=False) # Test Python IO routines py = sphere.sim(fluid=True) py.readbin("../input/" + orig.sid + ".bin", verbose=False) compare(orig, py, "Python IO:") # Test C++ IO routines orig.run() #orig.run(dry=True) #orig.run(verbose=True, hideinputfile=False, cudamemcheck=True) cpp = sphere.sim(fluid=True) cpp.readbin("../output/" + orig.sid + ".output00000.bin", verbose=False) compare(orig, cpp, "C++ IO: ")
#!/usr/bin/env python ''' Validate the implemented contact models by observing the behavior of two particles. ''' import sphere import numpy import pytestutils ### Particle-particle interaction ############################################## ## Linear elastic collisions # Normal impact: Check for conservation of momentum (sum(v_i*m_i)) orig = sphere.sim(np=2, sid='contactmodeltest') after = sphere.sim(np=2, sid='contactmodeltest') sphere.cleanup(orig) #orig.radius[:] = [1.0, 2.0] orig.radius[:] = [1.0, 1.0] orig.x[0,:] = [5.0, 5.0, 2.0] orig.x[1,:] = [5.0, 5.0, 4.05] orig.setYoungsModulus(7.0e9) v_orig = 1 orig.vel[0,2] = v_orig orig.defineWorldBoundaries(L=[10,10,10]) orig.initTemporal(total = 0.1, file_dt = 0.01) orig.run(dry=True) orig.run(verbose=False) after.readlast(verbose=False)
#!/usr/bin/env python import sphere from pytestutils import * sim = sphere.sim('fluid_particle_interaction', fluid=True) sim.cleanup() sim.defineWorldBoundaries([1.0, 1.0, 1.0], dx=0.1) sim.initFluid() sim.rho[0] = 1000.0 # particle density = fluid density sim.setDEMstepsPerCFDstep(100) # No gravity, pressure gradient enforced by Dirichlet boundaries. # The particle should be sucked towards the low pressure print('# Test 1: Test pressure gradient force') sim.p_f[:, :, 0] = 10.0 sim.p_f[:, :, -1] = 1.0 sim.addParticle([0.5, 0.5, 0.5], 0.05) sim.initTemporal(total=0.01, file_dt=0.001) sim.run(verbose=False) #sim.run(dry=True) #sim.run(cudamemcheck=True) #sim.writeVTKall() sim.readlast() test(sim.vel[0, 2] > 0.0, 'Particle velocity:') # Sidewards gravity, homogenous pressure, Neumann boundaries. # Fluid should flow towards +x and drag particles in the same direction print('# Test 2: Test fluid drag force')
### EXPERIMENT SETUP ### initialization = True collapse = True rendering = True plots = True # Number of particles np = 1e4 # Common simulation id sim_id = 'collapse' ### INITIALIZATION ### # New class init = sphere.sim(np=np, nd=3, nw=0, sid=sim_id + '-init') # Set radii init.generateRadii(mean=0.1) # Use default params init.defaultParams( k_n=1.0e6, k_t=1.0e6, # normal and tangential stiffnesses gamma_n=100.0, gamma_t=100.0, # normal and tangential viscosities mu_s=0.3, mu_d=0.3) # static and dynamic frictions # Initialize positions in random grid (also sets world size) hcells = np**(1.0 / 3.0)
def rateStatePlot(sid): matplotlib.rcParams.update({'font.size': 7, 'font.family': 'sans-serif'}) matplotlib.rc('text', usetex=True) matplotlib.rcParams['text.latex.preamble'] = [r"\usepackage{amsmath}"] rasterized = True # rasterize colored areas (pcolormesh and colorbar) # izfactor = 4 # factor for vertical discretization in xvel izfactor = 1 # factor for vertical discretization in poros ############# # DATA READ # ############# sim = sphere.sim(sid, fluid=False) sim.readfirst() # nsteps = 2 # nsteps = 10 # nsteps = 400 nsteps = sim.status() t = numpy.empty(nsteps) # Stress, pressure and friction sigma_def = numpy.empty_like(t) sigma_eff = numpy.empty_like(t) tau_def = numpy.empty_like(t) tau_eff = numpy.empty_like(t) p_f_bar = numpy.empty_like(t) p_f_top = numpy.empty_like(t) mu = numpy.empty_like(t) # shear friction # shear velocity plot v = numpy.empty_like(t) # velocity I = numpy.empty_like(t) # inertia number # displacement and mean porosity plot xdisp = numpy.empty_like(t) phi_bar = numpy.empty_like(t) # mean horizontal porosity plot poros = numpy.empty((sim.num[2], nsteps)) xvel = numpy.zeros((sim.num[2]*izfactor, nsteps)) zpos_c = numpy.empty(sim.num[2]*izfactor) dz = sim.L[2]/(sim.num[2]*izfactor) for i in numpy.arange(sim.num[2]*izfactor): zpos_c[i] = i*dz + 0.5*dz # Contact statistics plot n = numpy.empty(nsteps) coordinationnumber = numpy.empty(nsteps) nkept = numpy.empty(nsteps) for i in numpy.arange(nsteps): sim.readstep(i+1, verbose=verbose) # use step 1 to n t[i] = sim.currentTime() sigma_def[i] = sim.currentNormalStress('defined') sigma_eff[i] = sim.currentNormalStress('effective') tau_def[i] = sim.shearStress('defined') tau_eff[i] = sim.shearStress('effective') mu[i] = tau_eff[i]/sigma_eff[i] #mu[i] = tau_eff[i]/sigma_def[i] I[i] = sim.inertiaParameterPlanarShear() v[i] = sim.shearVelocity() xdisp[i] = sim.shearDisplacement() #poros[:, i] = numpy.average(numpy.average(sim.phi, axis=0), axis=0) # calculate mean values of xvel dz = sim.L[2]/(sim.num[2]*izfactor) for iz in numpy.arange(sim.num[2]*izfactor): z_bot = iz*dz z_top = (iz+1)*dz idx = numpy.nonzero((sim.x[:, 2] >= z_bot) & (sim.x[:, 2] < z_top)) #import ipdb; ipdb.set_trace() if idx[0].size > 0: # xvel[iz,i] = numpy.mean(numpy.abs(sim.vel[I,0])) # xvel[iz, i] = numpy.mean(sim.vel[idx, 0]) xvel[iz, i] = numpy.mean(sim.vel[idx, 0])/sim.shearVelocity() loaded_contacts = 0 if calculateforcechains: if i > 0 and calculateforcechainhistory: loaded_contacts_prev = numpy.copy(loaded_contacts) pairs_prev = numpy.copy(sim.pairs) loaded_contacts = sim.findLoadedContacts( threshold=sim.currentNormalStress()*2.) # sim.currentNormalStress()/1000.) n[i] = numpy.size(loaded_contacts) sim.findCoordinationNumber() coordinationnumber[i] = sim.findMeanCoordinationNumber() if calculateforcechainhistory: nfound = 0 if i > 0: for a in loaded_contacts[0]: for b in loaded_contacts_prev[0]: if (sim.pairs[:, a] == pairs_prev[:, b]).all(): nfound += 1 nkept[i] = nfound print nfound print coordinationnumber[i] if calculateforcechains: numpy.savetxt(sid + '-fc.txt', (n, nkept, coordinationnumber)) else: if plotforcechains: n, nkept, coordinationnumber = numpy.loadtxt(sid + '-fc.txt') # Transform time from model time to real time [s] #t = t/t_DEM_to_t_real # integrate velocities to displacement along x (xdispint) # Taylor two term expansion xdispint = numpy.zeros_like(t) v_limit = 2.78e-3 # 1 m/hour (WIP) dt = (t[1] - t[0]) dt2 = dt*2. for i in numpy.arange(t.size): if i > 0 and i < t.size-1: acc = (numpy.min([v[i+1], v_limit]) - numpy.min([v[i-1], v_limit]))/dt2 xdispint[i] = xdispint[i-1] +\ numpy.min([v[i], v_limit])*dt + 0.5*acc*dt**2 elif i == t.size-1: xdispint[i] = xdispint[i-1] + numpy.min([v[i], v_limit])*dt ############ # PLOTTING # ############ bbox_x = 0.03 bbox_y = 0.96 verticalalignment = 'top' horizontalalignment = 'left' fontweight = 'bold' bbox = {'facecolor': 'white', 'alpha': 1.0, 'pad': 3} # Time in days #t = t/(60.*60.*24.) nplots = 4 fig = plt.figure(figsize=[3.5, 8.0/4.0*nplots]) # ax1: v, ax2: I ax1 = plt.subplot(nplots, 1, 1) lns0 = ax1.plot(t, v, '-k', label="$v$", linewidth=linewidth) # lns1 = ax1.plot(t, sigma_eff/1000., '-k', label="$\\sigma'$") # lns2 = ax1.plot(t, tau_def/1000., '-r', label="$\\tau$") # ns2 = ax1.plot(t, tau_def/1000., '-r') #lns3 = ax1.plot(t, tau_eff/1000., '-r', label="$\\tau'$", linewidth=linewidth) ax1.set_ylabel('Shear velocity $v$ [ms$^{-1}$]') ax2 = ax1.twinx() ax2color = 'blue' # lns4 = ax2.plot(t, p_f_top/1000.0 + 80.0, '-', # color=ax2color, # label='$p_\\text{f}^\\text{forcing}$') # lns5 = ax2.semilogy(t, I, ':', lns5 = ax2.semilogy(t, I, '--', color=ax2color, label='$I$', linewidth=linewidth) ax2.set_ylabel('Inertia number $I$ [-]') ax2.yaxis.label.set_color(ax2color) for tl in ax2.get_yticklabels(): tl.set_color(ax2color) #ax2.legend(loc='upper right') #lns = lns0+lns1+lns2+lns3+lns4+lns5 #lns = lns0+lns1+lns2+lns3+lns5 #lns = lns1+lns3+lns5 #lns = lns0+lns3+lns5 lns = lns0+lns5 labs = [l.get_label() for l in lns] # ax2.legend(lns, labs, loc='upper right', ncol=3, # fancybox=True, framealpha=legend_alpha) #ax1.set_ylim([-30, 200]) #ax2.set_ylim([-115, 125]) # ax1.text(bbox_x, bbox_y, 'A', ax1.text(bbox_x, bbox_y, 'a', horizontalalignment=horizontalalignment, verticalalignment=verticalalignment, fontweight=fontweight, bbox=bbox, transform=ax1.transAxes) # ax3: mu, ax4: unused ax3 = plt.subplot(nplots, 1, 2, sharex=ax1) #ax3.semilogy(t, mu, 'k', linewidth=linewidth) alpha=1.0 if smooth_friction: alpha=0.5 ax3.plot(t, mu, 'k', alpha=alpha, linewidth=linewidth) if smooth_friction: # smoothed ax3.plot(t, smooth(mu, smooth_window), linewidth=2) # label='', linewidth=1, # alpha=alpha, color=color[c]) ax3.set_ylabel('Bulk friction $\\mu = \\tau\'/N\'$ [-]') #ax3.set_ylabel('Bulk friction $\\mu = \\tau\'/N$ [-]') # ax3.text(bbox_x, bbox_y, 'B', ax3.text(bbox_x, bbox_y, 'b', horizontalalignment=horizontalalignment, verticalalignment=verticalalignment, fontweight=fontweight, bbox=bbox, transform=ax3.transAxes) # ax7: n, ax8: unused ax7 = plt.subplot(nplots, 1, 3, sharex=ax1) if plotforcechains: ax7.plot(t[:n.size], coordinationnumber, 'k', linewidth=linewidth) ax7.set_ylabel('Coordination number $\\bar{n}$ [-]') #ax7.semilogy(t, n - nkept, 'b', label='$\Delta n_\\text{heavy}$') #ax7.set_ylim([1.0e1, 2.0e4]) #ax7.set_ylim([-0.2, 9.8]) ax7.set_ylim([-0.2, 5.2]) # ax7.text(bbox_x, bbox_y, 'D', ax7.text(bbox_x, bbox_y, 'c', horizontalalignment=horizontalalignment, verticalalignment=verticalalignment, fontweight=fontweight, bbox=bbox, transform=ax7.transAxes) # ax9: porosity or xvel, ax10: unused #ax9 = plt.subplot(nplots, 1, 5, sharex=ax1) ax9 = plt.subplot(nplots, 1, 4, sharex=ax1) #poros_min = 0.375 #poros_max = 0.45 poros[:, 0] = poros[:, 2] # remove erroneous porosity increase #cmap = matplotlib.cm.get_cmap('Blues_r') cmap = matplotlib.cm.get_cmap('afmhot') # im9 = ax9.pcolormesh(t, zpos_c, poros, #zpos_c = zpos_c[:-1] xvel = xvel[:-1] # xvel[xvel < 0.0] = 0.0 # ignore negative velocities # im9 = ax9.pcolormesh(t, zpos_c, poros, im9 = ax9.pcolormesh(t, zpos_c, xvel, cmap=cmap, #vmin=poros_min, vmax=poros_max, #norm=matplotlib.colors.LogNorm(vmin=1.0e-8, vmax=xvel.max()), shading='goraud', rasterized=rasterized) ax9.set_ylim([zpos_c[0], sim.w_x[0]]) ax9.set_ylabel('Vertical position $z$ [m]') cbaxes = fig.add_axes([0.32, 0.1, 0.4, 0.01]) # x,y,w,h # ax9.add_patch(matplotlib.patches.Rectangle( # (3.0, 0.04), # x,y # 15., # dx # .15, # dy # fill=True, # linewidth=1, # facecolor='white')) # ax9.add_patch(matplotlib.patches.Rectangle( # (1.5, 0.04), # x,y # 7., # dx # .15, # dy # fill=True, # linewidth=1, # facecolor='white', # alpha=legend_alpha)) cb9 = plt.colorbar(im9, cax=cbaxes, #ticks=[poros_min, poros_min + 0.5*(poros_max-poros_min), poros_max], #ticks=[xvel.min(), xvel.min() + 0.5*(xvel.max()-xvel.min()), xvel.max()], orientation='horizontal', # extend='min', cmap=cmap) # cmap.set_under([8./255., 48./255., 107./255.]) # for poros # cmap.set_under([1.0e-3, 1.0e-3, 1.0e-3]) # for xvel # cb9.outline.set_color('w') cb9.outline.set_edgecolor('w') from matplotlib import ticker tick_locator = ticker.MaxNLocator(nbins=4) cb9.locator = tick_locator cb9.update_ticks() #cb9.set_label('Mean horizontal porosity [-]') cb9.set_label('Norm. avg. horiz. vel. [-]', color='w') ''' ax9.text(0.5, 0.4, 'Mean horizontal porosity [-]\\\\', horizontalalignment='center', verticalalignment='center', bbox={'facecolor':'white', 'alpha':1.0, 'pad':3}) ''' cb9.solids.set_rasterized(rasterized) # change text color of colorbar to white #axes_obj = plt.getp(im9, 'axes') #plt.setp(plt.getp(axes_obj, 'yticklabels'), color='w') #plt.setp(plt.getp(axes_obj, 'xticklabels'), color='w') #plt.setp(plt.getp(cb9.ax.axes, 'yticklabels'), color='w') cb9.ax.yaxis.set_tick_params(color='w') # cb9.yaxis.label.set_color(ax2color) for tl in cb9.ax.get_xticklabels(): tl.set_color('w') cb9.ax.yaxis.set_tick_params(color='w') # ax9.text(bbox_x, bbox_y, 'E', ax9.text(bbox_x, bbox_y, 'd', horizontalalignment=horizontalalignment, verticalalignment=verticalalignment, fontweight=fontweight, bbox=bbox, transform=ax9.transAxes) plt.setp(ax1.get_xticklabels(), visible=False) #plt.setp(ax2.get_xticklabels(), visible=False) plt.setp(ax3.get_xticklabels(), visible=False) #plt.setp(ax4.get_xticklabels(), visible=False) #plt.setp(ax5.get_xticklabels(), visible=False) #plt.setp(ax6.get_xticklabels(), visible=False) plt.setp(ax7.get_xticklabels(), visible=False) #plt.setp(ax8.get_xticklabels(), visible=False) ax1.set_xlim([numpy.min(t), numpy.max(t)]) #ax2.set_ylim([1e-5, 1e-3]) ax3.set_ylim([-0.2, 1.2]) ax9.set_xlabel('Time [s]') fig.tight_layout() plt.subplots_adjust(hspace=0.05) filename = sid + '-combined.' + outformat plt.savefig(filename) plt.close() #shutil.copyfile(filename, '/home/adc/articles/own/3/graphics/' + filename) print(filename)
#!/usr/bin/env python from pytestutils import * import sphere #import sys import numpy #import matplotlib.pyplot as plt print("### CFD tests - Dirichlet BCs ###") # Iteration and conservation of mass test # No gravity, no pressure gradients => no flow print("# No forcing") orig = sphere.sim(np = 0, nd = 3, nw = 0, sid = "cfdtest", fluid = True) cleanup(orig) orig.defaultParams() #orig.defineWorldBoundaries([1.0,1.0,1.0], dx=0.1) orig.defineWorldBoundaries([0.4,0.3,0.4], dx=0.1) orig.initFluid(cfd_solver = 1) #orig.initFluid(mu = 8.9e-4) orig.initTemporal(total = 0.2, file_dt = 0.01, dt = 1.0e-7) #orig.g[2] = -10.0 orig.time_file_dt = orig.time_dt*0.99 orig.time_total = orig.time_dt*10 #orig.run(dry=True) py = sphere.sim(sid = orig.sid, fluid = True) orig.run(verbose=False) #orig.run(verbose=True) zeros = numpy.zeros((orig.num)) py.readlast(verbose = False)
#!/usr/bin/env python import sphere import numpy import sys # launch with: # $ python consolidation-curves <DEVICE> <C_PHI> <C_GRAD_P> # Unique simulation parameters device = int(sys.argv[1]) c_phi = float(sys.argv[2]) c_grad_p = float(sys.argv[3]) sim = sphere.sim('cons-sigma0=' + str(5.0e3) + '-c_phi=' + \ str(c_phi) + '-c_grad_p=' + str(c_grad_p), fluid=True) sim.readlast() sigma0 = 10.0e3 sim.sid = 'cons-sigma0=' + str(sigma0) + '-c_phi=' + str(c_phi) + \ '-c_grad_p=' + str(c_grad_p) + '-tall' print('\n###### ' + sim.sid + ' ######') # Checkerboard colors sim.checkerboardColors() sim.cleanup() #sim.adjustUpperWall() sim.zeroKinematics() #sim.consolidate(normal_stress = sigma0) sim.w_sigma0[0] = sigma0
#!/usr/bin/env python import sphere import sys def print_usage(): print('Usage: ' + sys.argv[0] + ' <simulation id> <fluid> <device> [duration]') print('where "simulation id" is a string and "fluid" is either 0 or 1.') print('"device" is the number of the GPU device.') print( 'The total simulation can optionally be defined to continue from the ' 'current time and "duration" seconds more.') if len(sys.argv) < 2: print_usage() sys.exit(1) else: sim = sphere.sim(sys.argv[1], fluid=int(sys.argv[2])) sim.readlast() if len(sys.argv) == 5: sim.time_total[0] = sim.time_current[0] + float(sys.argv[4]) sim.run(device=sys.argv[3])
#!/usr/bin/env python import sphere import numpy import subprocess sid = 'shear-sigma0=20000.0-hw' imgformat = 'png' sim = sphere.sim(sid, fluid=False) subprocess.call('mkdir -p ' + sid + '-fc', shell=True) d = 0 for i in numpy.arange(210,300): #for i in numpy.arange(240,260): print("File: %d, output: %s-fc/%05d.png" % (i, sid, d)) sim.readstep(i, verbose=False) #sim.forcechains(lc = 3.0e1, uc=1.0e2) sim.forcechains(lc = 30.0, uc=1.0e2) subprocess.call('mv shear-sigma0=20000-0-hw-fc.' + imgformat \ + ' ' + sid + '-fc/%05d.png' % (d), shell=True) d += 1 subprocess.call('cd ' + sid + '-fc && sh ./make_video.sh', shell=True)
#!/usr/bin/env python from pytestutils import * import sphere #### Input/output tests #### print("### Input/output tests ###") # Generate data in python orig = sphere.sim(np=100, nw=1, sid="test-initgrid") orig.generateRadii(histogram=False) orig.defaultParams() orig.g[2] = 0.0 orig.initRandomGridPos() orig.initTemporal(current=0.0, total=0.0) orig.time_total = 2.0 * orig.time_dt orig.time_file_dt = orig.time_dt orig.writebin(verbose=False) # Test the test compare(orig, orig, "Comparison:") # Test Python IO routines py = sphere.sim() py.readbin("../input/" + orig.sid + ".bin", verbose=False) compare(orig, py, "Python IO:") # Test C++ IO routines #orig.run(verbose=True, hideinputfile=True) orig.run(dry=True) #orig.run(valgrind=True) orig.run()
# cohesion, 1 denotes a wet simulation with capillary cohesion. # GRAVITY toggles gravitational acceleration. Without it, the particles are # placed in the middle of a volume. With it enabled, the particles are put on # top of a flat wall. import sphere # import numpy import sys device = int(sys.argv[1]) cohesion = int(sys.argv[2]) gravity = int(sys.argv[3]) # Create packing sim = sphere.sim("cap-cohesion=" + str(cohesion) + "-init-grav=" + str(gravity), np=2000) # sim.mu_s[0] = 0.0 # sim.mu_d[0] = 0.0 # sim.k_n[0] = 1.0e7 # sim.k_t[0] = 1.0e7 sim.generateRadii(psd="uni", mean=1.0e-3, variance=1.0e-4) sim.contactModel(1) sim.initRandomGridPos(gridnum=[24, 24, 10000], padding=1.4) sim.defaultParams(gamma_t=1.0e3, capillaryCohesion=1) sim.initTemporal(5.0, file_dt=0.01, epsilon=0.07) # I = numpy.nonzero(sim.x[:,2] < sim.L[2]*0.5) # sim.vel[I[0], 2] = 0.01 # add a instability seeding perturbation # I = numpy.nonzero(sim.x[:,2] > sim.L[2]*0.5) # sim.vel[I[0], 2] = -0.01 # add a instability seeding perturbation if gravity == 1: sim.g[2] = -10.0
#!/usr/bin/env python import sphere import numpy cube = sphere.sim('cube-init') cube.readlast() cube.adjustUpperWall(z_adjust=1.0) # Fill out grid with cubic packages grid = numpy.array(( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ))
#!/usr/bin/env python import sphere init = sphere.sim('cube-init', np=1e3) init.generateRadii(psd='uni', mean=0.01, variance=0.002) init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size) init.initRandomGridPos(gridnum=(7, 7, 1e12)) # Disable friction to dissipate energy fast init.k_n[0] = 1.0e8 init.mu_s[0] = 0.5 init.mu_d[0] = 0.5 # Choose the tangential contact model # 1) Visco-frictional (somewhat incorrect, fast computations) # 2) Elastic-viscous-frictional (more correct, slow computations in dense # packings) init.contactmodel[0] = 2 # Add gravitational acceleration init.g[2] = -10.0 # Set duration of simulation, automatically determine timestep, etc. init.initTemporal(total=6.0, file_dt=0.2) print(init.num) init.run(dry=True)
if smoothed_results: friction_smooth = [[], [], [], []] dilation = [[], [], [], []] p_min = [[], [], [], []] p_mean = [[], [], [], []] p_max = [[], [], [], []] f_n_mean = [[], [], [], []] f_n_max = [[], [], [], []] v_f_z_mean = [[], [], [], []] fluid=True # dry shear #sid = 'shear-sigma0=' + sys.argv[1] + '-hw' sid = 'halfshear-sigma0=' + sys.argv[1] + '-shear' sim = sphere.sim(sid) sim.readlast(verbose=False) sim.visualize('shear') shear_strain[0] = sim.shear_strain #shear_strain[0] = numpy.arange(sim.status()+1) friction[0] = sim.tau/sim.sigma_eff if smoothed_results: friction_smooth[0] = smooth(friction[0], smooth_window) dilation[0] = sim.dilation if contact_forces: f_n_mean[0] = numpy.zeros_like(shear_strain[0]) f_n_max[0] = numpy.zeros_like(shear_strain[0]) for i in numpy.arange(sim.status()): sim.readstep(i, verbose=False) sim.findNormalForces()
rendering = True plots = True # Number of particles np = 1e4 # Common simulation id sim_id = "shear-test" # Deviatoric stress [Pa] Nlist = [80e3] ### INITIALIZATION ### # New class init = sphere.sim(np=np, nd=3, nw=0, sid=sim_id + "-init") # Save radii init.generateRadii(mean=0.02) # Use default params init.defaultParams(gamma_n=100.0, mu_s=0.6, mu_d=0.6) # Add gravity init.g[2] = -9.81 # Periodic x and y boundaries init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size) hcells = np**(1.0 / 3.0)
#!/usr/bin/env python from pytestutils import * import sphere import numpy #''' print("### Steady state, no gravity, no forcing, Dirichlet+Dirichlet BCs") orig = sphere.sim('darcy_particles', np=1000) orig.cleanup() #orig.generateRadii(histogram=False, psd='uni', radius_mean=5.0e-4, radius_variance=5.0e-5) orig.defaultParams() orig.generateRadii(psd='uni', mean=5.0e-2, variance=5.0e-5) orig.initRandomGridPos([20, 20, 200]) orig.initTemporal(total=0.005, file_dt=0.001) orig.initFluid(cfd_solver=1) #orig.p_f[5,3,2] *= 1.5 #orig.k_c[0] = 4.6e-15 orig.k_c[0] = 4.6e-10 #orig.g[2] = -10.0 orig.setStiffnessNormal(36.4e9) orig.setStiffnessTangential(36.4e9 / 3.0) orig.run(verbose=False) #orig.writeVTKall() py = sphere.sim(sid=orig.sid, fluid=True) py.readlast(verbose=False) zeros = numpy.zeros((orig.num)) py.readlast(verbose=False) compareNumpyArrays(zeros, py.p_f, "Conservation of pressure:") # Fluid flow should be very small
#!/usr/bin/env python from pytestutils import * import sphere import sys import numpy import matplotlib.pyplot as plt print('### CFD tests - Dirichlet/Neumann BCs ###') print('''# Neumann bottom, Dirichlet top BC. # No gravity, no pressure gradients => no flow''') orig = sphere.sim("neumann", fluid=True) cleanup(orig) orig.defaultParams(mu_s=0.4, mu_d=0.4) orig.defineWorldBoundaries([0.4, 0.4, 1], dx=0.1) orig.initFluid(mu=8.9e-4) #orig.initFluid(mu = 0.0) orig.initTemporal(total=0.05, file_dt=0.005, dt=1.0e-4) orig.c_v[0] = 0.1 #orig.c_phi[0] = 0.1 py = sphere.sim(sid=orig.sid, fluid=True) orig.bc_bot[0] = 1 # No-flow BC at bottom (Neumann) #orig.run(dry=True) orig.run(verbose=False) #orig.run(device=2) #orig.writeVTKall() py.readlast(verbose=False) zeros = numpy.zeros((orig.num)) py.readlast(verbose=False) compareNumpyArraysClose(zeros,
# $ python shear-starter.py <DEVICE> <FLUID> <C_PHI> <C_GRAD_P> <SIGMA_0> device = int(sys.argv[1]) wet = int(sys.argv[2]) c_phi = float(sys.argv[3]) c_grad_p = float(sys.argv[4]) sigma0 = float(sys.argv[5]) #sim = sphere.sim('diffusivity-sigma0=' + str(sigma0) + '-c_phi=' + \ # str(c_phi) + '-c_grad_p=' + str(c_grad_p), fluid=True) if wet == 1: fluid = True else: fluid = False sim = sphere.sim('cons2-20kPa', fluid=False) sim.readlast() #if sigma0 == 20.0e3 and c_phi == 1.0 and c_grad_p == 0.1: # sim.sid = 'shear-sigma0=20000.0-c_phi=1.0-c_grad_p=0.1-hi_mu-lo_visc-hw-noshear' # sim.readlast() if fluid: sim.id('shear2-sigma0=' + str(sigma0) + '-c_phi=' + str(c_phi) + \ '-c_grad_p=' + str(c_grad_p) + '-hi_mu-lo_visc-hw') else: sim.id('shear2-sigma0=' + str(sigma0) + '-hw') print(sim.sid) sim.fluid = fluid
import sphere import numpy ### EXPERIMENT SETUP ### rendering = True plots = True # Number of particles np = 5e2 # Common simulation id sim_id = "gas-test" ### INITIALIZATION ### # New class init = sphere.sim(np = np, nd = 3, nw = 0, sid = sim_id + "-init") # Save radii init.generateRadii(mean = 0.02) # Use default params init.defaultParams(gamma_n = 100.0, mu_s = 0.6, mu_d = 0.6) # Add gravity # init.g[2] = -9.81 # Periodic x and y boundaries init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size) hcells = np**(1.0/3.0)
ax1.set_xlim([numpy.min(t), numpy.max(t)]) #ax2.set_ylim([1e-5, 1e-3]) ax3.set_ylim([-0.2, 1.2]) ax9.set_xlabel('Time [s]') fig.tight_layout() plt.subplots_adjust(hspace=0.05) filename = sid + '-combined.' + outformat plt.savefig(filename) plt.close() #shutil.copyfile(filename, '/home/adc/articles/own/3/graphics/' + filename) print(filename) # Loop through parameter values for effective_stress in effective_stresses: for velfac in velfacs: for mu_s in mu_s_vals: for mu_d in mu_s_vals: jobname = jobname_prefix + '{}Pa-v={}-mu_s={}-mu_d={}'.format( effective_stress, velfac, mu_s, mu_d) print(jobname) sim = sphere.sim(jobname) #sim.visualize('shear') rateStatePlot(jobname)
#!/usr/bin/env python from pytestutils import * import sphere #### Input/output tests #### print("### Memory tests ###") # Generate data in python orig = sphere.sim(np = 100, nw = 1, sid = "test-initgrid") orig.generateRadii(histogram = False) orig.defaultParams() orig.initRandomGridPos() orig.initTemporal(current = 0.0, total = 0.0) orig.time_total = 2.0*orig.time_dt; orig.time_file_dt = orig.time_dt; # Test C++ routines print("Valgrind: C++ routines") orig.run(verbose=False, hideinputfile=True, valgrind=True) # Test CUDA routines print("cuda-memcheck: CUDA routines") orig.run(verbose=False, hideinputfile=True, cudamemcheck=True) # Remove temporary files cleanup(orig)
#!/usr/bin/env python from pytestutils import * import sphere import numpy #''' print("### Steady state, no gravity, no forcing, Dirichlet+Dirichlet BCs") orig = sphere.sim('darcy_particles', np = 1000) orig.cleanup() #orig.generateRadii(histogram=False, psd='uni', radius_mean=5.0e-4, radius_variance=5.0e-5) orig.defaultParams() orig.generateRadii(psd='uni', mean=5.0e-2, variance=5.0e-5) orig.initRandomGridPos([20, 20, 200]) orig.initTemporal(total=0.005, file_dt=0.001) orig.initFluid(cfd_solver=1) #orig.p_f[5,3,2] *= 1.5 #orig.k_c[0] = 4.6e-15 orig.k_c[0] = 4.6e-10 #orig.g[2] = -10.0 orig.setStiffnessNormal(36.4e9) orig.setStiffnessTangential(36.4e9/3.0) orig.run(verbose=False) #orig.writeVTKall() py = sphere.sim(sid = orig.sid, fluid = True) py.readlast(verbose=False) zeros = numpy.zeros((orig.num)) py.readlast(verbose = False) compareNumpyArrays(zeros, py.p_f, "Conservation of pressure:") # Fluid flow should be very small
#!/usr/bin/env python import sphere from pytestutils import * sim = sphere.sim('fluid_particle_interaction', fluid=True) sim.cleanup() sim.defineWorldBoundaries([1.0, 1.0, 1.0], dx = 0.1) sim.initFluid() sim.rho[0] = 1000.0 # particle density = fluid density sim.setDEMstepsPerCFDstep(100) # No gravity, pressure gradient enforced by Dirichlet boundaries. # The particle should be sucked towards the low pressure print('# Test 1: Test pressure gradient force') sim.p_f[:,:,0] = 10.0 sim.p_f[:,:,-1] = 1.0 sim.addParticle([0.5, 0.5, 0.5], 0.05) sim.initTemporal(total=0.01, file_dt=0.001) sim.run(verbose=False) #sim.run(dry=True) #sim.run(cudamemcheck=True) #sim.writeVTKall() sim.readlast() test(sim.vel[0,2] > 0.0, 'Particle velocity:')
# Number of particles np = 2e4 # Common simulation id sim_id = 'segregation' # Deviatoric stress [Pa] #devslist = [80e3, 10e3, 20e3, 40e3, 60e3, 120e3] devslist = [120e3] #devs = 0 ### INITIALIZATION ### # New class init = sphere.sim(np=np, nd=3, nw=0, sid=sim_id + '-init') # Save radii init.generateRadii(mean=0.08) # Use default params init.defaultParams(gamma_n=100.0, mu_s=0.4, mu_d=0.4) init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size) hcells = np**(1.0 / 3.0) * 0.6 init.initRandomGridPos(gridnum=numpy.array([hcells, hcells, 1e9])) # Choose the tangential contact model # 1) Visco-frictional (somewhat incorrect, fast computations)
# COHESION should have the value of 0 or 1. 0 denotes a dry simulation without # cohesion, 1 denotes a wet simulation with capillary cohesion. # GRAVITY toggles gravitational acceleration. Without it, the particles are # placed in the middle of a volume. With it enabled, the particles are put on # top of a flat wall. import sphere #import numpy import sys device = int(sys.argv[1]) cohesion = int(sys.argv[2]) gravity = int(sys.argv[3]) # Create packing sim = sphere.sim('cap-cohesion=' + str(cohesion) + '-init-grav=' \ + str(gravity), np=2000) #sim.mu_s[0] = 0.0 #sim.mu_d[0] = 0.0 #sim.k_n[0] = 1.0e7 #sim.k_t[0] = 1.0e7 sim.generateRadii(psd='uni', mean=1.0e-3, variance=1.0e-4) sim.contactModel(1) sim.initRandomGridPos(gridnum=[24, 24, 10000], padding=1.4) sim.defaultParams(gamma_t = 1.0e3, capillaryCohesion=1) sim.initTemporal(5.0, file_dt=0.01, epsilon=0.07) #I = numpy.nonzero(sim.x[:,2] < sim.L[2]*0.5) #sim.vel[I[0], 2] = 0.01 # add a instability seeding perturbation #I = numpy.nonzero(sim.x[:,2] > sim.L[2]*0.5) #sim.vel[I[0], 2] = -0.01 # add a instability seeding perturbation if gravity == 1: sim.g[2] = -10.0
#!/usr/bin/env python import sphere sim = sphere.sim('init2', np=10000) sim.generateRadii(psd='uni', radius_mean=0.02, radius_variance=0.01) sim.initRandomGridPos([12, 12, 1000]) sim.initTemporal(10.0, file_dt=0.05, epsilon=0.07) sim.gamma_n[0] = 1000.0 sim.gamma_wn[0] = 1000.0 sim.periodicBoundariesXY() sim.g[2] = -9.81 sim.run() sim.writeVTKall()
#!/usr/bin/env python import sphere from pytestutils import * orig = sphere.sim('cfd_incl', fluid=True) orig.cleanup() #orig.defineWorldBoundaries([0.3, 0.3, 0.3], dx = 0.1) orig.defineWorldBoundaries([0.3, 0.3, 0.3], dx = 0.06) orig.initFluid(mu=8.9e-4) # inviscid "fluids" (mu=0) won't work! #orig.initTemporal(total = 0.5, file_dt = 0.05, dt = 1.0e-4) orig.initTemporal(total = 1.0e-0, file_dt = 1.0e-1, dt = 1.0e-3) orig.bc_bot[0] = 1 # No-flow, free slip BC at bottom (Neumann) #orig.bc_bot[0] = 2 # No-flow, no slip BC at bottom (Neumann) #orig.bc_top[0] = 1 # No-flow, free slip BC at top (Neumann) angle = 10.0 # slab inclination in degrees g_magnitude = 10.0 orig.g[0] = numpy.sin(numpy.radians(angle))*g_magnitude orig.g[2] = -numpy.cos(numpy.radians(angle))*g_magnitude tau_d = orig.g * orig.rho_f * orig.L[2] # analytical driving stress v_sur = tau_d * orig.L[2] / orig.mu # analytical surface velocity # increase the max iterations for first step orig.setMaxIterations(1e5) # Homogeneous pressure, no gravity orig.run(verbose=False) orig.writeVTKall() py = sphere.sim(sid=orig.sid, fluid=True)
if window == 'flat': #moving average w = numpy.ones(window_len,'d') else: w = getattr(numpy, window)(window_len) y = numpy.convolve(w/w.sum(), s, mode='same') return y[window_len-1:-window_len+1] max_step = 400 friction = numpy.zeros(max_step) velratios = [] peakfrictions = [] sim = sphere.sim(sids[0], fluid=True) sim.readfirst(verbose=False) fig = plt.figure(figsize=(3.5, 3)) if False: it=0 for sid in sids: print '\n' + sid sim.id(sid) sim.fluid=fluids[it] it += 1 sim.readfirst(verbose=False) velratio = 1.0
device = int(sys.argv[1]) wet = int(sys.argv[2]) c_phi = float(sys.argv[3]) c_grad_p = float(sys.argv[4]) sigma0 = float(sys.argv[5]) #sim = sphere.sim('diffusivity-sigma0=' + str(sigma0) + '-c_phi=' + \ # str(c_phi) + '-c_grad_p=' + str(c_grad_p), fluid=True) if wet == 1: fluid = True else: fluid = False #sim = sphere.sim('diffusivity-sigma0=' + str(sigma0) +'-c_phi=1.0-c_grad_p=1.0', # fluid=True) sim = sphere.sim('diffusivity-sigma0=' + str(sigma0), fluid=True) sim.readlast() if sigma0 == 20.0e3 and c_phi == 1.0 and c_grad_p == 0.1: sim.sid = 'shear-sigma0=20000.0-c_phi=1.0-c_grad_p=0.1-hi_mu-lo_visc-hw-noshear' sim.readlast() if fluid: sim.sid = 'shear-sigma0=' + str(sigma0) + '-c_phi=' + str(c_phi) + \ '-c_grad_p=' + str(c_grad_p) + '-hi_mu-lo_visc-hw' else: sim.sid = 'shear-sigma0=' + str(sigma0) + '-hw' print(sim.sid) sim.fluid = fluid
# CUDA device to use device = 0 # Number of particles np = 1e4 # Common simulation id sim_id = "jp-long-shear-soft" # Deviatoric stress [Pa] devslist = [100e3] ### INITIALIZATION ### # New class init = sphere.sim(np=np, nd=3, nw=0, sid=sim_id + "-init") # Save radii init.generateRadii(mean=0.01) # Use default params init.defaultParams(k_n=1.16e7, k_t=1.16e7, gamma_n=100.0, mu_s=0.6, mu_d=0.6) # Add gravity init.g[2] = -9.81 # Periodic x and y boundaries init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size) hcells = np**(1.0/3.0)
#!/usr/bin/env python from pytestutils import * import sphere import sys import numpy import matplotlib.pyplot as plt print('### DEM/CFD tests - Dirichlet/Neumann BCs and a single particle ###') print('# No gravity') orig = sphere.sim('dem_cfd', fluid=True) cleanup(orig) orig.defaultParams(mu_s=0.4, mu_d=0.4) orig.addParticle([0.2, 0.2, 0.6], 0.05) orig.defineWorldBoundaries([0.4, 0.4, 1.0], dx=0.1) orig.initFluid(mu=8.9e-4) orig.initTemporal(total=0.5, file_dt=0.05, dt=1.0e-4) py = sphere.sim(sid=orig.sid, fluid=True) orig.bc_bot[0] = 1 # No-flow BC at bottom (Neumann) #orig.run(dry=True) orig.run(verbose=False) #orig.writeVTKall() py.readlast(verbose=False) ones = numpy.ones((orig.num)) zeros = numpy.zeros((orig.num[0], orig.num[1], orig.num[2], 3)) compareNumpyArraysClose(ones, py.p_f, 'Conservation of pressure:', tolerance=1.0e-1) compareNumpyArraysClose([0, 0, 0],
# $ ipython halfshear-darcy-starter.py <device> <fluid> <c_phi> <k_c> <sigma_0> <mu> <velfac> device = int(sys.argv[1]) wet = int(sys.argv[2]) c_phi = float(sys.argv[3]) k_c = float(sys.argv[4]) sigma0 = float(sys.argv[5]) mu = float(sys.argv[6]) velfac = float(sys.argv[7]) if wet == 1: fluid = True else: fluid = False sim = sphere.sim('halfshear-sigma0=' + str(sigma0), fluid=False) print('Input: ' + sim.sid) sim.readlast() sim.fluid = fluid if fluid: sim.id('halfshear-darcy-sigma0=' + str(sigma0) + '-k_c=' + str(k_c) + \ '-mu=' + str(mu) + '-velfac=' + str(velfac) + '-shear') else: sim.id('halfshear-sigma0=' + str(sigma0) + '-velfac=' + str(velfac) + \ '-shear') sim.checkerboardColors(nx=6,ny=3,nz=6) sim.cleanup() sim.adjustUpperWall() sim.zeroKinematics()
# Small value arrays smallval = 1e-8 s2_1 = numpy.ones((2, 1)) * smallval # Inter-particle distances to try (neg. for overlap) #distances = [0.2, 0.0, -0.2] #distances = [0.2, 0.0] distances = [] #distances = [0.2] for d in distances: radii = 0.5 print("## Inter-particle distance: " + str(d / radii) + " radii") sb = sphere.sim(np=2, sid='bondtest') cleanup(sb) # setup particles, bond, and simulation sb.x[0, :] = numpy.array((10.0, 10.0, 10.0)) sb.x[1, :] = numpy.array((10.0 + 2.0 * radii + d, 10.0, 10.0)) sb.radius = numpy.ones(sb.np) * radii sb.initGridAndWorldsize(margin=10, periodic=1, contactmodel=2, g=numpy.array([0.0, 0.0, 0.0])) sb.bond(0, 1) sb.defaultParams(gamma_n=0.0, gamma_t=0.0) #sb.initTemporal(total=0.5, file_dt=0.01) #sb.render(verbose=False) #visualize(sb.sid, "energy")
#N = 15e3 #N = 20e3 #N = 25e3 #N = 30e3 #N = 40e3 #dpdx = 10 # fluid-pressure gradient in Pa/m along x #dpdx = 100 # fluid-pressure gradient in Pa/m along x #dpdx = 200 # fluid-pressure gradient in Pa/m along x dpdx = 1000 #dpdx = 5e3 #dpdx = 10e3 #dpdx = 20e3 #dpdx = 40e3 sim = sphere.sim(id_prefix + '-relax', nw=0) if relaxation: cube = sphere.sim('cube-init') cube.readlast() cube.adjustUpperWall(z_adjust=1.0) # Fill out grid with cubic packages grid = numpy.array(( [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ))
#!/usr/bin/env python import sphere import sys def print_usage(): print('Usage: ' + sys.argv[0] + ' <simulation id> <fluid> <device> [duration]') print('where "simulation id" is a string and "fluid" is either 0 or 1.') print('"device" is the number of the GPU device.') print('The total simulation can optionally be defined to continue from the ' 'current time and "duration" seconds more.') if len(sys.argv) < 2: print_usage() sys.exit(1) else: sim = sphere.sim(sys.argv[1], fluid = int(sys.argv[2])) sim.readlast() if len(sys.argv) == 5: sim.time_total[0] = sim.time_current[0] + float(sys.argv[4]) sim.run(device=sys.argv[3])
#!/usr/bin/env python import sphere init = sphere.sim('cube-init', np=1e2) init.generateRadii(psd='uni', mean=0.01, variance=0.002) init.periodicBoundariesXY() # Initialize positions in random grid (also sets world size) init.initRandomGridPos(gridnum=(6, 6, 1e12)) # Disable friction to dissipate energy fast init.k_n[0] = 1.0e8 init.mu_s[0] = 0.0 init.mu_d[0] = 0.0 # Choose the tangential contact model # 1) Visco-frictional (somewhat incorrect, fast computations) # 2) Elastic-viscous-frictional (more correct, slow computations in dense # packings) init.contactmodel[0] = 1 # Add gravitational acceleration init.g[2] = -10.0 # Set duration of simulation, automatically determine timestep, etc. init.initTemporal(total=6.0, file_dt=0.2) print(init.num) init.run(dry = True)
# Number of particles np = 2e4 # Common simulation id sim_id = "shear-test-ocr" # Effective normal stresses during consolidation [Pa] Nlist = [10e3, 25e3, 50e3, 100e3, 250e3, 500e3] # Effective normal stresses during relaxation and shear [Pa] Nshear = 10e3 ### INITIALIZATION ### # New class init = sphere.sim(np = np, nd = 3, nw = 0, sid = sim_id + "-init") # Save radii with uniform size distribution init.generateRadii(psd = 'uni', mean = 1e-2, variance = 2e-3, histogram = True) # Set mechanical parameters init.setYoungsModulus(7e8) init.setStaticFriction(0.5) init.setDynamicFriction(0.5) init.setDampingNormal(5e1) init.setDampingTangential(0.0) # Add gravitational acceleration init.g[0] = 0.0 init.g[1] = 0.0 init.g[2] = -9.81
#!/usr/bin/env python import sphere from pytestutils import * orig = sphere.sim('cfd_incl', fluid=True) orig.cleanup() #orig.defineWorldBoundaries([0.3, 0.3, 0.3], dx = 0.1) orig.defineWorldBoundaries([0.3, 0.3, 0.3], dx=0.06) orig.initFluid(mu=8.9e-4) # inviscid "fluids" (mu=0) won't work! #orig.initTemporal(total = 0.5, file_dt = 0.05, dt = 1.0e-4) orig.initTemporal(total=1.0e-0, file_dt=1.0e-1, dt=1.0e-3) orig.bc_bot[0] = 1 # No-flow, free slip BC at bottom (Neumann) #orig.bc_bot[0] = 2 # No-flow, no slip BC at bottom (Neumann) #orig.bc_top[0] = 1 # No-flow, free slip BC at top (Neumann) angle = 10.0 # slab inclination in degrees g_magnitude = 10.0 orig.g[0] = numpy.sin(numpy.radians(angle)) * g_magnitude orig.g[2] = -numpy.cos(numpy.radians(angle)) * g_magnitude tau_d = orig.g * orig.rho_f * orig.L[2] # analytical driving stress v_sur = tau_d * orig.L[2] / orig.mu # analytical surface velocity # increase the max iterations for first step orig.setMaxIterations(1e5) # Homogeneous pressure, no gravity orig.run(verbose=False) orig.writeVTKall() py = sphere.sim(sid=orig.sid, fluid=True)