DOFVector.h 23.2 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
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file DOFVector.h */

#ifndef AMDIS_DOFVECTOR_H 
#define AMDIS_DOFVECTOR_H 
 
// ===========================================================================
// ===== includes ============================================================
// ===========================================================================

#include "FixVec.h"
#include "Global.h" 
#include "Flag.h" 
#include "RCNeighbourList.h" 
#include "DOFIterator.h"
#include "DOFIndexed.h"
#include "DOFContainer.h"
#include "MemoryManager.h"
#include "Boundary.h"
#include "CreatorInterface.h"
#include "Serializable.h"
#include "DOFMatrix.h" 
Thomas Witkowski's avatar
Thomas Witkowski committed
41
#include "BasisFunction.h"
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <vector> 
#include <memory> 
#include <list> 
 
namespace AMDiS {

  // ===========================================================================
  // ===== forward declarations ================================================
  // ===========================================================================

  class Mesh; 
  class FiniteElemSpace; 
  class ElInfo; 
  class DOFAdmin; 
  class BasisFunction; 
  class FillInfo; 
  class Quadrature; 
  class FastQuadrature;
  class DOFMatrix; 
  class MultiGridSortSolver; 
  class Operator;
  class ElementVector;
  class BoundaryManager;

66
  template<typename ResultType, typename ArgumentType> class AbstractFunction;
67
68
69
70
71
72


  template<typename T> 
  class DOFVectorBase : public DOFIndexed<T>
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
73

74
75
76
    DOFVectorBase() 
      : feSpace(NULL),
	elementVector(NULL),
Thomas Witkowski's avatar
Thomas Witkowski committed
77
78
        boundaryManager(NULL),
        nBasFcts(0)
79
    {}
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    
81
    DOFVectorBase(const FiniteElemSpace *f, std::string n);
82

Thomas Witkowski's avatar
Thomas Witkowski committed
83
    virtual ~DOFVectorBase();
84

Thomas Witkowski's avatar
Thomas Witkowski committed
85
86
87
88
89
    /** \brief 
     * For the given element, this function returns an array of all DOFs of this
     * DOFVector that are defined on this element.
     */
    virtual const T *getLocalVector(const Element *el, T* localVec) const;
90

Thomas Witkowski's avatar
Thomas Witkowski committed
91
92
93
94
    /** \brief
     * Evaluates the DOF vector at a set of quadrature points defined on the 
     * given element.
     */
95
96
    const T *getVecAtQPs(const ElInfo *elInfo, 
			 const Quadrature *quad,
97
			 const FastQuadrature *quadFast,
98
			 T *vecAtQPs) const;
99

Thomas Witkowski's avatar
Thomas Witkowski committed
100
101
102
103
104
105
    const T *getVecAtQPs(const ElInfo *smallElInfo, 
			 const ElInfo *largeElInfo,
			 const Quadrature *quad,
			 const FastQuadrature *quadFast,
			 T *vecAtQPs) const;

106
107
    const WorldVector<T> *getGrdAtQPs(const ElInfo *elInfo, 
				      const Quadrature *quad,
108
				      const FastQuadrature *quadFast,
109
				      WorldVector<T> *grdAtQPs) const;
110

Thomas Witkowski's avatar
Thomas Witkowski committed
111
112
113
114
115
116
    const WorldVector<T> *getGrdAtQPs(const ElInfo *smallElInfo, 
				      const ElInfo *largeElInfo,
				      const Quadrature *quad,
				      const FastQuadrature *quadFast,
				      WorldVector<T> *grdAtQPs) const;

117
118
    const WorldMatrix<T> *getD2AtQPs(const ElInfo *elInfo, 
				     const Quadrature *quad,
119
				     const FastQuadrature *quadFast,
120
				     WorldMatrix<T> *d2AtQPs) const;
121

Thomas Witkowski's avatar
Thomas Witkowski committed
122
    /// Returns the FE space the DOF vector is defined on.
123
    inline const FiniteElemSpace* getFESpace() const {
124
      return feSpace;
125
    }
126

Thomas Witkowski's avatar
Thomas Witkowski committed
127
128
129
130
131
132
133
134
135
136
137
138
139
    /** \brief
     * Assembles the element vector for the given ellement and adds the
     * element matrix to the current DOF vector.
     */ 
    void assemble(T factor, ElInfo *elInfo,			    
		  const BoundaryType *bound, 
		  Operator *op = NULL);

