SolutionDataStorage.h 4.42 KB
Newer Older
1
2
3
4
5
#ifndef AMDIS_SOLUTION_DATA_STORAGE_H
#define AMDIS_SOLUTION_DATA_STORAGE_H

#include <iostream>
#include <vector>
Thomas Witkowski's avatar
Thomas Witkowski committed
6
#include <map>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "DOFVector.h"
#include "SystemVector.h"
#include "Parameters.h"

namespace AMDiS {

  template<typename T>
  struct SolutionHelper
  {
    typedef FiniteElemSpace* type;
  };

  template <>
  struct SolutionHelper<SystemVector>
  {
    typedef std::vector<FiniteElemSpace*> type;
  };
  
Thomas Witkowski's avatar
Thomas Witkowski committed
25
26
27
28
29
30

  class DataContainer
  {
  public:
  };

31
32
33
34
  template<typename T>
  class SolutionDataStorage 
  {
  public:
35
36
37
    /** \brief
     *
     */
38
39
    SolutionDataStorage(std::string name);

40
41
42
    /** \brief
     *
     */
43
44
45
46
47
    ~SolutionDataStorage();

    /** \brief
     * Set one fix FE Space. All solutions are defined only on the given FE Space.     
     */
48
    void setFixFESpace(typename SolutionHelper<T>::type feSpace);
49

50
51
52
53
    /** \brief
     *
     */
    void push(T *solution,
54
	      double timestamp);
55
56
57
58
59
60
61

    /** \brief
     *
     */
    bool pop(T **solution,
	     double *timestep);

62
63
64
65
    /** \brief
     * Deletes all pointers and empties all internal vectors.
     */
    void clear();
66
	     
67
68
69
70
71
72
73
74
75

    /** \brief
     * Returns for a given solution number the corresponding fe Space. If the
     * the fe Space is fixed, the fe Space for all solutions is stored at
     * position 0.
     */
    typename SolutionHelper<T>::type getFeSpace(int i = 0) {
      return feSpaces[i];
    }
76

77
78
79
    /** \brief
     *
     */
80
81
82
83
    bool isPoped() {
      return poped;
    }

84
85
86
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
87
88
    void addContainer(std::string name);

89
90
91
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
92
93
    void push(std::string name, WorldVector<double> value);

94
95
96
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
97
98
    void pop(std::string name, WorldVector<double> &value);

99
100
101
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
102
103
    void reset(std::string name);

104
105
106
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
107
108
    void clear(std::string name);

109
  protected:
110
    /** \brief
111
112
     * Deletes the fe space and all it content, i.e., also the dof admin, 
     * mesh, etc.
113
     */
114
    void deleteFeSpace(FiniteElemSpace* feSpace);
115

116
117
118
    /** \brief
     * Deletes a list of fe spaces.
     */
119
    void deleteFeSpace(std::vector<FiniteElemSpace*> feSpaces) {
120
      for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
121
	deleteFeSpace(feSpaces[i]);
122
      }
123

124
      feSpaces.clear();
125
126
    }

127
128
129
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
130
131
132
133
    int addMemoryUsage(FiniteElemSpace* feSpace) {
      memoryUsage += feSpace->getMesh()->calcMemoryUsage();
    }

134
135
136
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
137
138
139
140
141
142
143
144
145
146
147
148
    int addMemoryUsage(std::vector<FiniteElemSpace*> feSpaces) {
      // Is used to determine equal meshes for different components.
      std::vector<Mesh*> meshes;

      for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
	if (find(meshes.begin(), meshes.end(), feSpaces[i]->getMesh()) != meshes.end()) {
	  memoryUsage += feSpaces[i]->getMesh()->calcMemoryUsage();
	  meshes.push_back(feSpaces[i]->getMesh());
	}
      }
    }

149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
    /** \brief
     * Number of MBytes of memory that can be used for solution storage.
     */
    int maxMemoryUsage;

    /** \brief
     * If true, it is allowed to write solutions also to disk.
     */
    bool useDisk;

    /** \brief
     * Directory, where solutions can be written temporarly.
     */
    std::string writeDirectory;

    /** \brief
     * If true, all solutions are defined only on one FE Space.
     */
    bool fixedFESpace;

    /** \brief
     * Here, all the solutions (i.e. either DOFVectors or SystemVectors)
     * are stored.
     */
173
    std::vector<T*> solutions;
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

    /** \brief
     * Stores to every solution its FE Space. If \ref fixedFESpace is set
     * to true, only one entry exists. This is than the FE Space for all
     * solutions.
     */
    std::vector< typename SolutionHelper<T>::type > feSpaces;

    /** \brief
     * Stores to every solutions the timestamp at which the solution was
     * created in the adaption loop.
     */
    std::vector<double> timestamps;

    /** \brief
     * Position of the latest valid solution.
     */
    int lastPos;

    /** \brief
     * If true, the last operation on the data storage was pop.
     */
    bool poped;
197
198
199
200
201

    /** \brief
     * Counts the memory usage of all solutions stored in memory.
     */
    int memoryUsage;
Thomas Witkowski's avatar
Thomas Witkowski committed
202

203
204
205
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
206
207
    std::map<std::string, std::vector<WorldVector<double > > > containers;

208
209
210
    /** \brief
     *
     */
Thomas Witkowski's avatar
Thomas Witkowski committed
211
    std::map<std::string, int> containersPos;
212
213
214
215
216
217
218
  };

}

#include "SolutionDataStorage.hh"

#endif // AMDIS_SOLUTION_DATA_STORAGE_H