All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
matrix_generation.hpp
Go to the documentation of this file.
#ifndef VIENNACL_TOOLS_MATRIX_GENERATION_HPP_
#define VIENNACL_TOOLS_MATRIX_GENERATION_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <string>
#include <fstream>
#include <sstream>
#include "viennacl/forwards.h"
#include "viennacl/meta/result_of.hpp"
#include "viennacl/tools/adapter.hpp"
#include <vector>
#include <map>
namespace viennacl
{
namespace tools
{
template<typename MatrixType>
void generate_fdm_laplace(MatrixType & A, vcl_size_t points_x, vcl_size_t points_y)
{
vcl_size_t total_unknowns = points_x * points_y;
A.clear();
A.resize(total_unknowns, total_unknowns, false);
for (vcl_size_t i=0; i<points_x; ++i)
{
for (vcl_size_t j=0; j<points_y; ++j)
{
vcl_size_t row = i + j * points_x;
A(row, row) = 4.0;
if (i > 0)
{
vcl_size_t col = (i-1) + j * points_x;
A(row, col) = -1.0;
}
if (j > 0)
{
vcl_size_t col = i + (j-1) * points_x;
A(row, col) = -1.0;
}
if (i < points_x-1)
{
vcl_size_t col = (i+1) + j * points_x;
A(row, col) = -1.0;
}
if (j < points_y-1)
{
vcl_size_t col = i + (j+1) * points_x;
A(row, col) = -1.0;
}
}
}
}
template<typename NumericT>
void generate_fdm_laplace(viennacl::compressed_matrix<NumericT> & A, vcl_size_t points_x, vcl_size_t points_y)
{
// Assemble into temporary matrix on CPU, then copy over:
std::vector< std::map<unsigned int, NumericT> > temp_A;
viennacl::tools::sparse_matrix_adapter<NumericT> adapted_A(temp_A);
generate_fdm_laplace(adapted_A, points_x, points_y);
viennacl::copy(temp_A, A);
}
template<typename NumericT>
void generate_fdm_laplace(viennacl::coordinate_matrix<NumericT> & A, vcl_size_t points_x, vcl_size_t points_y)
{
// Assemble into temporary matrix on CPU, then copy over:
std::vector< std::map<unsigned int, NumericT> > temp_A;
viennacl::tools::sparse_matrix_adapter<NumericT> adapted_A(temp_A);
generate_fdm_laplace(adapted_A, points_x, points_y);
viennacl::copy(temp_A, A);
}
template<typename NumericT>
void generate_fdm_laplace(viennacl::ell_matrix<NumericT> & A, vcl_size_t points_x, vcl_size_t points_y)
{
// Assemble into temporary matrix on CPU, then copy over:
std::vector< std::map<unsigned int, NumericT> > temp_A;
viennacl::tools::sparse_matrix_adapter<NumericT> adapted_A(temp_A);
generate_fdm_laplace(adapted_A, points_x, points_y);
viennacl::copy(temp_A, A);
}
template<typename NumericT>
void generate_fdm_laplace(viennacl::sliced_ell_matrix<NumericT> & A, vcl_size_t points_x, vcl_size_t points_y)
{
// Assemble into temporary matrix on CPU, then copy over:
std::vector< std::map<unsigned int, NumericT> > temp_A;
viennacl::tools::sparse_matrix_adapter<NumericT> adapted_A(temp_A);
generate_fdm_laplace(adapted_A, points_x, points_y);
viennacl::copy(temp_A, A);
}
template<typename NumericT>
void generate_fdm_laplace(viennacl::hyb_matrix<NumericT> & A, vcl_size_t points_x, vcl_size_t points_y)
{
// Assemble into temporary matrix on CPU, then copy over:
std::vector< std::map<unsigned int, NumericT> > temp_A;
viennacl::tools::sparse_matrix_adapter<NumericT> adapted_A(temp_A);
generate_fdm_laplace(adapted_A, points_x, points_y);
viennacl::copy(temp_A, A);
}
} //namespace tools
} //namespace viennacl
#endif
viennacl::hyb_matrix
Sparse matrix class using a hybrid format composed of the ELL and CSR format for storing the nonzeros...
Definition: forwards.h:406
adapter.hpp
Adapter classes for sparse matrices made of the STL type std::vector<std::map<SizeT, NumericT> >
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::tools::generate_fdm_laplace
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...
Definition: matrix_generation.hpp:48
viennacl::ell_matrix
Sparse matrix class using the ELLPACK format for storing the nonzeros.
Definition: ell_matrix.hpp:53
viennacl::sliced_ell_matrix
Sparse matrix class using the sliced ELLPACK with parameters C, .
Definition: forwards.h:403
viennacl::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::row
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:910
viennacl::copy
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) ...
Definition: circulant_matrix.hpp:150
viennacl::tools::sparse_matrix_adapter
Adapts a non-const sparse matrix type made up from std::vector<std::map<SizeT, NumericT> > to basic u...
Definition: adapter.hpp:357
viennacl::compressed_matrix< NumericT >
result_of.hpp
A collection of compile time type deductions.
viennacl::coordinate_matrix
A sparse square matrix, where entries are stored as triplets (i,j, val), where i and j are the row an...
Definition: coordinate_matrix.hpp:186