SolutionDataStorage.hh 3.13 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
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()
  {
26
    clear();
27
28
29
  }

  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
  {
    // If pop was the last operation, cleanup and reset the data storage.
    if (poped) {
48
      clear();
49
50
      poped = false;
    }
51
    
52
53
54
    solutions.push_back(solution);
    timestamps.push_back(timestamp);

55
56
    std::cout << "STACK SIZE = " << solutions.size() << std::endl;

57
    lastPos++;
58
    //    memoryUsage += solution->calcMemoryUsage();
59
60
61
62
  }

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

68
    push(solution, timestamp);
69

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

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

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

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

    lastPos--;
    poped = true;

    return true;
  }

95
96
  template<typename T>
  bool SolutionDataStorage<T>::pop(T **solution,
97
98
99
				   typename SolutionHelper<T>::type feSpace,
				   double *timestep)
				  
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  {
    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;
  }


114
  template<typename T>
115
  void SolutionDataStorage<T>::clear()
116
  {
117
118
    for (int i = 1; i < static_cast<int>(solutions.size()); i++) {
      DELETE solutions[i];
119
120
    }

121
122
123
124
    if (!fixedFESpace) {
      for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
	deleteFeSpace(feSpaces[i]);    
      }
125
126
    }

127
128
129
    solutions.clear();
    feSpaces.clear();
    timestamps.clear();
130

131
132
133
134
135
136
137
    lastPos = -1;    
  }

  template<typename T>
  void SolutionDataStorage<T>::deleteFeSpace(FiniteElemSpace *feSpace) 
  {
    if (feSpace) {
138
      DELETE feSpace->getMesh();         
139
140
      DELETE feSpace;
    }
141
  }
142

143
}