    void assemble2(T factor, 
		   ElInfo *mainElInfo, ElInfo *auxElInfo,
		   ElInfo *smallElInfo, ElInfo *largeElInfo,
		   const BoundaryType *bound, 
		   Operator *op = NULL);
140
141
142
143
144

    void addElementVector(T sign,
			  const ElementVector &elVec, 
			  const BoundaryType *bound,
			  bool add = true); 
Thomas Witkowski's avatar
Thomas Witkowski committed
145
146
147
148
149
150
151

    /* \brief
     * That function must be called after the matrix assembling has been finished. 
     * This makes it possible to start some cleanup or matrix data compressing 
     * procedures.
     */
    void finishAssembling();
152
153
154
155
156
157
158
159
 
    inline void addOperator(Operator* op, 
			    double *factor = NULL,
			    double *estFactor = NULL) 
    {
      operators.push_back(op);
      operatorFactor.push_back(factor);
      operatorEstFactor.push_back(estFactor);
160
    }
161

162
    inline std::vector<double*>::iterator getOperatorFactorBegin() {
163
      return operatorFactor.begin();
164
    }
165

166
    inline std::vector<double*>::iterator getOperatorFactorEnd() {
167
      return operatorFactor.end();
168
    }
169

170
    inline std::vector<double*>::iterator getOperatorEstFactorBegin() {
171
      return operatorEstFactor.begin();
172
    }
173

174
    inline std::vector<double*>::iterator getOperatorEstFactorEnd() {
175
      return operatorEstFactor.end();
176
    }
177
178


179
    inline std::vector<Operator*>::iterator getOperatorsBegin() {
180
      return operators.begin();
181
    }
182

183
    inline std::vector<Operator*>::iterator getOperatorsEnd() {
184
      return operators.end();
185
    }
186
187
188
189
190
191
192
193
194
195
196

    Flag getAssembleFlag();

    /** \brief
     * Evaluates \f[ u_h(x(\lambda)) = \sum_{i=0}^{m-1} vec[ind[i]] * 
     * \varphi^i(\lambda) \f] where \f$ \varphi^i \f$ is the i-th basis function,
     * \f$ x(\lambda) \f$ are the world coordinates of lambda and
     * \f$ m \f$ is the number of basis functions
     */
    T evalUh(const DimVec<double>& lambda, DegreeOfFreedom* ind);

197
    inline std::vector<Operator*>& getOperators() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
198
      return operators; 
199
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
200

201
    inline std::vector<double*>& getOperatorFactor() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
202
      return operatorFactor; 
203
    }
204

205
    inline std::vector<double*>& getOperatorEstFactor() { 
206
      return operatorEstFactor; 
207
    }
208

Thomas Witkowski's avatar
Thomas Witkowski committed
209
    /// Returns \ref name
210
    inline const std::string& getName() const { 
Thomas Witkowski's avatar
Thomas Witkowski committed
211
      return name; 
212
    } 
213

Thomas Witkowski's avatar
Thomas Witkowski committed
214
215
    inline BoundaryManager* getBoundaryManager() const { 
      return boundaryManager; 
216
    }
217
218
219

    inline void setBoundaryManager(BoundaryManager *bm) {
      boundaryManager = bm;
220
    }
221
222

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
223
    ///
224
225
    const FiniteElemSpace *feSpace;

Thomas Witkowski's avatar
Thomas Witkowski committed
226
    ///
227
    std::string name;
228

Thomas Witkowski's avatar
Thomas Witkowski committed
229
    ///
230
231
    ElementVector *elementVector;

Thomas Witkowski's avatar
Thomas Witkowski committed
232
    ///
233
    std::vector<Operator*> operators;
234

Thomas Witkowski's avatar
Thomas Witkowski committed
235
    ///
236
    std::vector<double*> operatorFactor;
237

Thomas Witkowski's avatar
Thomas Witkowski committed
238
    ///
239
    std::vector<double*> operatorEstFactor;
240

Thomas Witkowski's avatar
Thomas Witkowski committed
241
    ///
242
243
    BoundaryManager *boundaryManager;

Thomas Witkowski's avatar
Thomas Witkowski committed
244
    /// Number of basis functions of the used finite element space.
