LinearForm.hpp 4.47 KB
 Praetorius, Simon committed Sep 27, 2019 1 2 #pragma once  Müller, Felix committed Oct 09, 2019 3 4 #include  Praetorius, Simon committed Sep 27, 2019 5 6 #include #include  Müller, Felix committed Mar 12, 2020 7 8 #include #include  Praetorius, Simon committed Sep 27, 2019 9 10 11 12 13 14 15 16 17 18 19 20 21 #include #include #include namespace AMDiS { /// \brief The basic container that stores a base vector and a corresponding basis /** * A vector storing all the assembled Operators indexed with DOF indices. The vector * data is associated to a global basis. * * \tparam GB Basis of the vector * \tparam T Coefficient type to store in the vector  Praetorius, Simon committed Dec 30, 2019 22  * \tparam Traits Collection of parameter for the linear-algebra backend  Praetorius, Simon committed Sep 27, 2019 23  **/  Praetorius, Simon committed Jan 20, 2020 24  template >  Praetorius, Simon committed Sep 27, 2019 25  class LinearForm  Praetorius, Simon committed Dec 30, 2019 26  : public VectorFacade  Praetorius, Simon committed Sep 27, 2019 27  {  Praetorius, Simon committed Dec 30, 2019 28  using Super = VectorFacade;  29  using Self = LinearForm;  Praetorius, Simon committed Sep 27, 2019 30 31 32 33 34 35  public: /// The type of the functionspace basis associated to this linearform using GlobalBasis = GB; /// The type of the elements of the DOFVector  Praetorius, Simon committed Jan 20, 2020 36  using CoefficientType = T;  Praetorius, Simon committed Sep 27, 2019 37 38 39 40 41 42  /// The type of the vector filled on an element with local contributions using ElementVector = FlatVector; public: /// Constructor. Stores the shared_ptr of the basis and creates a new DataTransfer.  Praetorius, Simon committed Dec 30, 2019 43 44 45  explicit LinearForm(std::shared_ptr const& basis) : Super(*basis) , basis_(basis)  Praetorius, Simon committed Sep 27, 2019 46  {  Praetorius, Simon committed Dec 30, 2019 47  auto const localSize = basis->localView().maxSize();  Praetorius, Simon committed Sep 27, 2019 48 49 50  elementVector_.resize(localSize); }  Praetorius, Simon committed Jan 03, 2020 51 52 53 54 55 56 57  /// Wraps the passed global basis into a (non-destroying) shared_ptr template )> explicit LinearForm(GB_&& basis) : LinearForm(Dune::wrap_or_move(FWD(basis))) {}  Praetorius, Simon committed Dec 30, 2019 58 59  std::shared_ptr const& basis() const { return basis_; }  60 61 62 63 64  /// \brief Associate a local operator with this LinearForm /** * Stores an operator in a list that gets assembled during a call to \ref assemble(). * The operator may be assigned to a specific context, i.e. either an element * operator, an intersection operator, or a boundary operator.  Praetorius, Simon committed Sep 30, 2019 65 66  * The \p path tree paths specify the sub-basis for test functions the operator * is applied to.  67 68  * * \tparam ContextTag One of \ref tag::element_operator, \ref tag::intersection_operator  Praetorius, Simon committed Sep 30, 2019 69 70  * or \ref tag::boundary_operator indicating where to assemble * this operator.  71  * \tparam Expr An pre-operator that can be bound to a gridView, or a valid  Praetorius, Simon committed Sep 30, 2019 72 73  * GridOperator. * \tparam path A tree-path for the Basis  74 75 76 77 78 79 80 81 82 83 84  * * [[expects: path is valid tree-path in Basis]] * @{ **/ template void addOperator(ContextTag contextTag, Expr const& expr, TreePath path); // Add an operator to be assembled on the elements of the grid template void addOperator(Expr const& expr, TreePath path = {}) {  Müller, Felix committed Mar 12, 2020 85  using E = typename GlobalBasis::LocalView::Element;  86 87 88 89 90 91 92  addOperator(tag::element_operator{}, expr, path); } // Add an operator to be assembled on the intersections of the grid template void addIntersectionOperator(Expr const& expr, TreePath path = {}) {  Müller, Felix committed Mar 12, 2020 93  using I = typename GlobalBasis::LocalView::GridView::Intersection;  94 95 96 97  addOperator(tag::intersection_operator{}, expr, path); } /// @}  Praetorius, Simon committed Sep 27, 2019 98 99  /// Assemble the vector operators on the bound element.  Müller, Felix committed Mar 12, 2020 100 101  template )>  102  void assemble(LocalView const& localView);  Praetorius, Simon committed Sep 27, 2019 103 104 105 106 107 108 109 110 111 112  /// Assemble all vector operators added by \ref addOperator(). void assemble(); private: /// Dense vector to store coefficients during \ref assemble() ElementVector elementVector_; /// List of operators associated to nodes, filled in \ref addOperator(). VectorOperators operators_;  Praetorius, Simon committed Dec 30, 2019 113 114  std::shared_ptr basis_;  Praetorius, Simon committed Sep 27, 2019 115 116  };  117   Praetorius, Simon committed Apr 14, 2020 118  // deduction guide  Müller, Felix committed Oct 09, 2019 119 120 121  template LinearForm(GB&& basis) -> LinearForm>;  Praetorius, Simon committed Apr 14, 2020 122   Praetorius, Simon committed Sep 27, 2019 123   Müller, Felix committed Oct 09, 2019 124 125  template auto makeLinearForm(GB&& basis)  126 127  { using LF = LinearForm, T>;  Müller, Felix committed Oct 09, 2019 128  return LF{FWD(basis)};  129 130  }  Praetorius, Simon committed Sep 27, 2019 131 132 133 } // end namespace AMDiS #include