Mesh.cc 31.7 KB
Newer Older
1001
1002
    int oldVal = dim;
    in.read(reinterpret_cast<char*>(&dim), sizeof(int));
1003
    TEST_EXIT_DBG((oldVal == 0) || (dim == oldVal))("invalid dimension\n");
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031

    // read nVertices
    in.read(reinterpret_cast<char*>(&nVertices), sizeof(int));

    // read nEdges
    in.read(reinterpret_cast<char*>(&nEdges), sizeof(int));

    // read nLeaves
    in.read(reinterpret_cast<char*>(&nLeaves), sizeof(int));

    // read nElements
    in.read(reinterpret_cast<char*>(&nElements), sizeof(int));

    // read nFaces
    in.read(reinterpret_cast<char*>(&nFaces), sizeof(int));

    // read maxEdgeNeigh
    in.read(reinterpret_cast<char*>(&maxEdgeNeigh), sizeof(int));

    // diam
    diam.deserialize(in);

    // read preserveCoarseDOFs
    in.read(reinterpret_cast<char*>(&preserveCoarseDOFs), sizeof(bool));

    // read nDOFEl
    oldVal = nDOFEl;
    in.read(reinterpret_cast<char*>(&nDOFEl), sizeof(int));
1032
    TEST_EXIT_DBG((oldVal == 0) || (nDOFEl == oldVal))("invalid nDOFEl\n");
1033
1034
1035
1036
1037
1038
1039

    // read nDOF
    nDOF.deserialize(in);

    // read nNodeEl
    oldVal = nNodeEl;
    in.read(reinterpret_cast<char*>(&nNodeEl), sizeof(int));
1040
    TEST_EXIT_DBG((oldVal == 0) || (nNodeEl == oldVal))("invalid nNodeEl\n");
1041
1042
1043
1044
1045

    // read node
    node.deserialize(in);

    // read admins
1046
    int size;
1047
1048
    in.read(reinterpret_cast<char*>(&size), sizeof(int));
    admin.resize(size, NULL);
1049
    for (int i = 0; i < size; i++) {
1050
1051
1052
1053
1054
1055
1056
1057
1058
      if (!admin[i]) {
	admin[i] = NEW DOFAdmin(this);
      }
      admin[i]->deserialize(in);
    }

    // read macroElements
    in.read(reinterpret_cast<char*>(&size), sizeof(int));

Thomas Witkowski's avatar
Thomas Witkowski committed
1059
    std::vector< std::vector<int> > neighbourIndices(size);
1060

1061
    for (int i = 0; i < static_cast<int>(macroElements.size()); i++) {
1062
1063
1064
1065
1066
      if (macroElements[i]) {
	DELETE macroElements[i];
      }
    }
    macroElements.resize(size);
1067
    for (int i = 0; i < size; i++) {
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
      macroElements[i] = NEW MacroElement(dim);
      macroElements[i]->writeNeighboursTo(&(neighbourIndices[i]));
      macroElements[i]->deserialize(in);
    }

    // read elementIndex
    in.read(reinterpret_cast<char*>(&elementIndex), sizeof(int));

    // read initialized
    in.read(reinterpret_cast<char*>(&initialized), sizeof(bool));

    // set neighbour pointer in macro elements
1080
1081
1082
    int neighs = getGeo(NEIGH);
    for (int i = 0; i < static_cast<int>(macroElements.size()); i++) {
      for (int j = 0; j < neighs; j++) {
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
	int index = neighbourIndices[i][j];
	if(index != -1) {
	  macroElements[i]->setNeighbour(j, macroElements[index]);
	} else {
	  macroElements[i]->setNeighbour(j, NULL);
	}
      }
    }

    // set mesh pointer in elements
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(this, -1, CALL_EVERY_EL_PREORDER);
1095
    while (elInfo) {
1096
1097
1098
1099
1100
1101
1102
1103
1104
      elInfo->getElement()->setMesh(this);
      elInfo = stack.traverseNext(elInfo);
    }

    serializedDOFs.clear();
  }

  void Mesh::initialize() 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
