ElementData.h 3.92 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

/** \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:
46
    /// constructor
47
48
    ElementData(ElementData *dec = NULL) 
      : decorated(dec)
49
    {}
50

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

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

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

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

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

85
      return NULL;
86
    }
87

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

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

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

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

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

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

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

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

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

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

146
      decorated = d;
147
    }
148
149

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

}

#endif