Mesh.cc 30.5 KB
Newer Older
1001
    in.read(reinterpret_cast<char*>(&nNodeEl), sizeof(int));
1002
    TEST_EXIT_DBG((oldVal == 0) || (nNodeEl == oldVal))("invalid nNodeEl\n");
1003
1004
1005
1006
1007

    // read node
    node.deserialize(in);

    // read admins
1008
    int size;
1009
1010
    in.read(reinterpret_cast<char*>(&size), sizeof(int));
    admin.resize(size, NULL);
1011
    for (int i = 0; i < size; i++) {
1012
      if (!admin[i])
Thomas Witkowski's avatar
Thomas Witkowski committed
1013
	admin[i] = new DOFAdmin(this);
1014

1015
1016
1017
1018
1019
1020
      admin[i]->deserialize(in);
    }

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

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

1023
    for (int i = 0; i < static_cast<int>(macroElements.size()); i++) {
1024
      if (macroElements[i])
Thomas Witkowski's avatar
Thomas Witkowski committed
1025
	delete macroElements[i];
1026
    }
1027

1028
    macroElements.resize(size);
1029
    for (int i = 0; i < size; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
1030
      macroElements[i] = new MacroElement(dim);
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
      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
1042
1043
1044
    int neighs = getGeo(NEIGH);
    for (int i = 0; i < static_cast<int>(macroElements.size()); i++) {
      for (int j = 0; j < neighs; j++) {
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
	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);
1057
    while (elInfo) {
1058
1059
1060
1061
1062
1063
1064
1065
1066
      elInfo->getElement()->setMesh(this);
      elInfo = stack.traverseNext(elInfo);
    }

    serializedDOFs.clear();
  }

  void Mesh::initialize() 
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
1067
1068
1069
    std::string macroFilename("");
    std::string valueFilename("");
    std::string periodicFile("");
1070
1071
1072
1073
1074
1075
1076
1077
1078
    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()) {
1079
1080
1081
      macroFileInfo = MacroReader::readMacro(macroFilename.c_str(), this,
					     periodicFile == "" ? NULL : periodicFile.c_str(),
					     check);
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093

      // 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
1094
1095
    std::map<BoundaryType, VertexVector*>::iterator it;
    std::map<BoundaryType, VertexVector*>::iterator end = periodicAssociations.end();
1096
1097
1098
1099
1100
1101
1102
1103
    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
1104
1105
1106
    std::vector<DegreeOfFreedom> associatedToDOF1;
    std::map<BoundaryType, VertexVector*>::iterator it;
    std::map<BoundaryType, VertexVector*>::iterator end = periodicAssociations.end();
1107
1108
1109
    DegreeOfFreedom dof, assDOF;

    associatedToDOF1.push_back(dof1);
Thomas Witkowski's avatar
Thomas Witkowski committed
1110
1111
1112
    for (it = periodicAssociations.begin(); it != end; ++it) {
      int size = static_cast<int>(associatedToDOF1.size());
      for (int i = 0; i < size; i++) {
1113
1114
	dof = associatedToDOF1[i];
	assDOF = (*(it->second))[dof];
Thomas Witkowski's avatar
Thomas Witkowski committed
1115
	if (assDOF == dof2) {
1116
1117
	  return true;
	} else {
Thomas Witkowski's avatar
Thomas Witkowski committed
1118
1119
	  if (assDOF != dof) 
	    associatedToDOF1.push_back(assDOF);
1120
1121
1122
1123
1124
1125
1126
1127
	}
      }
    }
    return false;
  }

  void Mesh::clearMacroFileInfo()
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
1128
    macroFileInfo->clear();
Thomas Witkowski's avatar
Thomas Witkowski committed
1129
    delete macroFileInfo;
1130
    macroFileInfo = NULL;
1131
  }
1132
1133
1134

  int Mesh::calcMemoryUsage()
  {
1135
    int result = sizeof(Mesh);
1136

1137
1138
1139
1140
1141
1142
    result += nDOFEl;
    for (int i = 0; i < static_cast<int>(admin.size()); i++) {
      result += admin[i]->calcMemoryUsage();
      result += admin[i]->getUsedSize() * sizeof(DegreeOfFreedom);
    }
    
1143
1144
    for (int i = 0; i < static_cast<int>(macroElements.size()); i++)
      result += macroElements[i]->calcMemoryUsage();    
1145
1146
1147
    
    return result;
  }
1148
}
For faster browsing, not all history is shown. View entire blame