ElementData.h 4.53 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
// ============================================================================
// ==                                                                        ==
// == 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;

  /** \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 *decorated = NULL) 
      : decorated_(decorated)
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
61
62
	bool remove = 
	  decorated_->refineElementData(parent, child1, child2, elType);

63
	if (remove) {
64
65
66
67
68
69
	  ElementData *tmp = decorated_->decorated_;
	  delete decorated_;
	  decorated_ = tmp;
	}
      }
      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.
79
    virtual ElementData *clone() const {
80
      if (decorated_)
81
	return decorated_->clone();
82

83
      return NULL;
84
    }
85

86
87
88
89
    /// Returns the id of element data type.
    virtual const int getTypeID() const {
      return 0;
    }
90
91
92
93
94
95
96

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

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

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

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

    inline ElementData *getDecorated(int typeID) { 
115
      if (decorated_)
116
	return decorated_->getElementData(typeID);
117
      
118
      return NULL;
119
    }
120

121
122
123
124
125
126
    /** \ref
     * Search the \ref decorated_ chain for a specific type ID, and delets
     * this entry.
     */
    bool deleteDecorated(int typeID);

127
    /// Delets the whole \ref decorated_ chain.
128
    void deleteDecorated();
129
130
131
132

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

134
    inline void setDecorated(ElementData *d) {
135
136
137
138
      if (getTypeID() == 1)
	if (d != NULL)
	  std::cout<<"leafdata decorated with nonzero"<<std::endl;

139
140
      decorated_ = d;
    }
141
142

  protected:
143
    /// Pointer to next ElementData object in the chain of responsibility.
144
145
146
147
148
149
    ElementData *decorated_;
  };

}

#endif