Bubble.h 13.6 KB
Newer Older
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/

// Created by Roman Weissflog & Philipp Schulz



/** \file Bubble.h */

#ifndef AMDIS_BUBBLE_H
#define AMDIS_BUBBLE_H

#include <list>
#include <boost/numeric/mtl/mtl.hpp>
#include "AbstractFunction.h"
#include "BasisFunction.h"
#include "FixVec.h"

namespace AMDiS {

  /** \ingroup FEMSpace
  * \brief
  * Lagrange basis functions plus Bubble function. Sub class of BasisFunction
  */

  class Bubble : public BasisFunction
  {
  public:
    /// Creator class used in the BasisFunctionCreatorMap.
    class Creator : public BasisFunctionCreator
    {
      public:
	virtual ~Creator() {}
		
	/// Returns a new Lagrange object.
	BasisFunction* create()
	{
	  return getBubble(this->dim, this->dim + 1); // has to be generalized in later versions of bubble functions
	}
    };
    
    protected:
      /// Constructs lagrange/bubble basis functions with the given dim and degree.
      /// Constructor is protected to avoid multiple instantiation of identical
      /// basis functions. Use \ref getBubble instead.
      Bubble(int dim_, int degree_);

      /** \brief
      * destructor
      */
      virtual ~Bubble();

    public:
      /// Returns a pointer to lagrange and bubble basis functions with the given dim and
      /// degree. Multiple instantiation of identical basis functions is avoided
      /// by rembering once created basis functions in \ref allBasFcts.
      static Bubble* getBubble(int dim, int degree);

      /// Implements BasisFunction::interpol
      void interpol(const ElInfo *, int, const int *, 
		    AbstractFunction<double, WorldVector<double> >*, 
		    mtl::dense_vector<double>&) const override;

      /// Implements BasisFunction::interpol
      void interpol(const ElInfo *, int, 
		  const int *b_no,
		  AbstractFunction<WorldVector<double>, WorldVector<double> >*, 
		  mtl::dense_vector<WorldVector<double> >&) const override;

      /// Returns the barycentric coordinates of the i-th basis function.
      DimVec<double> *getCoords(int i) const override;


      /// Implements BasisFunction::getBound
      void getBound(const ElInfo*, BoundaryType *) const override;


      /** \brief
      * Calculates the local vertex indices which are involved in evaluating
      * the nodeIndex-th DOF at the positionIndex-th part of type position 
      * (VERTEX/EDGE/FACE/CENTER). nodeIndex determines the permutation
      * of the involved vertices. So in 1d for lagrange4 there are two DOFs at
      * the CENTER (which is an edge in this case). Then vertices[0] = {0, 1} and
      * vertices[1] = {1, 0}. This allows to use the same local basis function 
      * for all DOFs at the same position.
      */
      static void setVertices(int dim, int degree, 
			    GeoIndex position, int positionIndex, int nodeIndex, 
			    int** vertices);


      /// Implements BasisFunction::refineInter
      inline void refineInter(DOFIndexed<double> *drv, RCNeighbourList* list, int n) override
      {
	if (refineInter_fct)
	  (*refineInter_fct)(drv, list, n, this);
      }

      /// Implements BasisFunction::coarseRestrict
      inline void coarseRestr(DOFIndexed<double> *drv, RCNeighbourList* list, int n) override
      {
	if (coarseRestr_fct)
	  (*coarseRestr_fct)(drv, list, n, this);
      }

      /// Implements BasisFunction::coarseInter
      inline void coarseInter(DOFIndexed<double> *drv, RCNeighbourList* list, int n) override
      {
	if (coarseInter_fct)
	  (*coarseInter_fct)(drv, list, n, this);
      }

      /// Implements BasisFunction::getLocalIndices().
      void getLocalIndices(const Element *el,
			  const DOFAdmin *admin,
			  std::vector<DegreeOfFreedom> &dofs) const override;

      /// Implements BasisFunction::getLocalDofPtrVec()
      /// Returns an vector filled with all DOFs per position
      void getLocalDofPtrVec(const Element *el, 
			  const DOFAdmin *admin,
			  std::vector<const DegreeOfFreedom*>& vec) const override;

      /// Implements BasisFunction::l2ScpFctBas
      void l2ScpFctBas(Quadrature* q,
		      AbstractFunction<double, WorldVector<double> >* f,
		      DOFVector<double>* fh) override;

      /// Implements BasisFunction::l2ScpFctBas
      void l2ScpFctBas(Quadrature* q,
		      AbstractFunction<WorldVector<double>, WorldVector<double> >* f,
		      DOFVector<WorldVector<double> >* fh) override;

      static void clear();

