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

/** \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;

  // ============================================================================
  // ===== class ElementData ====================================================
  // ============================================================================

  /** \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:
    /** \brief
     * constructor
     */
    ElementData(ElementData *decorated = NULL) 
      : decorated_(decorated)
Naumann, Andreas's avatar
Naumann, Andreas committed
54
    {	}
55
56
57
58

    /** \brief
     * destructor
     */
59
    virtual ~ElementData();
60
61
62
63
64
65
66
67
68

    /** \brief
     * Refinement of parent to child1 and child2.
     */
    virtual bool refineElementData(Element* parent, 
				   Element* child1,
				   Element* child2,
				   int elType)
    {
69
      if (decorated_) {
70
71
72
	bool remove = 
	  decorated_->refineElementData(parent, child1, child2, elType);

73
	if (remove) {
74
75
76
77
78
79
	  ElementData *tmp = decorated_->decorated_;
	  delete decorated_;
	  decorated_ = tmp;
	}
      }
      return false;
80
    }
81
82
83
84
85
86
87

    /** \brief
     *
     */
    virtual void coarsenElementData(Element* parent, 
				    Element* thisChild,
				    Element* otherChild,
88
				    int elTypeParent);
89
90
91
92
93

    /** \brief
     * Returns a copy of this ElementData object including all decorated data.
     */
    virtual ElementData *clone() const {
94
      if (decorated_) {
95
96
97
	return decorated_->clone();
      }
      return NULL;
98
    }
99
100

    /** \brief
Naumann, Andreas's avatar
Naumann, Andreas committed
101
     * Returns the id of element data type.
102
     */
Naumann, Andreas's avatar
Naumann, Andreas committed
103
104
105
106
    virtual const int getTypeID() const 
	{
		return 0;
	}
107
108
109
110
111
112
113
114
115
116

    /** \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;

    /** \brief
     * Implements Serializable::serialize().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
117
    virtual void serialize(std::ostream& out);
118
119
120
121

    /** \brief
     * Implements Serializable::deserialize().
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
122
    virtual void deserialize(std::istream& in);
123
124
125
126
127

    /** \brief
     * Returns first element data in the chain which is of the spcified type.
     */
    inline ElementData *getElementData(int typeID) {
Thomas Witkowski's avatar
Thomas Witkowski committed
128
      if (this->isOfType(typeID)) {
129
130
	return this;
      } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
131
	if (decorated_) {
132
133
134
135
	  return decorated_->getElementData(typeID);
	}
      }
      return NULL;
136
    }
137
138

    inline ElementData *getDecorated(int typeID) { 
Thomas Witkowski's avatar
Thomas Witkowski committed
139
      if (decorated_) {
140
141
142
	return decorated_->getElementData(typeID);
      }
      return NULL;
143
    }
144

145
146
147
148
149
150
151
152
153
154
    /** \ref
     * Search the \ref decorated_ chain for a specific type ID, and delets
     * this entry.
     */
    bool deleteDecorated(int typeID);

    /** \ref
     * Delets the whole \ref decorated_ chain.
     */
    void deleteDecorated();
155
156
157
158

    inline ElementData *getDecorated() { 
      return decorated_; 
    }
159

160
    inline void setDecorated(ElementData *d) {
Naumann, Andreas's avatar
Naumann, Andreas committed
161
162
163
164
		if(getTypeID()==1)
		{
			if(d!=NULL) std::cout<<"leafdata decorated with nonzero"<<std::endl;
		}
165
166
      decorated_ = d;
    }
167
168
169
170
171
172
173
174
175
176
177

  protected:
    /** \brief
     * Pointer to next ElementData object in the chain of responsibility.
     */
    ElementData *decorated_;
  };

}

#endif