AdaptInfo.cc 5.56 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
120
121
#include <AdaptInfo.h>

namespace AMDiS {

  void AdaptInfo::setScalContents(int newSize) {
    int oldSize = scalContents.getSize();

    if (newSize > oldSize) { 
      scalContents.resize(newSize);

      char number[5];
      for (int i = oldSize; i < newSize; i++) {
	sprintf(number, "[%d]", i);
	scalContents[i] = new ScalContent(name + ::std::string(number)); 
      }
    }
  }

  void AdaptInfo::serialize(::std::ostream& out) {
    out << name << ::std::endl;
    out.write(reinterpret_cast<const char*>(&maxSpaceIteration), sizeof(int));
    out.write(reinterpret_cast<const char*>(&spaceIteration), sizeof(int));
    out.write(reinterpret_cast<const char*>(&timestepIteration), sizeof(int));
    out.write(reinterpret_cast<const char*>(&maxTimestepIteration), sizeof(int));
    out.write(reinterpret_cast<const char*>(&timeIteration), sizeof(int));
    out.write(reinterpret_cast<const char*>(&maxTimeIteration), sizeof(int));
    out.write(reinterpret_cast<const char*>(&time), sizeof(double));
    out.write(reinterpret_cast<const char*>(&startTime), sizeof(double));
    out.write(reinterpret_cast<const char*>(&endTime), sizeof(double));
    out.write(reinterpret_cast<const char*>(&timestep), sizeof(double));
    out.write(reinterpret_cast<const char*>(&minTimestep), sizeof(double));
    out.write(reinterpret_cast<const char*>(&maxTimestep), sizeof(double));
    out.write(reinterpret_cast<const char*>(&timestepNumber), sizeof(int));
    out.write(reinterpret_cast<const char*>(&solverIterations), sizeof(int));
    out.write(reinterpret_cast<const char*>(&maxSolverIterations), sizeof(int));
    out.write(reinterpret_cast<const char*>(&solverTolerance), sizeof(double));
    out.write(reinterpret_cast<const char*>(&solverResidual), sizeof(double));
    int size = scalContents.getSize();
    out.write(reinterpret_cast<const char*>(&size), sizeof(int));
    for (int i = 0; i < size; i++) {
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_sum)), 
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_t_sum)), 
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_max)),
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->est_t_max)),
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->spaceTolerance)), 
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->timeTolerance)), 
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->timeErrLow)), 
		sizeof(double));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->coarsenAllowed)),
		sizeof(int));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->refinementAllowed)),
		sizeof(int));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->refineBisections)),
		sizeof(int));
      out.write(reinterpret_cast<const char*>(&(scalContents[i]->coarseBisections)),
		sizeof(int));
    }
  }

  void AdaptInfo::deserialize(::std::istream& in) {
    in >> name;
    in.get();   // because of ::std::endl in serialization

    in.read(reinterpret_cast<char*>(&maxSpaceIteration), sizeof(int));
    in.read(reinterpret_cast<char*>(&spaceIteration), sizeof(int));
    in.read(reinterpret_cast<char*>(&timestepIteration), sizeof(int));
    in.read(reinterpret_cast<char*>(&maxTimestepIteration), sizeof(int));
    in.read(reinterpret_cast<char*>(&timeIteration), sizeof(int));
    in.read(reinterpret_cast<char*>(&maxTimeIteration), sizeof(int));
    in.read(reinterpret_cast<char*>(&time), sizeof(double));
    in.read(reinterpret_cast<char*>(&startTime), sizeof(double));
    in.read(reinterpret_cast<char*>(&endTime), sizeof(double));
    in.read(reinterpret_cast<char*>(&timestep), sizeof(double));
    in.read(reinterpret_cast<char*>(&minTimestep), sizeof(double));
    in.read(reinterpret_cast<char*>(&maxTimestep), sizeof(double));
    in.read(reinterpret_cast<char*>(&timestepNumber), sizeof(int));
    in.read(reinterpret_cast<char*>(&solverIterations), sizeof(int));
    in.read(reinterpret_cast<char*>(&maxSolverIterations), sizeof(int));
    in.read(reinterpret_cast<char*>(&solverTolerance), sizeof(double));
    in.read(reinterpret_cast<char*>(&solverResidual), sizeof(double));
    int size;
    in.read(reinterpret_cast<char*>(&size), sizeof(int));
    scalContents.resize(size);    
    for (int i = 0; i < size; i++) {
      //      if (!scalContents[i]) {
	char number[5];
	sprintf(number, "[%d]", i);
	scalContents[i] = new ScalContent(name + ::std::string(number)); 
	//    }
      in.read(reinterpret_cast<char*>(&(scalContents[i]->est_sum)), 
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->est_t_sum)), 
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->est_max)),
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->est_t_max)),
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->spaceTolerance)), 
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->timeTolerance)), 
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->timeErrLow)), 
	      sizeof(double));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->coarsenAllowed)),
	      sizeof(int));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->refinementAllowed)),
	      sizeof(int));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->refineBisections)),
	      sizeof(int));
      in.read(reinterpret_cast<char*>(&(scalContents[i]->coarseBisections)),
	      sizeof(int));
    }    
  }

}