tio_tests_fluid.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
       ---
       tio_tests_fluid.py (3249B)
       ---
            1 #!/usr/bin/env python
            2 from pytestutils import *
            3 import sphere
            4 
            5 #### Input/output tests ####
            6 print("### Fluid input/output tests - Navier Stokes CFD solver ###")
            7 
            8 # Generate data in python
            9 orig = sphere.sim(np=100, sid="test-initgrid-fluid", fluid=True)
           10 orig.cleanup()
           11 orig.generateRadii(histogram=False, mean=1.0)
           12 orig.defaultParams()
           13 orig.initRandomGridPos()
           14 orig.initFluid()
           15 orig.initTemporal(current=0.0, total=0.0)
           16 orig.time_total=2.0*orig.time_dt
           17 orig.time_file_dt = orig.time_dt
           18 orig.writebin(verbose=False)
           19 
           20 # Test Python IO routines
           21 py = sphere.sim(fluid=True)
           22 py.readbin("../input/" + orig.sid + ".bin", verbose=False)
           23 compare(orig, py, "Python IO:")
           24 
           25 # Test C++ IO routines
           26 orig.run(verbose=False)
           27 #orig.run(dry=True)
           28 #orig.run(verbose=True, hideinputfile=False, cudamemcheck=True)
           29 cpp = sphere.sim(fluid=True)
           30 cpp.readbin("../output/" + orig.sid + ".output00000.bin", verbose=False)
           31 compare(orig, cpp, "C++ IO:   ")
           32 
           33 # Test CUDA IO routines
           34 cuda = sphere.sim(fluid=True)
           35 cuda.readbin("../output/" + orig.sid + ".output00001.bin", verbose=False)
           36 cuda.time_current = orig.time_current
           37 cuda.time_step_count = orig.time_step_count
           38 compareNumpyArraysClose(orig.v_f, cuda.v_f, "cuda.v_f:", tolerance=1e-5)
           39 cuda.v_f = orig.v_f
           40 #compareNumpyArraysClose(orig.p_f, cuda.p_f, "cuda.p_f:", tolerance=0.1)
           41 cuda.p_f = orig.p_f
           42 if numpy.allclose(orig.x, cuda.x, 0.01):
           43     cuda.x = orig.x  # ignore small changes
           44 if numpy.max(numpy.abs(cuda.vel - orig.vel)) < 1.0e-5:
           45     cuda.vel = orig.vel  # ignore small changes
           46     cuda.xyzsum = orig.xyzsum
           47     cuda.force = orig.force
           48 compare(orig, cuda, "CUDA IO:  ")
           49 
           50 
           51 
           52 #### Input/output tests ####
           53 print("### Fluid input/output tests - Darcy CFD solver ###")
           54 
           55 # Generate data in python
           56 orig = sphere.sim(np=100, sid="test-initgrid-fluid", fluid=True)
           57 orig.cleanup()
           58 orig.generateRadii(histogram=False, mean=1.0)
           59 orig.defaultParams()
           60 orig.initRandomGridPos()
           61 
           62 orig.initFluid(cfd_solver = 1)
           63 orig.setMaxIterations(10)
           64 #orig.setMaxIterations(1000)
           65 orig.initTemporal(current=0.0, total=0.0)
           66 orig.time_total=2.0*orig.time_dt
           67 orig.time_file_dt = orig.time_dt
           68 orig.writebin(verbose=False)
           69 
           70 # Test Python IO routines
           71 py = sphere.sim(fluid=True)
           72 py.readbin("../input/" + orig.sid + ".bin", verbose=False)
           73 compare(orig, py, "Python IO:")
           74 
           75 # Test C++ IO routines
           76 orig.run(verbose=False)
           77 #orig.run(dry=True)
           78 #orig.run(verbose=True, hideinputfile=False, cudamemcheck=True)
           79 cpp = sphere.sim(fluid=True)
           80 cpp.readbin("../output/" + orig.sid + ".output00000.bin", verbose=False)
           81 compare(orig, cpp, "C++ IO:   ")
           82 
           83 # Test CUDA IO routines
           84 cuda = sphere.sim(fluid=True)
           85 cuda.readbin("../output/" + orig.sid + ".output00001.bin", verbose=False)
           86 cuda.time_current = orig.time_current
           87 cuda.time_step_count = orig.time_step_count
           88 compareNumpyArraysClose(orig.v_f, cuda.v_f, "cuda.v_f:", tolerance=1e-5)
           89 cuda.v_f = orig.v_f
           90 compareNumpyArraysClose(orig.p_f, cuda.p_f, "cuda.p_f:", tolerance=0.1)
           91 cuda.p_f = orig.p_f
           92 if numpy.allclose(orig.x, cuda.x, 0.01):
           93     cuda.x = orig.x  # ignore small changes
           94 if numpy.max(numpy.abs(cuda.vel - orig.vel)) < 1.0e-5:
           95     cuda.vel = orig.vel  # ignore small changes
           96     cuda.xyzsum = orig.xyzsum
           97     cuda.force = orig.force
           98 compare(orig, cuda, "CUDA IO:  ")
           99 
          100 # Remove temporary files
          101 cleanup(orig)