Liebe Gitlab-Nutzer, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

MacroElement.cc 4.19 KB
Newer Older
1 2
#include <string>
#include <map>
3 4 5 6 7 8
#include "MacroElement.h"
#include "Boundary.h"
#include "FiniteElemSpace.h"
#include "Mesh.h"
#include "FixVec.h"
#include "FixVecConvert.h"
9
#include "Serializer.h"
10 11 12 13 14 15 16 17 18 19 20 21

namespace AMDiS {

  MacroElement::MacroElement(int dim)
    : element(NULL),
      coord(dim, NO_INIT),
      boundary(dim, DEFAULT_VALUE, INTERIOR),
      projection(dim, NO_INIT),
      neighbour(dim, NO_INIT),
      oppVertex(dim, NO_INIT),
      index(-1), 
      elType(0),
22
      deserializedNeighbourIndices(NULL)
23 24 25 26 27 28 29
  {
    neighbour.set(NULL);
    projection.set(NULL);
  }

  MacroElement::~MacroElement()
  {
30
    if (element)
31
      delete element;    
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  }

  MacroElement& MacroElement::operator=(const MacroElement &el)
  {
    FUNCNAME("MacroElement::operator=()");

    if (this == &el)
      return *this;

    coord = el.coord;
    boundary = el.boundary;
    projection = el.projection;
    oppVertex = el.oppVertex;
    index = el.index;
    elType = el.elType;  
    
    return *this;
  }
50

51
  void MacroElement::serialize(std::ostream &out)
52 53
  {
    // write element-tree
Thomas Witkowski's avatar
Thomas Witkowski committed
54
    out << element->getTypeName() << "\n";
55 56 57
    element->serialize(out);

    // write coords
Thomas Witkowski's avatar
Thomas Witkowski committed
58
    int size = coord.getSize();
59 60
    SerUtil::serialize(out, size);

Thomas Witkowski's avatar
Thomas Witkowski committed
61
    for (int i = 0; i < size; i++)
62 63 64 65 66 67 68
      coord[i].serialize(out);

    // write boundary
    boundary.serialize(out);

    // write projection
    size = projection.getSize();
69
    SerUtil::serialize(out, size);
Thomas Witkowski's avatar
Thomas Witkowski committed
70
    for (int i = 0; i < size; i++) {
71
      int id = projection[i] ? projection[i]->getID() : -1;
72
      SerUtil::serialize(out, id);
73 74 75 76
    }

    // write neighbour
    size = neighbour.getSize();
77
    SerUtil::serialize(out, size);
Thomas Witkowski's avatar
Thomas Witkowski committed
78
    for (int i = 0; i < size; i++) {
79
      int index = neighbour[i] ? neighbour[i]->getIndex() : -1;
80
      SerUtil::serialize(out, index);
81 82 83 84 85 86
    }
  
    // write oppVertex
    oppVertex.serialize(out);

    // write index
87
    SerUtil::serialize(out, index);
88 89

    // write elType
90
    SerUtil::serialize(out, elType);
91 92
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
93
  void MacroElement::deserialize(std::istream &in)
94
  {
95 96 97 98
    FUNCNAME("MacroElement::deserialize()");

    // === Read element-tree. ===

Thomas Witkowski's avatar
Thomas Witkowski committed
99
    std::string typeName;
100 101 102
    in >> typeName;
    in.get();

103
    if (element) {
104 105
      TEST_EXIT(typeName == element->getTypeName())("wrong element type name\n");
    } else {
106
      if (typeName == "Line") 
Thomas Witkowski's avatar
Thomas Witkowski committed
107
	element = new Line(NULL);
108
      if (typeName == "Triangle") 
Thomas Witkowski's avatar
Thomas Witkowski committed
109
	element = new Triangle(NULL);
110
      if (typeName == "Tetrahedron") 
Thomas Witkowski's avatar
Thomas Witkowski committed
111
	element = new Tetrahedron(NULL);
112 113 114 115
    }

    element->deserialize(in);

116 117
    // === Read coords. ===

118
    int size;
119 120 121
    SerUtil::deserialize(in, size);
    
    if (coord.getSize())
122
      TEST_EXIT(coord.getSize() == size)("invalid size\n");
123
    else
124
      coord.initSize(size);
125 126
    
    for (int i = 0; i < size; i++)
127 128 129 130
      coord[i].deserialize(in);

    boundary.deserialize(in);

131
    // === Read projections. ===
132

133 134 135
    SerUtil::deserialize(in, size);

    if (projection.getSize())
136
      TEST_EXIT(projection.getSize() == size)("invalid size\n");
137
    else
138
      projection.initSize(size);
139
    
140
    for (int i = 0; i < size; i++) {
141
      int id;
142
      SerUtil::deserialize(in, id);
143 144 145
      projection[i] = (id != -1) ? Projection::getProjection(id) : NULL;
    }

146 147 148
    // === Read neighbour indices. ===

    SerUtil::deserialize(in, size);
149
  
150 151
    TEST_EXIT(deserializedNeighbourIndices)
      ("Neighbour indices for deserializing not set!\n");
152
    
153
    deserializedNeighbourIndices->resize(size);
154

155
    if (neighbour.getSize())
156
      TEST_EXIT(neighbour.getSize() == size)("invalid size\n");
157
    else
158
      neighbour.initSize(size);
159 160 161
    
    for (int i = 0; i < size; i++)
      SerUtil::deserialize(in, (*deserializedNeighbourIndices)[i]);
162

163
    deserializedNeighbourIndices = NULL;
164 165 166 167

    // read oppVertex
    oppVertex.deserialize(in);

168 169
    SerUtil::deserialize(in, index);
    SerUtil::deserialize(in, elType);
170 171
  }

172 173 174 175 176 177 178 179 180 181 182 183 184 185
  int MacroElement::calcMemoryUsage() 
  {
    int result = 0;

    result += sizeof(MacroElement);
    result += coord.getSize() * sizeof(WorldVector<double>);
    result += projection.getSize() * sizeof(Projection*);
    result += neighbour.getSize() * sizeof(MacroElement*);
    result += oppVertex.getSize() * sizeof(char);
    result += element->calcMemoryUsage();

    return result;
  }

186
}