/[escript]/branches/diaplayground/cusplibrary/testing/stencil.cu
ViewVC logotype

Contents of /branches/diaplayground/cusplibrary/testing/stencil.cu

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4955 - (show annotations)
Tue May 20 04:33:15 2014 UTC (5 years, 3 months ago) by caltinay
File size: 2802 byte(s)
added pristine copy of cusplibrary (apache license) to be used by ripley.

1 #include <unittest/unittest.h>
2
3 #include <cusp/gallery/stencil.h>
4
5 void TestGenerateMatrixFromStencil1d(void)
6 {
7 typedef int IndexType;
8 typedef float ValueType;
9 typedef thrust::tuple<IndexType> StencilIndex;
10 typedef thrust::tuple<StencilIndex,ValueType> StencilPoint;
11
12 cusp::array1d<StencilPoint, cusp::host_memory> stencil;
13
14 stencil.push_back(StencilPoint(StencilIndex(-1), 1));
15 stencil.push_back(StencilPoint(StencilIndex( 0), 2));
16 stencil.push_back(StencilPoint(StencilIndex( 2), 3));
17
18 cusp::dia_matrix<int, float, cusp::host_memory> matrix;
19 cusp::gallery::generate_matrix_from_stencil(matrix,
20 stencil,
21 StencilIndex(4));
22
23 // convert result to array2d
24 cusp::array2d<float, cusp::host_memory> R(matrix);
25
26 cusp::array2d<float, cusp::host_memory> E(4,4);
27
28 E(0,0) = 2; E(0,1) = 0; E(0,2) = 3; E(0,3) = 0;
29 E(1,0) = 1; E(1,1) = 2; E(1,2) = 0; E(1,3) = 3;
30 E(2,0) = 0; E(2,1) = 1; E(2,2) = 2; E(2,3) = 0;
31 E(3,0) = 0; E(3,1) = 0; E(3,2) = 1; E(3,3) = 2;
32
33 ASSERT_EQUAL_QUIET(R, E);
34 }
35 DECLARE_UNITTEST(TestGenerateMatrixFromStencil1d);
36
37 void TestGenerateMatrixFromStencil2d(void)
38 {
39 typedef int IndexType;
40 typedef float ValueType;
41 typedef thrust::tuple<IndexType,IndexType> StencilIndex;
42 typedef thrust::tuple<StencilIndex,ValueType> StencilPoint;
43
44 cusp::array1d<StencilPoint, cusp::host_memory> stencil;
45
46 stencil.push_back(StencilPoint(StencilIndex(-1, -1), 1));
47 stencil.push_back(StencilPoint(StencilIndex(-1, 0), 2));
48 stencil.push_back(StencilPoint(StencilIndex( 0, 0), 3));
49 stencil.push_back(StencilPoint(StencilIndex( 1, 0), 4));
50 stencil.push_back(StencilPoint(StencilIndex( 0, 2), 5));
51
52 // grid is 2x3
53 // [45]
54 // [23]
55 // [01]
56
57 cusp::dia_matrix<int, float, cusp::host_memory> matrix;
58 cusp::gallery::generate_matrix_from_stencil(matrix,
59 stencil,
60 StencilIndex(2,3));
61
62 // convert result to array2d
63 cusp::array2d<float, cusp::host_memory> R(matrix);
64
65 cusp::array2d<float, cusp::host_memory> E(6,6);
66
67 E(0,0) = 3; E(0,1) = 4; E(0,2) = 0; E(0,3) = 0; E(0,4) = 5; E(0,5) = 0;
68 E(1,0) = 2; E(1,1) = 3; E(1,2) = 0; E(1,3) = 0; E(1,4) = 0; E(1,5) = 5;
69 E(2,0) = 0; E(2,1) = 0; E(2,2) = 3; E(2,3) = 4; E(2,4) = 0; E(2,5) = 0;
70 E(3,0) = 1; E(3,1) = 0; E(3,2) = 2; E(3,3) = 3; E(3,4) = 0; E(3,5) = 0;
71 E(4,0) = 0; E(4,1) = 0; E(4,2) = 0; E(4,3) = 0; E(4,4) = 3; E(4,5) = 4;
72 E(5,0) = 0; E(5,1) = 0; E(5,2) = 1; E(5,3) = 0; E(5,4) = 2; E(5,5) = 3;
73
74 ASSERT_EQUAL_QUIET(R, E);
75 }
76 DECLARE_UNITTEST(TestGenerateMatrixFromStencil2d);
77

  ViewVC Help
Powered by ViewVC 1.1.26