LoAdSG
stencil.h
1#ifndef STENCIL_H
2#define STENCIL_H
3
4#include<iostream>
5#include<cmath>
6#include<vector>
7#include<map>
8#include "matrix.h"
9
10class Stencil{
11private:
12 int rows;
13
14 std::vector<std::map<int,double> > data;
15
16public:
17 Stencil(int rows_){
18 this->rows = rows_;
19 std::map<int,double> init;
20 init.insert(std::pair<int,double>(0,0.0));
21 for(int i=0;i<rows;i++){
22 data.push_back(init);
23 }
24 }
25
26 ~Stencil(){
27
28 }
29
30 int getRows(){
31 return rows;
32 }
33 bool exists(int row, int col){
34 std::map<int,double> &rowmap = data[row];
35 if(rowmap.find(col) != rowmap.end()){
36 return true;
37 }
38 else return false;
39 }
40
41 void create(int row, int col){
42 std::map<int,double> &rowmap = data[row];
43 rowmap.insert(std::pair<int,double>(col,0.0));
44 }
45
46 double& value(int row, int col){
47 std::map<int,double> &rowmap = data[row];
48 return rowmap[col];
49 }
50
51 Matrix multiply(Matrix &b){
52 Matrix c(b);
53 if(b.getCols() != 1 || b.getRows() != rows){
54 std::cerr<<"Stencil vector multiplication not possible";
55 }
56 for(int i=0;i<rows;i++){
57 c.value(i,0) = 0;
58 for(std::map<int,double>::iterator it = data[i].begin();it != data[i].end(); it++){
59 c.value(i,0) += b.value(it->first,0)*(it->second);
60 }
61 }
62 return c;
63 }
64};
65#endif // STENCIL_H
66