Thomas Witkowski's avatar
Thomas Witkowski committed
245
    int nBasFcts;
246

Thomas Witkowski's avatar
Thomas Witkowski committed
247
    /// Are used to store temporary local dofs of an element. Thread safe.
248
249
    std::vector<DegreeOfFreedom*> localIndices;

Thomas Witkowski's avatar
Thomas Witkowski committed
250
    /// Are used to store temporary local values of an element. Thread safe.
Thomas Witkowski's avatar
Thomas Witkowski committed
251
252
    std::vector<T*> localVectors;

Thomas Witkowski's avatar
Thomas Witkowski committed
253
    /// Temporarly used in \ref getGrdAtQPs. Thread safe.
Thomas Witkowski's avatar
Thomas Witkowski committed
254
255
    std::vector<DimVec<double>*> grdTmp;

Thomas Witkowski's avatar
Thomas Witkowski committed
256
    /// Temporarly used in \ref getGrdAtQPs. Thread safe.
257
258
    std::vector<DimVec<double>*> grdPhis;

Thomas Witkowski's avatar
Thomas Witkowski committed
259
    /// Temporarly used in \ref getD2AtQPs. Thread safe.
260
    std::vector<DimMat<double>*> D2Phis;
Thomas Witkowski's avatar
Thomas Witkowski committed
261

Thomas Witkowski's avatar
Thomas Witkowski committed
262
    /// Dimension of the mesh this DOFVectorBase belongs to
Thomas Witkowski's avatar
Thomas Witkowski committed
263
    int dim;
Thomas Witkowski's avatar
Thomas Witkowski committed
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


  // ===========================================================================
  // ===== defs ================================================================
  // ===========================================================================

  /** \brief
   * Specifies which operation should be done after coarsening
   */
  typedef enum{
    NO_OPERATION = 0,   
    COARSE_RESTRICT = 1,
    COARSE_INTERPOL = 2 
  } CoarsenOperation;
 
  // ===========================================================================
  // ===== class DOFVector =====================================================
  // ===========================================================================

  /** \ingroup DOFAdministration 
   * \brief
   * The DOFs described above are just integers that can be used as indices into 
   * vectors and matrices. During refinement and coarsening of the mesh, the 
   * number of used DOFs, the meaning of one integer index, and even the total 
   * range of DOFs change. To be able to handle these changes automatically for 
   * all vectors, which are indexed by the DOFs, special data structures are 
   * used which contain such vector data. Lists of these structures are kept in 
   * DOFAdmin, so that all vectors in the lists can be resized together with the
   * range of DOFs. During refinement and coarsening of elements, values can be
   * interpolated automatically to new DOFs, and restricted from old DOFs.
   */
  template<typename T> 
  class DOFVector : public DOFVectorBase<T>, public Serializable
  {  
  public:
    MEMORY_MANAGED(DOFVector<T>);

    /** \ingroup DOFAdministration
     * \brief
     * Enables the access of DOFVector<T>::Iterator. Alias for DOFIterator<T>
     */
    class Iterator : public DOFIterator<T> {
    public:
      Iterator(DOFIndexed<T> *c, DOFIteratorType type)
	: DOFIterator<T>(c, type)
310
      {}
311
312
313

      Iterator(DOFAdmin *admin, DOFIndexed<T> *c, DOFIteratorType type)
	: DOFIterator<T>(admin, c, type)
314
      {}
315
316
317
318
319
320
    };

    class Creator : public CreatorInterface<DOFVector<T> > {
    public:
      MEMORY_MANAGED(Creator);

321
322
323
      Creator(FiniteElemSpace *feSpace_) 
        : feSpace(feSpace_) 
      {}
324
325
326

      DOFVector<T> *create() { 
	return NEW DOFVector<T>(feSpace, ""); 
327
      }
328
329
330

      void free(DOFVector<T> *vec) { 
	DELETE vec; 
331
      }
332
333
334
335
336
337
338
339
340
341
342
343
344

    private:
      FiniteElemSpace *feSpace;
    };

  public:
    /** \brief
     * Empty constructor. No initialization!
     */
    DOFVector() 
      : DOFVectorBase<T>(), 
	feSpace(NULL),
	coarsenOperation(NO_OPERATION)
345
    {}
346
347
348
349

    /** \brief
     * Constructs a DOFVector with name n belonging to FiniteElemSpace f
     */
350
    DOFVector(const FiniteElemSpace* f, std::string n); 
351
352
353
354

    /** \brief
     * Initialization.
     */
355
    void init(const FiniteElemSpace* f, std::string n);
356
357
358
359
360

    /** \brief
     * Copy Constructor
     */
    DOFVector(const DOFVector& rhs) {
Thomas Witkowski's avatar
Thomas Witkowski committed
361
362
363
      *this = rhs;   
      name = rhs.name + "copy";
      if (feSpace && feSpace->getAdmin()) {
364
365
	(dynamic_cast<DOFAdmin*>(feSpace->getAdmin()))->addDOFIndexed(this);
      }
366
    }
367
368
369
370
371
372
373
374
375

    /** \brief
     * Destructor
     */
    virtual ~DOFVector();

    /** \brief
     * Returns iterator to the begin of \ref vec
     */
376
    typename std::vector<T>::iterator begin() { 
377
      return vec.begin(); 
378
    }
379
380
381
382

    /** \brief
     * Returns iterator to the end of \ref vec
     */
383
    typename std::vector<T>::iterator end() { 
384
      return vec.end(); 
385
    }
386
387
388
389
390
391
  
    /** \brief
     * Used by DOFAdmin to compress this DOFVector. Implementation of
     * DOFIndexedBase::compress()
     */
    virtual void compressDOFIndexed(int first, int last,
392
				    std::vector<DegreeOfFreedom> &newDof);
393
394
395
396
397
398

    /** \brief
     * Sets \ref coarsenOperation to op
     */
    inline void setCoarsenOperation(CoarsenOperation op) { 
      coarsenOperation = op; 
399
    }
400
401
402
403

    /** \brief
     * Returns \ref coarsenOperation
     */
404
405
    inline CoarsenOperation getCoarsenOperation() { 
      return coarsenOperation; 
406
    }
407
408
409
410

    /** \brief
     * Restriction after coarsening. Implemented for DOFVector<double>
     */
411
    inline void coarseRestrict(RCNeighbourList&, int) {}
412
413
414
415

    /** \brief
     * Interpolation after refinement.
     */
416
    inline void refineInterpol(RCNeighbourList&, int) {}
417
418
419
420

    /** \brief
     * Returns \ref vec
     */
421
    std::vector<T>& getVector() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
422
      return vec;
423
    }
