tadd file I/O for readjusting the grid size - 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
---
(DIR) commit 0a89b207e04b5030b5ee6fb42c2756a509d603d3
(DIR) parent 5adc4fde4fddd30f5591249a497353c17665df1b
(HTM) Author: Anders Damsgaard Christensen <adc@geo.au.dk>
Date: Fri, 2 Sep 2016 15:45:46 -0700
add file I/O for readjusting the grid size
Diffstat:
M python/sphere.py | 32 ++++++++++++++++++++++++++++++-
M src/file_io.cpp | 2 ++
M src/version.h | 2 +-
3 files changed, 34 insertions(+), 2 deletions(-)
---
(DIR) diff --git a/python/sphere.py b/python/sphere.py
t@@ -24,7 +24,7 @@ numpy.seterr(all='warn', over='raise')
# Sphere version number. This field should correspond to the value in
# `../src/version.h`.
-VERSION = 2.13
+VERSION = 2.14
# Transparency on plot legends
legend_alpha = 0.5
t@@ -103,6 +103,9 @@ class sim:
# Whether to treat the lateral boundaries as periodic (1) or not (0)
self.periodic = numpy.zeros(1, dtype=numpy.uint32)
+ # Adaptively resize grid to assemblage height (0: no, 1: yes)
+ self.adaptive = numpy.zeros(1, dtype=numpy.uint32)
+
## Particle data
# Particle position vectors [m]
self.x = numpy.zeros((self.np, self.nd), dtype=numpy.float64)
t@@ -475,6 +478,9 @@ class sim:
elif self.periodic != other.periodic:
print('periodic')
return 13
+ elif self.adaptive != other.adaptive:
+ print('adaptive')
+ return 13.5
elif (self.x != other.x).any():
print('x')
return 14
t@@ -1005,6 +1011,11 @@ class sim:
self.num = numpy.fromfile(fh, dtype=numpy.uint32, count=self.nd)
self.periodic = numpy.fromfile(fh, dtype=numpy.int32, count=1)
+ if self.version >= 2.14:
+ self.adaptive = numpy.fromfile(fh, dtype=numpy.int32, count=1)
+ else:
+ self.adaptive = 0
+
# Per-particle vectors
for i in numpy.arange(self.np):
self.x[i,:] =\
t@@ -1344,6 +1355,7 @@ class sim:
fh.write(self.L.astype(numpy.float64))
fh.write(self.num.astype(numpy.uint32))
fh.write(self.periodic.astype(numpy.uint32))
+ fh.write(self.adaptive.astype(numpy.uint32))
# Per-particle vectors
for i in numpy.arange(self.np):
t@@ -2459,6 +2471,24 @@ class sim:
'''
self.periodic[0] = 2
+ def adaptiveGrid(self):
+ '''
+ Set the height of the fluid grid to automatically readjust to the
+ height of the granular assemblage, as dictated by the position of the
+ top wall. This will readjust `self.L[2]` during the simulation to
+ equal the position of the top wall `self.w_x[0]`.
+
+ See also :func:`staticGrid()`
+ '''
+ self.adaptive[0] = 1
+
+ def staticGrid(self):
+ '''
+ Set the height of the fluid grid to be constant as set in `self.L[2]`.
+
+ See also :func:`adaptiveGrid()`
+ '''
+ self.adaptive[0] = 0
def initRandomPos(self, gridnum = numpy.array([12, 12, 36])):
'''
(DIR) diff --git a/src/file_io.cpp b/src/file_io.cpp
t@@ -111,6 +111,7 @@ void DEM::readbin(const char *target)
ifs.read(as_bytes(grid.L), sizeof(grid.L));
ifs.read(as_bytes(grid.num), sizeof(grid.num));
ifs.read(as_bytes(grid.periodic), sizeof(grid.periodic));
+ ifs.read(as_bytes(grid.adaptive), sizeof(grid.adaptive));
// Read kinematic values
for (i = 0; i<np; ++i) {
t@@ -437,6 +438,7 @@ void DEM::writebin(const char *target)
ofs.write(as_bytes(grid.L), sizeof(grid.L));
ofs.write(as_bytes(grid.num), sizeof(grid.num));
ofs.write(as_bytes(grid.periodic), sizeof(grid.periodic));
+ ofs.write(as_bytes(grid.adaptive), sizeof(grid.adaptive));
// Write kinematic values
for (i = 0; i<np; ++i) {
(DIR) diff --git a/src/version.h b/src/version.h
t@@ -2,6 +2,6 @@
#define VERSION_H_
// Define source code version
-const double VERSION = 2.13;
+const double VERSION = 2.14;
#endif