p1localbasis.hh
Go to the documentation of this file.00001
00002 #ifndef DUNE_P1_LOCALBASIS_HH
00003 #define DUNE_P1_LOCALBASIS_HH
00004
00005 #include <dune/common/fmatrix.hh>
00006
00007 #include <dune/localfunctions/common/localbasis.hh>
00008
00009 namespace Dune
00010 {
00022 template<class D, class R, int dim>
00023 class P1LocalBasis
00024 {
00025 public:
00027 typedef LocalBasisTraits<D,dim,Dune::FieldVector<D,dim>,R,1,Dune::FieldVector<R,1>,
00028 Dune::FieldMatrix<R,1,dim>, 2> Traits;
00029
00031 unsigned int size () const
00032 {
00033 return dim+1;
00034 }
00035
00037 inline void evaluateFunction (const typename Traits::DomainType& in,
00038 std::vector<typename Traits::RangeType>& out) const
00039 {
00040 out.resize(size());
00041 out[0] = 1.0;
00042 for (size_t i=0; i<dim; i++) {
00043 out[0] -= in[i];
00044 out[i+1] = in[i];
00045 }
00046 }
00047
00049 inline void
00050 evaluateJacobian (const typename Traits::DomainType& in,
00051 std::vector<typename Traits::JacobianType>& out) const
00052 {
00053 out.resize(size());
00054
00055 for (int i=0; i<dim; i++)
00056 out[0][0][i] = -1;
00057
00058 for (int i=0; i<dim; i++)
00059 for (int j=0; j<dim; j++)
00060 out[i+1][0][j] = (i==j);
00061
00062 }
00063
00065 template<unsigned int k>
00066 inline void evaluate (const typename Dune::array<int,k>& directions,
00067 const typename Traits::DomainType& in,
00068 std::vector<typename Traits::RangeType>& out) const
00069 {
00070 if (k==0)
00071 evaluateFunction(in, out);
00072 else if (k==1)
00073 {
00074 out.resize(size());
00075
00076 out[0] = -1;
00077 for (int i=0; i<dim; i++)
00078 out[i+1] = (i==directions[0]);
00079 }
00080 else if (k==2)
00081 {
00082 out.resize(size());
00083
00084 for (int i=0; i<dim+1; i++)
00085 out[i] = 0;
00086 }
00087 }
00088
00090 unsigned int order () const
00091 {
00092 return 1;
00093 }
00094 };
00095 }
00096 #endif