1105
1106
1107
    std::string macroFilename("");
    std::string valueFilename("");
    std::string periodicFile("");
1108
1109
1110
1111
1112
1113
1114
1115
1116
    int check = 1;

    GET_PARAMETER(0, name + "->macro file name",  &macroFilename);
    GET_PARAMETER(0, name + "->value file name",  &valueFilename);
    GET_PARAMETER(0, name + "->periodic file", &periodicFile);
    GET_PARAMETER(0, name + "->check", "%d", &check);
    GET_PARAMETER(0, name + "->preserve coarse dofs", "%d", &preserveCoarseDOFs);

    if (macroFilename.length()) {
1117
1118
1119
      macroFileInfo = MacroReader::readMacro(macroFilename.c_str(), this,
					     periodicFile == "" ? NULL : periodicFile.c_str(),
					     check);
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131

      // If there is no value file which should be written, we can delete
      // the information of the macro file.
      if (!valueFilename.length()) {
	clearMacroFileInfo();
      }
    }

    initialized = true;
  }

  bool Mesh::associated(DegreeOfFreedom dof1, DegreeOfFreedom dof2) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1132
1133
    std::map<BoundaryType, VertexVector*>::iterator it;
    std::map<BoundaryType, VertexVector*>::iterator end = periodicAssociations.end();
1134
1135
1136
1137
1138
1139
1140
1141
    for (it = periodicAssociations.begin(); it != end; ++it) {
      if ((*(it->second))[dof1] == dof2)
	return true;
    }
    return false;
  }

  bool Mesh::indirectlyAssociated(DegreeOfFreedom dof1, DegreeOfFreedom dof2) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1142
1143
1144
    std::vector<DegreeOfFreedom> associatedToDOF1;
    std::map<BoundaryType, VertexVector*>::iterator it;
    std::map<BoundaryType, VertexVector*>::iterator end = periodicAssociations.end();
1145
1146
1147
    DegreeOfFreedom dof, assDOF;

    associatedToDOF1.push_back(dof1);
Thomas Witkowski's avatar
Thomas Witkowski committed
1148
1149
1150
    for (it = periodicAssociations.begin(); it != end; ++it) {
      int size = static_cast<int>(associatedToDOF1.size());
      for (int i = 0; i < size; i++) {
1151
1152
	dof = associatedToDOF1[i];
	assDOF = (*(it->second))[dof];
Thomas Witkowski's avatar
Thomas Witkowski committed
1153
	if (assDOF == dof2) {
1154
1155
	  return true;
	} else {
Thomas Witkowski's avatar
Thomas Witkowski committed
1156
1157
	  if (assDOF != dof) 
	    associatedToDOF1.push_back(assDOF);
1158
1159
1160
1161
1162
1163
1164
1165
	}
      }
    }
    return false;
  }

  void Mesh::clearMacroFileInfo()
  {
1166
    macroFileInfo->clear(nEdges, nVertices);
1167
    DELETE macroFileInfo;
1168
    macroFileInfo = NULL;
1169
  }
1170
1171
1172

  int Mesh::calcMemoryUsage()
  {
1173
    int result = sizeof(Mesh);
1174

1175
1176
1177
1178
1179
1180
    result += nDOFEl;
    for (int i = 0; i < static_cast<int>(admin.size()); i++) {
      result += admin[i]->calcMemoryUsage();
      result += admin[i]->getUsedSize() * sizeof(DegreeOfFreedom);
    }
    
1181
1182
1183
1184
1185
1186
    for (int i = 0; i < static_cast<int>(macroElements.size()); i++) {
      result += macroElements[i]->calcMemoryUsage();
    }
    
    return result;
  }
1187
}
For faster browsing, not all history is shown. View entire blame