424
425
426
427

    /** \brief
     * Returns size of \ref vec
     */
428
429
    inline int getSize() const { 
      return vec.size();
430
    } 
431
432
433
434

    /** \brief
     * Returns used size of the vector.
     */
435
436
    inline int getUsedSize() const { 
      return feSpace->getAdmin()->getUsedSize(); 
437
    }
438
439
440
441
442

    /** \brief
     * Resizes \ref vec to n
     */
    inline void resize(int n) { 
443
444
      FUNCNAME("DOFVector<T>::resize()");
      TEST_EXIT_DBG((n >= 0))("Can't resize DOFVector to negative size\n"); 
445
      vec.resize(n);
446
    } 
447
448
449
450
451

    /** \brief
     * Resizes \ref vec to n and inits new values with init
     */
    inline void resize(int n, T init) { 
452
453
      FUNCNAME("DOFVector<T>::resize()");
      TEST_EXIT_DBG((n >= 0))("Can't resize DOFVector to negative size\n"); 
454
      vec.resize(n, init);
455
    } 
456
457
458
459
460
461

    /** \brief
     * Returns \ref vec[i]
     */
    inline const T& operator[](DegreeOfFreedom i) const {
      FUNCNAME("DOFVector<T>::operator[]");
462
463
      TEST_EXIT_DBG((i>= 0) && (i < static_cast<int>(vec.size())))
	("Illegal vector index %d.\n",i);
464
      return vec[i];
465
    } 
466

467
468
    inline int getSize() { 
      return vec.size(); 
469
    }
470
471
472
473
474
475

    /** \brief
     * Returns \ref vec[i]
     */
    inline T& operator[](DegreeOfFreedom i) {
      FUNCNAME("DOFVector<T>::operator[]");
476
477
      TEST_EXIT_DBG((i >= 0) && (i < static_cast<int>(vec.size())))
	("Illegal vector index %d.\n",i);
478
      return vec[i];
479
    }
