ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
matrix_generation.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_TOOLS_MATRIX_GENERATION_HPP_
2 #define VIENNACL_TOOLS_MATRIX_GENERATION_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2015, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include <string>
26 #include <fstream>
27 #include <sstream>
28 #include "viennacl/forwards.h"
31 
32 #include <vector>
33 #include <map>
34 
35 namespace viennacl
36 {
37 namespace tools
38 {
39 
47 template<typename MatrixType>
48 void generate_fdm_laplace(MatrixType & A, vcl_size_t points_x, vcl_size_t points_y)
49 {
50  typedef typename MatrixType::value_type ScalarType;
51 
52  vcl_size_t total_unknowns = points_x * points_y;
53 
54  A.clear();
55  A.resize(total_unknowns, total_unknowns, false);
56 
57  for (vcl_size_t i=0; i<points_x; ++i)
58  {
59  for (vcl_size_t j=0; j<points_y; ++j)
60  {
61  vcl_size_t row = i + j * points_x;
62 
63  A(row, row) = 4.0;
64 
65  if (i > 0)
66  {
67  vcl_size_t col = (i-1) + j * points_x;
68  A(row, col) = -1.0;
69  }
70 
71  if (j > 0)
72  {
73  vcl_size_t col = i + (j-1) * points_x;
74  A(row, col) = -1.0;
75  }
76 
77  if (i < points_x-1)
78  {
79  vcl_size_t col = (i+1) + j * points_x;
80  A(row, col) = -1.0;
81  }
82 
83  if (j < points_y-1)
84  {
85  vcl_size_t col = i + (j+1) * points_x;
86  A(row, col) = -1.0;
87  }
88  }
89  }
90 
91 }
92 
93 template<typename NumericT>
95 {
96  // Assemble into temporary matrix on CPU, then copy over:
97  std::vector< std::map<unsigned int, NumericT> > temp_A;
99  generate_fdm_laplace(adapted_A, points_x, points_y);
100  viennacl::copy(temp_A, A);
101 }
102 
103 template<typename NumericT>
105 {
106  // Assemble into temporary matrix on CPU, then copy over:
107  std::vector< std::map<unsigned int, NumericT> > temp_A;
109  generate_fdm_laplace(adapted_A, points_x, points_y);
110  viennacl::copy(temp_A, A);
111 }
112 
113 template<typename NumericT>
115 {
116  // Assemble into temporary matrix on CPU, then copy over:
117  std::vector< std::map<unsigned int, NumericT> > temp_A;
119  generate_fdm_laplace(adapted_A, points_x, points_y);
120  viennacl::copy(temp_A, A);
121 }
122 
123 template<typename NumericT>
125 {
126  // Assemble into temporary matrix on CPU, then copy over:
127  std::vector< std::map<unsigned int, NumericT> > temp_A;
129  generate_fdm_laplace(adapted_A, points_x, points_y);
130  viennacl::copy(temp_A, A);
131 }
132 
133 template<typename NumericT>
135 {
136  // Assemble into temporary matrix on CPU, then copy over:
137  std::vector< std::map<unsigned int, NumericT> > temp_A;
139  generate_fdm_laplace(adapted_A, points_x, points_y);
140  viennacl::copy(temp_A, A);
141 }
142 
143 
144 } //namespace tools
145 } //namespace viennacl
146 
147 
148 #endif
Sparse matrix class using a hybrid format composed of the ELL and CSR format for storing the nonzeros...
Definition: forwards.h:406
Adapter classes for sparse matrices made of the STL type std::vector >
This file provides the forward declarations for the main types used within ViennaCL.
void generate_fdm_laplace(MatrixType &A, vcl_size_t points_x, vcl_size_t points_y)
Generates a sparse matrix obtained from a simple finite-difference discretization of the Laplace equa...
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
Sparse matrix class using the ELLPACK format for storing the nonzeros.
Definition: ell_matrix.hpp:53
Sparse matrix class using the sliced ELLPACK with parameters C, .
Definition: forwards.h:403
std::size_t vcl_size_t
Definition: forwards.h:75
vector_expression< const matrix_base< NumericT, F >, const unsigned int, op_row > row(const matrix_base< NumericT, F > &A, unsigned int i)
Definition: matrix.hpp:900
void copy(std::vector< NumericT > &cpu_vec, circulant_matrix< NumericT, AlignmentV > &gpu_mat)
Copies a circulant matrix from the std::vector to the OpenCL device (either GPU or multi-core CPU) ...
float ScalarType
Definition: fft_1d.cpp:42
Adapts a non-const sparse matrix type made up from std::vector > to basic u...
Definition: adapter.hpp:357
A collection of compile time type deductions.
A sparse square matrix, where entries are stored as triplets (i,j, val), where i and j are the row an...