Canoe
Comprehensive Atmosphere N' Ocean Engine
RectGrid.h
Go to the documentation of this file.
1 #ifndef SRC_TRANSPORT_RECTGRID_H_
2 #define SRC_TRANSPORT_RECTGRID_H_
3 #include <deal.II/lac/sparse_matrix.h>
4 
5 #include <Eigen/Core>
6 
7 template <typename _Scalar, int _Dim>
8 class RectGrid {};
9 
10 template <typename _Scalar>
11 class RectGrid<_Scalar, 2> {
12  protected:
13  typedef _Scalar Scalar;
14  enum { Dimension = 2 };
15 
16  int m_nrows, m_ncols, m_nhalo, m_nrowsh, m_ncolsh;
17 
18  int64_t m_rank, m_rankh;
19 
20  Scalar m_dd; // reference grid size
21 
22  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> m_row_map, m_row_axis;
23 
24  Eigen::Matrix<Scalar, 1, Eigen::Dynamic> m_col_map, m_col_axis;
25 
26  Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> m_rowcol_map;
27 
28  dealii::SparsityPattern m_pattern;
29 
30  public:
31  RectGrid(int nrows, int ncols, int nhalo)
32  : m_nrows(nrows),
33  m_ncols(ncols),
34  m_nhalo(nhalo),
35  m_nrowsh(nrows + 2 * nhalo),
36  m_ncolsh(ncols + 2 * nhalo),
37  m_rank(nrows * ncols),
38  m_rankh(m_nrowsh * m_ncolsh),
39  m_row_map(nrows),
40  m_row_axis(nrows),
41  m_col_map(ncols),
42  m_col_axis(ncols),
43  m_rowcol_map(nrows, ncols),
44  m_pattern(m_rank, m_rankh, 9) {
45  for (int i = 0; i < m_nrows; i++)
46  for (int j = 0; j < m_ncols; j++) {
47  int64_t k = global(i, j);
48  m_pattern.add(k, globalh(i, j));
49  m_pattern.add(k, globalh(i - 1, j));
50  m_pattern.add(k, globalh(i, j - 1));
51  m_pattern.add(k, globalh(i + 1, j));
52  m_pattern.add(k, globalh(i, j + 1));
53  m_pattern.add(k, globalh(i - 1, j - 1));
54  m_pattern.add(k, globalh(i - 1, j + 1));
55  m_pattern.add(k, globalh(i + 1, j - 1));
56  m_pattern.add(k, globalh(i + 1, j + 1));
57  }
58  m_pattern.compress();
59 
60  // reference RectGrid is defined at [0, 1] x [0, 1]
61  m_dd = 1. / (nrows + 1);
62  }
63 
64  inline const dealii::SparsityPattern& pattern() const { return m_pattern; }
65 
66  inline int64_t global(int i, int j) const { return i * m_ncols + j; }
67 
68  inline int64_t globalh(int i, int j) const {
69  return (i + m_nhalo) * m_ncolsh + (j + m_nhalo);
70  }
71 
72  inline int rows() const { return m_nrows; }
73 
74  inline int rowsh() const { return m_nrowsh; }
75 
76  inline int cols() const { return m_ncols; }
77 
78  inline int colsh() const { return m_ncolsh; }
79 
80  inline int halo() const { return m_nhalo; }
81 
82  inline int64_t rank() const { return m_rank; }
83 
84  inline int64_t rankh() const { return m_rankh; }
85 
86  inline Scalar dd() const { return m_dd; }
87 };
88 
89 #endif // SRC_TRANSPORT_RECTGRID_H_
dealii::SparsityPattern m_pattern
Definition: RectGrid.h:28
RectGrid(int nrows, int ncols, int nhalo)
Definition: RectGrid.h:31
int cols() const
Definition: RectGrid.h:76
const dealii::SparsityPattern & pattern() const
Definition: RectGrid.h:64
int rowsh() const
Definition: RectGrid.h:74
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic > m_rowcol_map
Definition: RectGrid.h:26
int64_t rank() const
Definition: RectGrid.h:82
int colsh() const
Definition: RectGrid.h:78
Eigen::Matrix< Scalar, 1, Eigen::Dynamic > m_col_axis
Definition: RectGrid.h:24
Scalar dd() const
Definition: RectGrid.h:86
int64_t globalh(int i, int j) const
Definition: RectGrid.h:68
int64_t global(int i, int j) const
Definition: RectGrid.h:66
int rows() const
Definition: RectGrid.h:72
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > m_row_axis
Definition: RectGrid.h:22
int64_t rankh() const
Definition: RectGrid.h:84
int halo() const
Definition: RectGrid.h:80