BasisFunction.h 11.2 KB
 Peter Gottschling committed Feb 15, 2008 1 2 3 4 // ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == ==  Thomas Witkowski committed Dec 16, 2010 5 // == http://www.amdis-fem.org ==  Peter Gottschling committed Feb 15, 2008 6 7 // == == // ============================================================================  Thomas Witkowski committed Dec 16, 2010 8 9 10 11 12 13 14 15 16 17 18 19 // // Software License for AMDiS // // Copyright (c) 2010 Dresden University of Technology // All rights reserved. // Authors: Simon Vey, Thomas Witkowski et al. // // This file is part of AMDiS // // See also license.opensource.txt in the distribution.  Peter Gottschling committed Feb 15, 2008 20 21 22 23 24 25 26  /** \file BasisFunction.h */ #ifndef AMDIS_BASISFUNCTION_H #define AMDIS_BASISFUNCTION_H #include  Peter Gottschling committed Apr 28, 2009 27 #include "AMDiS_fwd.h"  Peter Gottschling committed Feb 15, 2008 28 29 #include "Global.h" #include "Boundary.h"  Thomas Witkowski committed Apr 29, 2008 30 #include "MatrixVector.h"  Thomas Witkowski committed Jan 12, 2012 31 #include "FixVec.h"  Peter Gottschling committed Feb 15, 2008 32 33 34  namespace AMDiS {  Thomas Witkowski committed Apr 18, 2011 35 36  using namespace std;  Thomas Witkowski committed May 07, 2009 37  /// Function interface for evaluating basis functions.  Thomas Witkowski committed Jun 20, 2008 38 39 40  class BasFctType { public:  Thomas Witkowski committed Oct 15, 2008 41  BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 42   Thomas Witkowski committed Oct 15, 2008 43  virtual ~BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 44 45 46 47  virtual double operator()(const DimVec&) const = 0; };  Thomas Witkowski committed Jun 18, 2010 48   Thomas Witkowski committed May 07, 2009 49  /// Function interface for evaluating gradients of basis functions.  Thomas Witkowski committed Jun 20, 2008 50 51 52  class GrdBasFctType { public:  Thomas Witkowski committed Oct 15, 2008 53  GrdBasFctType() {}  Thomas Witkowski committed Jun 20, 2008 54   Thomas Witkowski committed Oct 15, 2008 55  virtual ~GrdBasFctType() {}  Thomas Witkowski committed Jun 20, 2008 56   Thomas Witkowski committed Feb 24, 2011 57 58  virtual void operator()(const DimVec&, mtl::dense_vector&) const = 0;  Thomas Witkowski committed Jun 20, 2008 59 60  };  Thomas Witkowski committed Jun 18, 2010 61   Thomas Witkowski committed May 07, 2009 62  /// Function interface for evaluating second derivative of basis functions.  Thomas Witkowski committed Jun 20, 2008 63 64 65  class D2BasFctType { public:  Thomas Witkowski committed Oct 15, 2008 66  D2BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 67   Thomas Witkowski committed Oct 15, 2008 68  virtual ~D2BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 69   Thomas Witkowski committed Jan 19, 2010 70  virtual void operator()(const DimVec&, DimMat&) const = 0;  Thomas Witkowski committed Jun 20, 2008 71  };  Thomas Witkowski committed Jun 18, 2010 72   Thomas Witkowski committed Jun 20, 2008 73   Peter Gottschling committed Feb 15, 2008 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  typedef BasFctType *BFptr; typedef GrdBasFctType *GBFptr; typedef D2BasFctType *DBFptr; /** \ingroup FEMSpace * \brief * Base class for finite element basis functions. In order to build up a * finite element space, we have to specify a set of local basis functions. * Together with the correspondig DOF administration and the underlying mesh, * the finite element space is given. * This class holds the local basis functions and their derivatives of the * reference element. They are evaluated at barycentric coordinates, so they * can be used on every element of the mesh. */ class BasisFunction { protected:  Thomas Witkowski committed May 07, 2009 91  /// Creates a BasisFunction object of given dim and degree  Thomas Witkowski committed Apr 18, 2011 92  BasisFunction(string name, int dim, int degree);  Peter Gottschling committed Feb 15, 2008 93   Thomas Witkowski committed May 07, 2009 94  /// destructor  Peter Gottschling committed Feb 15, 2008 95 96 97  virtual ~BasisFunction(); public:  Thomas Witkowski committed May 07, 2009 98  /// compares two BasisFunction objects.  Thomas Witkowski committed Jun 10, 2009 99 100  virtual bool operator==(const BasisFunction& a) const {  Thomas Witkowski committed Apr 15, 2008 101  return a.getName() == name;  Thomas Witkowski committed Oct 15, 2008 102  }  Peter Gottschling committed Feb 15, 2008 103   Thomas Witkowski committed May 07, 2009 104  /// Returns !(*this == b)  Thomas Witkowski committed Jun 10, 2009 105 106  inline bool operator!=(const BasisFunction& b) const {  Thomas Witkowski committed Apr 15, 2008 107  return !(operator == (b));  Thomas Witkowski committed Oct 15, 2008 108  }  Peter Gottschling committed Feb 15, 2008 109   Thomas Witkowski committed May 07, 2009 110  /// Used by \ref getDOFIndices and \ref getVec  Peter Gottschling committed Feb 15, 2008 111 112 113 114  virtual int* orderOfPositionIndices(const Element* el, GeoIndex position, int positionIndex) const = 0; /** \brief  Thomas Witkowski committed Sep 23, 2008 115 116 117 118 119 120 121 122 123  * The second argument 'bound' has to be a pointer to a vector which has * to be filled. Its length is \ref nBasFcts (the number of basis functions * in the used finite element space). After calling this function, the i-th * entry of the array is the boundary type of the i-th basis function of this * element. * * This function needs boundary information within the ElInfo object; thus, * all routines using this function on the elements need the FILL_BOUND * flag during mesh traversal;  Peter Gottschling committed Feb 15, 2008 124  */  Thomas Witkowski committed Jun 26, 2009 125  virtual void getBound(const ElInfo*, BoundaryType *) const {}  Peter Gottschling committed Feb 15, 2008 126   Thomas Witkowski committed Apr 27, 2009 127  /// Returns \ref degree of BasisFunction  Praetorius, Simon committed Feb 15, 2013 128  inline int getDegree() const  Thomas Witkowski committed Jun 10, 2009 129  {  Peter Gottschling committed Feb 15, 2008 130  return degree;  Thomas Witkowski committed Oct 15, 2008 131  }  Peter Gottschling committed Feb 15, 2008 132   Thomas Witkowski committed Apr 27, 2009 133  /// Returns \ref dim of BasisFunction  Praetorius, Simon committed Feb 15, 2013 134  inline int getDim() const  Thomas Witkowski committed Jun 10, 2009 135  {  Peter Gottschling committed Feb 15, 2008 136  return dim;  Thomas Witkowski committed Oct 15, 2008 137  }  Peter Gottschling committed Feb 15, 2008 138   Thomas Witkowski committed Apr 27, 2009 139  /// Returns \ref nBasFcts which is the number of local basis functions  Praetorius, Simon committed Feb 15, 2013 140  inline int getNumber() const  Thomas Witkowski committed Jun 10, 2009 141  {  Peter Gottschling committed Feb 15, 2008 142  return nBasFcts;  Thomas Witkowski committed Oct 15, 2008 143  }  Peter Gottschling committed Feb 15, 2008 144   Thomas Witkowski committed Apr 27, 2009 145  /// Returns \ref name of BasisFunction  Thomas Witkowski committed Apr 18, 2011 146  inline string getName() const  Thomas Witkowski committed Jun 10, 2009 147  {  Peter Gottschling committed Feb 15, 2008 148  return name;  Thomas Witkowski committed Oct 15, 2008 149  }  Peter Gottschling committed Feb 15, 2008 150   Thomas Witkowski committed Apr 27, 2009 151  /// Returns \ref nDOF[i]  Thomas Witkowski committed Nov 26, 2010 152  int getNumberOfDofs(int i) const;  Peter Gottschling committed Feb 15, 2008 153   Thomas Witkowski committed Apr 27, 2009 154  /// Returns \ref nDOF  Thomas Witkowski committed Nov 26, 2010 155  inline DimVec* getNumberOfDofs() const  Thomas Witkowski committed Jun 10, 2009 156  {  Peter Gottschling committed Feb 15, 2008 157  return nDOF;  Thomas Witkowski committed Oct 15, 2008 158  }  Peter Gottschling committed Feb 15, 2008 159   Thomas Witkowski committed Apr 27, 2009 160  /// Initialisation of the \ref nDOF vector. Must be implemented by sub classes  Peter Gottschling committed Feb 15, 2008 161 162  virtual void setNDOF() = 0;  Thomas Witkowski committed Apr 27, 2009 163  /// Returns the barycentric coordinates of the i-th basis function.  Peter Gottschling committed Feb 15, 2008 164 165 166  virtual DimVec *getCoords(int i) const = 0; /** \brief  167  * Fills a vector with interpolation coefficients of the  Peter Gottschling committed Feb 15, 2008 168 169 170 171 172 173 174 175  * function f; if indices is a pointer to NULL, the coefficient for all * basis functions are calculated and the i-th entry in the vector is the * coefficient of the i-th basis function; if indices is non NULL, only the * coefficients for a subset of the local basis functions has to be * calculated; n is the number of those basis functions, indices[0], . . . * , indices[n-1] are the local indices of the basis functions where the * coefficients have to be calculated, and the i-th entry in the return * vector is then the coefficient of the indices[i]-th basis function; coeff  Thomas Witkowski committed Sep 24, 2012 176  * may be a pointer to a vector which has to be filled.  Peter Gottschling committed Feb 15, 2008 177 178 179 180 181  * such a function usually needs vertex coordinate information; thus, all * routines using this function on the elements need the FILL COORDS flag * during mesh traversal. * Must be implemented by sub classes. */  182 183 184 185 186  virtual void interpol(const ElInfo *el_info, int n, const int *indices, AbstractFunction > *f, mtl::dense_vector &coeff) const = 0;  Peter Gottschling committed Feb 15, 2008 187   Thomas Witkowski committed May 07, 2009 188  /// WorldVector valued interpol function.  189 190 191 192 193  virtual void interpol(const ElInfo *el_info, int no, const int *b_no, AbstractFunction, WorldVector > *f, mtl::dense_vector >& coeff) const = 0;  Peter Gottschling committed Feb 15, 2008 194   Thomas Witkowski committed May 07, 2009 195  /// Returns the i-th local basis function  Thomas Witkowski committed Jun 10, 2009 196 197  inline BasFctType *getPhi(int i) const {  Peter Gottschling committed Feb 15, 2008 198  return (*phi)[i];  Thomas Witkowski committed Oct 14, 2008 199  }  Peter Gottschling committed Feb 15, 2008 200   Thomas Witkowski committed May 07, 2009 201  /// Returns the gradient of the i-th local basis function  Thomas Witkowski committed Jun 10, 2009 202 203  inline GrdBasFctType *getGrdPhi(int i) const {  Thomas Witkowski committed May 07, 2009 204  return (*grdPhi)[i];  Thomas Witkowski committed Oct 14, 2008 205  }  Peter Gottschling committed Feb 15, 2008 206   Thomas Witkowski committed May 07, 2009 207  /// Returns the second derivative of the i-th local basis function  Thomas Witkowski committed Jun 10, 2009 208 209  inline D2BasFctType *getD2Phi(int i) const {  Peter Gottschling committed Feb 15, 2008 210  return (*d2Phi)[i];  Thomas Witkowski committed Oct 14, 2008 211  }  Peter Gottschling committed Feb 15, 2008 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234  /** \brief * Approximates the L2 scalar products of a given function with all basis * functions by numerical quadrature and adds the corresponding values to a * DOF vector; * f is a pointer for the evaluation of the given function in world * coordinates x and returns the value of that function at x; if f is a NULL * pointer, nothing is done; * fh is the DOF vector where at the i-th entry the approximation of the L2 * scalar product of the given function with the i-th global basis function * of fh->feSpace is stored; * quad is the quadrature for the approximation of the integral on each leaf * element of fh->feSpace->mesh; if quad is a NULL pointer, a default * quadrature which is exact of degree 2*fh->feSpace->basFcts->degree-2 is * used. * The integrals are approximated by looping over all leaf elements, * computing the approximations to the element contributions and adding * these values to the vector fh by add element vec(). * The vector fh is not initialized with 0.0; only the new contributions are * added */ virtual void l2ScpFctBas(Quadrature*, AbstractFunction >* /*f*/,  Thomas Witkowski committed Oct 14, 2008 235 236  DOFVector* /*fh*/) {}  Peter Gottschling committed Feb 15, 2008 237   Thomas Witkowski committed May 07, 2009 238  /// WorldVector valued l2ScpFctBas function  Peter Gottschling committed Feb 15, 2008 239 240  virtual void l2ScpFctBas(Quadrature* , AbstractFunction, WorldVector >* /*f*/,  Thomas Witkowski committed Oct 14, 2008 241 242  DOFVector >* /*fh*/) {}  Peter Gottschling committed Feb 15, 2008 243 244   Thomas Witkowski committed May 07, 2009 245 246  /// Interpolates a DOFIndexed after refinement virtual void refineInter(DOFIndexed *, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 247  {}  Peter Gottschling committed Feb 15, 2008 248   Thomas Witkowski committed May 07, 2009 249 250  /// Interpolates a DOFIndexed after coarsening virtual void coarseInter(DOFIndexed *, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 251  {}  Peter Gottschling committed Feb 15, 2008 252   Thomas Witkowski committed May 07, 2009 253 254  /// Restricts a DOFIndexed after coarsening virtual void coarseRestr(DOFIndexed *, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 255  {}  Peter Gottschling committed Feb 15, 2008 256   Thomas Witkowski committed May 07, 2009 257 258  /// Interpolates a DOFVector > after refinement virtual void refineInter(DOFVector >*, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 259  {}  Peter Gottschling committed Feb 15, 2008 260   Thomas Witkowski committed May 07, 2009 261 262  /// Interpolates a DOFVector > after coarsening virtual void coarseInter(DOFVector >*, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 263  {}  Peter Gottschling committed Feb 15, 2008 264   Thomas Witkowski committed May 07, 2009 265 266  /// Restricts a DOFVector > after coarsening virtual void coarseRestr(DOFVector >*, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 267  {}  Peter Gottschling committed Feb 15, 2008 268   Thomas Witkowski committed Mar 30, 2010 269  /// Returns local dof indices of the element for the given fe space.  Thomas Witkowski committed Sep 24, 2012 270 271 272 273  virtual void getLocalIndices(const Element *el, const DOFAdmin *admin, vector &indices) const {}  Thomas Witkowski committed Aug 18, 2009 274   Thomas Witkowski committed Sep 24, 2012 275  ///  Thomas Witkowski committed Jul 01, 2009 276 277  virtual void getLocalDofPtrVec(const Element *el, const DOFAdmin *admin,  Thomas Witkowski committed Apr 18, 2011 278  vector& vec) const  Thomas Witkowski committed Oct 14, 2008 279  {}  Thomas Witkowski committed Apr 29, 2008 280   Peter Gottschling committed Feb 15, 2008 281   Thomas Witkowski committed Sep 24, 2012 282 283  /// Evaluates elements value at barycentric coordinates lambda with local /// coefficient vector uh.  Thomas Witkowski committed Jan 12, 2012 284 285  template T evalUh(const DimVec& lambda, const mtl::dense_vector& uh) const;  Peter Gottschling committed Apr 28, 2009 286 287   Peter Gottschling committed Feb 15, 2008 288 289 290 291 292 293 294  /** \brief * Evaluates the gradient at barycentric coordinates lambda. Lambda is the * Jacobian of the barycentric coordinates. uh is the local coefficient * vector. If val is not NULL the result will be stored * there, otherwise a pointer to a static local variable is returned which * will be overwritten after the next call. */  Thomas Witkowski committed Jan 12, 2012 295 296 297 298 299 300  template typename GradientType::type& evalGrdUh(const DimVec& lambda, const DimVec >& Lambda, const mtl::dense_vector& uh, typename GradientType::type& val) const;  Peter Gottschling committed Feb 15, 2008 301 302 303 304 305 306 307 308 309 310  /** \brief * Evaluates the second derivative at barycentric coordinates lambda. * Lambda is the Jacobian of the barycentric coordinates. uh is the local * coefficient vector. If val is not NULL the result will be stored * there, otherwise a pointer to a static local variable is returned which * will be overwritten after the next call. */ const WorldMatrix& evalD2Uh(const DimVec& lambda, const DimVec >& Lambda,  Thomas Witkowski committed Jul 21, 2010 311 312  const ElementVector& uh, WorldMatrix* val) const;  Peter Gottschling committed Feb 15, 2008 313 314  protected:  Thomas Witkowski committed May 07, 2009 315  /// Textual description  Thomas Witkowski committed Apr 18, 2011 316  string name;  Peter Gottschling committed Feb 15, 2008 317   Thomas Witkowski committed May 07, 2009 318  /// Number of basisfunctions on one Element  Peter Gottschling committed Feb 15, 2008 319 320  int nBasFcts;  Thomas Witkowski committed May 07, 2009 321  /// Maximal degree of the basis functions  Peter Gottschling committed Feb 15, 2008 322 323  int degree;  Thomas Witkowski committed May 07, 2009 324  /// Dimension of the basis functions  Peter Gottschling committed Feb 15, 2008 325 326  int dim;  Thomas Witkowski committed May 07, 2009 327  /// Dimension of the world.  Thomas Witkowski committed Jul 01, 2008 328 329  int dow;  Thomas Witkowski committed May 07, 2009 330  /// Number of DOFs at the different positions  Peter Gottschling committed Feb 15, 2008 331 332  DimVec *nDOF;  Thomas Witkowski committed May 07, 2009 333  /// Vector of the local functions  Thomas Witkowski committed Apr 18, 2011 334  vector *phi;  Peter Gottschling committed Feb 15, 2008 335   Thomas Witkowski committed May 07, 2009 336  /// Vector of gradients  Thomas Witkowski committed Apr 18, 2011 337  vector *grdPhi;  Peter Gottschling committed Feb 15, 2008 338   Thomas Witkowski committed May 07, 2009 339  /// Vector of second derivatives  Thomas Witkowski committed Apr 18, 2011 340  vector *d2Phi;  Peter Gottschling committed Feb 15, 2008 341 342 343  }; }  Thomas Witkowski committed Jan 12, 2012 344 #include "BasisFunction.hh"  Peter Gottschling committed Feb 15, 2008 345 346  #endif // AMDIS_BASISFUNCTION_H