      /// Implements BasisFunction::isnodal
      bool isNodal() const override
      {
	return false;
      }


	
    protected:
      /// sets the barycentric coordinates (stored in \ref bary) of the local 
      /// basis functions.
      void setBary();		

      /// Implements BasisFunction::setNDOF
      void setNDOF() override;		

      /// Sets used function pointers
      void setFunctionPointer();

      /// Used by \ref getVec
      int* orderOfPositionIndices(const Element* el, 
				GeoIndex position, 
				int positionIndex) const override;

    private:
      /// barycentric coordinates of the locations of all basis functions
      std::vector<DimVec<double>* > *bary;

      /** \name static dim-degree-arrays
      * \{
      */
      static std::vector<DimVec<double>* > baryDimDegree;
      static DimVec<int>* ndofDimDegree;
      static int nBasFctsDimDegree;
      static std::vector<BasFctType*> phifunc;
      static std::vector<GrdBasFctType*> grdPhifunc;
      static std::vector<D2BasFctType*> D2Phifunc;
      /** \} */

      /// List of all used BasisFunctions in the whole program. Avoids duplicate
      /// instantiation of identical BasisFunctions. 
      static Bubble* Singleton;


    protected:
      /// Pointer to the used refineInter function
      void (*refineInter_fct)(DOFIndexed<double> *, RCNeighbourList*, int, BasisFunction*);

