DirichletBC.hpp 3.98 KB
 Praetorius, Simon committed Mar 13, 2016 1 2 3 4 5 6 #pragma once #include #include #include  Praetorius, Simon committed Sep 19, 2016 7 #include  Praetorius, Simon committed Dec 09, 2017 8 9 #include #include  Praetorius, Simon committed Mar 19, 2016 10   Praetorius, Simon committed Mar 13, 2016 11 12 namespace AMDiS {  Praetorius, Simon committed May 07, 2016 13 14  /// Implements a boundary condition of Dirichlet-type. /**  Praetorius, Simon committed Sep 19, 2016 15  * By calling the methods \ref init() and \ref finish before and after  Praetorius, Simon committed May 07, 2016 16  * assembling the system-matrix, respectively, dirichlet boundary conditions  Praetorius, Simon committed Nov 19, 2017 17  * can be applied to the matrix and system vector. Therefore, a predicate  Praetorius, Simon committed May 07, 2016 18  * functions indicates the DOFs where values should be enforced and a second  Praetorius, Simon committed Sep 19, 2016 19  * functor provided in the constructor is responsible for determining the  Praetorius, Simon committed May 07, 2016 20  * values to be set at the DOFs.  Praetorius, Simon committed Sep 19, 2016 21 22 23 24  * * In the \ref finish method the matrix is called with \ref applyDirichletBC * to erase the corresponding rows and columns for the DOF indices. This * application of boundary conditions can be symmetric if the matrix does  Praetorius, Simon committed May 07, 2016 25 26 27  * support this symmetric modification. As a result, this method returns a list * of columns values, that should be subtracted from the rhs. **/  Praetorius, Simon committed Dec 09, 2017 28  template  Praetorius, Simon committed Mar 13, 2016 29 30 31 32  class DirichletBC { public: template && Concepts::Functor) >  Praetorius, Simon committed Mar 13, 2016 35 36  DirichletBC(Predicate&& predicate, Values&& values) : predicate(std::forward(predicate))  Praetorius, Simon committed Mar 13, 2016 37  , values(std::forward(values))  Praetorius, Simon committed Mar 13, 2016 38  {}  Praetorius, Simon committed Sep 19, 2016 39 40   Praetorius, Simon committed Nov 19, 2017 41 42 43  /// Prepare the matrix, rhs and solution block for assembling dirichlet /// boundary conditions, e.g. collect the corresponding indices of boundary /// DOFS for later elimination in \ref finish.  Praetorius, Simon committed Dec 09, 2017 44 45 46 47 48 49 50 51 52  template void init(Matrix& /*matrix*/, VectorX& /*rhs*/, VectorB& /*solution*/, RowBasis const& rowBasis, ColBasis const& /*colBasis*/) { using RowNode = typename RowBasis::LocalView::Tree; initImpl(rowBasis, typename RowNode::NodeTag{}); }  Praetorius, Simon committed Sep 19, 2016 53 54   Praetorius, Simon committed Nov 19, 2017 55 56 57 58 59 60 61  /// \brief Apply dirichlet BC to matrix and vector, i.e., add a unit-row /// to the matrix and optionally delete the corresponding matrix-column. /** If DBC is set for matrix block {R,C}, then \p apply_row means that * the block-row R is assembled, and \p apply_col means that the block-col C * is assembled. The \p matrix, \p rhs, and \p solution correspond to the * currently visited blocks of system-matrix and system-vector. **/  Praetorius, Simon committed Dec 09, 2017 62 63  template void finish(Matrix& matrix,  Praetorius, Simon committed Nov 08, 2017 64  VectorX& rhs,  Praetorius, Simon committed Dec 09, 2017 65 66 67 68 69 70 71 72 73 74 75 76 77  VectorB& solution, RowBasis const& rowBasis, ColBasis const& colBasis); protected: template void initImpl(RowBasis const& rowBasis, Dune::TypeTree::LeafNodeTag); template void initImpl(RowBasis const& rowBasis, Dune::TypeTree::PowerNodeTag); template void initImpl(RB const&, RowNodeTag) {}  Praetorius, Simon committed Sep 19, 2016 78   Praetorius, Simon committed Mar 13, 2016 79  private:  Praetorius, Simon committed Dec 09, 2017 80 81  std::function predicate; std::function values;  Praetorius, Simon committed Sep 19, 2016 82   Praetorius, Simon committed Mar 13, 2016 83 84 85 86  bool initialized = false; std::vector dirichletNodes; };  Praetorius, Simon committed Dec 09, 2017 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106  template struct DirichletData { using WorldVector = typename GlobalBasis::GridView::template Codim<0>::Geometry::GlobalCoordinate; template struct type { std::list>> scalar; std::list>> vector; void push_back(std::shared_ptr> const& bc) { scalar.push_back(bc); } void push_back(std::shared_ptr> const& bc) { vector.push_back(bc); } }; }; template using Constraints = MatrixData::template type>;  Praetorius, Simon committed Mar 13, 2016 107 108 109 } // end namespace AMDiS #include "DirichletBC.inc.hpp"