BasisFunction.h 13.5 KB
 Peter Gottschling committed Feb 15, 2008 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // ============================================================================ // == == // == AMDiS - Adaptive multidimensional simulations == // == == // ============================================================================ // == == // == crystal growth group == // == == // == Stiftung caesar == // == Ludwig-Erhard-Allee 2 == // == 53175 Bonn == // == germany == // == == // ============================================================================ // == == // == http://www.caesar.de/cg/AMDiS == // == == // ============================================================================ /** \file BasisFunction.h */ #ifndef AMDIS_BASISFUNCTION_H #define AMDIS_BASISFUNCTION_H #include  Peter Gottschling committed Apr 28, 2009 26 #include "AMDiS_fwd.h"  Peter Gottschling committed Feb 15, 2008 27 28 #include "Global.h" #include "Boundary.h"  Thomas Witkowski committed Apr 29, 2008 29 #include "MatrixVector.h"  Peter Gottschling committed Feb 15, 2008 30 31 32  namespace AMDiS {  Thomas Witkowski committed May 07, 2009 33  /// Function interface for evaluating basis functions.  Thomas Witkowski committed Jun 20, 2008 34 35 36  class BasFctType { public:  Thomas Witkowski committed Oct 15, 2008 37  BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 38   Thomas Witkowski committed Oct 15, 2008 39  virtual ~BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 40 41 42 43  virtual double operator()(const DimVec&) const = 0; };  Thomas Witkowski committed May 07, 2009 44  /// Function interface for evaluating gradients of basis functions.  Thomas Witkowski committed Jun 20, 2008 45 46 47  class GrdBasFctType { public:  Thomas Witkowski committed Oct 15, 2008 48  GrdBasFctType() {}  Thomas Witkowski committed Jun 20, 2008 49   Thomas Witkowski committed Oct 15, 2008 50  virtual ~GrdBasFctType() {}  Thomas Witkowski committed Jun 20, 2008 51 52 53 54 55  virtual void operator()(const DimVec&, DimVec&) const = 0; };  Thomas Witkowski committed May 07, 2009 56  /// Function interface for evaluating second derivative of basis functions.  Thomas Witkowski committed Jun 20, 2008 57 58 59  class D2BasFctType { public:  Thomas Witkowski committed Oct 15, 2008 60  D2BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 61   Thomas Witkowski committed Oct 15, 2008 62  virtual ~D2BasFctType() {}  Thomas Witkowski committed Jun 20, 2008 63 64 65 66 67  virtual void operator()(const DimVec&, DimMat&) const = 0; };  Peter Gottschling committed Feb 15, 2008 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84  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 85  /// Creates a BasisFunction object of given dim and degree  Thomas Witkowski committed Oct 15, 2008 86  BasisFunction(const std::string& name, int dim, int degree);  Peter Gottschling committed Feb 15, 2008 87   Thomas Witkowski committed May 07, 2009 88  /// destructor  Peter Gottschling committed Feb 15, 2008 89 90 91  virtual ~BasisFunction(); public:  Thomas Witkowski committed May 07, 2009 92  /// compares two BasisFunction objects.  Thomas Witkowski committed Jun 10, 2009 93 94  virtual bool operator==(const BasisFunction& a) const {  Thomas Witkowski committed Apr 15, 2008 95  return a.getName() == name;  Thomas Witkowski committed Oct 15, 2008 96  }  Peter Gottschling committed Feb 15, 2008 97   Thomas Witkowski committed May 07, 2009 98  /// Returns !(*this == b)  Thomas Witkowski committed Jun 10, 2009 99 100  inline bool operator!=(const BasisFunction& b) const {  Thomas Witkowski committed Apr 15, 2008 101  return !(operator == (b));  Thomas Witkowski committed Oct 15, 2008 102  }  Peter Gottschling committed Feb 15, 2008 103   Thomas Witkowski committed May 07, 2009 104  /// Used by \ref getDOFIndices and \ref getVec  Peter Gottschling committed Feb 15, 2008 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125  virtual int* orderOfPositionIndices(const Element* el, GeoIndex position, int positionIndex) const = 0; /** \brief * Pointer to a function which connects the set of local basis functions * with its global DOFs. * getDOFIndices(el, admin, dof) returns a pointer to a const vector of * length \ref nBasFcts where the i-th entry is the index of the DOF * associated to the i-th basis function; arguments are the actual element * el and the DOF admin admin of the corresponding finite element space * (these indices depend on all defined DOF admins and thus on the * corresponding admin); if the last argument dof is NULL, getDOFndices * has to provide memory for storing this vector, which is overwritten on the * next call of getDOFIndices; if dof is not NULL, dof is a pointer to a * vector which has to be filled; */ virtual const DegreeOfFreedom* getDOFIndices(const Element*, const DOFAdmin&, DegreeOfFreedom*) const = 0; /** \brief  Thomas Witkowski committed Sep 23, 2008 126 127 128 129 130 131 132 133 134  * 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 135  */  Thomas Witkowski committed Sep 23, 2008 136  virtual void getBound(const ElInfo*, BoundaryType *) const {};  Peter Gottschling committed Feb 15, 2008 137   Thomas Witkowski committed Apr 27, 2009 138  /// Returns \ref degree of BasisFunction  Thomas Witkowski committed Jun 10, 2009 139 140  inline const int getDegree() const {  Peter Gottschling committed Feb 15, 2008 141  return degree;  Thomas Witkowski committed Oct 15, 2008 142  }  Peter Gottschling committed Feb 15, 2008 143   Thomas Witkowski committed Apr 27, 2009 144  /// Returns \ref dim of BasisFunction  Thomas Witkowski committed Jun 10, 2009 145 146  inline const int getDim() const {  Peter Gottschling committed Feb 15, 2008 147  return dim;  Thomas Witkowski committed Oct 15, 2008 148  }  Peter Gottschling committed Feb 15, 2008 149   Thomas Witkowski committed Apr 27, 2009 150  /// Returns \ref nBasFcts which is the number of local basis functions  Thomas Witkowski committed Jun 10, 2009 151 152  inline const int getNumber() const {  Peter Gottschling committed Feb 15, 2008 153  return nBasFcts;  Thomas Witkowski committed Oct 15, 2008 154  }  Peter Gottschling committed Feb 15, 2008 155   Thomas Witkowski committed Apr 27, 2009 156  /// Returns \ref name of BasisFunction  Thomas Witkowski committed Jun 10, 2009 157 158  inline const std::string& getName() const {  Peter Gottschling committed Feb 15, 2008 159  return name;  Thomas Witkowski committed Oct 15, 2008 160  }  Peter Gottschling committed Feb 15, 2008 161   Thomas Witkowski committed Apr 27, 2009 162  /// Returns \ref nDOF[i]  Peter Gottschling committed Feb 15, 2008 163 164  int getNumberOfDOFs(int i) const;  Thomas Witkowski committed Apr 27, 2009 165  /// Returns \ref nDOF  Thomas Witkowski committed Jun 10, 2009 166 167  inline DimVec* getNumberOfDOFs() const {  Peter Gottschling committed Feb 15, 2008 168  return nDOF;  Thomas Witkowski committed Oct 15, 2008 169  }  Peter Gottschling committed Feb 15, 2008 170   Thomas Witkowski committed Apr 27, 2009 171  /// Initialisation of the \ref nDOF vector. Must be implemented by sub classes  Peter Gottschling committed Feb 15, 2008 172 173  virtual void setNDOF() = 0;  Thomas Witkowski committed Apr 27, 2009 174  /// Returns the barycentric coordinates of the i-th basis function.  Peter Gottschling committed Feb 15, 2008 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198  virtual DimVec *getCoords(int i) const = 0; /** \brief * Returns a pointer to a const vector with interpolation coefficients of the * 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 * may be a pointer to a vector which has to be filled * (compare the dof argument of \ref getDOFIndices()); * 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. */ virtual const double* interpol(const ElInfo *el_info, int n, const int *indices, AbstractFunction > *f, double *coeff) = 0;  Thomas Witkowski committed May 07, 2009 199  /// WorldVector valued interpol function.  Peter Gottschling committed Feb 15, 2008 200 201 202 203 204 205  virtual const WorldVector* interpol(const ElInfo *el_info, int no, const int *b_no, AbstractFunction,WorldVector > *f, WorldVector *vec) = 0;  Thomas Witkowski committed May 07, 2009 206  /// Returns the i-th local basis function  Thomas Witkowski committed Jun 10, 2009 207 208  inline BasFctType *getPhi(int i) const {  Peter Gottschling committed Feb 15, 2008 209  return (*phi)[i];  Thomas Witkowski committed Oct 14, 2008 210  }  Peter Gottschling committed Feb 15, 2008 211   Thomas Witkowski committed May 07, 2009 212  /// Returns the gradient of the i-th local basis function  Thomas Witkowski committed Jun 10, 2009 213 214  inline GrdBasFctType *getGrdPhi(int i) const {  Thomas Witkowski committed May 07, 2009 215  return (*grdPhi)[i];  Thomas Witkowski committed Oct 14, 2008 216  }  Peter Gottschling committed Feb 15, 2008 217   Thomas Witkowski committed May 07, 2009 218  /// Returns the second derivative of the i-th local basis function  Thomas Witkowski committed Jun 10, 2009 219 220  inline D2BasFctType *getD2Phi(int i) const {  Peter Gottschling committed Feb 15, 2008 221  return (*d2Phi)[i];  Thomas Witkowski committed Oct 14, 2008 222  }  Peter Gottschling committed Feb 15, 2008 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245  /** \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 246 247  DOFVector* /*fh*/) {}  Peter Gottschling committed Feb 15, 2008 248   Thomas Witkowski committed May 07, 2009 249  /// WorldVector valued l2ScpFctBas function  Peter Gottschling committed Feb 15, 2008 250 251  virtual void l2ScpFctBas(Quadrature* , AbstractFunction, WorldVector >* /*f*/,  Thomas Witkowski committed Oct 14, 2008 252 253  DOFVector >* /*fh*/) {}  Peter Gottschling committed Feb 15, 2008 254 255   Thomas Witkowski committed May 07, 2009 256 257  /// Interpolates a DOFIndexed after refinement virtual void refineInter(DOFIndexed *, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 258  {}  Peter Gottschling committed Feb 15, 2008 259   Thomas Witkowski committed May 07, 2009 260 261  /// Interpolates a DOFIndexed after coarsening virtual void coarseInter(DOFIndexed *, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 262  {}  Peter Gottschling committed Feb 15, 2008 263   Thomas Witkowski committed May 07, 2009 264 265  /// Restricts a DOFIndexed after coarsening virtual void coarseRestr(DOFIndexed *, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 266  {}  Peter Gottschling committed Feb 15, 2008 267   Thomas Witkowski committed May 07, 2009 268 269  /// Interpolates a DOFVector > after refinement virtual void refineInter(DOFVector >*, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 270  {}  Peter Gottschling committed Feb 15, 2008 271   Thomas Witkowski committed May 07, 2009 272 273  /// Interpolates a DOFVector > after coarsening virtual void coarseInter(DOFVector >*, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 274  {}  Peter Gottschling committed Feb 15, 2008 275   Thomas Witkowski committed May 07, 2009 276 277  /// Restricts a DOFVector > after coarsening virtual void coarseRestr(DOFVector >*, RCNeighbourList*, int)  Thomas Witkowski committed Oct 14, 2008 278  {}  Peter Gottschling committed Feb 15, 2008 279   Thomas Witkowski committed Apr 15, 2009 280  /// Returns local dof indices of the element for the given fe space.  Peter Gottschling committed Feb 15, 2008 281 282 283 284 285  virtual const DegreeOfFreedom *getLocalIndices(const Element*, const DOFAdmin*, DegreeOfFreedom*) const { return NULL;  Thomas Witkowski committed Oct 14, 2008 286  }  Peter Gottschling committed Feb 15, 2008 287   Thomas Witkowski committed Apr 15, 2009 288  /// Returns local dof indices of the element for the given fe space.  Thomas Witkowski committed Apr 29, 2008 289 290 291  virtual void getLocalIndicesVec(const Element*, const DOFAdmin*, Vector*) const  Thomas Witkowski committed Oct 14, 2008 292  {}  Thomas Witkowski committed Apr 29, 2008 293   Peter Gottschling committed Feb 15, 2008 294 295 296 297 298 299  /** \brief * Evaluates elements value at barycentric coordinates lambda with local * coefficient vector uh. */ double evalUh(const DimVec& lambda, const double* uh) const;  Peter Gottschling committed Apr 28, 2009 300   Thomas Witkowski committed Mar 05, 2008 301 302 303 304 305 306 307 308  /** \brief * Evaluates elements value at barycentric coordinates lambda with local * coefficient vector uh. 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 WorldVector& evalUh(const DimVec& lambda, const WorldVector* uh, WorldVector* val) const;  Peter Gottschling committed Apr 28, 2009 309   Peter Gottschling committed Feb 15, 2008 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332  /** \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. */ const WorldVector& evalGrdUh(const DimVec& lambda, const DimVec >& Lambda, const double* uh, WorldVector* val) const; /** \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, const double* uh, WorldMatrix* val) const; protected:  Thomas Witkowski committed May 07, 2009 333  /// Textual description  Thomas Witkowski committed Aug 29, 2008 334  std::string name;  Peter Gottschling committed Feb 15, 2008 335   Thomas Witkowski committed May 07, 2009 336  /// Number of basisfunctions on one Element  Peter Gottschling committed Feb 15, 2008 337 338  int nBasFcts;  Thomas Witkowski committed May 07, 2009 339  /// Maximal degree of the basis functions  Peter Gottschling committed Feb 15, 2008 340 341  int degree;  Thomas Witkowski committed May 07, 2009 342  /// Dimension of the basis functions  Peter Gottschling committed Feb 15, 2008 343 344  int dim;  Thomas Witkowski committed May 07, 2009 345  /// Dimension of the world.  Thomas Witkowski committed Jul 01, 2008 346 347  int dow;  Thomas Witkowski committed May 07, 2009 348  /// Number of DOFs at the different positions  Peter Gottschling committed Feb 15, 2008 349 350  DimVec *nDOF;  Thomas Witkowski committed May 07, 2009 351  /// Vector of the local functions  Thomas Witkowski committed Aug 29, 2008 352  std::vector *phi;  Peter Gottschling committed Feb 15, 2008 353   Thomas Witkowski committed May 07, 2009 354  /// Vector of gradients  Thomas Witkowski committed Aug 29, 2008 355  std::vector *grdPhi;  Peter Gottschling committed Feb 15, 2008 356   Thomas Witkowski committed May 07, 2009 357  /// Vector of second derivatives  Thomas Witkowski committed Aug 29, 2008 358  std::vector *d2Phi;  Thomas Witkowski committed Jul 01, 2008 359 360 361 362 363  /** \brief * Is used by function evalGrdUh. To make it thread safe, we need a * temporary DimVec for every thread. */  Thomas Witkowski committed Aug 29, 2008 364  std::vector* > grdTmpVec1;  Thomas Witkowski committed Jul 01, 2008 365 366 367 368 369  /** \brief * Is used by function evalGrdUh. To make it thread safe, we need a * temporary DimVec for every thread. */  Thomas Witkowski committed Aug 29, 2008 370  std::vector* > grdTmpVec2;  Peter Gottschling committed Feb 15, 2008 371 372 373 374 375  }; } #endif // AMDIS_BASISFUNCTION_H