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