SolutionDataStorage.h 3.31 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
85
86
87
88
89
90
91
92
93
    /** \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.
     */
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
    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.
     */
120
    std::vector<T*> solutions;
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

    /** \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;
144
145
146
147
148

    /** \brief
     * Counts the memory usage of all solutions stored in memory.
     */
    int memoryUsage;
149
150
151
152
153
154
155
  };

}

#include "SolutionDataStorage.hh"

#endif // AMDIS_SOLUTION_DATA_STORAGE_H