Thomas Witkowski's avatar
Thomas Witkowski committed
480
 
481
482
483
484
485
486
487
488
489
    /** \brief
     * Calculates Integral of this DOFVector
     */
    double Int(Quadrature* q = NULL) const;

    /** \brief
     * Calculates L1 norm of this DOFVector
     */
    double L1Norm(Quadrature* q = NULL) const;
Thomas Witkowski's avatar
Thomas Witkowski committed
490
 
491
492
493
494
495
    /** \brief
     * Calculates L2 norm of this DOFVector
     */
    inline double L2Norm(Quadrature* q = NULL) const {
      return sqrt(L2NormSquare());
496
    }
497
498
499
500
501
502
503
504
505
506
507

    /** \brief
     * Calculates square of L2 norm of this DOFVector
     */
    double L2NormSquare(Quadrature* q = NULL) const;

    /** \brief
     * Calculates H1 norm of this DOFVector
     */
    inline double H1Norm(Quadrature* q = NULL) const {
      return sqrt(H1NormSquare());
508
    }
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529

    /** \brief
     * Calculates square of H1 norm of this DOFVector
     */
    double H1NormSquare(Quadrature* q = NULL) const;  

    /** \brief
     * Calculates euclidian norm of this DOFVector
     */
    double nrm2() const; 

    /** \brief
     * Returns square of the euclidian norm.
     */
    double squareNrm2() const;

    /** \brief
     * Calculates l2 norm of this DOFVector
     */
    inline double l2norm() const { 
      return nrm2();
530
    }
531
532
533
534
535
536
537
538
539
540
541

    /** \brief
     * Calculates the absolute sum of this DOFVector
     */
    T asum() const; 

    /** \brief
     * Calculates the l1 norm of this DOFVector
     */
    inline double l1norm() const { 
      return asum();
542
    } 
543
544
545
546
547

    /** \brief
     * Calculates doublewell of this DOFVector
     */
    double DoubleWell(Quadrature* q = NULL) const;
Thomas Witkowski's avatar
Thomas Witkowski committed
548
 
549
550
551
552
    /** \brief
     * Calculates the sum of this DOFVector
     */
    T sum() const; 
Thomas Witkowski's avatar
Thomas Witkowski committed
553
 
554
555
556
557
558
559
560
561
562
563
564
    /** \brief
     * Sets \ref vec[i] = val, i=0 , ... , size
     */
    void set(T val); 

    /** \brief
     * Assignment operator for setting complete vector to a certain value d
     */
    inline DOFVector<T>& operator=(T d) {
      set(d); 
      return *this;
565
    } 
566
567
568
569

    /** \brief
     * Assignment operator between two vectors
     */
570
    DOFVector<T>& operator=(const DOFVector<T>&); 
571
572
573
574
575
576
577
578
579
580
581
582
583
584

    /** \brief
     * vec[i] = v.vec[i]
     */
    void copy(const DOFVector<T>& v); 

    /** \brief
     * Returns minimum of DOFVector
     */
    T min() const; 

    /** \brief
     * Returns maximum of DOFVector
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
585
586
587
588
589
590
    T max() const;

    /** \brief
     * Returns absolute maximum of DOFVector
     */
    T absMax() const;
591
592
593
594
595

    /** \brief
     * Used by interpol while mesh traversal
     */
    static int interpolFct(ElInfo* elinfo);
596
 
597
598
599
600
601
    /** \brief
     * Prints \ref vec to stdout
     */
    void print() const; 

602
603
604
    /** \brief
     *
     */
605
606
    int calcMemoryUsage() const;

607
608
609
610
611
612
613
614
615
616
    /** \brief
     * Computes the coefficients of the interpolant of the function fct and
     * stores these in the DOFVector
     */
    void interpol(AbstractFunction<T, WorldVector<double> > *fct);

    void interpol(DOFVector<T> *v, double factor);

    // ===== Serializable implementation =====

617
    void serialize(std::ostream &out) {
618
619
620
      unsigned int size = vec.size();
      out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
      out.write(reinterpret_cast<const char*>(&(vec[0])), size * sizeof(T));
621
    }
622

