@@ -15,10 +15,10 @@ def now_s():
1515 return time .process_time_ns () / (10 ** 9 )
1616
1717
18- def test_marching_cubes_calls ( ):
18+ def marching_cubes_calls ( dtype ):
1919 print ("\n Testing marching cubes calls" )
2020
21- particles = np .array (meshio .read (VTK_PATH ).points , dtype = np . float32 )
21+ particles = np .array (meshio .read (VTK_PATH ).points , dtype = dtype )
2222 reconstruction = pysplashsurf .reconstruct_surface (
2323 particles ,
2424 particle_radius = 0.025 ,
@@ -40,6 +40,14 @@ def test_marching_cubes_calls():
4040 assert verts_after < verts_before
4141
4242
43+ def test_marching_cubes_calls_f32 ():
44+ marching_cubes_calls (np .float32 )
45+
46+
47+ def test_marching_cubes_calls_f64 ():
48+ marching_cubes_calls (np .float64 )
49+
50+
4351def reconstruction_pipeline (
4452 input_file ,
4553 output_file ,
@@ -76,9 +84,10 @@ def reconstruction_pipeline(
7684 quad_max_interior_angle = 135.0 ,
7785 subdomain_grid = False ,
7886 subdomain_num_cubes_per_dim = 64 ,
87+ dtype
7988):
8089 mesh = meshio .read (input_file )
81- particles = np .array (mesh .points , dtype = np . float64 )
90+ particles = np .array (mesh .points , dtype = dtype )
8291
8392 if attributes_to_interpolate is None :
8493 attributes_to_interpolate = []
@@ -88,7 +97,7 @@ def reconstruction_pipeline(
8897 for attr in attributes_to_interpolate :
8998 if attr in mesh .point_data :
9099 if mesh .point_data [attr ].dtype .kind == "f" :
91- attrs [attr ] = mesh .point_data [attr ].astype (np . float64 )
100+ attrs [attr ] = mesh .point_data [attr ].astype (dtype )
92101 else :
93102 attrs [attr ] = mesh .point_data [attr ].astype (np .int64 )
94103
@@ -131,11 +140,11 @@ def reconstruction_pipeline(
131140 mesh_with_data .write_to_file (output_file )
132141
133142
134- def test_no_post_processing ( ):
143+ def no_post_processing_test ( dtype ):
135144 start = now_s ()
136145 subprocess .run (
137146 [BINARY_PATH ]
138- + f"reconstruct { VTK_PATH } -o { DIR .joinpath ('test_bin.vtk' )} -r=0.025 -l=2.0 -c=0.5 -t=0.6 -d=on --subdomain-grid=on --mesh-cleanup=off --mesh-smoothing-weights=off --mesh-smoothing-iters=0 --normals=off --normals-smoothing-iters=0" .split (),
147+ + f"reconstruct { VTK_PATH } -o { DIR .joinpath ('test_bin.vtk' )} -r=0.025 -l=2.0 -c=0.5 -t=0.6 { " -d=on" if dtype == np . float64 else "" } --subdomain-grid=on --mesh-cleanup=off --mesh-smoothing-weights=off --mesh-smoothing-iters=0 --normals=off --normals-smoothing-iters=0" .split (),
139148 check = True ,
140149 )
141150 print ("Binary done in" , now_s () - start )
@@ -144,24 +153,25 @@ def test_no_post_processing():
144153 reconstruction_pipeline (
145154 VTK_PATH ,
146155 DIR .joinpath ("test.vtk" ),
147- particle_radius = np . float64 ( 0.025 ) ,
148- smoothing_length = np . float64 ( 2.0 ) ,
149- cube_size = np . float64 ( 0.5 ) ,
150- iso_surface_threshold = np . float64 ( 0.6 ) ,
156+ particle_radius = 0.025 ,
157+ smoothing_length = 2.0 ,
158+ cube_size = 0.5 ,
159+ iso_surface_threshold = 0.6 ,
151160 mesh_smoothing_weights = False ,
152161 mesh_smoothing_iters = 0 ,
153162 normals_smoothing_iters = 0 ,
154163 mesh_cleanup = False ,
155164 compute_normals = False ,
156165 subdomain_grid = True ,
166+ dtype = dtype
157167 )
158168 print ("Python done in" , now_s () - start )
159169
160170 binary_mesh = meshio .read (DIR .joinpath ("test_bin.vtk" ))
161171 python_mesh = meshio .read (DIR .joinpath ("test.vtk" ))
162172
163- binary_verts = np .array (binary_mesh .points , dtype = np . float64 )
164- python_verts = np .array (python_mesh .points , dtype = np . float64 )
173+ binary_verts = np .array (binary_mesh .points , dtype = dtype )
174+ python_verts = np .array (python_mesh .points , dtype = dtype )
165175
166176 print ("# of vertices binary:" , len (binary_verts ))
167177 print ("# of vertices python:" , len (python_verts ))
@@ -174,11 +184,19 @@ def test_no_post_processing():
174184 assert np .allclose (binary_verts , python_verts )
175185
176186
177- def test_with_post_processing ():
187+ def test_no_post_processing_f32 ():
188+ no_post_processing_test (np .float32 )
189+
190+
191+ def test_no_post_processing_f64 ():
192+ no_post_processing_test (np .float64 )
193+
194+
195+ def with_post_processing_test (dtype ):
178196 start = now_s ()
179197 subprocess .run (
180198 [BINARY_PATH ]
181- + f"reconstruct { VTK_PATH } -o { DIR .joinpath ('test_bin.vtk' )} -r=0.025 -l=2.0 -c=0.5 -t=0.6 -d=on --subdomain-grid=on --interpolate_attribute velocity --decimate-barnacles=on --mesh-cleanup=on --mesh-smoothing-weights=on --mesh-smoothing-iters=25 --normals=on --normals-smoothing-iters=10 --output-smoothing-weights=on --generate-quads=off" .split (),
199+ + f"reconstruct { VTK_PATH } -o { DIR .joinpath ('test_bin.vtk' )} -r=0.025 -l=2.0 -c=0.5 -t=0.6 { " -d=on" if dtype == np . float64 else "" } --subdomain-grid=on --interpolate_attribute velocity --decimate-barnacles=on --mesh-cleanup=on --mesh-smoothing-weights=on --mesh-smoothing-iters=25 --normals=on --normals-smoothing-iters=10 --output-smoothing-weights=on --generate-quads=off" .split (),
182200 check = True ,
183201 )
184202 print ("Binary done in" , now_s () - start )
@@ -188,12 +206,12 @@ def test_with_post_processing():
188206 VTK_PATH ,
189207 DIR .joinpath ("test.vtk" ),
190208 attributes_to_interpolate = ["velocity" ],
191- particle_radius = np . float64 ( 0.025 ) ,
192- smoothing_length = np . float64 ( 2.0 ) ,
193- cube_size = np . float64 ( 0.5 ) ,
194- iso_surface_threshold = np . float64 ( 0.6 ) ,
209+ particle_radius = 0.025 ,
210+ smoothing_length = 2.0 ,
211+ cube_size = 0.5 ,
212+ iso_surface_threshold = 0.6 ,
195213 mesh_smoothing_weights = True ,
196- mesh_smoothing_weights_normalization = np . float64 ( 13.0 ) ,
214+ mesh_smoothing_weights_normalization = 13.0 ,
197215 mesh_smoothing_iters = 25 ,
198216 normals_smoothing_iters = 10 ,
199217 generate_quads = False ,
@@ -203,15 +221,16 @@ def test_with_post_processing():
203221 decimate_barnacles = True ,
204222 output_mesh_smoothing_weights = True ,
205223 output_raw_normals = True ,
224+ dtype = dtype
206225 )
207226 print ("Python done in" , now_s () - start )
208227
209228 binary_mesh = meshio .read (DIR .joinpath ("test_bin.vtk" ))
210229 python_mesh = meshio .read (DIR .joinpath ("test.vtk" ))
211230
212231 # Compare number of vertices
213- binary_verts = np .array (binary_mesh .points , dtype = np . float64 )
214- python_verts = np .array (python_mesh .points , dtype = np . float64 )
232+ binary_verts = np .array (binary_mesh .points , dtype = dtype )
233+ python_verts = np .array (python_mesh .points , dtype = dtype )
215234
216235 print ("# of vertices binary:" , len (binary_verts ))
217236 print ("# of vertices python:" , len (python_verts ))
@@ -249,3 +268,11 @@ def test_with_post_processing():
249268 print ("Python verts:" , python_verts )
250269
251270 assert np .allclose (binary_verts , python_verts )
271+
272+
273+ def test_with_post_processing_f32 ():
274+ with_post_processing_test (np .float32 )
275+
276+
277+ def test_with_post_processing_f64 ():
278+ with_post_processing_test (np .float64 )
0 commit comments