ArhReader.cc 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#include <fstream>

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

namespace AMDiS {
  
  using namespace std;

11
  void ArhReader::read(string filename, Mesh *mesh, bool ignoreFinerMesh)
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  {
    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 = "";
31
32
33
    uint32_t nMacroElements = 0;
    uint32_t nValueVectors = 0;
    uint32_t nAllValues = 0;
34
35
36
37
38
39

    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);

40
41
42
43
    for (unsigned int i = 0; i < nMacroElements; i++) {
      uint32_t elIndex = 0;
      uint32_t nStructureCodes = 0;
      uint32_t codeSize = 0;
44
45
46
47
48

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

49
      vector<unsigned long int> structureCode(nStructureCodes);
50
      file.read(reinterpret_cast<char*>(&(structureCode[0])), 8 * nStructureCodes);
51
52
53

      MeshStructure elementStructure;
      elementStructure.init(structureCode, codeSize);
54
      elementStructure.fitMeshToStructure(mesh, refManager, 
55
					  false, elIndex, ignoreFinerMesh);
56

57
      uint32_t nValuesPerVector = 0;
58
59
      file.read(reinterpret_cast<char*>(&nValuesPerVector), 4);

60
      for (unsigned int j = 0; j < nValuesPerVector * nValueVectors; j++) {
61
62
63
64
65
66
67
68
69
70
	double value = 0.0;
	file.read(reinterpret_cast<char*>(&value), 8);
      }
    }

    file.close();

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