SolutionDataStorage.h 4.39 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

    /** \brief
     *
     */
59
    void push(T *solution,
60
61
	      typename SolutionHelper<T>::type feSpace,
	      double timestamp);
62

63
64
65
66
67
68
    /** \brief
     *
     */
    bool pop(T **solution,
	     double *timestep);

69
70
71
    /** \brief
     *
     */
72
    bool pop(T **solution,
73
74
	     typename SolutionHelper<T>::type feSpace,
	     double *timestep);
75
76
77
78
79

    /** \brief
     * Deletes all pointers and empties all internal vectors.
     */
    void clear();
80
	     
81
82
83
84
85
86
87
88
89

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

91
92
93
94
    bool isPoped() {
      return poped;
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
95
96
97
98
99
100
101
102
103
104
    void addContainer(std::string name);

    void push(std::string name, WorldVector<double> value);

    void pop(std::string name, WorldVector<double> &value);

    void reset(std::string name);

    void clear(std::string name);

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

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

120
      feSpaces.clear();
121
122
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    int addMemoryUsage(FiniteElemSpace* feSpace) {
      memoryUsage += feSpace->getMesh()->calcMemoryUsage();
    }

    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());
	}
      }
    }

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    /** \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.
     */
163
    std::vector<T*> solutions;
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

    /** \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;
187
188
189
190
191

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

    std::map<std::string, std::vector<WorldVector<double > > > containers;

    std::map<std::string, int> containersPos;
196
197
198
199
200
201
202
  };

}

#include "SolutionDataStorage.hh"

#endif // AMDIS_SOLUTION_DATA_STORAGE_H