Memosa-FVM  0.2
Array2D.h
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifndef _ARRAY2D_H_
6 #define _ARRAY2D_H_
7 
8 #include "ArrayBase.h"
9 #include <iostream>
10 #include <iomanip>
11 #include "NumType.h"
12 
13 template <class T>
14 class Array2D
15 {
16 
17 public:
18 
19 
20  explicit Array2D(const int row_size, const int col_size):
21  _self(*this),
22  _rowSize(row_size),
23  _colSize(col_size),
24  _length(row_size*col_size),
25  _data(new T[_length])
26  {
27  init();
28  }
29 
30 
32  {
33  delete [] _data;
34  }
35 
36 
37  int getRow() const { return _rowSize; }
38  int getCol() const { return _colSize; }
39 
40 
46  T& operator()(const int i, const int j)
47  {
48  return _data[i*_colSize+j];
49  }
50 
51  const T& operator()(const int i, const int j) const
52  {
53  return _data[i*_colSize+j];
54  }
55  void operator=(const T& x){
56  for ( int i = 0; i < _length; i++ )
57  _data[i] = x;
58  }
59  //copy of aij to this array
60  void partialCopyFrom(const Array2D& aij){
61  const int nrow = aij.getRow();
62  const int ncol = aij.getCol();
63  for ( int i = 0; i < nrow; i++ ){
64  for ( int j = 0; j < ncol; j++){
65  _self(i,j) = aij(i,j);
66  }
67  }
68  }
69  //partial copy of this array to aij
70  void partialCopyTo(Array2D& aij){
71  const int nrow = aij.getRow();
72  const int ncol = aij.getCol();
73  for ( int i = 0; i < nrow; i++ ){
74  for ( int j = 0; j < ncol; j++){
75  aij(i,j) = _self(i,j);
76  }
77  }
78  }
79 
80  void zeros()
81  {
82  for ( int i = 0; i < _length; i++ )
84  }
85  void setIdentity()
86  {
87  for ( int i = 0; i < _rowSize; i++ ){
88  for ( int j = 0; j < _colSize; j++){
89  if ( i == j )
91 
92  }
93  }
94  }
95 
96 
97  void* getData() { return _data;}
98  int getDataSize() const
99  {
101  }
102 
103 
104  void print(ostream& os) const
105  {
106  for ( int i = 0; i < _rowSize; i++){
107  for ( int j = 0; j < _colSize; j++ ){
108  os << std::setprecision(14) << this->operator()(i,j) << " ";
109  }
110  os << "\n";
111  }
112  os << endl;
113  }
114 
115 private:
116  Array2D(const Array2D&);
117  void init()
118  {
119  for ( int i = 0; i < _length; i++ )
120  _data[i] = NumTypeTraits<T>::getZero();//NumTypeTraits<T>::getNegativeUnity();
121  }
122 
124 
125  int _rowSize;
126  int _colSize;
127  int _length;
128  T* _data;
129 };
130 
131 
132 #endif
int getRow() const
Definition: Array2D.h:37
void * getData()
Definition: Array2D.h:97
void partialCopyFrom(const Array2D &aij)
Definition: Array2D.h:60
Array2D(const int row_size, const int col_size)
Definition: Array2D.h:20
int _colSize
Definition: Array2D.h:126
int _rowSize
Definition: Array2D.h:125
void partialCopyTo(Array2D &aij)
Definition: Array2D.h:70
T & operator()(const int i, const int j)
Definition: Array2D.h:46
~Array2D()
Definition: Array2D.h:31
void operator=(const T &x)
Definition: Array2D.h:55
void init()
Definition: Array2D.h:117
Array2D & _self
Definition: Array2D.h:123
void setIdentity()
Definition: Array2D.h:85
void print(ostream &os) const
Definition: Array2D.h:104
int getCol() const
Definition: Array2D.h:38
const T & operator()(const int i, const int j) const
Definition: Array2D.h:51
T * _data
Definition: Array2D.h:128
void zeros()
Definition: Array2D.h:80
int getDataSize() const
Definition: Array2D.h:98
int _length
Definition: Array2D.h:127