dune-pdelab  2.0.0
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/static_assert.hh>
10 #include <dune/common/typetraits.hh>
11 
13 
14 namespace Dune {
15  namespace PDELab {
16 
18  template<typename GF1, typename GF2, class = void>
20  public GridFunctionBase<
21  GridFunctionTraits<
22  typename GF1::Traits::GridViewType,
23  typename GF1::Traits::RangeFieldType, 1,
24  FieldVector<typename GF1::Traits::RangeFieldType, 1> >,
25  ProductGridFunctionAdapter<GF1,GF2> >
26  {
27  dune_static_assert(unsigned(GF1::Traits::dimRange) ==
28  unsigned(GF2::Traits::dimRange),
29  "ProductGridFunctionAdapter: Operands must have "
30  "matching range dimensions, or one operand must be "
31  "scalar-valued.");
32 
33  typedef GridFunctionTraits<
34  typename GF1::Traits::GridViewType,
35  typename GF1::Traits::RangeFieldType, 1,
36  FieldVector<typename GF1::Traits::RangeFieldType, 1> > T;
38 
39  GF1& gf1;
40  GF2& gf2;
41 
42  public:
43  typedef typename Base::Traits Traits;
44 
45  ProductGridFunctionAdapter(GF1& gf1_, GF2& gf2_)
46  : gf1(gf1_), gf2(gf2_)
47  { }
48 
49  void evaluate(const typename Traits::ElementType &e,
50  const typename Traits::DomainType &x,
51  typename Traits::RangeType &y) const {
52  typename GF1::Traits::RangeType y1;
53  gf1.evaluate(e,x,y1);
54  typename GF2::Traits::RangeType y2;
55  gf2.evaluate(e,x,y2);
56  y = y1 * y2;
57  }
58 
59  const typename Traits::GridViewType& getGridView() const {
60  return gf1.getGridView();
61  }
62 
63  template<typename Time>
64  void setTime(Time time) {
65  gf1.setTime(time);
66  gf2.setTime(time);
67  }
68  };
69 
71  template<typename GF1, typename GF2>
73  GF1, GF2,
74  typename enable_if<
75  GF1::Traits::dimRange == 1 && GF2::Traits::dimRange != 1
76  >::type> :
77  public GridFunctionBase<typename GF2::Traits,
78  ProductGridFunctionAdapter<GF1,GF2> >
79  {
80  typedef typename GF2::Traits T;
82 
83  GF1& gf1;
84  GF2& gf2;
85 
86  public:
87  typedef typename Base::Traits Traits;
88 
89  ProductGridFunctionAdapter(GF1& gf1_, GF2& gf2_)
90  : gf1(gf1_), gf2(gf2_)
91  { }
92 
93  void evaluate(const typename Traits::ElementType &e,
94  const typename Traits::DomainType &x,
95  typename Traits::RangeType &y) const {
96  typename GF1::Traits::RangeType y1;
97  gf1.evaluate(e,x,y1);
98  gf2.evaluate(e,x,y);
99  y *= y1;
100  }
101 
102  const typename Traits::GridViewType& getGridView() const {
103  return gf1.getGridView();
104  }
105 
106  template<typename Time>
107  void setTime(Time time) {
108  gf1.setTime(time);
109  gf2.setTime(time);
110  }
111  };
112 
114  template<typename GF1, typename GF2>
116  GF1, GF2,
117  typename enable_if<
118  GF1::Traits::dimRange != 1 && GF2::Traits::dimRange == 1
119  >::type> :
120  public ProductGridFunctionAdapter<GF2, GF1>
121  {
122  public:
123  ProductGridFunctionAdapter(GF1& gf1, GF2& gf2)
124  : ProductGridFunctionAdapter<GF2, GF1>(gf2, gf1)
125  { }
126  };
127 
128  } // namspace PDELab
129 } // namspace Dune
130 
131 #endif // DUNE_PDELAB_FUNCTION_PRODUCT_HH
ProductGridFunctionAdapter(GF1 &gf1_, GF2 &gf2_)
Definition: product.hh:45
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:118
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: product.hh:49
Dune::FieldVector< GV::Grid::ctype, GV::dimension > DomainType
domain type in dim-size coordinates
Definition: function.hh:49
const Traits::GridViewType & getGridView() const
Definition: product.hh:59
void evaluate(const typename Traits::ElementType &e, const typename Traits::DomainType &x, typename Traits::RangeType &y) const
Definition: product.hh:93
leaf of a function tree
Definition: function.hh:577
void setTime(Time time)
Definition: product.hh:64
traits class holding the function signature, same as in local function
Definition: function.hh:176
T Traits
Export type traits.
Definition: function.hh:192
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:115
Product of two GridFunctions.
Definition: product.hh:19
Base::Traits Traits
Definition: product.hh:43
const E & e
Definition: interpolate.hh:172