623
    void deserialize(std::istream &in) {
624
625
626
627
      unsigned int size;
      in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
      vec.resize(size);
      in.read(reinterpret_cast<char*>(&(vec[0])), size * sizeof(T));
628
    }
629
630
631
632
633
634
635

    DOFVector<WorldVector<T> > *getGradient(DOFVector<WorldVector<T> >*) const;

    WorldVector<DOFVector<T>*> *getGradient(WorldVector<DOFVector<T>*> *grad) const;

    DOFVector<WorldVector<T> >*

636
    getRecoveryGradient(DOFVector<WorldVector<T> >*) const;
637

Thomas Witkowski's avatar
Thomas Witkowski committed
638
  protected: 
639
640
641
642
643
644
645
646
647
    /** \brief
     * Used by Int while mesh traversal
     */
    static int Int_fct(ElInfo* elinfo);

    /** \brief
     * Used by L1Norm while mesh traversal
     */
    static int L1Norm_fct(ElInfo* elinfo);
Thomas Witkowski's avatar
Thomas Witkowski committed
648
 
649
650
651
652
653
654
655
656
657
658
    /** \brief
     * Used by L2Norm while mesh traversal
     */
    static int L2Norm_fct(ElInfo* elinfo);

    /** \brief
     * Used by H1Norm while mesh traversal
     */
    static int H1Norm_fct(ElInfo* elinfo);

659
660
661
662
663
    /** \brief
     * Used by DoubleWell while mesh traversal
     */
    static int DoubleWell_fct(ElInfo* elinfo);

664
665
666
667
  protected: 
    /** \brief
     * Name of this DOFVector
     */
668
    std::string name; 
669
670
671
672
673
674
675
676
677

    /** \brief
     * FiniteElemSpace of the vector
     */
    const FiniteElemSpace *feSpace; 

    /** \brief
     * Data container
     */
678
    std::vector<T> vec; 
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
 
    /** \brief
     * Specifies what operation should be performed after coarsening
     */
    CoarsenOperation coarsenOperation;

    /** \brief
     * Used by \ref interpol
     */
    AbstractFunction<T, WorldVector<double> > *interFct;

    /** \brief
     * Used for mesh traversal
     */
    static DOFVector<T> *traverseVector;

  protected:
    /** \brief
     * Used while calculating vector norms
     */
    static FastQuadrature *quad_fast;

    /** \brief
     * Stores the last calculated vector norm
     */
    static double norm;
  }; 

Thomas Witkowski's avatar
Thomas Witkowski committed
707
708
  // ===============================================================================

709
710
711
712
713
714
  template<>
  void DOFVector<double>::refineInterpol(RCNeighbourList&, int); 

  template<>
  void DOFVector<double>::coarseRestrict(RCNeighbourList&, int); 

Thomas Witkowski's avatar
Thomas Witkowski committed
715
716
  inline double min(const DOFVector<double>& v) {
    return v.min();
717
  } 
Thomas Witkowski's avatar
Thomas Witkowski committed
718
719
720

  inline double max(const DOFVector<double>& v) {
    return v.max();
721
  }
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740

  // ===========================================================================
  // ===== class DOFVectorDOF ==================================================
  // ===========================================================================

  /** \ingroup DOFAdministration
   * \brief
   * A DOFVector that stores DOF indices.
   */
  class DOFVectorDOF : public DOFVector<DegreeOfFreedom>,
		       public DOFContainer
  {
  public:  
    MEMORY_MANAGED(DOFVectorDOF);

    /** \brief
     * Calls constructor of DOFVector<DegreeOfFreedom> and registers itself
     * as DOFContainer at DOFAdmin
     */
741
    DOFVectorDOF(const FiniteElemSpace* feSpace_, std::string name_)
742
743
744
      : DOFVector<DegreeOfFreedom>(feSpace_, name_)
    {
      feSpace->getAdmin()->addDOFContainer(this);
745
    }
746
747
748
749
750
751
  
    /** \brief
     * Deregisters itself at DOFAdmin.
     */
    ~DOFVectorDOF() {
      feSpace->getAdmin()->removeDOFContainer(this);
752
    }
753
754
755
756
757
758
759

    /** \brief
     * Implements DOFContainer::operator[]() by calling 
     * DOFVEctor<DegreeOfFreedom>::operator[]()
     */
    DegreeOfFreedom& operator[](DegreeOfFreedom i) {
      return DOFVector<DegreeOfFreedom>::operator[](i);
760
    }
761
762
763
764
765
766

    /** \brief
     * Implements DOFIndexedBase::getSize()
     */
    int getSize() const {
      return DOFVector<DegreeOfFreedom>::getSize();
767
    }
768
769
770
771
772
773
774
775
776
777
778
779
780
781

    /** \brief
     * Implements DOFIndexedBase::resize()
     */
    void resize(int size) {
      DOFVector<DegreeOfFreedom>::resize(size);
    }

    void freeDOFContent(DegreeOfFreedom dof);

  protected:
    DOFVectorDOF();
  };

