SolutionDataStorage.hh 2.86 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
28
29
namespace AMDiS {

  template<typename T>
  SolutionDataStorage<T>::SolutionDataStorage(std::string name)
    : maxMemoryUsage(100),
      useDisk(true),
      writeDirectory(""),
      fixedFESpace(false),
      lastPos(-1),
      poped(false)
  {
    solutions.empty();
    feSpaces.empty();
    timestamps.empty();
    
    int tmp = 0;
    GET_PARAMETER(0, name + "->memory usage", "%d", &maxMemoryUsage);
    GET_PARAMETER(0, name + "->use disk", "%d", &tmp);
    useDisk = (tmp == 0) ? false : true;
    GET_PARAMETER(0, name + "->directory", &writeDirectory);
  }

  template<typename T>
  SolutionDataStorage<T>::~SolutionDataStorage()
  {
    cleanup();
  }

  template<typename T>
30
  void SolutionDataStorage<T>::setFixFESpace(typename SolutionHelper<T>::type feSpace)
31
32
33
34
35
36
37
  {
    FUNCNAME("SolutionDataStorage::setFixFESpace()");

    TEST_EXIT(solutions.size() == 0)("Cannot set FE Space, if solutions already stored!\n");

    fixedFESpace = true;
    feSpaces.push_back(feSpace);
38

Thomas Witkowski's avatar
Thomas Witkowski committed
39
    addMemoryUsage(feSpace);
40
41
42
43
  }

  template<typename T>
  void SolutionDataStorage<T>::push(T *solution,
44
				    double timestamp)
45
46
47
48
49
50
51
52
53
54
  {
    // If pop was the last operation, cleanup and reset the data storage.
    if (poped) {
      cleanup();
      poped = false;
    }

    solutions.push_back(solution);
    timestamps.push_back(timestamp);

55
    lastPos++;
56
    memoryUsage += solution->calcMemoryUsage();
57
58
59
60
  }

  template<typename T>
  void SolutionDataStorage<T>::push(T *solution,
61
62
				    typename SolutionHelper<T>::type feSpace,
				    double timestamp)
63
  {
64
65
    FUNCNAME("SolutionDataStorage<T>::push()");

66
    push(solution, timestamp);
67

68
    // Store fe space only, if we do not have a fixed fe space.
69
70
    TEST_EXIT(!fixedFESpace)("push wit fe space not possible!\n");

71
72
73
74
75
76
    if (!fixedFESpace) {
      feSpaces.push_back(feSpace);
    }
  }

  template<typename T>
77
78
  bool SolutionDataStorage<T>::pop(T **solution,
				   double *timestamp)
79
80
81
82
83
  {
    if (lastPos < 0) {
      return false;
    }

84
    *solution = solutions[lastPos];
85
86
87
88
89
90
91
92
    *timestamp = timestamps[lastPos];

    lastPos--;
    poped = true;

    return true;
  }

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  template<typename T>
  bool SolutionDataStorage<T>::pop(T **solution,
				   double *timestep,
				   typename SolutionHelper<T>::type feSpace)
  {
    if (!pop(solution, timestep))
      return false;

    if (!fixedFESpace) {
      feSpace = feSpaces[lastPos + 1]; // + 1, because lastPos was decremented in pop call above
    } else {
      feSpace = feSpaces[0];
    }

    return true;
  }


111
112
113
  template<typename T>
  void SolutionDataStorage<T>::cleanup()
  {
114
115
    for (int i = 0; i < static_cast<int>(solutions.size()); i++) {
      DELETE solutions[i];    
116
117
    }

118
119
120
121
    if (!fixedFESpace) {
      for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
	deleteFeSpace(feSpaces[i]);    
      }
122
123
124
125
126
127
128
129
130
131
    }

    solutions.empty();
    feSpaces.empty();
    timestamps.empty();

    lastPos = -1;
  }
  
}