AMDiS  0.3
The Adaptive Multi-Dimensional Simulation Toolbox
LocalOperator.hpp
1 #pragma once
2 
3 #include <cassert>
4 #include <type_traits>
5 
6 // #include <amdis/GridFunctions.hpp>
7 #include <amdis/ContextGeometry.hpp>
8 #include <amdis/Output.hpp>
9 #include <amdis/common/TypeTraits.hpp>
10 #include <amdis/functions/Order.hpp>
11 #include <amdis/typetree/FiniteElementType.hpp>
12 
13 namespace AMDiS
14 {
20 
27  template <class Derived, class LC>
29  {
30  using ContextType = Impl::ContextTypes<LC>;
31 
32  public:
34  using LocalContext = LC;
35 
37  using Element = typename ContextType::Entity;
38 
40  using Geometry = typename Element::Geometry;
41 
43  template <class GridView>
44  void init(GridView const& gridView)
45  {
46  derived().init_impl(gridView);
47  }
48 
50 
57  void bind(Element const& element, Geometry const& geometry)
58  {
59  if (!bound_) {
60  isSimplex_ = geometry.type().isSimplex();
61  isAffine_ = geometry.affine();
62  bound_ = true;
63  }
64 
65  derived().bind_impl(element, geometry);
66  }
67 
69  void unbind()
70  {
71  derived().unbind_impl();
72  bound_ = false;
73  }
74 
76 
82  template <class CG, class RN, class CN, class Mat>
83  void calculateElementMatrix(CG const& contextGeo, RN const& rowNode, CN const& colNode, Mat& elementMatrix)
84  {
85  assert( bound_ );
86  derived().getElementMatrix(contextGeo, rowNode, colNode, elementMatrix);
87  }
88 
90 
95  template <class CG, class Node, class Vec>
96  void calculateElementVector(CG const& contextGeo, Node const& node, Vec& elementVector)
97  {
98  assert( bound_ );
99  derived().getElementVector(contextGeo, node, elementVector);
100  }
101 
102 
103  Derived & derived() { return static_cast<Derived&>(*this); }
104  Derived const& derived() const { return static_cast<Derived const&>(*this); }
105 
106 
107  protected:
108 
109  // default implementation. Can be overridden in the derived classes
110  template <class GridView>
111  void init_impl(GridView const& /*gridView*/) {}
112 
113  // default implementation. Can be overridden in the derived classes
114  template <class Element, class Geometry>
115  void bind_impl(Element const& /*element*/, Geometry const& /*geometry*/) {}
116 
117  // default implementation. Can be overridden in the derived classes
118  void unbind_impl() {}
119 
121 
129  template <class RN, class CN>
130  int getDegree(int derivOrder, int coeffDegree, RN const& rowNode, CN const& colNode) const
131  {
132  assert( bound_ );
133  test_warning(coeffDegree >= 0,
134  "polynomial order of coefficient function not determined. Use order 4 by default.");
135 
136  int psiDegree = order(rowNode);
137  int phiDegree = order(colNode);
138 
139  int degree = psiDegree + phiDegree + (coeffDegree >= 0 ? coeffDegree : 4);
140  if (isSimplex_)
141  degree -= derivOrder;
142  if (isAffine_)
143  degree += 1; // oder += (derivOrder+1)
144 
145  return degree;
146  }
147 
149 
154  template <class Node>
155  int getDegree(int derivOrder, int coeffDegree, Node const& node) const
156  {
157  assert( bound_ );
158  test_warning(coeffDegree >= 0,
159  "polynomial order of coefficient function not determined. Use order 4 by default.");
160 
161  int psiDegree = order(node);
162 
163  int degree = psiDegree + (coeffDegree >= 0 ? coeffDegree : 4);
164  if (isSimplex_)
165  degree -= derivOrder;
166  if (isAffine_)
167  degree += 1; // oder += (derivOrder+1)
168 
169  return degree;
170  }
171 
172  protected:
173 
174  bool isSimplex_ = false; //< the bound element is a simplex
175  bool isAffine_ = false; //< the bound geometry is affine
176  bool bound_ = false; //< an element is bound to the operator
177  };
178 
179 
181 
186  template <class Derived, class LC, class GV>
187  auto makeLocalOperator(LocalOperator<Derived, LC> const& localOp, GV const& /*gridView*/)
188  {
189  return localOp.derived();
190  }
191 
192 } // end namespace AMDiS
Contains all classes needed for solving linear and non linear equation systems.
Definition: AdaptBase.hpp:6
void calculateElementMatrix(CG const &contextGeo, RN const &rowNode, CN const &colNode, Mat &elementMatrix)
Assemble a local element matrix on the element that is bound.
Definition: LocalOperator.hpp:83
int getDegree(int derivOrder, int coeffDegree, RN const &rowNode, CN const &colNode) const
Return the quadrature degree for a matrix operator.
Definition: LocalOperator.hpp:130
LC LocalContext
The element or intersection the operator is assembled on.
Definition: LocalOperator.hpp:34
auto order(F const &f) -> decltype(&F::operator(), f.order())
polynomial order of functions
Definition: Order.hpp:11
void init(GridView const &gridView)
Initialize the local operator on the current gridView.
Definition: LocalOperator.hpp:44
auto makeLocalOperator(PreGridFunctionOperator< Args... > op, GridView const &gridView)
Definition: GridFunctionOperator.hpp:258
The main implementation of an operator to be used in a Assembler.
Definition: LocalOperator.hpp:28
typename ContextType::Entity Element
The codim=0 grid entity.
Definition: LocalOperator.hpp:37
void calculateElementVector(CG const &contextGeo, Node const &node, Vec &elementVector)
Assemble a local element vector on the element that is bound.
Definition: LocalOperator.hpp:96
int getDegree(int derivOrder, int coeffDegree, Node const &node) const
Return the quadrature degree for a vector operator.
Definition: LocalOperator.hpp:155
void bind(Element const &element, Geometry const &geometry)
Binds operator to element and geometry.
Definition: LocalOperator.hpp:57
void test_warning(bool condition, std::string const &str, Args &&... args)
test for condition and in case of failure print message
Definition: Output.hpp:183
void unbind()
Unbinds operator from element.
Definition: LocalOperator.hpp:69
typename Element::Geometry Geometry
The geometry of the Element.
Definition: LocalOperator.hpp:40