Canoe
Comprehensive Atmosphere N' Ocean Engine
Advection.h
Go to the documentation of this file.
1 #ifndef SRC_TRANSPORT_ADVECTION_H_
2 #define SRC_TRANSPORT_ADVECTION_H_
3 #include <deal.II/lac/sparse_matrix.h>
4 
5 #include "Variable.h"
6 
7 template <typename _Scalar, int _Dim, int _Order = 4>
8 class Advection {};
9 
10 template <typename _Scalar>
11 class Advection<_Scalar, 2, 4> {
12  protected:
13  typedef _Scalar Scalar;
14  enum { Dimension = 2 };
15 
17 
19 
20  dealii::SparseMatrix<Scalar> m_jacobian;
21 
22  public:
24  const Variable<Scalar, Dimension>& streamf)
25  : m_grid(grid), m_streamf(streamf), m_jacobian(grid.pattern()) {}
26 
27  void update() {
28  for (int i = 0; i < m_grid.rows(); i++)
29  for (int j = 0; j < m_grid.cols(); j++) {
30  int64_t k = m_grid.global(i, j);
31  m_jacobian.set(k, m_grid.globalh(i - 1, j - 1),
32  -m_streamf.val(i, j - 1) + m_streamf.val(i - 1, j));
33  m_jacobian.set(k, m_grid.globalh(i - 1, j),
34  -m_streamf.val(i - 1, j - 1) - m_streamf.val(i, j - 1) +
35  m_streamf.val(i - 1, j + 1) +
36  m_streamf.val(i, j + 1));
37  m_jacobian.set(k, m_grid.globalh(i - 1, j + 1),
38  +m_streamf.val(i, j + 1) - m_streamf.val(i - 1, j));
39  m_jacobian.set(k, m_grid.globalh(i, j - 1),
40  -m_streamf.val(i + 1, j - 1) - m_streamf.val(i + 1, j) +
41  m_streamf.val(i - 1, j - 1) +
42  m_streamf.val(i - 1, j));
43  m_jacobian.set(k, m_grid.globalh(i, j + 1),
44  +m_streamf.val(i + 1, j) + m_streamf.val(i + 1, j + 1) -
45  m_streamf.val(i - 1, j) -
46  m_streamf.val(i - 1, j + 1));
47  m_jacobian.set(k, m_grid.globalh(i + 1, j - 1),
48  -m_streamf.val(i + 1, j) + m_streamf.val(i, j - 1));
49  m_jacobian.set(k, m_grid.globalh(i + 1, j),
50  +m_streamf.val(i, j - 1) + m_streamf.val(i + 1, j - 1) -
51  m_streamf.val(i, j + 1) -
52  m_streamf.val(i + 1, j + 1));
53  m_jacobian.set(k, m_grid.globalh(i + 1, j + 1),
54  +m_streamf.val(i + 1, j) - m_streamf.val(i, j + 1));
55  }
56  m_jacobian *= 1. / (12. * m_grid.dd() * m_grid.dd());
57  }
58 
59  inline dealii::SparseMatrix<Scalar>& operator()() { return m_jacobian; }
60 
61  inline const dealii::SparseMatrix<Scalar>& operator()() const {
62  return m_jacobian;
63  }
64 };
65 
66 #endif // SRC_TRANSPORT_ADVECTION_H_
Advection(const RectGrid< Scalar, Dimension > &grid, const Variable< Scalar, Dimension > &streamf)
Definition: Advection.h:23
const Variable< Scalar, Dimension > & m_streamf
Definition: Advection.h:18
dealii::SparseMatrix< Scalar > m_jacobian
Definition: Advection.h:20
const dealii::SparseMatrix< Scalar > & operator()() const
Definition: Advection.h:61
dealii::SparseMatrix< Scalar > & operator()()
Definition: Advection.h:59
const RectGrid< Scalar, Dimension > & m_grid
Definition: Advection.h:16