source: trunk/anuga_work/anuga_cuda/src/utilities/check_result.py

Last change on this file was 9017, checked in by steve, 11 years ago

Adding in Zhe (John) Weng's anuga_cuda code as obtained from googlecode https://code.google.com/p/anuga-cuda

File size: 47.5 KB
Line 
1#!/usr/bin/env python
2
3import numpy 
4from utilities import cpy_back_and_cmp
5
6
7
8global_cnt = 0
9name_list = ['max_speed', 
10                'stage_edge', 'elevation_edge', 'xmom_edge', 'ymom_edge', 
11                'height_edge', 'xvelocity_edge', 'yvelocity_edge', 
12               
13                'stage_centroid', 'elevation_centroid', 'xmom_centroid',
14                'ymom_centroid', 
15                'height_centroid', 'xvelocity_centroid', 
16                'yvelocity_centroid', 
17                'friction_centroid',
18               
19                'stage_vertex', 'elevation_vertex', 'xmom_vertex', 
20                'ymom_vertex', 
21                'height_vertex', 'xvelocity_vertex', 'yvelocity_vertex', 
22               
23                'stage_explicit_update', 'xmom_explicit_update', 
24                'ymom_explicit_update', 
25                'stage_semi_implicit_update', 'xmom_semi_implicit_update', 
26                'ymom_semi_implicit_update', 
27
28                'stage_x_gradient', 'elevation_x_gradient', 
29                'xmom_x_gradient', 
30                'ymom_x_gradient', 'height_x_gradient', 
31                'xvelocity_x_gradient', 
32                'yvelocity_x_gradient', 
33               
34                'stage_y_gradient', 'elevation_y_gradient', 
35                'xmom_y_gradient', 
36                'ymom_y_gradient', 'height_y_gradient', 
37                'xvelocity_y_gradient', 
38                'yvelocity_y_gradient', 
39
40                'stage_boundary', 'elevation_boundary', 'xmom_boundary', 
41                'ymom_boundary', 
42                'height_boundary', 'xvelocity_boundary', 
43                'yvelocity_boundary' 
44            ]
45
46
47def approx_equal(a, b, approx=True):
48    """Check result with tolerance.
49   
50    return abs(a-b) <= abs(a)*tolerance
51    """
52
53    if approx:
54        if abs(a-b) > abs(a)*pow(10,-6):
55            return False
56        else: 
57            return True
58    else:
59        if a != b:
60            return False
61        else:
62            return True
63
64
65
66
67
68def check_result(a, b):
69    """Check result correctness. """
70
71    global global_cnt
72    global name_list
73    if not numpy.allclose(a, b):
74        print global_cnt, name_list[global_cnt]
75        cnt = 0
76        if a.shape.__len__()  == 1:
77            for i in range(a.shape[0]):
78                if ( a[i] != b[i]):
79                    cnt += 1
80                    if cnt <= 10:
81                        print i, a[i], b[i] 
82        else:
83            for i in range(a.shape[0]):
84                if ( a[i] != b[i]).any():
85                    cnt += 1
86                    if cnt <= 10:
87                        print i, a[i], b[i] 
88        print cnt
89    global_cnt += 1
90
91
92
93def check_all(domain, test_domain):
94    """Check all the result"""
95
96    global global_cnt
97    global_cnt = 0
98    print domain.flux_timestep, test_domain.flux_timestep
99   
100   
101    check_result(domain.max_speed, test_domain.max_speed)
102   
103   
104    check_result(domain.quantities['stage'].edge_values, 
105            test_domain.quantities['stage'].edge_values)
106    check_result(domain.quantities['elevation'].edge_values, 
107            test_domain.quantities['elevation'].edge_values)
108    check_result(domain.quantities['xmomentum'].edge_values, 
109            test_domain.quantities['xmomentum'].edge_values)
110    check_result(domain.quantities['ymomentum'].edge_values, 
111            test_domain.quantities['ymomentum'].edge_values)
112    check_result(domain.quantities['height'].edge_values, 
113            test_domain.quantities['height'].edge_values)
114    check_result(domain.quantities['xvelocity'].edge_values, 
115            test_domain.quantities['xvelocity'].edge_values)
116    check_result(domain.quantities['yvelocity'].edge_values, 
117            test_domain.quantities['yvelocity'].edge_values)
118   
119   
120    check_result(domain.quantities['stage'].centroid_values, 
121            test_domain.quantities['stage'].centroid_values)
122    check_result(domain.quantities['elevation'].centroid_values, 
123            test_domain.quantities['elevation'].centroid_values)
124    check_result(domain.quantities['xmomentum'].centroid_values, 
125            test_domain.quantities['xmomentum'].centroid_values)
126    check_result(domain.quantities['ymomentum'].centroid_values, 
127            test_domain.quantities['ymomentum'].centroid_values)
128    check_result(domain.quantities['height'].centroid_values, 
129            test_domain.quantities['height'].centroid_values)
130    check_result(domain.quantities['xvelocity'].centroid_values, 
131            test_domain.quantities['xvelocity'].centroid_values)
132    check_result(domain.quantities['yvelocity'].centroid_values, 
133            test_domain.quantities['yvelocity'].centroid_values)
134    check_result(domain.quantities['friction'].centroid_values, 
135            test_domain.quantities['friction'].centroid_values)
136   
137   
138    check_result(domain.quantities['stage'].vertex_values, 
139            test_domain.quantities['stage'].vertex_values)
140    check_result(domain.quantities['elevation'].vertex_values, 
141            test_domain.quantities['elevation'].vertex_values)
142    check_result(domain.quantities['xmomentum'].vertex_values, 
143            test_domain.quantities['xmomentum'].vertex_values)
144    check_result(domain.quantities['ymomentum'].vertex_values, 
145            test_domain.quantities['ymomentum'].vertex_values)
146    check_result(domain.quantities['height'].vertex_values, 
147            test_domain.quantities['height'].vertex_values)
148    check_result(domain.quantities['xvelocity'].vertex_values, 
149            test_domain.quantities['xvelocity'].vertex_values)
150    check_result(domain.quantities['yvelocity'].vertex_values, 
151            test_domain.quantities['yvelocity'].vertex_values)
152   
153   
154    check_result(domain.quantities['stage'].explicit_update, 
155            test_domain.quantities['stage'].explicit_update)
156    check_result(domain.quantities['xmomentum'].explicit_update, 
157            test_domain.quantities['xmomentum'].explicit_update)
158    check_result(domain.quantities['ymomentum'].explicit_update, 
159            test_domain.quantities['ymomentum'].explicit_update)
160   
161       
162    check_result(domain.quantities['stage'].semi_implicit_update, 
163            test_domain.quantities['stage'].semi_implicit_update)
164    check_result(domain.quantities['xmomentum'].semi_implicit_update, 
165            test_domain.quantities['xmomentum'].semi_implicit_update)
166    check_result(domain.quantities['ymomentum'].semi_implicit_update, 
167            test_domain.quantities['ymomentum'].semi_implicit_update)
168   
169   
170    check_result(domain.quantities['stage'].x_gradient, 
171            test_domain.quantities['stage'].x_gradient)
172    check_result(domain.quantities['elevation'].x_gradient, 
173            test_domain.quantities['elevation'].x_gradient)
174    check_result(domain.quantities['xmomentum'].x_gradient, 
175            test_domain.quantities['xmomentum'].x_gradient)
176    check_result(domain.quantities['ymomentum'].x_gradient, 
177            test_domain.quantities['ymomentum'].x_gradient)
178    check_result(domain.quantities['height'].x_gradient, 
179            test_domain.quantities['height'].x_gradient)
180    check_result(domain.quantities['xvelocity'].x_gradient, 
181            test_domain.quantities['xvelocity'].x_gradient)
182    check_result(domain.quantities['yvelocity'].x_gradient, 
183            test_domain.quantities['yvelocity'].x_gradient)
184   
185   
186    check_result(domain.quantities['stage'].y_gradient, 
187            test_domain.quantities['stage'].y_gradient)
188    check_result(domain.quantities['elevation'].y_gradient, 
189            test_domain.quantities['elevation'].y_gradient)
190    check_result(domain.quantities['xmomentum'].y_gradient, 
191            test_domain.quantities['xmomentum'].y_gradient)
192    check_result(domain.quantities['ymomentum'].y_gradient, 
193            test_domain.quantities['ymomentum'].y_gradient)
194    check_result(domain.quantities['height'].y_gradient, 
195            test_domain.quantities['height'].y_gradient)
196    check_result(domain.quantities['xvelocity'].y_gradient, 
197            test_domain.quantities['xvelocity'].y_gradient)
198    check_result(domain.quantities['yvelocity'].y_gradient, 
199            test_domain.quantities['yvelocity'].y_gradient)
200   
201   
202    check_result(domain.quantities['stage'].boundary_values, 
203            test_domain.quantities['stage'].boundary_values)
204    check_result(domain.quantities['elevation'].boundary_values, 
205            test_domain.quantities['elevation'].boundary_values)
206    check_result(domain.quantities['xmomentum'].boundary_values, 
207            test_domain.quantities['xmomentum'].boundary_values)
208    check_result(domain.quantities['ymomentum'].boundary_values, 
209            test_domain.quantities['ymomentum'].boundary_values)
210    check_result(domain.quantities['height'].boundary_values, 
211            test_domain.quantities['height'].boundary_values)
212    check_result(domain.quantities['xvelocity'].boundary_values, 
213            test_domain.quantities['xvelocity'].boundary_values)
214    check_result(domain.quantities['yvelocity'].boundary_values, 
215            test_domain.quantities['yvelocity'].boundary_values)
216
217
218
219def check_all_with_copy_back(domain, test_domain):
220    """Check all the result"""
221
222    global global_cnt
223    global_cnt = 0
224    print domain.flux_timestep, test_domain.flux_timestep
225   
226   
227    check_result(domain, test_domain, "max_speed")
228   
229   
230    check_result(domain.quantities['stage'], 
231            test_domain.quantities['stage'], "edge_values")
232    check_result(domain.quantities['elevation'], 
233            test_domain.quantities['elevation'], "edge_values")
234    check_result(domain.quantities['xmomentum'], 
235            test_domain.quantities['xmomentum'], "edge_values")
236    check_result(domain.quantities['ymomentum'], 
237            test_domain.quantities['ymomentum'], "edge_values")
238    check_result(domain.quantities['height'], 
239            test_domain.quantities['height'], "edge_values")
240    check_result(domain.quantities['xvelocity'], 
241            test_domain.quantities['xvelocity'], "edge_values")
242    check_result(domain.quantities['yvelocity'], 
243            test_domain.quantities['yvelocity'], "edge_values")
244   
245   
246    check_result(domain.quantities['stage'], 
247            test_domain.quantities['stage'], "centroid_values")
248    check_result(domain.quantities['elevation'], 
249            test_domain.quantities['elevation'], "centroid_values")
250    check_result(domain.quantities['xmomentum'], 
251            test_domain.quantities['xmomentum'], "centroid_values")
252    check_result(domain.quantities['ymomentum'], 
253            test_domain.quantities['ymomentum'], "centroid_values")
254    check_result(domain.quantities['height'], 
255            test_domain.quantities['height'], "centroid_values")
256    check_result(domain.quantities['xvelocity'], 
257            test_domain.quantities['xvelocity'], "centroid_values")
258    check_result(domain.quantities['yvelocity'], 
259            test_domain.quantities['yvelocity'], "centroid_values")
260    check_result(domain.quantities['friction'], 
261            test_domain.quantities['friction'], "centroid_values")
262   
263   
264    check_result(domain.quantities['stage'], 
265            test_domain.quantities['stage'], "vertex_values")
266    check_result(domain.quantities['elevation'], 
267            test_domain.quantities['elevation'], "vertex_values")
268    check_result(domain.quantities['xmomentum'], 
269            test_domain.quantities['xmomentum'], "vertex_values")
270    check_result(domain.quantities['ymomentum'], 
271            test_domain.quantities['ymomentum'], "vertex_values")
272    check_result(domain.quantities['height'], 
273            test_domain.quantities['height'], "vertex_values")
274    check_result(domain.quantities['xvelocity'], 
275            test_domain.quantities['xvelocity'], "vertex_values")
276    check_result(domain.quantities['yvelocity'], 
277            test_domain.quantities['yvelocity'], "vertex_values")
278   
279   
280    check_result(domain.quantities['stage'], 
281            test_domain.quantities['stage'], "explicit_update")
282    check_result(domain.quantities['xmomentum'], 
283            test_domain.quantities['xmomentum'], "explicit_update")
284    check_result(domain.quantities['ymomentum'], 
285            test_domain.quantities['ymomentum'], "explicit_update")
286   
287       
288    check_result(domain.quantities['stage'], 
289            test_domain.quantities['stage'], "semi_implicit_update")
290    check_result(domain.quantities['xmomentum'], 
291            test_domain.quantities['xmomentum'], "semi_implicit_update")
292    check_result(domain.quantities['ymomentum'], 
293            test_domain.quantities['ymomentum'], "semi_implicit_update")
294   
295   
296    check_result(domain.quantities['stage'], 
297            test_domain.quantities['stage'], "x_gradient")
298    check_result(domain.quantities['elevation'], 
299            test_domain.quantities['elevation'], "x_gradient")
300    check_result(domain.quantities['xmomentum'], 
301            test_domain.quantities['xmomentum'], "x_gradient")
302    check_result(domain.quantities['ymomentum'], 
303            test_domain.quantities['ymomentum'], "x_gradient")
304    check_result(domain.quantities['height'], 
305            test_domain.quantities['height'], "x_gradient")
306    check_result(domain.quantities['xvelocity'], 
307            test_domain.quantities['xvelocity'], "x_gradient")
308    check_result(domain.quantities['yvelocity'], 
309            test_domain.quantities['yvelocity'], "x_gradient")
310   
311   
312    check_result(domain.quantities['stage'], 
313            test_domain.quantities['stage'], "y_gradient")
314    check_result(domain.quantities['elevation'], 
315            test_domain.quantities['elevation'], "y_gradient")
316    check_result(domain.quantities['xmomentum'], 
317            test_domain.quantities['xmomentum'], "y_gradient")
318    check_result(domain.quantities['ymomentum'], 
319            test_domain.quantities['ymomentum'], "y_gradient")
320    check_result(domain.quantities['height'], 
321            test_domain.quantities['height'], "y_gradient")
322    check_result(domain.quantities['xvelocity'], 
323            test_domain.quantities['xvelocity'], "y_gradient")
324    check_result(domain.quantities['yvelocity'], 
325            test_domain.quantities['yvelocity'], "y_gradient")
326   
327   
328    check_result(domain.quantities['stage'], 
329            test_domain.quantities['stage'], "boundary_values")
330    check_result(domain.quantities['elevation'], 
331            test_domain.quantities['elevation'], "boundary_values")
332    check_result(domain.quantities['xmomentum'], 
333            test_domain.quantities['xmomentum'], "boundary_values")
334    check_result(domain.quantities['ymomentum'], 
335            test_domain.quantities['ymomentum'], "boundary_values")
336    check_result(domain.quantities['height'], 
337            test_domain.quantities['height'], "boundary_values")
338    check_result(domain.quantities['xvelocity'], 
339            test_domain.quantities['xvelocity'], "boundary_values")
340    check_result(domain.quantities['yvelocity'], 
341            test_domain.quantities['yvelocity'], "boundary_values")
342   
343
344
345
346def test_distribute_to_vertexs_and_edges(domain, IO = 'Output'):
347    """Pair-testing check point for distribute_to_vertices_and_edges """
348
349    # For time-dependence issues, used to synchronize the kernel
350    #ctx.synchronize()
351
352    gpu = domain.using_gpu
353    rg = domain.rearranged_domain
354    sc = domain.cotesting_domain
355
356    s1 = domain.quantities['stage']
357    xm1 = domain.quantities['xmomentum']
358    ym1 = domain.quantities['ymomentum']
359    e1 = domain.quantities['elevation']
360
361    s2 = domain.cotesting_domain.quantities['stage']
362    xm2 = domain.cotesting_domain.quantities['xmomentum']
363    ym2 = domain.cotesting_domain.quantities['ymomentum']
364    e2 = domain.cotesting_domain.quantities['elevation']
365
366    h1 = domain.quantities['height']
367    xv1 = domain.quantities['xvelocity']
368    yv1 = domain.quantities['yvelocity']
369
370    h2 = sc.quantities['height']
371    xv2 = sc.quantities['xvelocity']
372    yv2 = sc.quantities['yvelocity']
373   
374
375    res = []
376
377
378    res.append( numpy.allclose( domain.flux_timestep,
379        domain.cotesting_domain.flux_timestep))
380    res.append( cpy_back_and_cmp( s1, s2, 'edge_values', gpu, rg))
381    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
382    res.append( cpy_back_and_cmp( s1, s2, 'vertex_values', gpu, rg))
383    res.append( cpy_back_and_cmp( s1, s2, 'x_gradient_values', gpu, rg))
384    res.append( cpy_back_and_cmp( s1, s2, 'y_gradient_values', gpu, rg))
385
386    res.append( cpy_back_and_cmp( xm1, xm2,'edge_values', gpu, rg))
387    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
388    res.append( cpy_back_and_cmp( xm1, xm2,'vertex_values', gpu, rg))
389    res.append( cpy_back_and_cmp( s1, s2, 'x_gradient_values', gpu, rg))
390    res.append( cpy_back_and_cmp( s1, s2, 'y_gradient_values', gpu, rg))
391
392    res.append( cpy_back_and_cmp( ym1, ym2,'edge_values', gpu, rg))
393    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
394    res.append( cpy_back_and_cmp( ym1, ym2,'vertex_values', gpu, rg))
395    res.append( cpy_back_and_cmp( s1, s2, 'x_gradient_values', gpu, rg))
396    res.append( cpy_back_and_cmp( s1, s2, 'y_gradient_values', gpu, rg))
397
398
399    res.append( cpy_back_and_cmp( e1, e2, 'centroid_values', gpu, rg))
400    res.append( cpy_back_and_cmp( e1, e2, 'vertex_values', gpu, rg))
401
402    res.append( cpy_back_and_cmp(h1, h2,'vertex_values', gpu, rg))
403    res.append( cpy_back_and_cmp(xv1, xv2,'vertex_values', gpu, rg))
404    res.append( cpy_back_and_cmp(yv1, yv2,'vertex_values', gpu, rg))
405
406    if res.count(True) + res.count(-1) != res.__len__():
407        raise Exception( " --> distribute_to_vertices_and_edges ", res)
408
409
410
411
412def test_evolve_one_euler_step(domain):
413    """Pari-testing check point for evolve_one_euler_step"""
414
415    # For time-dependence issues
416    #ctx.synchronize()
417
418    gpu = domain.using_gpu
419    rg = domain.rearranged_domain
420
421    s1 = domain.quantities['stage']
422    xm1 = domain.quantities['xmomentum']
423    ym1 = domain.quantities['ymomentum']
424    e1 = domain.quantities['elevation']
425    h1 = domain.quantities['height']
426    xv1 = domain.quantities['xvelocity']
427    yv1 = domain.quantities['yvelocity']
428    f1 = domain.quantities['friction']
429
430    s2 = domain.cotesting_domain.quantities['stage']
431    xm2 = domain.cotesting_domain.quantities['xmomentum']
432    ym2 = domain.cotesting_domain.quantities['ymomentum']
433    e2 = domain.cotesting_domain.quantities['elevation']
434    h2 = domain.cotesting_domain.quantities['height']
435    xv2 = domain.cotesting_domain.quantities['xvelocity']
436    yv2 = domain.cotesting_domain.quantities['yvelocity']
437    f2 = domain.cotesting_domain.quantities['friction']
438
439
440    res = []
441    res.append( numpy.allclose( domain.flux_timestep,
442        domain.cotesting_domain.flux_timestep))
443    res.append( numpy.allclose( domain.recorded_max_timestep,
444        domain.cotesting_domain.recorded_max_timestep))
445    res.append( numpy.allclose( domain.recorded_min_timestep,
446        domain.cotesting_domain.recorded_min_timestep))
447   
448    res.append( numpy.allclose( domain.smallsteps, 
449        domain.cotesting_domain.smallsteps ))
450
451    res.append( cpy_back_and_cmp( s1, s2, 'explicit_update' , gpu, rg))
452    res.append( cpy_back_and_cmp( s1, s2, 'semi_implicit_update', gpu, rg))
453    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values' , gpu, rg))
454
455
456    res.append( cpy_back_and_cmp( xm1, xm2,'explicit_update', gpu, rg))
457    res.append( cpy_back_and_cmp( xm1, xm2,'semi_implicit_update', gpu,rg))
458    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
459   
460
461    res.append( cpy_back_and_cmp( ym1, ym2,'explicit_update', gpu, rg))
462    res.append( cpy_back_and_cmp( ym1, ym2,'semi_implicit_update', gpu,rg))
463    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
464   
465
466    if res.count(True) + res.count(-1) != res.__len__():
467        raise Exception( " --> evolve_one_euler_step ", res)
468
469
470
471
472def test_update_ghosts(domain):
473    """Pari-testing check point for update_ghosts"""
474
475    # For time-dependence issues
476    #ctx.synchronize()
477
478    gpu = domain.using_gpu
479    rg = domain.rearranged_domain
480
481    sc = domain.cotesting_domain
482
483    s1 = domain.quantities['stage']
484    xm1 = domain.quantities['xmomentum']
485    ym1 = domain.quantities['ymomentum']
486    e1 = domain.quantities['elevation']
487
488    s2 = domain.cotesting_domain.quantities['stage']
489    xm2 = domain.cotesting_domain.quantities['xmomentum']
490    ym2 = domain.cotesting_domain.quantities['ymomentum']
491    e2 = domain.cotesting_domain.quantities['elevation']
492
493    res = []
494    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values' , gpu, rg))
495    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
496    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
497
498    # This for update_timestep check point
499    res.append( cpy_back_and_cmp( e1, e2, 'edge_values' , gpu, rg))
500
501
502    if res.count(True) + res.count(-1) != res.__len__():
503        print " --> update_ghosts ",res
504
505
506
507
508def test_update_extrema(domain):
509    """Pari-testing check point for update_extrema"""
510
511    # For time-dependence issues
512    #ctx.synchronize()
513
514    gpu = domain.using_gpu
515    rg = domain.rearranged_domain
516    sc = domain.cotesting_domain
517
518    res = []
519    if res.count(True) + res.count(-1) != res.__len__():
520        raise Exception( " --> update_extrema ", res)
521   
522
523
524def test_update_timestep(domain):
525    """Pari-testing check point for update_timestep"""
526
527    # For time-dependence issues
528    #ctx.synchronize()
529
530    gpu = domain.using_gpu
531    rg = domain.rearranged_domain
532    sc = domain.cotesting_domain
533
534    res = []
535    res.append( numpy.allclose(domain._order_ , sc._order_ ))
536    res.append( numpy.allclose(domain.default_order , sc.default_order ))
537    res.append( numpy.allclose(domain.get_time() , sc.get_time() ))
538    res.append( numpy.allclose(domain.CFL , sc.CFL ))
539    res.append( numpy.allclose(domain.smallsteps , sc.smallsteps ))
540    res.append( numpy.allclose(domain.max_smallsteps , sc.max_smallsteps ))
541    res.append( numpy.allclose(
542        domain.recorded_max_timestep , sc.recorded_max_timestep ))
543    res.append( numpy.allclose(
544        domain.recorded_min_timestep , sc.recorded_min_timestep ))
545    res.append( numpy.allclose(
546        domain.evolve_max_timestep , sc.evolve_max_timestep ))
547    res.append( numpy.allclose(
548        domain.evolve_min_timestep , sc.evolve_min_timestep ))
549    res.append( numpy.allclose(domain.flux_timestep , sc.flux_timestep ))
550
551
552    if res.count(True) + res.count(-1) != res.__len__():
553        raise Exception( " --> update_timestep ",res)
554
555
556
557def test_update_conserved_quantities(domain, output =True):
558    """Pari-testing check point for update_conserved_quantities"""
559
560    # For time-dependence issues
561    #ctx.synchronize()
562
563    gpu = domain.using_gpu
564    rg = domain.rearranged_domain
565
566    for name in domain.conserved_quantities:
567        Q1 = domain.quantities[name]
568   
569        Q2 = domain.cotesting_domain.quantities[name]
570   
571        res = []
572        res.append( cpy_back_and_cmp( Q1, Q2, "centroid_values", gpu, rg))
573        if output:
574            res.append( cpy_back_and_cmp( 
575                Q1, Q2, "semi_implicit_update", gpu, rg))
576        res.append( cpy_back_and_cmp( Q1, Q2, "explicit_update", gpu, rg))
577        res.append( numpy.allclose(
578                domain.timestep, domain.cotesting_domain.timestep))
579       
580        if res.count(True) + res.count(-1) != res.__len__():
581            if not res[0]:
582                cnt = 0
583                for i in range(Q1.centroid_values.shape[0]):
584                    if not numpy.allclose( Q1.centroid_values[i] , 
585                                            Q2.centroid_values[i]):
586                        if cnt < 5 :
587                            print i, Q1.centroid_values[i], \
588                                Q2.centroid_values[i]
589                        cnt += 1
590                print 0, cnt, Q1.centroid_values, Q2.centroid_values
591            if not res[1]:
592                print 1, Q1.semi_implicit_update, Q2.semi_implicit_update
593            if not res[2]:
594                print 2, Q1.explicit_update, Q2.explicit_update
595
596            raise Exception("Error: update_conserved_quantities",name, res)
597
598
599
600def test_manning_friction_implicit(domain):
601    """Pari-testing check point for manning_friction_implicit"""
602
603    # For time-dependence issues
604    #ctx.synchronize()
605
606    gpu = domain.using_gpu
607    rg = domain.rearranged_domain
608    sc = domain.cotesting_domain
609
610
611    s1 = domain.quantities['stage']
612    xm1 = domain.quantities['xmomentum']
613    ym1 = domain.quantities['ymomentum']
614    e1 = domain.quantities['elevation']
615    f1 = domain.quantities['friction']
616
617    s2 = sc.quantities['stage']
618    xm2 = sc.quantities['xmomentum']
619    ym2 = sc.quantities['ymomentum']
620    e2 = sc.quantities['elevation']
621    f2 = sc.quantities['friction']
622
623    res = []
624    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
625
626    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
627    res.append( cpy_back_and_cmp( xm1, xm2,'semi_implicit_update', gpu,rg))
628
629    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
630    res.append( cpy_back_and_cmp( ym1, ym2,'semi_implicit_update', gpu,rg))
631
632    res.append( cpy_back_and_cmp( e1, e2, 'vertex_values', gpu, rg))
633
634    res.append( cpy_back_and_cmp( f1, f2, 'centroid_values', gpu, rg))
635
636    if res.count(True) + res.count(-1) != res.__len__():
637        import math
638        h = []
639        S = []
640        tmp_xmom = []
641        tmp_ymom = []
642        for i in range(domain.number_of_elements):
643            if f2.centroid_values[i] > domain.minimum_allowed_height :
644                h.append( s2.centroid_values[i] - \
645                    (   e2.vertex_values[i][0] + \
646                        e2.vertex_values[i][1] + \
647                        e2.vertex_values[i][2])/3
648                    )
649                if h[i] >= domain.minimum_allowed_height: 
650                    S.append( -domain.g * \
651                        f1.centroid_values[i] *f1.centroid_values[i] * \
652                        math.sqrt( 
653                            xm2.centroid_values[i]*xm2.centroid_values[i]+\
654                            ym2.centroid_values[i]*ym2.centroid_values[i]))
655                    S[i] /= pow (h[i], 7.0/3)
656                else:
657                    S.append( 0 )
658            else:
659                h.append(0)
660                S.append(0)
661
662           
663        if domain.use_sloped_mannings:
664            raise Exception( " --> manning friction sloped ", res)
665        else:
666            raise Exception( " --> manning friction flat ", res)
667
668
669
670def test_update_boundary(domain, inputOnly=False):
671    """Pari-testing check point for update_boundary"""
672
673    # For time-dependence issues
674    #ctx.synchronize()
675
676    from anuga.shallow_water.boundaries import Reflective_boundary
677    from anuga.abstract_2d_finite_volumes.generic_boundary_conditions \
678            import Transmissive_boundary, Dirichlet_boundary, \
679                    Compute_fluxes_boundary, Time_boundary, Time_boundary,\
680                    Time_boundary
681
682
683    gpu = domain.using_gpu
684    rg = domain.rearranged_domain
685    sc = domain.cotesting_domain
686
687    s1 = domain.quantities['stage']
688    xm1 = domain.quantities['xmomentum']
689    ym1 = domain.quantities['ymomentum']
690    e1 = domain.quantities['elevation']
691    h1 = domain.quantities['height']
692    xv1 = domain.quantities['xvelocity']
693    yv1 = domain.quantities['yvelocity']
694
695    s2 = sc.quantities['stage']
696    xm2 = sc.quantities['xmomentum']
697    ym2 = sc.quantities['ymomentum']
698    e2 = sc.quantities['elevation']
699    h2 = sc.quantities['height']
700    xv2 = sc.quantities['xvelocity']
701    yv2 = sc.quantities['yvelocity']
702   
703    for tag in domain.tag_boundary_cells:
704        B1 = domain.boundary_map[tag]
705        if B1 is None :
706            continue
707
708        ids1 = domain.tag_boundary_cells[tag]
709        if ids1 is None:
710            continue
711
712        B2 = sc.boundary_map[tag]
713
714        if isinstance( B1, Reflective_boundary):
715           
716            ipt = []
717            res = []
718
719            ipt.append( cpy_back_and_cmp(s1, s2,'edge_values', gpu, rg))
720            ipt.append( cpy_back_and_cmp(e1, e2,'edge_values', gpu, rg))
721            ipt.append( cpy_back_and_cmp(h1, h2,'edge_values', gpu, rg))
722            ipt.append( cpy_back_and_cmp(xm1, xm2,'edge_values', gpu, rg))
723            ipt.append( cpy_back_and_cmp(ym1, ym2,'edge_values', gpu, rg))
724            ipt.append( cpy_back_and_cmp(xv1, xv2,'edge_values', gpu, rg))
725            ipt.append( cpy_back_and_cmp(yv1, yv2,'edge_values', gpu, rg))
726
727            res.append( cpy_back_and_cmp(s1, s2,'boundary_values', gpu,rg))
728            res.append( cpy_back_and_cmp(e1, e2,'boundary_values', gpu,rg))
729            res.append( cpy_back_and_cmp(h1, h2,'boundary_values', gpu,rg))
730            res.append( cpy_back_and_cmp(xm1,xm2,'boundary_values',gpu,rg))
731            res.append( cpy_back_and_cmp(ym1,ym2,'boundary_values',gpu,rg))
732            res.append( cpy_back_and_cmp(xv1,xv2,'boundary_values',gpu,rg))
733            res.append( cpy_back_and_cmp(yv1,yv2,'boundary_values',gpu,rg))
734
735            if ipt.count(True) + ipt.count(0) != ipt.__len__():
736               print "\n  Input values check ", ipt
737               if not res[0]:
738                   print "se", s1.edge_values, s2.edge_values
739               if not res[1]:
740                   print "ee", e1.edge_values, e2.edge_values
741               if not res[2]:
742                   print "he", h1.edge_values, h2.edge_values
743               if not res[3]:
744                   print "xme", xm1.edge_values, xm2.edge_values
745               if not res[4]:
746                   print "yme", ym1.edge_values, ym2.edge_values
747               if not res[5]:
748                   print "xve", xv1.edge_values, xv2.edge_values
749               if not res[6]:
750                   print "yve", yv1.edge_values, yv2.edge_values
751
752            if not inputOnly and res.count(True) != res.__len__():
753                print "\n Error in update_boundary", tag, res
754                if not res[0]:
755                    print "sb", s1.boundary_values, s2.boundary_values
756                if not res[1]:
757                    print "eb", e1.boundary_values, e2.boundary_values
758                if not res[2]:
759                    print "hb", h1.boundary_values, h2.boundary_values
760                if not res[3]:
761                    print "xmb", xm1.boundary_values, xm2.boundary_values
762                if not res[4]:
763                    print "ymb", ym1.boundary_values, ym2.boundary_values
764                if not res[5]:
765                    print "xvb", xv1.boundary_values, xv2.boundary_values
766                if not res[6]:
767                    print "yvb", yv1.boundary_values, yv2.boundary_values
768
769
770
771                raise Exception("Error in update_boundary reflective "+ tag)
772
773        elif isinstance( B1, Dirichlet_boundary ):
774            for j ,name in enumerate(domain.evolved_quantities):
775                Q1 = domain.quantities[name]
776                Q2 = sc.quantities[name]
777                if not cpy_back_and_cmp(Q1, Q2, "boundary_values"):
778                    print "Error in update_boundary", tag, name, Q1.boundary_values, Q2.boundary_values
779                    raise Exception()
780            if len( B1.dirichlet_values ) != \
781                        len(domain.evolved_quantities):
782                   
783                for j, name in enumerate(domain.conserved_quantities):
784                    Q1 = domain.quantities[name].boundary_values
785                    Q2 = sc.quantities[name].boundary_values
786                    if not numpy.allclose(Q1, Q2):
787                        print "Error in update_boundary", tag, name
788                        raise Exception()
789
790
791
792def test_update_other_quantities(domain):
793    """Pari-testing check point for update_other_quantities"""
794
795    # For time-dependence issues
796    #ctx.synchronize()
797
798    gpu = domain.using_gpu
799    rg = domain.rearranged_domain
800    sc = domain.cotesting_domain
801
802    h1 = domain.quantities['height']
803    xv1 = domain.quantities['xvelocity']
804    yv1 = domain.quantities['yvelocity']
805
806    h2 = sc.quantities['height']
807    xv2 = sc.quantities['xvelocity']
808    yv2 = sc.quantities['yvelocity']
809   
810    res = []
811
812    res.append( cpy_back_and_cmp(h1, h2,'edge_values', gpu, rg))
813    res.append( cpy_back_and_cmp(xv1, xv2,'edge_values', gpu, rg))
814    res.append( cpy_back_and_cmp(yv1, yv2,'edge_values', gpu, rg))
815
816    res.append( cpy_back_and_cmp(h1, h2,'vertex_values', gpu, rg))
817    res.append( cpy_back_and_cmp(xv1, xv2,'vertex_values', gpu, rg))
818    res.append( cpy_back_and_cmp(yv1, yv2,'vertex_values', gpu, rg))
819
820    res.append( cpy_back_and_cmp(h1, h2,'centroid_values', gpu, rg))
821    res.append( cpy_back_and_cmp(xv1, xv2,'centroid_values', gpu, rg))
822    res.append( cpy_back_and_cmp(yv1, yv2,'centroid_values', gpu, rg))
823
824    if res.count(True) + res.count(-1) != res.__len__():
825       raise Exception("Error in update_other_quantities", res)
826
827
828
829def test_compute_fluxes(domain):
830    """Pari-testing check point for compute_fluxes"""
831
832    # For time-dependence issues
833    #ctx.synchronize()
834
835    gpu = domain.using_gpu
836    rg = domain.rearranged_domain
837    sc = domain.cotesting_domain
838
839    s1 = domain.quantities['stage']
840    xm1 = domain.quantities['xmomentum']
841    ym1 = domain.quantities['ymomentum']
842    e1 = domain.quantities['elevation']
843    h1 = domain.quantities['height']
844    xv1 = domain.quantities['xvelocity']
845    yv1 = domain.quantities['yvelocity']
846    f1 = domain.quantities['friction']
847
848    s2 = sc.quantities['stage']
849    xm2 = sc.quantities['xmomentum']
850    ym2 = sc.quantities['ymomentum']
851    e2 = sc.quantities['elevation']
852    h2 = sc.quantities['height']
853    xv2 = sc.quantities['xvelocity']
854    yv2 = sc.quantities['yvelocity']
855    f2 = sc.quantities['friction']
856
857
858    res = []
859    res.append( numpy.allclose(domain.flux_timestep, sc.flux_timestep))
860
861
862    res.append( cpy_back_and_cmp( s1, s2, 'explicit_update' , gpu, rg))
863    res.append( cpy_back_and_cmp( s1, s2, 'edge_values' , gpu, rg))
864    res.append( cpy_back_and_cmp( s1, s2, 'boundary_values' , gpu, rg))
865
866
867    res.append( cpy_back_and_cmp( xm1, xm2,'explicit_update', gpu, rg))
868    res.append( cpy_back_and_cmp( xm1, xm2,'edge_values', gpu, rg))
869    res.append( cpy_back_and_cmp( xm1, xm2,'boundary_values', gpu, rg))
870   
871
872    res.append( cpy_back_and_cmp( ym1, ym2,'explicit_update', gpu, rg))
873    res.append( cpy_back_and_cmp( ym1, ym2,'edge_values', gpu, rg))
874    res.append( cpy_back_and_cmp( ym1, ym2,'boundary_values', gpu, rg))
875   
876
877    if res.count(True) + res.count(-1) != res.__len__():
878        if not res[0]:
879            print "   flux_timestep %.9lf %.9lf" % (
880                    domain.flux_timestep, sc.flux_timestep)
881        if not res[1]:
882            for i in range(domain.number_of_elements):
883                if not numpy.allclose( 
884                        s1.explicit_update[i], s2.explicit_update[i]):
885                    print 0,i, s1.explicit_update[i], s2.explicit_update[i]
886        if not res[4]:
887            for i in range(domain.number_of_elements):
888                if not numpy.allclose( 
889                        xm1.explicit_update[i], xm2.explicit_update[i]):
890                    print 1,i,xm1.explicit_update[i],xm2.explicit_update[i]
891        if not res[7]:
892            for i in range(domain.number_of_elements):
893                if not numpy.allclose( 
894                        ym1.explicit_update[i], ym2.explicit_update[i]):
895                    print 2,i,ym1.explicit_update[i],ym2.explicit_update[i]
896
897        res_name = ['flux_timestep',
898                    'stage_explicit', 'stage_edge', 'stage_boundary', 
899                    'xmom_explicit', 'xmom_edge', 'xmom_boundary',
900                    'ymom_explicit', 'ymom_edge', 'ymom_boundary']
901        raise Exception( " --> compute_fluxes", [ b for a,b in zip(res, res_name) if not a ])
902
903
904   
905def test_compute_forcing_terms(domain):
906    """Pari-testing check point for compute_forcing_terms"""
907
908    # For time-dependence issues
909    #ctx.synchronize()
910
911    gpu = domain.using_gpu
912    rg = domain.rearranged_domain
913    sc = domain.cotesting_domain
914
915
916    s1 = domain.quantities['stage']
917    xm1 = domain.quantities['xmomentum']
918    ym1 = domain.quantities['ymomentum']
919    e1 = domain.quantities['elevation']
920    f1 = domain.quantities['friction']
921
922    s2 = sc.quantities['stage']
923    xm2 = sc.quantities['xmomentum']
924    ym2 = sc.quantities['ymomentum']
925    e2 = sc.quantities['elevation']
926    f2 = sc.quantities['friction']
927
928    res = []
929    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
930
931    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
932    res.append( cpy_back_and_cmp( xm1, xm2,'semi_implicit_update', gpu,rg))
933
934    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
935    res.append( cpy_back_and_cmp( ym1, ym2,'semi_implicit_update', gpu,rg))
936
937    res.append( cpy_back_and_cmp( e1, e2, 'centroid_values', gpu, rg))
938    res.append( cpy_back_and_cmp( e1, e2, 'vertex_values', gpu, rg))
939
940    res.append( cpy_back_and_cmp( f1, f2, 'centroid_values', gpu, rg))
941
942    if res.count(True) + res.count(-1) != res.__len__():
943        raise Exception( " --> compute_forcing_terms ", res)
944
945
946
947def test_protect_against_infinitesimal_and_negative_heights(domain):
948    """Pari-testing check point for
949        protect_against_infinitesimal_and_negative_heights
950    """
951
952    # For time-dependence issues
953    #ctx.synchronize()
954
955    gpu = domain.using_gpu
956    rg = domain.rearranged_domain
957    sc = domain.cotesting_domain
958
959
960    s1 = domain.quantities['stage']
961    xm1 = domain.quantities['xmomentum']
962    ym1 = domain.quantities['ymomentum']
963    e1 = domain.quantities['elevation']
964
965    s2 = sc.quantities['stage']
966    xm2 = sc.quantities['xmomentum']
967    ym2 = sc.quantities['ymomentum']
968    e2 = sc.quantities['elevation']
969
970    res = []
971    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
972
973    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
974
975    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
976
977    res.append( cpy_back_and_cmp( e1, e2, 'centroid_values', gpu, rg))
978
979
980    if res.count(True) + res.count(-1) != res.__len__():
981        raise Exception( " --> protect_against_infinitesimal_and_negative_heights ",res)
982
983
984
985def test_extrapolate_second_order_sw(domain):
986    """Pari-testing check point for extrapolate_second_order_sw"""
987
988    # For time-dependence issues
989    #ctx.synchronize()
990
991    gpu = domain.using_gpu
992    rg = domain.rearranged_domain
993    sc = domain.cotesting_domain
994
995
996    s1 = domain.quantities['stage']
997    xm1 = domain.quantities['xmomentum']
998    ym1 = domain.quantities['ymomentum']
999    e1 = domain.quantities['elevation']
1000
1001    s2 = sc.quantities['stage']
1002    xm2 = sc.quantities['xmomentum']
1003    ym2 = sc.quantities['ymomentum']
1004    e2 = sc.quantities['elevation']
1005
1006    res = []
1007    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
1008    res.append( cpy_back_and_cmp( s1, s2, 'vertex_values', gpu, rg))
1009
1010    res.append( cpy_back_and_cmp( e1, e2, 'centroid_values', gpu, rg))
1011    res.append( cpy_back_and_cmp( e1, e2, 'vertex_values', gpu, rg))
1012
1013    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
1014    res.append( cpy_back_and_cmp( xm1, xm2,'vertex_values', gpu, rg))
1015
1016    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
1017    res.append( cpy_back_and_cmp( ym1, ym2,'vertex_values', gpu, rg))
1018
1019    res.append( domain.epsilon == sc.epsilon)
1020    res.append( domain.minimum_allowed_height == sc.minimum_allowed_height)
1021    res.append( domain.beta_w == sc.beta_w)
1022    res.append( domain.beta_w_dry == sc.beta_w_dry)
1023    res.append( domain.beta_uh == sc.beta_uh)
1024    res.append( domain.beta_uh_dry == sc.beta_uh_dry)
1025    res.append( domain.beta_vh == sc.beta_vh)
1026    res.append( domain.beta_vh_dry == sc.beta_vh_dry)
1027    res.append( domain.optimise_dry_cells == sc.optimise_dry_cells)
1028
1029    res.append( cpy_back_and_cmp( domain,sc,"surrogate_neighbours",gpu,rg))
1030    res.append( cpy_back_and_cmp( domain,sc,"number_of_boundaries",gpu,rg))
1031    res.append( cpy_back_and_cmp( domain,sc,"centroid_coordinates",gpu,rg))
1032    res.append( cpy_back_and_cmp( domain,sc,"vertex_coordinates",gpu,rg))
1033
1034    if res.count(True) + res.count(-1) != res.__len__():
1035        print res
1036
1037        if False:
1038            for i in range(domain.number_of_elements):
1039                if (xm1.vertex_values[i] != xm2.vertex_values[i]).all():
1040                    if domain.number_of_boundaries[i] == 1:
1041                        print i, xm1.vertex_values[i], xm2.vertex_values[i]
1042                    cnt += 1
1043            print cnt
1044
1045        raise Exception( " --> extrapolate_second_order_sw ", res)
1046
1047
1048
1049def test_balance_deep_and_shallow(domain):
1050    """Pari-testing check point for balance_deep_and_shallow"""
1051
1052    # For time-dependence issues
1053    #ctx.synchronize()
1054
1055    gpu = domain.using_gpu
1056    rg = domain.rearranged_domain
1057    sc = domain.cotesting_domain
1058
1059
1060    s1 = domain.quantities['stage']
1061    xm1 = domain.quantities['xmomentum']
1062    ym1 = domain.quantities['ymomentum']
1063    e1 = domain.quantities['elevation']
1064
1065    s2 = sc.quantities['stage']
1066    xm2 = sc.quantities['xmomentum']
1067    ym2 = sc.quantities['ymomentum']
1068    e2 = sc.quantities['elevation']
1069
1070    res = []
1071    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
1072    res.append( cpy_back_and_cmp( s1, s2, 'vertex_values', gpu, rg))
1073
1074    res.append( cpy_back_and_cmp( xm1, xm2,'centroid_values', gpu, rg))
1075    res.append( cpy_back_and_cmp( xm1, xm2,'vertex_values', gpu, rg))
1076
1077    res.append( cpy_back_and_cmp( ym1, ym2,'centroid_values', gpu, rg))
1078    res.append( cpy_back_and_cmp( ym1, ym2,'vertex_values', gpu, rg))
1079
1080    res.append( cpy_back_and_cmp( e1, e2, 'centroid_values', gpu, rg))
1081    res.append( cpy_back_and_cmp( e1, e2, 'vertex_values', gpu, rg))
1082
1083
1084    if res.count(True) + res.count(-1) != res.__len__():
1085        raise Exception( " --> balance_deep_and_shallow ", res)
1086       
1087
1088
1089def test_interpolate_from_vertices_to_edges(domain):
1090    """Pari-testing check point for interpolate_from_vertices_to_edges"""
1091
1092    # For time-dependence issues
1093    #ctx.synchronize()
1094
1095    gpu = domain.using_gpu
1096    rg = domain.rearranged_domain
1097    sc = domain.cotesting_domain
1098
1099
1100    s1 = domain.quantities['stage']
1101    xm1 = domain.quantities['xmomentum']
1102    ym1 = domain.quantities['ymomentum']
1103
1104    s2 = sc.quantities['stage']
1105    xm2 = sc.quantities['xmomentum']
1106    ym2 = sc.quantities['ymomentum']
1107
1108    res = []
1109    res.append( cpy_back_and_cmp( s1, s2, 'vertex_values', gpu, rg))
1110    res.append( cpy_back_and_cmp( s1, s2, 'edge_values', gpu, rg))
1111
1112    res.append( cpy_back_and_cmp( xm1, xm2,'vertex_values', gpu, rg))
1113    res.append( cpy_back_and_cmp( xm1, xm2,'edge_values', gpu, rg))
1114
1115    res.append( cpy_back_and_cmp( ym1, ym2,'vertex_values', gpu, rg))
1116    res.append( cpy_back_and_cmp( ym1, ym2,'edge_values', gpu, rg))
1117
1118
1119    if res.count(True) + res.count(-1) != res.__len__():
1120        for i in range(domain.number_of_elements):
1121            if not numpy.allclose(s1.edge_values[i], s2.edge_values[i]):
1122                print i, s1.edge_values[i], s2.edge_values[i]
1123        raise Exception( " --> interpolate_from_vertices_to_edges ", res)
1124
1125
1126
1127def test_extrapolate_second_order_and_limit_by_vertex(domain):
1128    """Pari-testing check point for
1129        extrapolate_second_order_and_limit_by_vertex
1130    """
1131
1132    # For time-dependence issues
1133    #ctx.synchronize()
1134
1135    gpu = domain.using_gpu
1136    rg = domain.rearranged_domain
1137    sc = domain.cotesting_domain
1138
1139
1140    s1 = domain.quantities['stage']
1141    xm1 = domain.quantities['xmomentum']
1142    ym1 = domain.quantities['ymomentum']
1143
1144    s2 = sc.quantities['stage']
1145    xm2 = sc.quantities['xmomentum']
1146    ym2 = sc.quantities['ymomentum']
1147
1148    res = []
1149    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
1150    res.append( cpy_back_and_cmp( s1, s2, 'vertex_values', gpu, rg))
1151    res.append( cpy_back_and_cmp( s1, s2, 'edge_values', gpu, rg))
1152    res.append( cpy_back_and_cmp( s1, s2, 'x_gradient', gpu, rg))
1153    res.append( cpy_back_and_cmp( s1, s2, 'y_gradient', gpu, rg))
1154
1155
1156    res.append( cpy_back_and_cmp( x1, x2, 'centroid_values', gpu, rg))
1157    res.append( cpy_back_and_cmp( x1, x2, 'vertex_values', gpu, rg))
1158    res.append( cpy_back_and_cmp( x1, x2, 'edge_values', gpu, rg))
1159    res.append( cpy_back_and_cmp( x1, x2, 'x_gradient', gpu, rg))
1160    res.append( cpy_back_and_cmp( x1, x2, 'y_gradient', gpu, rg))
1161
1162
1163    res.append( cpy_back_and_cmp( y1, y2, 'centroid_values', gpu, rg))
1164    res.append( cpy_back_and_cmp( y1, y2, 'vertex_values', gpu, rg))
1165    res.append( cpy_back_and_cmp( y1, y2, 'edge_values', gpu, rg))
1166    res.append( cpy_back_and_cmp( y1, y2, 'x_gradient', gpu, rg))
1167    res.append( cpy_back_and_cmp( y1, y2, 'y_gradient', gpu, rg))
1168
1169
1170    if res.count(True) + res.count(-1) != res.__len__():
1171        raise Exception( " --> extrapolate_second_order_and_limit_by_vertex ", res)
1172
1173   
1174
1175def test_extrapolate_first_order(domain):
1176    """Pari-testing check point for extrapolate_first_order"""
1177
1178    # For time-dependence issues
1179    #ctx.synchronize()
1180
1181    gpu = domain.using_gpu
1182    rg = domain.rearranged_domain
1183    sc = domain.cotesting_domain
1184
1185
1186    s1 = domain.quantities['stage']
1187    xm1 = domain.quantities['xmomentum']
1188    ym1 = domain.quantities['ymomentum']
1189
1190    s2 = sc.quantities['stage']
1191    xm2 = sc.quantities['xmomentum']
1192    ym2 = sc.quantities['ymomentum']
1193
1194    res = []
1195    res.append( cpy_back_and_cmp( s1, s2, 'centroid_values', gpu, rg))
1196    res.append( cpy_back_and_cmp( s1, s2, 'vertex_values', gpu, rg))
1197    res.append( cpy_back_and_cmp( s1, s2, 'edge_values', gpu, rg))
1198
1199
1200    res.append( cpy_back_and_cmp( x1, x2, 'centroid_values', gpu, rg))
1201    res.append( cpy_back_and_cmp( x1, x2, 'vertex_values', gpu, rg))
1202    res.append( cpy_back_and_cmp( x1, x2, 'edge_values', gpu, rg))
1203
1204    res.append( cpy_back_and_cmp( y1, y2, 'centroid_values', gpu, rg))
1205    res.append( cpy_back_and_cmp( y1, y2, 'vertex_values', gpu, rg))
1206    res.append( cpy_back_and_cmp( y1, y2, 'edge_values', gpu, rg))
1207
1208
1209    if res.count(True) + res.count(-1) != res.__len__():
1210        raise Exception( " --> extrapolate_first_order ", res)
1211
1212
1213
1214def test_update_centroids_of_velocities_and_height(domain):
1215    """Pari-testing check point for
1216        update_centroids_of_velocities_and_height
1217    """
1218
1219    # For time-dependence issues
1220    #ctx.synchronize()
1221
1222    gpu = domain.using_gpu
1223    rg = domain.rearranged_domain
1224    sc = domain.cotesting_domain
1225
1226    s1 = domain.quantities['stage']
1227    xm1 = domain.quantities['xmomentum']
1228    ym1 = domain.quantities['ymomentum']
1229    e1 = domain.quantities['elevation']
1230    h1 = domain.quantities['height']
1231    xv1 = domain.quantities['xvelocity']
1232    yv1 = domain.quantities['yvelocity']
1233
1234    s2 = sc.quantities['stage']
1235    xm2 = sc.quantities['xmomentum']
1236    ym2 = sc.quantities['ymomentum']
1237    e2 = sc.quantities['elevation']
1238    h2 = sc.quantities['height']
1239    xv2 = sc.quantities['xvelocity']
1240    yv2 = sc.quantities['yvelocity']
1241   
1242           
1243    res = []
1244
1245    res.append( cpy_back_and_cmp(s1, s2,'boundary_values', gpu, rg))
1246    res.append( cpy_back_and_cmp(e1, e2,'boundary_values', gpu, rg))
1247    res.append( cpy_back_and_cmp(h1, h2,'boundary_values', gpu, rg))
1248    res.append( cpy_back_and_cmp(xm1, xm2,'boundary_values', gpu, rg))
1249    res.append( cpy_back_and_cmp(ym1, ym2,'boundary_values', gpu, rg))
1250    res.append( cpy_back_and_cmp(xv1, xv2,'boundary_values', gpu, rg))
1251    res.append( cpy_back_and_cmp(yv1, yv2,'boundary_values', gpu, rg))
1252
1253    res.append( cpy_back_and_cmp(s1, s2,'centroid_values', gpu, rg))
1254    res.append( cpy_back_and_cmp(e1, e2,'centroid_values', gpu, rg))
1255    res.append( cpy_back_and_cmp(h1, h2,'centroid_values', gpu, rg))
1256    res.append( cpy_back_and_cmp(xm1, xm2,'centroid_values', gpu, rg))
1257    res.append( cpy_back_and_cmp(ym1, ym2,'centroid_values', gpu, rg))
1258    res.append( cpy_back_and_cmp(xv1, xv2,'centroid_values', gpu, rg))
1259    res.append( cpy_back_and_cmp(yv1, yv2,'centroid_values', gpu, rg))
1260
1261    if res.count(True) + res.count(-1) != res.__len__():
1262        if not res[12]:
1263            for i in range(domain.number_of_elements):
1264                if not numpy.allclose(
1265                        xv1.centroid_values[i],
1266                        xv2.centroid_values[i]) :
1267                    print "  xvelocity centroid %d %lf %lf" % \
1268                        (i, xv1.centroid_values[i], xv2.centroid_values[i])
1269        raise Exception("Error in update_centroids_of_velocities_and_height", res)
1270
1271
Note: See TracBrowser for help on using the repository browser.