Introduction
Introduction Statistics Contact Development Disclaimer Help
tTests incorporated with CMake - sphere - GPU-based 3D discrete element method …
git clone git://src.adamsgaard.dk/sphere
Log
Files
Refs
LICENSE
---
commit 5d7e811dcb4c7226689594b13015a7aa466e7d03
parent 38656ba76b71da03143f5195572cf5df4f0c7aae
Author: Anders Damsgaard <[email protected]>
Date: Fri, 25 Jan 2013 15:21:07 +0100
Tests incorporated with CMake
Diffstat:
M CMakeLists.txt | 31 +++++++++++++++++++----------…
A tests/CMakeLists.txt | 8 ++++++++
A tests/io_tests.py | 40 +++++++++++++++++++++++++++++…
A tests/porosity_tests.py | 62 +++++++++++++++++++++++++++++…
A tests/pytestutils.py | 30 ++++++++++++++++++++++++++++++
R python/tests.py -> tests/tests.py | 0
6 files changed, 159 insertions(+), 12 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
t@@ -1,28 +1,35 @@
# Create input/output folders
-FILE(MAKE_DIRECTORY input)
-FILE(MAKE_DIRECTORY output)
-FILE(MAKE_DIRECTORY img_out)
-FILE(MAKE_DIRECTORY gnuplot/data)
+file(MAKE_DIRECTORY input)
+file(MAKE_DIRECTORY output)
+file(MAKE_DIRECTORY img_out)
+file(MAKE_DIRECTORY gnuplot/data)
# The name of the project.
-PROJECT(sphere_CUDA)
+project(sphere_CUDA)
# CMake minimum version required
# FindCUDA script is distributed since version 2.8
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
+cmake_minimum_required(VERSION 2.8)
# Find CUDA
-FIND_PACKAGE(CUDA REQUIRED)
+find_package(CUDA REQUIRED)
# Find OpenMP
-FIND_PACKAGE(OpenMP)
+find_package(OpenMP)
# Find Boost components
#find_package(Boost COMPONENTS system filesystem unit_test_framework REQUIRED)
-#SET(CMAKE_BUILD_TYPE Debug)
-SET(CMAKE_BUILD_TYPE Release)
+# Uncomment to enable testing
+enable_testing()
+# Set build type
+#set(CMAKE_BUILD_TYPE Debug)
+set(CMAKE_BUILD_TYPE Release)
-#Add source directory to project.
-ADD_SUBDIRECTORY(src)
+
+# Add source directory to project.
+add_subdirectory(src)
+
+# Add tests
+add_subdirectory(tests)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
t@@ -0,0 +1,8 @@
+
+find_package(PythonInterp REQUIRED)
+
+add_test(io_tests ${PYTHON_EXECUTABLE}
+ ${CMAKE_CURRENT_BINARY_DIR}/io_tests.py)
+
+add_test(porosity_tests ${PYTHON_EXECUTABLE}
+ ${CMAKE_CURRENT_BINARY_DIR}/porosity_tests.py)
diff --git a/tests/io_tests.py b/tests/io_tests.py
t@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+from pytestutils import *
+
+#### Input/output tests ####
+print("### Input/output tests ###")
+
+# Generate data in python
+orig = Spherebin(np = 100, nw = 1, sid = "test-initgrid")
+orig.generateRadii(histogram = False)
+orig.defaultParams()
+orig.initRandomGridPos(g = numpy.zeros(orig.nd))
+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 = Spherebin()
+py.readbin("../input/" + orig.sid + ".bin", verbose=False)
+compare(orig, py, "Python IO:")
+
+# Test C++ IO routines
+orig.run(verbose=False, hideinputfile=True)
+#orig.run()
+cpp = Spherebin()
+cpp.readbin("../output/" + orig.sid + ".output00000.bin", verbose=False)
+compare(orig, cpp, "C++ IO: ")
+
+# Test CUDA IO routines
+cuda = Spherebin()
+cuda.readbin("../output/" + orig.sid + ".output00001.bin", verbose=False)
+cuda.time_current = orig.time_current
+cuda.time_step_count = orig.time_step_count
+compare(orig, cuda, "CUDA IO: ")
+
+# Remove temporary files
+cleanup(orig)
+
+
+
diff --git a/tests/porosity_tests.py b/tests/porosity_tests.py
t@@ -0,0 +1,62 @@
+#!/usr/bin/env python
+from pytestutils import *
+
+#### Porosity tests ####
+print("### porosity tests ###")
+
+# Generate data in python
+orig = Spherebin(np = 100, nw = 1, sid = "test-initgrid")
+orig.generateRadii(histogram = False)
+orig.defaultParams()
+orig.initRandomGridPos(g = numpy.zeros(orig.nd))
+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)
+
+def testPorosities(spherebin):
+
+ # Number of vertical slices
+ slicevals = [1, 2, 4]
+ i = 1 # iterator var
+ for slices in slicevals:
+
+ # Find correct value of bulk porosity
+ n_bulk = spherebin.bulkPorosity()
+ #print("Bulk: " + str(n_bulk))
+
+ porosity = spherebin.porosity(slices = slices)[0]
+ #print("Avg: " + str(numpy.average(porosity)))
+ #print(porosity)
+
+ # Check if average of porosity function values matches the bulk porosi…
+ compareFloats(n_bulk, numpy.average(porosity), \
+ spherebin.sid + ": Porosity average to bulk porosity ("\
+ + str(i) + "/" + str(len(slicevals)) + "):")
+ i += 1
+
+# Test data from previous test
+testPorosities(orig)
+
+# Simple cubic packing of uniform spheres
+# The theoretical porosity is (4/3*pi*r^3)/(2r)^3 = 0.476
+sidelen = 10
+cubic = Spherebin(np = sidelen**3, sid='cubic')
+radius = 1.0
+cubic.generateRadii(psd='uni', radius_mean=radius, radius_variance=0.0, histog…
+for ix in range(sidelen):
+ for iy in range(sidelen):
+ for iz in range(sidelen):
+ i = ix + sidelen * (iy + sidelen * iz) # linear index
+ cubic.x[i,0] = ix*radius*2.0 + radius
+ cubic.x[i,1] = iy*radius*2.0 + radius
+ cubic.x[i,2] = iz*radius*2.0 + radius
+cubic.L[:] = 2.0 * radius * sidelen
+
+cubic.initTemporal(0.2)
+cubic.initGrid()
+
+testPorosities(cubic)
+
+cleanup(cubic)
+
diff --git a/tests/pytestutils.py b/tests/pytestutils.py
t@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+
+from sphere import *
+import subprocess
+
+def passed():
+ return "\tPassed"
+
+def failed():
+ return "\tFailed"
+
+def compare(first, second, string):
+ if (first == second):
+ print(string + passed())
+ else:
+ print(string + failed())
+
+def compareFloats(first, second, string, criterion=1e-5):
+ if abs(first-second) < criterion:
+ print(string + passed())
+ else :
+ print(string + failed())
+
+def cleanup(spherebin):
+ 'Remove temporary files'
+ subprocess.call("rm -f ../input/" + spherebin.sid + ".bin", shell=True)
+ subprocess.call("rm -f ../output/" + spherebin.sid + ".*.bin", shell=True)
+ print("")
+
+
diff --git a/python/tests.py b/tests/tests.py
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.