AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
Assembler.hpp
1 #pragma once
2 
3 #include <functional>
4 #include <memory>
5 #include <type_traits>
6 
7 #include <dune/common/shared_ptr.hh>
8 #include <dune/geometry/quadraturerules.hh>
9 
10 #include <amdis/ContextGeometry.hpp>
11 #include <amdis/AssemblerInterface.hpp>
12 #include <amdis/common/Concepts.hpp>
13 #include <amdis/typetree/FiniteElementType.hpp>
14 
15 namespace AMDiS
16 {
18 
21  template <class Traits, class Operator, class... Nodes>
22  class Assembler
23  : public AssemblerInterface<Traits, Nodes...>
24  {
25  using Super = AssemblerInterface<Traits, Nodes...>;
26 
27  using LocalContext = typename Traits::LocalContext;
28  using Element = typename Super::Element;
29  using Geometry = typename Super::Geometry;
30  using ElementContainer = typename Traits::ElementContainer;
31 
32  public:
33 
35  explicit Assembler(Operator const& op)
36  : op_(Dune::wrap_or_move(op))
37  {}
38 
40  explicit Assembler(Operator&& op)
41  : op_(Dune::wrap_or_move(std::move(op)))
42  {}
43 
45  explicit Assembler(std::reference_wrapper<Operator> op)
46  : op_(Dune::wrap_or_move(op.get()))
47  {}
48 
50 
54  void bind(Element const& element, Geometry const& geometry) final
55  {
56  element_ = &element;
57  geometry_ = &geometry;
58  op_->bind(element, geometry);
59  }
60 
62 
66  void unbind() final
67  {
68  op_->unbind();
69  geometry_ = nullptr;
70  element_ = nullptr;
71  }
72 
74 
79  void assemble(LocalContext const& localContext, Nodes const&... nodes,
80  ElementContainer& ElementContainer) final
81  {
82  ContextGeometry<LocalContext> contextGeo{localContext, element(), geometry()};
83  assembleImpl(contextGeo, nodes..., ElementContainer);
84  }
85 
86 
87 #ifndef DOXYGEN
88 
89  protected: // implementation detail
90 
91  // matrix assembling
92  template <class CG, class RN, class CN, class Mat>
93  void assembleImpl(CG const& contextGeo, RN const& rowNode, CN const& colNode, Mat& elementMatrix)
94  {
95  op_->calculateElementMatrix(contextGeo, rowNode, colNode, elementMatrix);
96  }
97 
98  // vector assembling
99  template <class CG, class Node, class Vec>
100  void assembleImpl(CG const& contextGeo, Node const& node, Vec& elementVector)
101  {
102  op_->calculateElementVector(contextGeo, node, elementVector);
103  }
104 
105 #endif // DOXYGEN
106 
107  public:
108 
110  Element const& element() const
111  {
112  assert( element_ );
113  return *element_;
114  }
115 
117  Geometry const& geometry() const
118  {
119  assert( geometry_ );
120  return *geometry_;
121  }
122 
123 
124  private:
125 
127  std::shared_ptr<Operator> op_;
128 
129  Element const* element_ = nullptr;
130  Geometry const* geometry_ = nullptr;
131  };
132 
133 
135  template <class Traits, class Operator, class... Nodes>
136  auto makeAssembler(Operator&& op, Nodes const&...)
137  {
138  return Assembler<Traits, Underlying_t<Operator>, Nodes...>{FWD(op)};
139  }
140 
141 } // end namespace AMDiS
typename Element::Geometry Geometry
The geometry of the Element.
Definition: AssemblerInterface.hpp:30
Implementation of interface AssemblerBase.
Definition: Assembler.hpp:22
Definition: AdaptiveGrid.hpp:373
void assemble(LocalContext const &localContext, Nodes const &... nodes, ElementContainer &ElementContainer) final
Implementation of AssemblerBase::assemble.
Definition: Assembler.hpp:79
Definition: FieldMatVec.hpp:12
Geometry const & geometry() const
return the geometry of the bound element
Definition: Assembler.hpp:117
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
auto makeAssembler(Operator &&op, Nodes const &...)
Generate a Assembler on a given LocalContext LC (element or intersection)
Definition: Assembler.hpp:136
Assembler(std::reference_wrapper< Operator > op)
Constructor. Stores the reference to the operator.
Definition: Assembler.hpp:45
Abstract base-class of a Assembler.
Definition: AssemblerInterface.hpp:21
Wrapper class for element and geometry.
Definition: ContextGeometry.hpp:43
Element const & element() const
return the bound entity (of codim 0)
Definition: Assembler.hpp:110
void unbind() final
Implementation of AssemblerBase::unbind.
Definition: Assembler.hpp:66
Assembler(Operator const &op)
Constructor. Stores a copy of operator op.
Definition: Assembler.hpp:35
void bind(Element const &element, Geometry const &geometry) final
Implementation of AssemblerInterface::bind.
Definition: Assembler.hpp:54
Assembler(Operator &&op)
Constructor. Stores a copy of operator op.
Definition: Assembler.hpp:40
typename ContextType::Entity Element
The codim=0 grid entity.
Definition: AssemblerInterface.hpp:28