ArhReader.cc 1.82 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
#include <fstream>

#include "ArhReader.h"
#include "Mesh.h"
#include "MeshStructure.h"

namespace AMDiS {
  
  using namespace std;

  void ArhReader::read(string filename, Mesh *mesh)
  {
    FUNCNAME("ArhReader::read()");

    RefinementManager *refManager;
    switch (mesh->getDim()) {
    case 2:
      refManager = new RefinementManager2d();
      break;
    case 3:
      refManager = new RefinementManager3d();
      break;
    default:
      ERROR_EXIT("Should not happen!\n");
    }

    ifstream file;
    file.open(filename.c_str(), ios::in | ios::binary);

    string typeId = "";
    long nMacroElements = 0;
    long nValueVectors = 0;
    long nAllValues = 0;

    file.read(const_cast<char*>(typeId.data()), 4);
    file.read(reinterpret_cast<char*>(&nMacroElements), 4);
    file.read(reinterpret_cast<char*>(&nValueVectors), 4);
    file.read(reinterpret_cast<char*>(&nAllValues), 4);

    for (long i = 0; i < nMacroElements; i++) {
      long elIndex = 0;
      long nStructureCodes = 0;
      long codeSize = 0;

      file.read(reinterpret_cast<char*>(&elIndex), 4);
      file.read(reinterpret_cast<char*>(&nStructureCodes), 4);
      file.read(reinterpret_cast<char*>(&codeSize), 4);

      vector<unsigned long> structureCode(nStructureCodes);
      file.read(reinterpret_cast<char*>(&(structureCode[0])), 4 * nStructureCodes);

      MeshStructure elementStructure;
      elementStructure.init(structureCode, codeSize);
      elementStructure.fitMeshToStructure(mesh, refManager, false, false, elIndex);

      long nValuesPerVector = 0;
      file.read(reinterpret_cast<char*>(&nValuesPerVector), 4);

      for (long j = 0; j < nValuesPerVector * nValueVectors; j++) {
	double value = 0.0;
	file.read(reinterpret_cast<char*>(&value), 8);
      }
    }

    file.close();

    MSG("ARH file read from: %s\n", filename.c_str());
  }
}