dune-localfunctions  2.2.1
q1localbasis.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil -*-
2 #ifndef DUNE_Q1_LOCALBASIS_HH
3 #define DUNE_Q1_LOCALBASIS_HH
4 
5 #include <dune/common/fmatrix.hh>
6 
8 
9 namespace Dune
10 {
22  template<class D, class R, int dim>
24  {
25  public:
26  typedef LocalBasisTraits<D,dim,Dune::FieldVector<D,dim>,R,1,Dune::FieldVector<R,1>,
27  Dune::FieldMatrix<R,1,dim> > Traits;
28 
30  unsigned int size () const
31  {
32  return 1<<dim;
33  }
34 
36  inline void evaluateFunction (const typename Traits::DomainType& in,
37  std::vector<typename Traits::RangeType>& out) const
38  {
39  out.resize(size());
40 
41  for (size_t i=0; i<size(); i++) {
42 
43  out[i] = 1;
44 
45  for (int j=0; j<dim; j++)
46  // if j-th bit of i is set multiply with in[j], else with 1-in[j]
47  out[i] *= (i & (1<<j)) ? in[j] : 1-in[j];
48 
49  }
50 
51  }
52 
54  inline void
55  evaluateJacobian (const typename Traits::DomainType& in, // position
56  std::vector<typename Traits::JacobianType>& out) const // return value
57  {
58  out.resize(size());
59 
60  // Loop over all shape functions
61  for (size_t i=0; i<size(); i++) {
62 
63  // Loop over all coordinate directions
64  for (int j=0; j<dim; j++) {
65 
66  // Initialize: the overall expression is a product
67  // if j-th bit of i is set to -1, else 1
68  out[i][0][j] = (i & (1<<j)) ? 1 : -1;
69 
70  for (int k=0; k<dim; k++) {
71 
72  if (j!=k)
73  // if k-th bit of i is set multiply with in[j], else with 1-in[j]
74  out[i][0][j] *= (i & (1<<k)) ? in[k] : 1-in[k];
75 
76  }
77 
78  }
79 
80  }
81 
82  }
83 
85  unsigned int order () const
86  {
87  return 1;
88  }
89  };
90 }
91 #endif