AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Constraints.hpp
1 #pragma once
2 
3 #include <list>
4 
5 #include <Eigen/SparseCore>
6 
7 #include <amdis/common/Index.hpp>
8 #include <amdis/linearalgebra/Constraints.hpp>
9 #include <amdis/linearalgebra/eigen/MatrixBackend.hpp>
10 #include <amdis/linearalgebra/eigen/VectorBackend.hpp>
11 
12 namespace AMDiS
13 {
14  template <class T, int O>
16  {
18  using Vector = EigenVector<T>;
19 
20  template <class BitVector>
21  static void dirichletBC(Matrix& mat, Vector& sol, Vector& rhs, BitVector const& nodes, bool setDiagonal = true)
22  {
23  clearDirichletRow(mat.matrix(), nodes, setDiagonal);
24 
25  // copy solution dirichlet data to rhs vector
26  for (typename Vector::size_type i = 0; i < sol.vector().size(); ++i) {
27  if (nodes[i])
28  rhs.vector()[i] = sol.vector()[i];
29  }
30  }
31 
32  template <class BitVector, class Associations>
33  static void periodicBC(Matrix& mat, Vector& sol, Vector& rhs, BitVector const& left, Associations const& left2right,
34  bool setDiagonal = true)
35  {
36  error_exit("Not implemented");
37  }
38 
39  protected:
40  template <class BitVector>
41  static void clearDirichletRow(Eigen::SparseMatrix<T, Eigen::ColMajor>& mat, BitVector const& nodes, bool setDiagonal)
42  {
43  using Mat = Eigen::SparseMatrix<T, Eigen::ColMajor>;
44  for (typename Mat::Index c = 0; c < mat.outerSize(); ++c) {
45  for (typename Mat::InnerIterator it(mat, c); it; ++it) {
46  if (nodes[it.row()]) {
47  it.valueRef() = (setDiagonal && it.row() == it.col() ? T(1) : T(0));
48  break;
49  }
50  }
51  }
52  }
53 
54  template <class BitVector>
55  static void clearDirichletRow(Eigen::SparseMatrix<T, Eigen::RowMajor>& mat, BitVector const& nodes, bool setDiagonal)
56  {
57  using Mat = Eigen::SparseMatrix<T, Eigen::RowMajor>;
58  for (typename Mat::Index r = 0; r < mat.outerSize(); ++r) {
59  if (nodes[r]) {
60  for (typename Mat::InnerIterator it(mat, r); it; ++it) {
61  it.valueRef() = (setDiagonal && it.row() == it.col() ? T(1) : T(0));
62  }
63  }
64  }
65  }
66  };
67 
68 } // end namespace AMDiS
void error_exit(std::string const &str, Args &&... args)
print a message and exit
Definition: Output.hpp:142
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
The basic container that stores a base vector and a corresponding basis.
Definition: VectorBackend.hpp:16
The basic container that stores a base matrix and a corresponding row/column feSpace.
Definition: MatrixBackend.hpp:19
typename BaseVector::Index size_type
The index/size - type.
Definition: VectorBackend.hpp:27
BaseMatrix & matrix()
Return a reference to the data-matrix matrix.
Definition: MatrixBackend.hpp:37
BaseVector const & vector() const
Return the data-vector vector_.
Definition: VectorBackend.hpp:42
Definition: Constraints.hpp:13