SolutionDataStorage.h 3.67 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
41
42
43
    ~SolutionDataStorage();

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

44
45
46
47
48
49
50
51
52
53
    /** \brief
     *
     */
    void push(T *solution,
	      double timestamp,
	      bool cleanupSolution = true);

    /** \brief
     *
     */
54
55
    void push(T *solution,
	      double timestamp,
56
	      typename SolutionHelper<T>::type feSpace,
57
58
59
	      bool cleanupSolution = true,
	      bool cleanupFeSpace = true);

60
61
62
63
64
65
66
    /** \brief
     *
     */
    bool pop(T **solution,
	     double *timestep);

    bool pop(T **solution,
67
	     double *timestep,
68
69
70
71
72
73
74
75
76
77
	     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];
    }
78
79

  protected:
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    /** \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) {
      for (int i = 0; i < static_cast<int>(feSpaces.size()); i++)
	DELETE feSpaces[i];

      feSpaces.empty();
    }

    /** \brief
     * Deletes all pointers and empties all internal vectors.
     */
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    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.
     */
124
    std::vector<T*> solutions;
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

    /** \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
     * Stores to each solution, if the data storage is allowed to delete 
     * the solution by itself.
     */
    std::vector<bool> cleanupSolutions;

    /** \brief
     * Stores to each fe space, if the data storage is allowed to delete
     * the fe space by itself.
     */
    std::vector<bool> cleanupFeSpaces;

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

    /** \brief
     * If true, the last operation on the data storage was pop.
     */
    bool poped;
  };

}

#include "SolutionDataStorage.hh"

#endif // AMDIS_SOLUTION_DATA_STORAGE_H