SolutionDataStorage.hh 3.14 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
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()
  {
  }

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

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

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

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

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

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

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

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

65
    push(solution, timestamp);
66

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

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

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

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

    lastPos--;
    poped = true;

    return true;
  }

92
93
  template<typename T>
  bool SolutionDataStorage<T>::pop(T **solution,
94
95
96
				   typename SolutionHelper<T>::type feSpace,
				   double *timestep)
				  
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  {
    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
  template<typename T>
112
  void SolutionDataStorage<T>::clear()
113
  {
114
115
    for (int i = 1; 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
    solutions.clear();
    feSpaces.clear();
    timestamps.clear();
127

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
    lastPos = -1;    
  }

  template<typename T>
  void SolutionDataStorage<T>::deleteFeSpace(FiniteElemSpace *feSpace) 
  {
    if (feSpace) {
      if (feSpace->getMesh()) {
	DELETE feSpace->getMesh();
      }
      if (feSpace->getAdmin()) {
	DELETE feSpace->getAdmin();
      }
      
      DELETE feSpace;
    }
144
  }
145

146
}