1 #ifndef SRC_TRANSPORT_ADVECTION_H_
2 #define SRC_TRANSPORT_ADVECTION_H_
3 #include <deal.II/lac/sparse_matrix.h>
7 template <
typename _Scalar,
int _Dim,
int _Order = 4>
10 template <
typename _Scalar>
14 enum { Dimension = 2 };
25 : m_grid(grid), m_streamf(streamf), m_jacobian(grid.pattern()) {}
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));
56 m_jacobian *= 1. / (12. * m_grid.dd() * m_grid.dd());
59 inline dealii::SparseMatrix<Scalar>&
operator()() {
return m_jacobian; }
61 inline const dealii::SparseMatrix<Scalar>&
operator()()
const {
Advection(const RectGrid< Scalar, Dimension > &grid, const Variable< Scalar, Dimension > &streamf)
const Variable< Scalar, Dimension > & m_streamf
dealii::SparseMatrix< Scalar > m_jacobian
const dealii::SparseMatrix< Scalar > & operator()() const
dealii::SparseMatrix< Scalar > & operator()()
const RectGrid< Scalar, Dimension > & m_grid