dune-localfunctions  2.5.0
refinedp1localbasis.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_REFINED_P1_LOCALBASIS_HH
4 #define DUNE_REFINED_P1_LOCALBASIS_HH
5 
10 #include <numeric>
11 
12 #include <dune/common/fmatrix.hh>
13 
15 
16 namespace Dune
17 {
18  template<class D, class R, int dim>
20  : public RefinedSimplexLocalBasis<D,dim>
21  {
22  public:
24  {
25  DUNE_THROW(Dune::NotImplemented,"RefinedP1LocalBasis not implemented for dim > 3.");
26  }
27  };
28 
52  template<class D, class R>
53  class RefinedP1LocalBasis<D,R,1>
54  : public RefinedSimplexLocalBasis<D,1>
55  {
56  public:
58  typedef LocalBasisTraits<D,1,Dune::FieldVector<D,1>,R,1,Dune::FieldVector<R,1>,
59  Dune::FieldMatrix<R,1,1> > Traits;
60 
62  unsigned int size () const
63  {
64  return 3;
65  }
66 
68  inline void evaluateFunction (const typename Traits::DomainType& in,
69  std::vector<typename Traits::RangeType>& out) const
70  {
71  out.resize(3);
72 
73  int subElement;
74  typename Traits::DomainType local;
75  this->getSubElement(in, subElement, local);
76 
77  switch (subElement) {
78  case 0 :
79 
80  out[0] = 1 - local[0];
81  out[1] = local[0];
82  out[2] = 0;
83  break;
84 
85  case 1 :
86 
87  out[0] = 0;
88  out[1] = 1 - local[0];
89  out[2] = local[0];
90  break;
91 
92  }
93 
94  }
95 
97  inline void
98  evaluateJacobian (const typename Traits::DomainType& in, // position
99  std::vector<typename Traits::JacobianType>& out) const // return value
100  {
101  out.resize(3);
102 
103  int subElement;
104  typename Traits::DomainType local;
105  this->getSubElement(in, subElement, local);
106 
107  switch (subElement) {
108  case 0 :
109 
110  out[0][0][0] = -2;
111  out[1][0][0] = 2;
112  out[2][0][0] = 0;
113  break;
114 
115  case 1 :
116 
117  out[0][0][0] = 0;
118  out[1][0][0] = -2;
119  out[2][0][0] = 2;
120  break;
121 
122  }
123  }
124 
126  void partial (const std::array<unsigned int, 1>& order,
127  const typename Traits::DomainType& in, // position
128  std::vector<typename Traits::RangeType>& out) const // return value
129  {
130  auto totalOrder = order[0];
131  if (totalOrder == 0) {
132  evaluateFunction(in, out);
133  } else if (totalOrder == 1)
134  {
135  out.resize(3);
136 
137  int subElement;
138  typename Traits::DomainType local;
139  this->getSubElement(in, subElement, local);
140 
141  switch (subElement) {
142  case 0:
143  out[0] = -2;
144  out[1] = 2;
145  out[2] = 0;
146  break;
147  case 1:
148  out[0] = 0;
149  out[1] = -2;
150  out[2] = 2;
151  break;
152  }
153  } else {
154  out.resize(3);
155  out[0] = out[1] = out[2] = 0;
156  }
157  }
158 
162  unsigned int order () const
163  {
164  return 1;
165  }
166 
167  };
168 
193  template<class D, class R>
194  class RefinedP1LocalBasis<D,R,2>
195  : public RefinedSimplexLocalBasis<D,2>
196  {
197  public:
199  typedef LocalBasisTraits<D,2,Dune::FieldVector<D,2>,R,1,Dune::FieldVector<R,1>,
200  Dune::FieldMatrix<R,1,2> > Traits;
201 
203  unsigned int size () const
204  {
205  return 6;
206  }
207 
209  inline void evaluateFunction (const typename Traits::DomainType& in,
210  std::vector<typename Traits::RangeType>& out) const
211  {
212  out.resize(6);
213 
214  int subElement;
215  typename Traits::DomainType local;
216  this->getSubElement(in, subElement, local);
217 
218  switch (subElement) {
219  case 0 :
220 
221  out[0] = 1 - local[0] - local[1];
222  out[1] = local[0];
223  out[2] = 0;
224  out[3] = local[1];
225  out[4] = 0;
226  out[5] = 0;
227  break;
228 
229  case 1 :
230 
231  out[0] = 0;
232  out[1] = 1 - local[0] - local[1];
233  out[2] = local[0];
234  out[3] = 0;
235  out[4] = local[1];
236  out[5] = 0;
237  break;
238 
239  case 2 :
240 
241  out[0] = 0;
242  out[1] =