DOFIndexed.h 3.94 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
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.


20
21
22
23
24
25

/** \file DOFIndexed.h */

#ifndef AMDIS_DOFINDEXED_H
#define AMDIS_DOFINDEXED_H

26
#include <cassert>
27
28
29
#include <vector>
#include "Global.h"
#include "DOFIterator.h"
30
#include "AMDiS_fwd.h"
31
32
33
34
35
36
37
38
39
40
41
42

namespace AMDiS {

  /** \ingroup DOFAdministration
   * \brief
   * Interface for objects that stores information indexed by DOF indices
   * (like DOFVector or DOFMatrix). This interface is template type independent,
   * so a DOFAdmin can handle a single list of DOFIndexedBase objects. 
   */
  class DOFIndexedBase
  {
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
43
    virtual ~DOFIndexedBase() {}
44

Thomas Witkowski's avatar
Thomas Witkowski committed
45
    /// Returns the actual size. Must be overriden by sub classes
46
47
    virtual int getSize() const = 0;

Thomas Witkowski's avatar
Thomas Witkowski committed
48
    /// Resizes the object to size. Must be overriden by sub classes
49
50
    virtual void resize(int size) = 0;

51
52
53
54
55
56
57
58
    /// Check that object's size is equal to \p size or 0.  If object's size is 0 change it to \p size.
    virtual void checked_change_dim(int size)
    {
	assert(getSize() == 0 || getSize() == size); 
	if (getSize() == 0)
	    resize(size);
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
59
    /// Used by DOFAdmin::compress. Must be overriden by sub classes
60
    virtual void compressDOFIndexed(int first, int last, 
61
				    std::vector<DegreeOfFreedom> &newDOF) = 0;
62

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
63
64
    /// Performs needed action when a DOF index is freed. Can be overriden in
    /// sub classes. The default behavior is to do nothing.
Thomas Witkowski's avatar
Thomas Witkowski committed
65
    virtual void freeDOFContent(int) {}
66

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
67
68
    /// Interpolation after refinement. Can be overriden in subclasses.
    /// The default behavior is to do nothing.
Thomas Witkowski's avatar
Thomas Witkowski committed
69
    virtual void refineInterpol(RCNeighbourList&, int) {}
70

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
71
72
    /// Restriction after coarsening. Can be overriden in subclasses.
    /// The default behavior is to do nothing.
Thomas Witkowski's avatar
Thomas Witkowski committed
73
    virtual void coarseRestrict(RCNeighbourList&, int) {}
74

Thomas Witkowski's avatar
Blub    
Thomas Witkowski committed
75
76
    /// Returns the finite element space of this DOFIndexed object. Must be
    /// overriden in sub classes. 
77
    virtual const FiniteElemSpace* getFeSpace() const = 0;
78
79
80
81
82
83
84
85
86
  };

  /** \ingroup DOFAdministration
   * \brief
   * Templated interface for DOFIndexed objects.
   */
  template<typename T>
  class DOFIndexed : public DOFIndexedBase
  {
Praetorius, Simon's avatar
Praetorius, Simon committed
87
  public: // typedefs
Praetorius, Simon's avatar
Praetorius, Simon committed
88
89
90
91
    typedef T 			value_type;
    typedef DegreeOfFreedom	size_type;
    typedef value_type&		reference;
    typedef value_type const&	const_reference;
Praetorius, Simon's avatar
Praetorius, Simon committed
92
93
94

    typedef typename std::vector<value_type>::iterator		iterator;
    typedef typename std::vector<value_type>::const_iterator	const_iterator;
Praetorius, Simon's avatar
Praetorius, Simon committed
95
    
96
  public:
Thomas Witkowski's avatar
Thomas Witkowski committed
97
    virtual ~DOFIndexed() {}
98

Thomas Witkowski's avatar
Thomas Witkowski committed
99
    /// Returns iterator to the begin of container
Praetorius, Simon's avatar
Praetorius, Simon committed
100
    virtual iterator begin() = 0;
101

Thomas Witkowski's avatar
Thomas Witkowski committed
102
    /// Returns iterator to the end of container
Praetorius, Simon's avatar
Praetorius, Simon committed
103
104
105
106
    virtual iterator end() = 0;

    /// Returns iterator to the begin of container
    virtual const_iterator begin() const = 0;
107

Praetorius, Simon's avatar
Praetorius, Simon committed
108
109
110
    /// Returns iterator to the end of container
    virtual const_iterator end() const = 0;
    
Thomas Witkowski's avatar
Thomas Witkowski committed
111
    /// Returns container element at index i
Praetorius, Simon's avatar
Praetorius, Simon committed
112
    virtual reference operator[](size_type i) = 0;
113

Thomas Witkowski's avatar
Thomas Witkowski committed
114
    /// Returns container element at index i
Praetorius, Simon's avatar
Praetorius, Simon committed
115
    virtual const_reference operator[](size_type i) const = 0;
116
117
118
119
  };

  void mv(MatrixTranspose transpose, 
	  const DOFMatrix &a, 
120
	  const DOFIndexed<double> &x,
121
122
	  DOFIndexed<double> &result,
	  bool add = false); 
123
} // namespace AMDiS
124
125

#endif // AMDIS_DOFINDEXED_H