Thomas Witkowski's avatar
Thomas Witkowski committed
782
783
784
785
786


  // ===============================================================================


787
788
789
  template<typename T>
  double norm(DOFVector<T> *vec) {
    return vec->nrm2();
790
  }
791
792
793
794

  template<typename T>
  double L2Norm(DOFVector<T> *vec) {
    return vec->L2Norm();
795
  }
796
797
798
799

  template<typename T>
  double H1Norm(DOFVector<T> *vec) {
    return vec->H1Norm();
800
  }
801
802
803
804

  template<typename T>
  void print(DOFVector<T> *vec) {
    vec->print();
805
  }
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858

  // point wise multiplication
  template<typename T>
  const DOFVector<T>& operator*=(DOFVector<T>& x, const DOFVector<T>& y);

  // multiplication with scalar

  template<typename T>
  const DOFVector<T>& operator*=(DOFVector<T>& x, T scal);

  // scalar product

  template<typename T>
  T operator*(DOFVector<T>& x, DOFVector<T>& y);

  // addition

  template<typename T>
  const DOFVector<T>& operator+=(DOFVector<T>& x, const DOFVector<T>& y);

  // subtraction

  template<typename T>
  const DOFVector<T>& operator-=(DOFVector<T>& x, const DOFVector<T>& y);

  template<typename T>
  const DOFVector<T>& operator*(const DOFVector<T>& v, double d);

  template<typename T>
  const DOFVector<T>& operator*(double d, const DOFVector<T>& v);

  template<typename T>
  const DOFVector<T>& operator+(const DOFVector<T>&v1 , const DOFVector<T>& v2);



  // y = a*x + y

  template<typename T>
  void axpy(double a,const DOFVector<T>& x, DOFVector<T>& y);

  // matrix vector product
  template<typename T>
  void mv(MatrixTranspose transpose, 
	  const DOFMatrix &a, 
	  const DOFVector<T> &x,
	  DOFVector<T> &result,
	  bool add = false); 

  template<typename T>
  void xpay(double a,const DOFVector<T>& x,DOFVector<T>& y);

  template<typename T>
859
860
861
  inline void scal(T a, DOFVector<T>& y) {
    y *= a;
  }
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877

  template<typename T>
  inline const DOFVector<T>& mult(double scal,
				  const DOFVector<T>& v,
				  DOFVector<T>& result);

  template<typename T>
  inline const DOFVector<T>& add(const DOFVector<T>& v,
				 double scal,
				 DOFVector<T>& result);

  template<typename T>
  inline const DOFVector<T>& add(const DOFVector<T>& v1,
				 const DOFVector<T>& v2,
				 DOFVector<T>& result);

878
879
880
881
882
883
884
885
886
  template<typename T>
  inline const DOFVector<T>& mod(const DOFVector<T>& v,
				 DOFVector<T>& result);

  template<typename T>
  inline const DOFVector<T>& Tanh(const DOFVector<T>& v,
				  DOFVector<T>& result);


887
  template<typename T>
888
  inline void set(DOFVector<T>& vec, T d) {
889
    vec.set(d);
890
  }
891
892

  template<typename T>
893
  inline void setValue(DOFVector<T>& vec, T d) {
894
    vec.set(d);
895
  }
896
897
898
899

  template<typename T>
  inline int size(DOFVector<T> *vec) {
    return vec->getUsedSize();
900
  }
901
902
903
904
905
906
907
908

  WorldVector<DOFVector<double>*> *transform(DOFVector<WorldVector<double> > *vec,
					     WorldVector<DOFVector<double>*> *result);
}

#include "DOFVector.hh"

#endif  // !_DOFVECTOR_H_