tporosity_tests.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
       ---
       tporosity_tests.py (1851B)
       ---
            1 #!/usr/bin/env python
            2 from pytestutils import *
            3 import sphere
            4 
            5 #### Porosity tests ####
            6 print("### porosity tests ###")
            7 
            8 # Generate data in python
            9 orig = sphere.sim(np = 100, nw = 1, sid = "test-initgrid")
           10 orig.generateRadii(histogram = False)
           11 orig.defaultParams()
           12 orig.initRandomGridPos()
           13 orig.initTemporal(current = 0.0, total = 0.0)
           14 orig.time_total = 2.0*orig.time_dt;
           15 orig.time_file_dt = orig.time_dt;
           16 orig.writebin(verbose=False)
           17 
           18 def testPorosities(sim):
           19 
           20     # Number of vertical slices
           21     slicevals = [1, 2, 4]
           22     i = 1   # iterator var
           23     for slices in slicevals:
           24 
           25         # Find correct value of bulk porosity
           26         n_bulk = sim.bulkPorosity(trim=False)
           27         #print("Bulk: " + str(n_bulk))
           28 
           29         porosity = sim.porosity(slices = slices)[0]
           30         #print("Avg: " + str(numpy.average(porosity)))
           31         #print(porosity)
           32 
           33         # Check if average of porosity function values matches the bulk porosity
           34         compareFloats(n_bulk, numpy.average(porosity), \
           35                 sim.sid + ": Porosity average to bulk porosity ("\
           36                 + str(i) + "/" + str(len(slicevals)) + "):")
           37         i += 1
           38 
           39 # Test data from previous test
           40 testPorosities(orig)
           41 
           42 # Simple cubic packing of uniform spheres
           43 # The theoretical porosity is (4/3*pi*r^3)/(2r)^3 = 0.476
           44 sidelen = 10
           45 cubic = sphere.sim(np = sidelen**3, sid='cubic')
           46 radius = 1.0
           47 cubic.generateRadii(psd='uni', mean=radius, variance=0.0, histogram=False)
           48 for ix in range(sidelen):
           49     for iy in range(sidelen):
           50         for iz in range(sidelen):
           51             i = ix + sidelen * (iy + sidelen * iz) # linear index
           52             cubic.x[i,0] = ix*radius*2.0 + radius
           53             cubic.x[i,1] = iy*radius*2.0 + radius
           54             cubic.x[i,2] = iz*radius*2.0 + radius
           55 cubic.L[:] = 2.0 * radius * sidelen
           56 
           57 cubic.initTemporal(0.2)
           58 cubic.initGrid()
           59 
           60 testPorosities(cubic)
           61 
           62 cleanup(cubic)
           63