SolutionDataStorage.hh 2.83 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
39
40

    std::cout << "MESH = " << static_cast<double>(feSpace[0]->getMesh()->calcMemoryUsage()) / (1024.0 * 1024.0) << std::endl;
    WAIT_REALLY;
41
42
43
44
  }

  template<typename T>
  void SolutionDataStorage<T>::push(T *solution,
45
				    double timestamp)
46
47
48
49
50
51
52
53
54
55
  {
    // 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);

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

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

67
68
69
70
71
72
73
    // Store fe space only, if we do not have a fixed fe space.
    if (!fixedFESpace) {
      feSpaces.push_back(feSpace);
    }
  }

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

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

    lastPos--;
    poped = true;

    return true;
  }

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  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;
  }


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

115
116
    for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
      deleteFeSpace(feSpaces[i]);    
117
118
119
120
121
122
123
124
125
126
    }

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

    lastPos = -1;
  }
  
}