SolutionDataStorage.h 3.87 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
#ifndef AMDIS_SOLUTION_DATA_STORAGE_H
#define AMDIS_SOLUTION_DATA_STORAGE_H

#include <iostream>
#include <vector>
#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;
  };
  
  template<typename T>
  class SolutionDataStorage 
  {
  public:
28
29
30
    /** \brief
     *
     */
31
32
    SolutionDataStorage(std::string name);

33
34
35
    /** \brief
     *
     */
36
37
38
39
40
    ~SolutionDataStorage();

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

43
44
45
46
    /** \brief
     *
     */
    void push(T *solution,
47
	      double timestamp);
48
49
50
51

    /** \brief
     *
     */
52
53
    void push(T *solution,
	      double timestamp,
54
	      typename SolutionHelper<T>::type feSpace);
55

56
57
58
59
60
61
62
    /** \brief
     *
     */
    bool pop(T **solution,
	     double *timestep);

    bool pop(T **solution,
63
	     double *timestep,
64
65
66
67
68
69
70
71
72
73
	     typename SolutionHelper<T>::type feSpace);

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

  protected:
76
77
78
79
80
81
82
83
84
    /** \brief
     * Auxiliary function for deleting either a single fe space, or a
     * vector of fe spaces.
     */
    void deleteFeSpace(FiniteElemSpace* feSpace) {
      DELETE feSpace;
    }

    void deleteFeSpace(std::vector<FiniteElemSpace*> feSpaces) {
85
      for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
86
	DELETE feSpaces[i];
87
      }
88
89
90
91

      feSpaces.empty();
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    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());
	}
      }
    }

108
109
110
    /** \brief
     * Deletes all pointers and empties all internal vectors.
     */
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    void cleanup();

    /** \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.
     */
137
    std::vector<T*> solutions;
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

    /** \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;
161
162
163
164
165

    /** \brief
     * Counts the memory usage of all solutions stored in memory.
     */
    int memoryUsage;
166
167
168
169
170
171
172
  };

}

#include "SolutionDataStorage.hh"

#endif // AMDIS_SOLUTION_DATA_STORAGE_H