/[escript]/trunk/cusplibrary/cusp/gallery/grid.h
ViewVC logotype

Contents of /trunk/cusplibrary/cusp/gallery/grid.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5148 - (show annotations)
Mon Sep 15 01:25:23 2014 UTC (5 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 3179 byte(s)
Merging ripley diagonal storage + CUDA support into trunk.
Options file version has been incremented due to new options
'cuda' and 'nvccflags'.

1 /*
2 * Copyright 2008-2009 NVIDIA Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*! \file poisson.h
18 * \brief Poisson matrix generators
19 */
20
21 #pragma once
22
23 #include <cusp/detail/config.h>
24
25 #include <cusp/gallery/stencil.h>
26
27 namespace cusp
28 {
29 namespace gallery
30 {
31 /*! \addtogroup gallery Matrix Gallery
32 * \addtogroup grid Grid
33 * \ingroup gallery
34 * \{
35 */
36
37 /*! \p grid2d: Create a matrix representing a 2d \p m by \p n grid.
38 *
39 * \param matrix output
40 * \param m number of grid rows
41 * \param n number of grid columns
42 * \tparam MatrixType matrix container
43 *
44 * \code
45 * #include <cusp/gallery/grid.h>
46 * #include <cusp/coo_matrix.h>
47 * #include <cusp/print.h>
48 *
49 * int main(void)
50 * {
51 * cusp::coo_matrix<int, float, cusp::device_memory> A;
52 *
53 * // create a matrix for a 4x4 grid
54 * cusp::gallery::grid2d(A, 4, 4);
55 *
56 * // print matrix
57 * cusp::print(A);
58 *
59 * return 0;
60 * }
61 * \endcode
62 *
63 */
64 template <typename MatrixType>
65 void grid2d( MatrixType& matrix, size_t m, size_t n)
66 {
67 CUSP_PROFILE_SCOPED();
68
69 typedef typename MatrixType::index_type IndexType;
70 typedef typename MatrixType::value_type ValueType;
71 typedef thrust::tuple<IndexType,IndexType> StencilIndex;
72 typedef thrust::tuple<StencilIndex,ValueType> StencilPoint;
73
74 cusp::array1d<StencilPoint, cusp::host_memory> stencil;
75 stencil.push_back(StencilPoint(StencilIndex( 0, -1), 1));
76 stencil.push_back(StencilPoint(StencilIndex( -1, 0), 1));
77 stencil.push_back(StencilPoint(StencilIndex( 1, 0), 1));
78 stencil.push_back(StencilPoint(StencilIndex( 0, 1), 1));
79
80 cusp::gallery::generate_matrix_from_stencil(matrix, stencil, StencilIndex(m,n));
81 }
82 template <typename MatrixType>
83 void grid3d( MatrixType& matrix, size_t m, size_t n, size_t l)
84 {
85 CUSP_PROFILE_SCOPED();
86
87 typedef typename MatrixType::index_type IndexType;
88 typedef typename MatrixType::value_type ValueType;
89 typedef thrust::tuple<IndexType,IndexType,IndexType> StencilIndex;
90 typedef thrust::tuple<StencilIndex,ValueType> StencilPoint;
91
92 cusp::array1d<StencilPoint, cusp::host_memory> stencil;
93 for( IndexType k = -1; k <= 1; k++ )
94 for( IndexType j = -1; j <= 1; j++ )
95 for( IndexType i = -1; i <= 1; i++ )
96 if(i==0 && j==0 && k== 0) continue;
97 else stencil.push_back(StencilPoint(StencilIndex( i, j, k), 1));
98
99 cusp::gallery::generate_matrix_from_stencil(matrix, stencil, StencilIndex(m,n,l));
100 }
101 /*! \}
102 */
103
104 } // end namespace gallery
105 } // end namespace cusp

  ViewVC Help
Powered by ViewVC 1.1.26