DUNE PDELab (git)

product.hh
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
10
11#include <dune/pdelab/common/function.hh>
12
13namespace 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,
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 std::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 std::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)
124 { }
125 };
126
127 } // namspace PDELab
128} // namspace Dune
129
130#endif // DUNE_PDELAB_FUNCTION_PRODUCT_HH
vector space out of a tensor product of fields.
Definition: fvector.hh:91
leaf of a function tree
Definition: function.hh:302
T Traits
Export type traits.
Definition: function.hh:193
Product of two GridFunctions.
Definition: product.hh:25
Traits for type conversions and type information.
Implements a vector constructed from a given type representing a field and a compile-time given size.
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
traits class holding the function signature, same as in local function
Definition: function.hh:183
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)