      static void  refineInter2_1d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);
      static void  refineInter3_2d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);
      static void  refineInter4_3d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);

      /// Pointer to the used coarseRestr function
      void (*coarseRestr_fct)(DOFIndexed<double> *, RCNeighbourList*, int, BasisFunction*);

      static void  coarseRestr2_1d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);
      static void  coarseRestr3_2d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);
      static void  coarseRestr4_3d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);

      /// Pointer to the used coarseInter function
      void (*coarseInter_fct)(DOFIndexed<double> *, RCNeighbourList*, int, BasisFunction*);  

      static void  coarseInter2_1d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);
      static void  coarseInter3_2d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);
      static void  coarseInter4_3d(DOFIndexed<double> *, RCNeighbourList*, int, 
				  BasisFunction*);


      /// AbstractFunction which implements lagrange/bubble basis functions
      class Phi : public BasFctType
      {
	public:
	  /// Constructs the local lagrange/bubble basis function for the given position,
	  /// positionIndex and nodeIndex. owner_ is a pointer to the Bubble 
	  /// object this basis function belongs to.
	  Phi(Bubble* owner, GeoIndex position, int positionIndex, int nodeIndex);

	  /// Destructor
	  virtual ~Phi();

	private:
	  /// vertices needed for evaluation of this function
	  int* vertices;

	  /// Pointer to the evaluating function
	  double (*func)(const DimVec<double>& lambda, int* vert);

	  /// Returns \ref func(lambda, vertices)
	  inline double operator()(const DimVec<double>& lambda) const override
	  {
	    return func(lambda, vertices);
	  }

	  // ====== Lagrange, degree = 1 =====================================
	  // vertex
	  inline static double phi1v(const DimVec<double>& lambda, int* vertices) 
	  {
	    return lambda[vertices[0]]; 
	  }

	  // ====== Bubble ===================================================
          // 1d
          inline static double phi2c(const DimVec<double>& lambda, int* vertices) 
          {
	    return (4.0 * lambda[vertices[0]] * lambda[vertices[1]]);
          }

          // 2d
	  inline static double phi3c(const DimVec<double>& lambda, int* vertices) 
	  {
	    return 27.0 * lambda[vertices[0]] * lambda[vertices[1]] * lambda[vertices[2]];
	  }

          // 3d
	  inline static double phi4c(const DimVec<double>& lambda, int* vertices) 
	  {
	    return 256.0 * lambda[vertices[0]] * lambda[vertices[1]] * 
	      lambda[vertices[2]] * lambda[vertices[3]];
	  }
      };


      /// AbstractFunction which implements gradients of Lagrange/Bubble basis functions.
      /// See \ref Phi
      class GrdPhi : public GrdBasFctType
      {	
	public:
	  GrdPhi(Bubble* owner, GeoIndex position, int positionIndex, int nodeIndex);

	  virtual ~GrdPhi();
	private:
	  int* vertices;
  
	  void (*func)(const DimVec<double>& lambda, 
			int* vertices_, 
			mtl::dense_vector<double>& result);

	  inline void operator()(const DimVec<double>& lambda, 
				mtl::dense_vector<double>& result) const override
	  {
	    func(lambda, vertices, result);
	  }

	// ====== Lagrange1 ================================================
	// vertex
	inline static void grdPhi1v(const DimVec<double>&, 
				  int* vertices, 
				  mtl::dense_vector<double>& result) 
	{
	  result = 0.0;
	  result[vertices[0]] = 1.0;
	}

	// ======= Bubble ==================================================
        inline static void grdPhi2c(const DimVec<double>& lambda, 
	  			  int* vertices, 
				  mtl::dense_vector<double>& result) 
        {
	  result = 0.0;
	  result[vertices[0]] = 4.0 * lambda[vertices[1]];
	  result[vertices[1]] = 4.0 * lambda[vertices[0]];
        }


	inline static void grdPhi3c(const DimVec<double>& lambda, 
				      int* vertices, 
				      mtl::dense_vector<double>& result) 
	{
	  result = 0.0;
	  result[vertices[0]] = 27.0 * lambda[vertices[1]] * lambda[vertices[2]];
	  result[vertices[1]] = 27.0 * lambda[vertices[0]] * lambda[vertices[2]];
	  result[vertices[2]] = 27.0 * lambda[vertices[0]] * lambda[vertices[1]];
	}

        inline static void grdPhi4c(const DimVec<double>& lambda, 
				  int* vertices,
				  mtl::dense_vector<double>& result) 
        {
	  result = 0.0;
	  result[0] = 
	    256.0 * lambda[vertices[1]] * lambda[vertices[2]] * lambda[vertices[3]];
	  result[1] = 
	    256.0 * lambda[vertices[0]] * lambda[vertices[2]] * lambda[vertices[3]];
	  result[2] = 
	    256.0 * lambda[vertices[0]] * lambda[vertices[1]] * lambda[vertices[3]];
	  result[3] = 
	    256.0 * lambda[vertices[0]] * lambda[vertices[1]] * lambda[vertices[2]];
        }
      };


      /// AbstractFunction which implements second derivatives of Lagrange/Bubble basis
      /// functions. See \ref Phi
      class D2Phi : public D2BasFctType
      {
      public:
	D2Phi(Bubble* owner, GeoIndex position, int positionIndex, int nodeIndex);

	virtual ~D2Phi();

      private:
	int* vertices;

	void (*func)(const DimVec<double>& lambda, int* vertices_, DimMat<double>& result);

	inline void operator()(const DimVec<double>& lambda, DimMat<double>& result) const override
	{
	  return func(lambda, vertices, result);
	}

	// ===== Lagrange1 ================================================
	// vertex
	inline static void D2Phi1v(const DimVec<double>&, int*, DimMat<double>& result) 
	{
	  result.set(0.0);
	}


	// ===== Bubble ===================================================
        inline static void D2Phi2c(const DimVec<double>&, int* vertices, 
				 DimMat<double>& result) 
        {
	  result.set(0.0);
	  result[vertices[0]][vertices[1]] = 4.0;
	  result[vertices[1]][vertices[0]] = 4.0;
        }

	inline static void D2Phi3c(const DimVec<double>& lambda, int* vertices, 
				      DimMat<double>& result) 
	{
	  result.set(0.0);
	  result[vertices[0]][vertices[1]] = 
	  result[vertices[1]][vertices[0]] = 27.0 * lambda[vertices[2]];
	  result[vertices[0]][vertices[2]] = 
	  result[vertices[2]][vertices[0]] = 27.0 * lambda[vertices[1]];
	  result[vertices[1]][vertices[2]] = 
	  result[vertices[2]][vertices[1]] = 27.0 * lambda[vertices[0]];
	}

        inline static void D2Phi4c(const DimVec<double>& lambda, int* vertices, 
				 DimMat<double>& result) 
        {
	  result.set(0.0);
	  result[vertices[0]][vertices[1]] = 
	    result[vertices[1]][vertices[0]] = 
	    256.0 * lambda[vertices[2]] * lambda[vertices[3]];
	  result[vertices[0]][vertices[2]] = 
	    result[vertices[2]][vertices[0]] = 
	    256.0 * lambda[vertices[1]] * lambda[vertices[3]];
	  result[vertices[0]][vertices[3]] = 
	    result[vertices[3]][vertices[0]] = 
	    256.0 * lambda[vertices[1]] * lambda[vertices[2]];
	  result[vertices[1]][vertices[2]] = 
	    result[vertices[2]][vertices[1]] = 
	    256.0 * lambda[vertices[0]] * lambda[vertices[3]];
	  result[vertices[1]][vertices[3]] = 
	    result[vertices[3]][vertices[1]] = 
	    256.0 * lambda[vertices[0]] * lambda[vertices[2]];
	  result[vertices[2]][vertices[3]] = 
	    result[vertices[3]][vertices[2]] = 
	    256.0 * lambda[vertices[0]] * lambda[vertices[1]];
        }
      };
    };
}

#endif // AMDIS_Bubble_H