dune-pdelab  2.4.1
product.hh
Go to the documentation of this file.
1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=8 sw=2 sts=2:
3 #ifndef DUNE_PDELAB_FUNCTION_PRODUCT_HH
4 #define DUNE_PDELAB_FUNCTION_PRODUCT_HH
5 
6 // #include <cstddef>
7 
8 #include <dune/common/fvector.hh>
9 #include <dune/common/typetraits.hh>
10 
12 
13 namespace Dune {
14  namespace PDELab {
15 
17  template<typename GF1, typename GF2, class = void>
19  public GridFunctionBase<
20  GridFunctionTraits<
21  typename GF1::Traits::GridViewType,
22  typename GF1::Traits::RangeFieldType, 1,
23  FieldVector<typename GF1::Traits::RangeFieldType, 1> >,
24  ProductGridFunctionAdapter<GF1,GF2> >
25  {
26  static_assert(unsigned(GF1::Traits::dimRange) ==
27  unsigned(GF2::Traits::dimRange),
28  "ProductGridFunctionAdapter: Operands must have "
29  "matching range dimensions, or one operand must be "
30  "scalar-valued.");
31 
32  typedef GridFunctionTraits<
33  typename GF1::Traits::GridViewType,
34  typename GF1::Traits::RangeFieldType, 1,
35  FieldVector<typename GF1::Traits::RangeFieldType, 1> > T;
37 
38  GF1& gf1;
39  GF2& gf2;
40 
41  public:
42  typedef typename Base::Traits Traits;
43 
44  ProductGridFunctionAdapter(GF1& gf1_, GF2& gf2_)
45  : gf1(gf1_), gf2(gf2_)
46  { }
47 
48  void evaluate(const typename Traits::ElementType &e,
49  const typename Traits::DomainType &x,
50  typename Traits::RangeType &y) const {
51  typename GF1::Traits::RangeType y1;
52  gf1.evaluate(e,x,y1);
53  typename GF2::Traits::RangeType y2;
54  gf2.evaluate(e,x,y2);
55  y = y1 * y2;
56  }
57 
58  const typename Traits::GridViewType& getGridView() const {
59  return gf1.getGridView();
60  }
61 
62  template<typename Time>
63  void setTime(Time time) {
64  gf1.setTime(time);
65  gf2.setTime(time);
66  }
67  };
68 
70  template<typename GF1, typename GF2>
72  GF1, GF2,
73  typename enable_if<
74  GF1::Traits::dimRange == 1 && GF2::Traits::dimRange != 1
75  >::type> :
76  public GridFunctionBase<typename GF2::Traits,
77  ProductGridFunctionAdapter<GF1,GF2> >
78  {
79  typedef typename GF2::Traits T;
81 
82  GF1& gf1;
83  GF2& gf2;
84 
85  public:
86  typedef typename Base::Traits Traits;
87 
88  ProductGridFunctionAdapter(GF1& gf1_, GF2& gf2_)
89  : gf1(gf1_), gf2(gf2_)
90  { }
91 
92  void evaluate(const typename Traits::ElementType &e,
93  const typename Traits::DomainType &x,
94  typename Traits::RangeType &y) const {
95  typename GF1::Traits::RangeType y1;
96  gf1.evaluate(e,x,y1);
97  gf2.evaluate(e,x,y);
98  y *= y1;
99  }
100 
101  const typename Traits::GridViewType& getGridView() const {
102  return gf1.getGridView();
103  }
104 
105  template<typename Time>
106  void setTime(Time time) {
107  gf1.setTime(time);
108  gf2.setTime(time);
109  }
110  };
111 
113  template<typename GF1, typename GF2>
115  GF1, GF2,
116  typename enable_if<
117  GF1::Traits::dimRange != 1 && GF2::Traits::dimRange == 1
118  >::type> :
119  public ProductGridFunctionAdapter<GF2, GF1>
120  {
121  public:
122  ProductGridFunctionAdapter(GF1& gf1, GF2& gf2)
123  : ProductGridFunctionAdapter<GF2, GF1>(gf2, gf1)
124  { }
125  };
126 
127  } // namspace PDELab
128 } // namspace Dune
129 
130 #endif // DUNE_PDELAB_FUNCTION_PRODUCT_HH
const Traits::GridViewType & getGridView() const
Definition: product.hh:58
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: product.hh:92
ProductGridFunctionAdapter(GF1 &gf1_, GF2 &gf2_)
Definition: product.hh:44
Base::Traits Traits
Definition: product.hh:42
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:114
Definition: adaptivity.hh:27
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:117
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: product.hh:48
Product of two GridFunctions.
Definition: product.hh:18
const Entity & e
Definition: localfunctionspace.hh:111
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:48
T Traits
Export type traits.
Definition: function.hh:191
void setTime(Time time)
Definition: product.hh:63
leaf of a function tree
Definition: function.hh:576
traits class holding the function signature, same as in local function
Definition: function.hh:175