ElementData.h 4.53 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
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
// ==                                                                        ==
// ============================================================================

/** \file ElementData.h */

#ifndef AMDIS_ELEMENTDATA_H
#define AMDIS_ELEMENTDATA_H

#include "Serializable.h"
#include "CreatorMap.h"

namespace AMDiS {

  const int ESTIMATABLE = 1;
  const int COARSENABLE = 2;
  const int PERIODIC = 3;
  const int ELEMENT_REGION = 4;
  const int SURFACE_REGION = 5;

  /** \brief
   * Base class for element data. To allow to assign arbitrary data to arbitrary
   * elements at run time, the decorator pattern in combination with the
   * chain-of-responsibility pattern is applied. So only data have to be managed 
   * at each element which are used for this element at this time.
   */
  class ElementData : public Serializable
  {
  public:
45
    /// constructor
46
47
    ElementData(ElementData *dec = NULL) 
      : decorated(dec)
48
    {}
49

50
    /// destructor
51
    virtual ~ElementData();
52

53
    /// Refinement of parent to child1 and child2.
54
55
56
57
58
    virtual bool refineElementData(Element* parent, 
				   Element* child1,
				   Element* child2,
				   int elType)
    {
59
      if (decorated) {
60
	bool remove = 
61
	  decorated->refineElementData(parent, child1, child2, elType);
62

63
	if (remove) {
64
65
66
	  ElementData *tmp = decorated->decorated;
	  delete decorated;
	  decorated = tmp;
67
68
69
	}
      }
      return false;
70
    }
71

72
    ///
73
74
75
    virtual void coarsenElementData(Element* parent, 
				    Element* thisChild,
				    Element* otherChild,
76
				    int elTypeParent);
77

78
    /// Returns a copy of this ElementData object including all decorated data.
Thomas Witkowski's avatar
Thomas Witkowski committed
79
80
    virtual ElementData *clone() const 
    {
81
82
      if (decorated)
	return decorated->clone();
83

84
      return NULL;
85
    }
86

87
    /// Returns the id of element data type.
Thomas Witkowski's avatar
Thomas Witkowski committed
88
89
    virtual const int getTypeID() const 
    {
90
91
      return 0;
    }
92
93
94
95
96
97
98

    /** \brief
     * Returns whether the ElemnetData object is of the type specified by 
     * typeName. Must return true, even if typeName describes a base class.
     */
    virtual bool isOfType(int typeID) const = 0;

99
    /// Implements Serializable::serialize().
Thomas Witkowski's avatar
Thomas Witkowski committed
100
    virtual void serialize(std::ostream& out);
101

102
    /// Implements Serializable::deserialize().
Thomas Witkowski's avatar
Thomas Witkowski committed
103
    virtual void deserialize(std::istream& in);
104

105
    /// Returns first element data in the chain which is of the spcified type.
Thomas Witkowski's avatar
Thomas Witkowski committed
106
107
    inline ElementData *getElementData(int typeID) 
    {
Thomas Witkowski's avatar
Thomas Witkowski committed
108
      if (this->isOfType(typeID)) {
109
110
	return this;
      } else {
111
112
	if (decorated)
	  return decorated->getElementData(typeID);
113
114
      }
      return NULL;
115
    }
116

Thomas Witkowski's avatar
Thomas Witkowski committed
117
118
    inline ElementData *getDecorated(int typeID) 
    { 
119
120
      if (decorated)
	return decorated->getElementData(typeID);
121
      
122
      return NULL;
123
    }
124

125
    /** \ref
126
     * Search the \ref decorated chain for a specific type ID, and delets
127
128
129
130
     * this entry.
     */
    bool deleteDecorated(int typeID);

131
    /// Delets the whole \ref decorated chain.
132
    void deleteDecorated();
133

Thomas Witkowski's avatar
Thomas Witkowski committed
134
135
    inline ElementData *getDecorated() 
    { 
136
      return decorated; 
137
    }
138

Thomas Witkowski's avatar
Thomas Witkowski committed
139
140
    inline void setDecorated(ElementData *d) 
    {
141
142
      if (getTypeID() == 1)
	if (d != NULL)
Thomas Witkowski's avatar
Thomas Witkowski committed
143
	  std::cout << "leafdata decorated with nonzero" << std::endl;
144

145
      decorated = d;
146
    }
147
148

  protected:
149
    /// Pointer to next ElementData object in the chain of responsibility.
150
    ElementData *decorated;
151
152
153
154
155
  };

}

#endif