45 GEntity *
const entity,
bool binary,
char *str,
48 std::size_t numPhy = 0;
50 if(fread(&numPhy,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
53 std::vector<int> phyTags(numPhy);
54 if(fread(&phyTags[0],
sizeof(
int), numPhy, fp) != numPhy) {
return false; }
57 for(std::size_t i = 0; i < numPhy; i++) {
62 sscanf(str,
"%lu %[0-9- ]", &numPhy, str);
63 for(std::size_t i = 0; i < numPhy; i++) {
66 if(i == numPhy - 1 && entity->
dim() == 0) {
67 if(sscanf(str,
"%d", &phyTag) != 1) {
return false; }
70 if(sscanf(str,
"%d %[0-9- ]", &phyTag, str) != 2) {
return false; }
80 GEntity *
const entity,
bool binary,
83 std::size_t numBrep = 0;
84 std::vector<GEntity *> boundingEntities;
85 std::vector<int> boundingSign;
88 if(fread(&numBrep,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
91 std::vector<int> brepTags(numBrep);
92 if(fread(&brepTags[0],
sizeof(
int), numBrep, fp) != numBrep) {
95 if(
swap)
SwapBytes((
char *)&brepTags[0],
sizeof(
int), numBrep);
97 for(std::size_t i = 0; i < numBrep; i++) {
101 Msg::Warning(
"Entity %d not found in the Brep of entity %d",
102 brepTags[i], entity->
tag());
105 boundingEntities.push_back(brep);
106 boundingSign.push_back((std::abs(brepTags[i]) == brepTags[i] ? 1 : -1));
111 sscanf(str,
"%lu %[0-9- ]", &numBrep, str);
112 for(std::size_t i = 0; i < numBrep; i++) {
115 if(i != numBrep - 1) {
116 if(sscanf(str,
"%d %[0-9- ]", &entityTag, str) != 2) {
return false; }
119 if(sscanf(str,
"%d", &entityTag) != 1) {
return false; }
125 Msg::Warning(
"Entity %d not found in the Brep of entity %d", entityTag,
129 boundingEntities.push_back(brep);
130 boundingSign.push_back((std::abs(entityTag) == entityTag ? 1 : -1));
135 switch(entity->
dim()) {
137 if(boundingEntities.size() == 2) {
138 reinterpret_cast<GEdge *
>(entity)->setBeginVertex(
139 reinterpret_cast<GVertex *
>(boundingEntities[0]));
140 reinterpret_cast<GEdge *
>(entity)->setEndVertex(
141 reinterpret_cast<GVertex *
>(boundingEntities[1]));
143 else if(boundingEntities.size() == 1) {
144 if(boundingSign[0] == 1) {
145 reinterpret_cast<GEdge *
>(entity)->setBeginVertex(
146 reinterpret_cast<GVertex *
>(boundingEntities[0]));
149 reinterpret_cast<GEdge *
>(entity)->setEndVertex(
150 reinterpret_cast<GVertex *
>(boundingEntities[0]));
155 std::vector<int>
tags(boundingEntities.size());
156 for(std::size_t i = 0; i < boundingEntities.size(); i++)
157 tags[i] = std::abs(boundingEntities[i]->tag());
158 reinterpret_cast<GFace *
>(entity)->setBoundEdges(
tags, boundingSign);
161 std::vector<int>
tags(boundingEntities.size());
162 for(std::size_t i = 0; i < boundingEntities.size(); i++)
163 tags[i] = std::abs(boundingEntities[i]->tag());
164 reinterpret_cast<GRegion *
>(entity)->setBoundFaces(
tags, boundingSign);
172 bool swap,
double version,
bool partition,
173 int dim,
int &tag,
int &parentDim,
174 int &parentTag, std::vector<int> &partitions,
175 double &minX,
double &minY,
double &minZ,
176 double &maxX,
double &maxY,
double &maxZ)
181 if(fread(dataInt,
sizeof(
int), 3, fp) != 3) {
return false; }
184 parentDim = dataInt[1];
185 parentTag = dataInt[2];
187 if(fread(&numPart,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
188 partitions.resize(numPart, 0);
189 if(fread(&partitions[0],
sizeof(
int), numPart, fp) != numPart) {
192 if(
swap)
SwapBytes((
char *)&partitions[0],
sizeof(
int), numPart);
193 double dataDouble[6];
194 const std::size_t nbb = (dim > 0) ? 6 : 3;
195 if(fread(dataDouble,
sizeof(
double), nbb, fp) != nbb) {
return false; }
197 minX = dataDouble[0];
198 minY = dataDouble[1];
199 minZ = dataDouble[2];
200 maxX = dataDouble[(nbb == 6) ? 3 : 0];
201 maxY = dataDouble[(nbb == 6) ? 4 : 1];
202 maxZ = dataDouble[(nbb == 6) ? 5 : 2];
205 std::size_t numPart = 0;
206 if(fscanf(fp,
"%d %d %d %lu", &tag, &parentDim, &parentTag, &numPart) !=
210 partitions.resize(numPart, 0);
211 for(std::size_t i = 0; i < numPart; i++) {
212 if(fscanf(fp,
"%d", &partitions[i]) != 1) {
return false; }
214 if(version < 4.1 || dim > 0) {
215 if(fscanf(fp,
"%lf %lf %lf %lf %lf %lf", &minX, &minY, &minZ, &maxX,
216 &maxY, &maxZ) != 6) {
221 if(fscanf(fp,
"%lf %lf %lf", &minX, &minY, &minZ) != 3) {
228 if(!fgets(str, sizeofstr, fp)) {
return false; }
234 if(fread(&dataInt,
sizeof(
int), 1, fp) != 1) {
return false; }
236 double dataDouble[6];
237 const std::size_t nbb = (dim > 0) ? 6 : 3;
238 if(fread(dataDouble,
sizeof(
double), nbb, fp) != nbb) {
return false; }
241 minX = dataDouble[0];
242 minY = dataDouble[1];
243 minZ = dataDouble[2];
244 maxX = dataDouble[(nbb == 6) ? 3 : 0];
245 maxY = dataDouble[(nbb == 6) ? 4 : 1];
246 maxZ = dataDouble[(nbb == 6) ? 5 : 2];
249 if(version < 4.1 || dim > 0) {
250 if(fscanf(fp,
"%d %lf %lf %lf %lf %lf %lf", &tag, &minX, &minY, &minZ,
251 &maxX, &maxY, &maxZ) != 7) {
256 if(fscanf(fp,
"%d %lf %lf %lf", &tag, &minX, &minY, &minZ) != 4) {
263 if(!fgets(str, sizeofstr, fp)) {
return false; }
270 bool binary,
bool swap,
double version)
273 std::size_t numPartitions = 0;
274 std::size_t ghostSize = 0;
275 std::vector<int> ghostTags;
278 if(fread(&numPartitions,
sizeof(std::size_t), 1, fp) != 1) {
281 if(
swap)
SwapBytes((
char *)&numPartitions,
sizeof(std::size_t), 1);
283 if(fread(&ghostSize,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
284 if(
swap)
SwapBytes((
char *)&ghostSize,
sizeof(std::size_t), 1);
286 ghostTags.resize(2 * ghostSize);
287 if(fread(&ghostTags[0],
sizeof(
int), 2 * ghostSize, fp) !=
291 if(
swap)
SwapBytes((
char *)&ghostTags[0],
sizeof(
int), 2 * ghostSize);
295 if(fscanf(fp,
"%lu", &numPartitions) != 1) {
return false; }
296 if(fscanf(fp,
"%lu", &ghostSize) != 1) {
return false; }
298 ghostTags.resize(2 * ghostSize);
299 for(std::size_t i = 0; i < 2 * ghostSize; i += 2) {
300 if(fscanf(fp,
"%d %d", &ghostTags[i], &ghostTags[i + 1]) != 2) {
309 for(std::size_t i = 0; i < 2 * ghostSize; i += 2) {
313 new ghostEdge(model, ghostTags[i], ghostTags[i + 1]);
314 model->
add(ghostEntities);
318 new ghostFace(model, ghostTags[i], ghostTags[i + 1]);
319 model->
add(ghostEntities);
323 new ghostRegion(model, ghostTags[i], ghostTags[i + 1]);
324 model->
add(ghostEntities);
331 std::size_t numEntities[4] = {0, 0, 0, 0};
333 if(fread(numEntities,
sizeof(std::size_t), 4, fp) != 4) {
return false; }
334 if(
swap)
SwapBytes((
char *)numEntities,
sizeof(std::size_t), 4);
337 if(fscanf(fp,
"%lu %lu %lu %lu", &numEntities[0], &numEntities[1],
338 &numEntities[2], &numEntities[3]) != 4) {
345 int nume = numEntities[0] + numEntities[1] + numEntities[2] + numEntities[3];
346 std::size_t strl = std::max(4096, 128 * nume);
347 char *str =
new char[strl];
350 Msg::Info(
"%d partition entit%s", nume, nume > 1 ?
"ies" :
"y");
352 Msg::Info(
"%d entit%s", nume, nume > 1 ?
"ies" :
"y");
354 for(
int dim = 0; dim < 4; dim++) {
355 for(std::size_t i = 0; i < numEntities[dim]; i++) {
356 int tag = 0, parentDim = 0, parentTag = 0;
357 std::vector<int> partitions;
358 double minX = 0., minY = 0., minZ = 0., maxX = 0., maxY = 0., maxZ = 0.;
360 dim, tag, parentDim, parentTag, partitions, minX,
361 minY, minZ, maxX, maxY, maxZ)) {
390 ge =
new partitionEdge(model, tag,
nullptr,
nullptr, partitions);
462 static std::pair<std::size_t, MVertex *> *
464 std::size_t &totalNumNodes, std::size_t &maxNodeNum,
bool swap,
467 std::size_t numBlock = 0, minTag = 0, maxTag = 0;
473 if(fread(data,
sizeof(std::size_t), 4, fp) != 4) {
return nullptr; }
476 totalNumNodes = data[1];
482 if(fscanf(fp,
"%lu %lu %lu %lu", &numBlock, &totalNumNodes, &minTag,
488 if(fscanf(fp,
"%lu %lu", &numBlock, &totalNumNodes) != 2) {
494 std::size_t nodeRead = 0;
495 std::size_t minNodeNum = std::numeric_limits<std::size_t>::max();
497 std::pair<std::size_t, MVertex *> *vertexCache =
498 new std::pair<std::size_t, MVertex *>[totalNumNodes];
500 Msg::Info(
"%lu node%s", totalNumNodes, totalNumNodes > 1 ?
"s" :
"");
503 for(std::size_t i = 0; i < numBlock; i++) {
505 int entityTag = 0, entityDim = 0;
506 std::size_t numNodes = 0;
510 if(fread(data,
sizeof(
int), 3, fp) != 3) {
511 delete[] vertexCache;
517 parametric = data[2];
519 if(fread(&numNodes,
sizeof(std::size_t), 1, fp) != 1) {
520 delete[] vertexCache;
523 if(
swap)
SwapBytes((
char *)&numNodes,
sizeof(std::size_t), 1);
527 if(fscanf(fp,
"%d %d %d %lu", &entityDim, &entityTag, ¶metric,
529 delete[] vertexCache;
534 if(fscanf(fp,
"%d %d %d %lu", &entityTag, &entityDim, ¶metric,
536 delete[] vertexCache;
546 Msg::Info(
"Creating discrete point %d", entityTag);
553 Msg::Info(
"Creating discrete curve %d", entityTag);
560 Msg::Info(
"Creating discrete surface %d", entityTag);
567 Msg::Info(
"Creating discrete volume %d", entityTag);
574 Msg::Error(
"Invalid dimension %d to create discrete entity", entityDim);
575 delete[] vertexCache;
582 if(parametric) n += entityDim;
584 std::vector<std::size_t>
tags(numNodes);
586 if(fread(&
tags[0],
sizeof(std::size_t), numNodes, fp) != numNodes) {
587 delete[] vertexCache;
591 std::vector<double> coord(n * numNodes);
592 if(fread(&coord[0],
sizeof(
double), n * numNodes, fp) != n * numNodes) {
593 delete[] vertexCache;
596 if(
swap)
SwapBytes((
char *)&coord[0],
sizeof(
double), n * numNodes);
598 for(std::size_t j = 0; j < numNodes; j++) {
600 std::size_t tagNode =
tags[j];
602 mv =
new MFaceVertex(coord[k], coord[k + 1], coord[k + 2], entity,
603 coord[k + 3], coord[k + 4], tagNode);
606 mv =
new MEdgeVertex(coord[k], coord[k + 1], coord[k + 2], entity,
607 coord[k + 3], tagNode);
611 new MVertex(coord[k], coord[k + 1], coord[k + 2], entity, tagNode);
616 minNodeNum = std::min(minNodeNum, tagNode);
617 maxNodeNum = std::max(maxNodeNum, tagNode);
618 vertexCache[nodeRead] = std::make_pair(tagNode, mv);
620 if(totalNumNodes > 100000)
626 for(std::size_t j = 0; j < numNodes; j++) {
627 if(fscanf(fp,
"%lu", &
tags[j]) != 1) {
628 delete[] vertexCache;
633 for(std::size_t j = 0; j < numNodes; j++) {
634 std::size_t tagNode = 0;
635 if(version >= 4.1) { tagNode =
tags[j]; }
637 if(fscanf(fp,
"%lu", &tagNode) != 1) {
638 delete[] vertexCache;
644 double x, y,
z, u, v;
645 if(fscanf(fp,
"%lf %lf %lf %lf %lf", &x, &y, &
z, &u, &v) != 5) {
646 delete[] vertexCache;
653 if(fscanf(fp,
"%lf %lf %lf %lf", &x, &y, &
z, &u) != 4) {
654 delete[] vertexCache;
661 if(fscanf(fp,
"%lf %lf %lf", &x, &y, &
z) != 3) {
662 delete[] vertexCache;
666 for(std::size_t k = 3; k < n; k++) {
668 if(fscanf(fp,
"%lf", &dummy) != 1) {
669 delete[] vertexCache;
673 mv =
new MVertex(x, y,
z, entity, tagNode);
677 minNodeNum = std::min(minNodeNum, tagNode);
678 maxNodeNum = std::max(maxNodeNum, tagNode);
679 vertexCache[nodeRead] = std::make_pair(tagNode, mv);
681 if(totalNumNodes > 100000)
688 if(minTag != minNodeNum || maxTag != maxNodeNum)
689 Msg::Warning(
"Min/Max node tags reported in section header are wrong: "
690 "(%d/%d) != (%d/%d)",
691 minTag, maxTag, minNodeNum, maxNodeNum);
696 if(minNodeNum == 1 && maxNodeNum == totalNumNodes) {
700 else if(maxNodeNum < 10 * totalNumNodes) {
702 "Vertex numbering is fairly dense - still caching with a vector");
713 static std::pair<std::size_t, std::pair<MElement *, int> > *
715 std::size_t &totalNumElements, std::size_t &maxElementNum,
716 bool swap,
double version)
719 std::size_t numBlock = 0, minTag = 0, maxTag = 0;
720 totalNumElements = 0;
725 if(fread(data,
sizeof(std::size_t), 4, fp) != 4) {
return nullptr; }
728 totalNumElements = data[1];
734 if(fscanf(fp,
"%lu %lu %lu %lu", &numBlock, &totalNumElements, &minTag,
740 if(fscanf(fp,
"%lu %lu", &numBlock, &totalNumElements) != 2) {
746 std::size_t elementRead = 0;
747 std::size_t minElementNum = std::numeric_limits<std::size_t>::max();
749 std::pair<std::size_t, std::pair<MElement *, int> > *elementCache =
750 new std::pair<std::size_t, std::pair<MElement *, int> >[totalNumElements];
751 Msg::Info(
"%lu element%s", totalNumElements, totalNumElements > 1 ?
"s" :
"");
754 for(std::size_t i = 0; i < numBlock; i++) {
755 int entityTag = 0, entityDim = 0, elmType = 0;
756 std::size_t numElements = 0;
760 if(fread(data,
sizeof(
int), 3, fp) != 3) {
761 delete[] elementCache;
769 if(fread(&numElements,
sizeof(std::size_t), 1, fp) != 1) {
770 delete[] elementCache;
773 if(
swap)
SwapBytes((
char *)&numElements,
sizeof(std::size_t), 1);
777 if(fscanf(fp,
"%d %d %d %lu", &entityDim, &entityTag, &elmType,
778 &numElements) != 4) {
779 delete[] elementCache;
784 if(fscanf(fp,
"%d %d %d %lu", &entityTag, &entityDim, &elmType,
785 &numElements) != 4) {
786 delete[] elementCache;
794 Msg::Error(
"Unknown entity %d of dimension %d", entityTag, entityDim);
795 delete[] elementCache;
799 static_cast<ghostEdge *
>(entity)->haveMesh(
true);
802 static_cast<ghostFace *
>(entity)->haveMesh(
true);
805 static_cast<ghostRegion *
>(entity)->haveMesh(
true);
810 std::size_t n = 1 + numVertPerElm;
811 std::vector<std::size_t> data(numElements * n);
812 if(fread(&data[0],
sizeof(std::size_t), numElements * n, fp) !=
814 delete[] elementCache;
818 SwapBytes((
char *)&data[0],
sizeof(std::size_t), numElements * n);
820 std::vector<MVertex *> vertices(numVertPerElm, (
MVertex *)
nullptr);
821 for(std::size_t j = 0; j < numElements * n; j += n) {
822 for(
int k = 0; k < numVertPerElm; k++) {
825 Msg::Error(
"Unknown node %lu in element %lu", data[j + k + 1],
827 delete[] elementCache;
834 elmType, vertices, data[j], 0,
false, 0,
nullptr,
nullptr,
nullptr);
836 Msg::Error(
"Could not create element %lu of type %d", data[j],
838 delete[] elementCache;
847 minElementNum = std::min(minElementNum, data[j]);
848 maxElementNum = std::max(maxElementNum, data[j]);
850 elementCache[elementRead] =
851 std::make_pair(data[j], std::make_pair(
element, entityTag));
854 if(totalNumElements > 100000)
859 for(std::size_t j = 0; j < numElements; j++) {
860 std::size_t elmTag = 0;
861 if(fscanf(fp,
"%lu", &elmTag) != 1) {
862 delete[] elementCache;
865 if(!fgets(str,
sizeof(str), fp)) {
866 delete[] elementCache;
870 std::vector<MVertex *> vertices(numVertPerElm, (
MVertex *)
nullptr);
872 for(
int k = 0; k < numVertPerElm; k++) {
873 std::size_t vertexTag = 0;
874 if(k != numVertPerElm - 1) {
875 if(sscanf(str,
"%lu %[0-9- ]", &vertexTag, str) != 2) {
876 delete[] elementCache;
881 if(sscanf(str,
"%lu", &vertexTag) != 1) {
882 delete[] elementCache;
889 Msg::Error(
"Unknown node %lu in element %lu", vertexTag, elmTag);
890 delete[] elementCache;
897 elmType, vertices, elmTag, 0,
false, 0,
nullptr,
nullptr,
nullptr);
899 Msg::Error(
"Could not create element %lu of type %d", elmTag,
901 delete[] elementCache;
910 minElementNum = std::min(minElementNum, elmTag);
911 maxElementNum = std::max(maxElementNum, elmTag);
913 elementCache[elementRead] =
914 std::make_pair(elmTag, std::make_pair(
element, entityTag));
917 if(totalNumElements > 100000)
924 if(minElementNum == 1 && maxElementNum == totalNumElements) {
928 else if(maxElementNum < 10 * totalNumElements) {
930 "Element numbering is fairly dense - still caching with a vector");
942 bool swap,
double version)
944 std::size_t numPeriodicLinks = 0;
946 if(fread(&numPeriodicLinks,
sizeof(std::size_t), 1, fp) != 1) {
949 if(
swap)
SwapBytes((
char *)&numPeriodicLinks,
sizeof(std::size_t), 1);
952 if(fscanf(fp,
"%lu", &numPeriodicLinks) != 1) {
return false; }
955 for(std::size_t i = 0; i < numPeriodicLinks; i++) {
956 int slaveDim = 0, slaveTag = 0, masterTag = 0;
960 if(fread(data,
sizeof(
int), 3, fp) != 3) {
return false; }
967 if(fscanf(fp,
"%d %d %d", &slaveDim, &slaveTag, &masterTag) != 3) {
972 GEntity *slave =
nullptr, *master =
nullptr;
989 Msg::Info(
"Could not find periodic entity %d of dimension %d", slaveTag,
994 Msg::Info(
"Could not find periodic source entity %d of dimension %d",
995 masterTag, slaveDim);
999 std::size_t correspondingVertexSize = 0;
1001 std::size_t numAffine;
1002 if(fread(&numAffine,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
1003 if(
swap)
SwapBytes((
char *)&numAffine,
sizeof(std::size_t), 1);
1005 std::vector<double> tfo(numAffine);
1006 if(fread(&tfo[0],
sizeof(
double), numAffine, fp) != numAffine) {
1009 if(
swap)
SwapBytes((
char *)&tfo[0],
sizeof(
double), numAffine);
1015 if(fread(&correspondingVertexSize,
sizeof(std::size_t), 1, fp) != 1) {
1019 SwapBytes((
char *)&correspondingVertexSize,
sizeof(std::size_t), 1);
1022 if(version >= 4.1) {
1023 std::size_t numAffine;
1024 if(!fscanf(fp,
"%lu", &numAffine)) {
return false; }
1026 std::vector<double> tfo(numAffine);
1027 for(std::size_t i = 0; i < numAffine; i++) {
1028 if(fscanf(fp,
"%lf", &tfo[i]) != 1) {
return false; }
1035 if(fscanf(fp,
"%lu", &correspondingVertexSize) != 1) {
return false; }
1039 if(!fscanf(fp,
"%s", affine)) {
return false; }
1040 if(!strncmp(affine,
"Affine", 6)) {
1041 if(!fgets(affine,
sizeof(affine), fp)) {
return false; }
1042 std::vector<double> tfo(16);
1044 "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf "
1046 &tfo[0], &tfo[1], &tfo[2], &tfo[3], &tfo[4], &tfo[5],
1047 &tfo[6], &tfo[7], &tfo[8], &tfo[9], &tfo[10], &tfo[11],
1048 &tfo[12], &tfo[13], &tfo[14], &tfo[15]) != 16) {
1052 if(fscanf(fp,
"%lu", &correspondingVertexSize) != 1) {
return false; }
1056 if(sscanf(affine,
"%lu", &correspondingVertexSize) != 1) {
1063 for(std::size_t j = 0; j < correspondingVertexSize; j++) {
1064 std::size_t v1 = 0, v2 = 0;
1066 std::size_t data[2];
1067 if(fread(data,
sizeof(std::size_t), 2, fp) != 2) {
return false; }
1073 if(fscanf(fp,
"%lu %lu", &v1, &v2) != 2) {
return false; }
1080 if(!mv1) {
Msg::Info(
"Could not find periodic node %d", v1); }
1082 Msg::Info(
"Could not find periodic node %d", v2);
1093 std::size_t numGhostCells = 0;
1095 if(fread(&numGhostCells,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
1096 if(
swap)
SwapBytes((
char *)&numGhostCells,
sizeof(std::size_t), 1);
1099 if(fscanf(fp,
"%lu", &numGhostCells) != 1) {
return false; }
1102 std::multimap<std::pair<MElement *, int>,
int> ghostCells;
1103 for(std::size_t i = 0; i < numGhostCells; i++) {
1104 std::size_t elmTag = 0;
1106 std::size_t numGhostPartitions = 0;
1110 if(fread(&elmTag,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
1111 if(
swap)
SwapBytes((
char *)&elmTag,
sizeof(std::size_t), 1);
1112 if(fread(&partNum,
sizeof(
int), 1, fp) != 1) {
return false; }
1114 if(fread(&numGhostPartitions,
sizeof(std::size_t), 1, fp) != 1) {
1117 if(
swap)
SwapBytes((
char *)&numGhostPartitions,
sizeof(std::size_t), 1);
1120 if(fscanf(fp,
"%lu %d %lu", &elmTag, &partNum, &numGhostPartitions) !=
1124 if(!fgets(str,
sizeof(str), fp)) {
return false; }
1129 Msg::Error(
"No element with tag %lu", elmTag);
1133 for(std::size_t j = 0; j < numGhostPartitions; j++) {
1134 int ghostPartition = 0;
1137 if(fread(&ghostPartition,
sizeof(
int), 1, fp) != 1) {
return false; }
1138 if(
swap)
SwapBytes((
char *)&ghostPartition,
sizeof(
int), 1);
1141 if(j == numGhostPartitions - 1) {
1142 if(sscanf(str,
"%d", &ghostPartition) != 1) {
return false; }
1145 if(sscanf(str,
"%d %[0-9- ]", &ghostPartition, str) != 2) {
1151 ghostCells.insert(std::make_pair(std::make_pair(elm, partNum),
1156 std::vector<GEntity *> ghostEntities(model->
getNumPartitions() + 1,
nullptr);
1157 std::vector<GEntity *> entities;
1159 for(std::size_t i = 0; i < entities.size(); i++) {
1163 partNum =
static_cast<ghostEdge *
>(ge)->getPartition();
1168 if(partNum >= 0 && partNum < (
int)ghostEntities.size())
1169 ghostEntities[partNum] = ge;
1172 for(
auto it = ghostCells.begin(); it != ghostCells.end(); ++it) {
1173 if(it->second >= (
int)ghostEntities.size()) {
1174 Msg::Error(
"Invalid partition %d in ghost elements", it->second);
1177 GEntity *ge = ghostEntities[it->second];
1179 Msg::Warning(
"Missing ghost entity on partition %d", it->second);
1182 static_cast<ghostEdge *
>(ge)->addElement(
1183 it->first.first->getType(), it->first.first, it->first.second);
1186 static_cast<ghostFace *
>(ge)->addElement(
1187 it->first.first->getType(), it->first.first, it->first.second);
1191 it->first.first->getType(), it->first.first, it->first.second);
1199 if(
CTX::instance()->mesh.ignoreParametrizationMsh4)
return true;
1201 std::size_t nParamE, nParamF;
1204 if(fread(&nParamE,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
1205 if(fread(&nParamF,
sizeof(std::size_t), 1, fp) != 1) {
return false; }
1208 if(fscanf(fp,
"%lu %lu", &nParamE, &nParamF) != 2) {
return false; }
1212 Msg::Info(
"%lu parametrizations", nParamF);
1215 for(std::size_t edge = 0; edge < nParamE; edge++) {
1218 if(fread(&tag,
sizeof(
int), 1, fp) != 1) {
return false; }
1221 if(fscanf(fp,
"%d", &tag) != 1) {
return false; }
1232 for(std::size_t face = 0; face < nParamF; face++) {
1235 if(fread(&tag,
sizeof(
int), 1, fp) != 1) {
return false; }
1238 if(fscanf(fp,
"%d", &tag) != 1) {
return false; }
1244 if(!
df->readParametrization(fp, binary))
return false;
1257 bool partitioned =
false;
1258 FILE *fp =
Fopen(name.c_str(),
"rb");
1260 Msg::Error(
"Unable to open file '%s'", name.c_str());
1264 char str[1024] =
"x";
1265 double version = 1.0;
1266 bool binary =
false,
swap =
false, postpro =
false;
1269 while(str[0] !=
'$') {
1270 if(!fgets(str,
sizeof(str), fp) || feof(fp))
break;
1273 std::string sectionName(&str[1]);
1274 std::string endSectionName =
"End" + sectionName;
1278 if(!strncmp(&str[1],
"MeshFormat", 10)) {
1279 if(!fgets(str,
sizeof(str), fp) || feof(fp)) {
1286 if(sscanf(str,
"%lf %d %lu", &version, &format, &size) != 3) {
1294 if(fread(&one,
sizeof(
int), 1, fp) != 1) {
1300 Msg::Debug(
"Swapping bytes from binary file");
1304 if(binary && size !=
sizeof(std::size_t)) {
1305 Msg::Error(
"Binary file has sizeof(size_t) = %d, not matching "
1306 "machine sizeof(size_t) = %d",
1307 size,
sizeof(std::size_t));
1310 if(binary && version < 4.1) {
1311 Msg::Error(
"Can only read MSH 4.0 format in ASCII mode");
1315 else if(!strncmp(&str[1],
"PhysicalNames", 13)) {
1316 if(!fgets(str,
sizeof(str), fp) || feof(fp)) {
1325 std::vector<GModel::piter> iterators;
1328 int dim = 0, tag = 0;
1329 if(fscanf(fp,
"%d %d", &dim, &tag) != 2) {
1334 if(!fgets(name,
sizeof(name), fp)) {
1344 else if(!strncmp(&str[1],
"Entities", 8)) {
1351 else if(!strncmp(&str[1],
"PartitionedEntities", 19)) {
1353 Msg::Error(
"Could not read partitioned entities");
1359 else if(!strncmp(&str[1],
"Nodes", 5)) {
1363 std::size_t totalNumNodes = 0, maxNodeNum;
1364 std::pair<std::size_t, MVertex *> *vertexCache =
readMSH4Nodes(
1365 this, fp, binary, dense, totalNumNodes, maxNodeNum,
swap, version);
1374 for(std::size_t i = 0; i < totalNumNodes; i++) {
1379 Msg::Info(
"Skipping duplicate node %d", vertexCache[i].first);
1384 for(std::size_t i = 0; i < totalNumNodes; i++) {
1389 Msg::Info(
"Skipping duplicate node %d", vertexCache[i].first);
1393 delete[] vertexCache;
1395 else if(!strncmp(&str[1],
"Elements", 8)) {
1397 std::size_t totalNumElements = 0, maxElementNum = 0;
1398 std::pair<std::size_t, std::pair<MElement *, int> > *elementCache =
1400 maxElementNum,
swap, version);
1409 for(std::size_t i = 0; i < totalNumElements; i++) {
1414 Msg::Info(
"Skipping duplicate element %d", elementCache[i].first);
1419 for(std::size_t i = 0; i < totalNumElements; i++) {
1424 Msg::Info(
"Skipping duplicate element %d", elementCache[i].first);
1428 delete[] elementCache;
1430 else if(!strncmp(&str[1],
"Periodic", 8)) {
1432 Msg::Error(
"Could not read periodic section");
1437 else if(!strncmp(&str[1],
"GhostElements", 13)) {
1444 else if(!strncmp(&str[1],
"Parametrizations", 16)) {
1446 Msg::Error(
"Could not read parametrizations");
1451 else if(!strncmp(&str[1],
"NodeData", 8) ||
1452 !strncmp(&str[1],
"ElementData", 11) ||
1453 !strncmp(&str[1],
"ElementNodeData", 15)) {
1457 else if(strlen(&str[1]) > 0){
1458 sectionName.pop_back();
1459 Msg::Info(
"Storing section $%s as model attribute", sectionName.c_str());
1460 std::vector<std::string> section;
1462 if(!fgets(str,
sizeof(str), fp) || feof(fp) ||
1463 !strncmp(&str[1], endSectionName.c_str(), endSectionName.size())) {
1467 if(s.back() ==
'\n') s.pop_back();
1468 if(s.back() ==
'\r') s.pop_back();
1469 section.push_back(s);
1474 while(strncmp(&str[1], endSectionName.c_str(), endSectionName.size())) {
1475 if(!fgets(str,
sizeof(str), fp) || feof(fp)) {
break; }
1485 std::vector<GEntity *> entities;
1487 for(std::size_t i = 0; i < entities.size(); i++) {
1527 return postpro ? 2 : 1;
1534 std::size_t phySize = phys.size();
1535 fwrite(&phySize,
sizeof(std::size_t), 1, fp);
1536 for(std::size_t i = 0; i < phys.size(); i++) {
1538 fwrite(&phy,
sizeof(
int), 1, fp);
1543 fprintf(fp,
"%lu", phys.size());
1544 for(std::size_t i = 0; i < phys.size(); i++) {
1545 fprintf(fp,
" %d", phys[i]);
1552 double scalingFactor,
bool binary,
int dim,
1555 double bb[6] = {0., 0., 0., 0., 0., 0.};
1556 if(!boundBox.
empty()) {
1557 boundBox *= scalingFactor;
1558 bb[0] = boundBox.
min().
x();
1559 bb[1] = boundBox.
min().
y();
1560 bb[2] = boundBox.
min().
z();
1561 bb[3] = boundBox.
max().
x();
1562 bb[4] = boundBox.
max().
y();
1563 bb[5] = boundBox.
max().
z();
1565 if(binary) { fwrite(bb,
sizeof(
double), (dim > 0) ? 6 : 3, fp); }
1567 std::size_t n = (version < 4.1 || dim > 0) ? 6 : 3;
1568 for(std::size_t i = 0; i < n; i++) fprintf(fp,
"%.16g ", bb[i]);
1573 bool binary,
double scalingFactor,
double version,
1574 std::map<GEntity*, SBoundingBox3d> *entityBounds)
1576 std::set<GEntity *, GEntityPtrFullLessThan> ghost;
1577 std::set<GRegion *, GEntityPtrLessThan> regions;
1578 std::set<GFace *, GEntityPtrLessThan>
faces;
1579 std::set<GEdge *, GEntityPtrLessThan>
edges;
1580 std::set<GVertex *, GEntityPtrLessThan> vertices;
1584 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
1589 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
1595 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
1607 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
1612 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
1619 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
1628 regions.insert(*it);
1633 fprintf(fp,
"$PartitionedEntities\n");
1635 fprintf(fp,
"$Entities\n");
1640 fwrite(&numPartitions,
sizeof(std::size_t), 1, fp);
1643 std::size_t ghostSize = ghost.size();
1644 std::vector<int>
tags;
1646 tags.resize(2 * ghostSize);
1648 for(
auto it = ghost.begin(); it != ghost.end(); ++it) {
1650 tags[index] = (*it)->tag();
1654 tags[index] = (*it)->tag();
1658 tags[index] = (*it)->tag();
1664 fwrite(&ghostSize,
sizeof(std::size_t), 1, fp);
1665 if(ghostSize) { fwrite(&
tags[0],
sizeof(
int), 2 * ghostSize, fp); }
1667 std::size_t verticesSize = vertices.size();
1668 std::size_t edgesSize =
edges.size();
1669 std::size_t facesSize =
faces.size();
1670 std::size_t regionsSize = regions.size();
1671 fwrite(&verticesSize,
sizeof(std::size_t), 1, fp);
1672 fwrite(&edgesSize,
sizeof(std::size_t), 1, fp);
1673 fwrite(&facesSize,
sizeof(std::size_t), 1, fp);
1674 fwrite(®ionsSize,
sizeof(std::size_t), 1, fp);
1676 for(
auto it = vertices.begin(); it != vertices.end(); ++it) {
1677 int entityTag = (*it)->tag();
1678 fwrite(&entityTag,
sizeof(
int), 1, fp);
1681 int parentEntityDim = 0, parentEntityTag = 0;
1686 fwrite(&parentEntityDim,
sizeof(
int), 1, fp);
1687 fwrite(&parentEntityTag,
sizeof(
int), 1, fp);
1690 std::size_t numPart = partitions.size();
1691 fwrite(&numPart,
sizeof(std::size_t), 1, fp);
1692 fwrite(&partitions[0],
sizeof(
int), partitions.size(), fp);
1694 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1699 for(
auto it =
edges.begin(); it !=
edges.end(); ++it) {
1700 std::vector<GVertex *> vertices;
1701 std::vector<int> ori;
1702 if((*it)->getBeginVertex()) {
1703 vertices.push_back((*it)->getBeginVertex());
1706 if((*it)->getEndVertex()) {
1707 vertices.push_back((*it)->getEndVertex());
1710 std::size_t verticesSize = vertices.size();
1711 int entityTag = (*it)->tag();
1712 fwrite(&entityTag,
sizeof(
int), 1, fp);
1715 int parentEntityDim = 0, parentEntityTag = 0;
1720 fwrite(&parentEntityDim,
sizeof(
int), 1, fp);
1721 fwrite(&parentEntityTag,
sizeof(
int), 1, fp);
1724 std::size_t numPart = partitions.size();
1725 fwrite(&numPart,
sizeof(std::size_t), 1, fp);
1726 fwrite(&partitions[0],
sizeof(
int), partitions.size(), fp);
1728 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1731 fwrite(&verticesSize,
sizeof(std::size_t), 1, fp);
1733 for(
auto itv = vertices.begin(); itv != vertices.end(); itv++) {
1734 int brepTag = ori[oriI] * (*itv)->tag();
1735 fwrite(&brepTag,
sizeof(
int), 1, fp);
1740 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
1741 std::vector<GEdge *>
const &
edges = (*it)->edges();
1742 std::vector<int>
const &ori = (*it)->edgeOrientations();
1743 std::size_t edgesSize =
edges.size();
1744 int entityTag = (*it)->tag();
1745 fwrite(&entityTag,
sizeof(
int), 1, fp);
1748 int parentEntityDim = 0, parentEntityTag = 0;
1753 fwrite(&parentEntityDim,
sizeof(
int), 1, fp);
1754 fwrite(&parentEntityTag,
sizeof(
int), 1, fp);
1757 std::size_t numPart = partitions.size();
1758 fwrite(&numPart,
sizeof(std::size_t), 1, fp);
1759 fwrite(&partitions[0],
sizeof(
int), partitions.size(), fp);
1761 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1764 fwrite(&edgesSize,
sizeof(std::size_t), 1, fp);
1765 std::vector<int>
tags, signs;
1766 for(
auto ite =
edges.begin(); ite !=
edges.end(); ite++)
1767 tags.push_back((*ite)->tag());
1769 signs.insert(signs.end(), ori.begin(), ori.end());
1771 if(
tags.size() == signs.size()) {
1772 for(std::size_t i = 0; i <
tags.size(); i++)
1773 tags[i] *= (signs[i] > 0 ? 1 : -1);
1775 for(std::size_t i = 0; i <
tags.size(); i++) {
1776 int brepTag =
tags[i];
1777 fwrite(&brepTag,
sizeof(
int), 1, fp);
1781 for(
auto it = regions.begin(); it != regions.end(); ++it) {
1782 std::vector<GFace *>
faces = (*it)->faces();
1783 std::vector<int>
const &ori = (*it)->faceOrientations();
1784 std::size_t facesSize =
faces.size();
1785 int entityTag = (*it)->tag();
1786 fwrite(&entityTag,
sizeof(
int), 1, fp);
1789 int parentEntityDim = 0, parentEntityTag = 0;
1794 fwrite(&parentEntityDim,
sizeof(
int), 1, fp);
1795 fwrite(&parentEntityTag,
sizeof(
int), 1, fp);
1798 std::size_t numPart = partitions.size();
1799 fwrite(&numPart,
sizeof(std::size_t), 1, fp);
1800 fwrite(&partitions[0],
sizeof(
int), partitions.size(), fp);
1802 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1805 fwrite(&facesSize,
sizeof(std::size_t), 1, fp);
1806 std::vector<int>
tags, signs;
1807 for(
auto itf =
faces.begin(); itf !=
faces.end(); itf++)
1808 tags.push_back((*itf)->tag());
1809 for(
auto itf = ori.begin(); itf != ori.end(); itf++)
1810 signs.push_back(*itf);
1811 if(
tags.size() == signs.size()) {
1812 for(std::size_t i = 0; i <
tags.size(); i++)
1813 tags[i] *= (signs[i] > 0 ? 1 : -1);
1815 for(std::size_t i = 0; i <
tags.size(); i++) {
1816 int brepTag =
tags[i];
1817 fwrite(&brepTag,
sizeof(
int), 1, fp);
1827 std::size_t ghostSize = ghost.size();
1828 std::vector<int>
tags;
1830 tags.resize(2 * ghostSize);
1832 for(
auto it = ghost.begin(); it != ghost.end(); ++it) {
1834 tags[index] = (*it)->tag();
1838 tags[index] = (*it)->tag();
1842 tags[index] = (*it)->tag();
1848 fprintf(fp,
"%lu\n", ghostSize);
1850 for(std::size_t i = 0; i < 2 * ghostSize; i += 2) {
1851 fprintf(fp,
"%d %d\n",
tags[i],
tags[i + 1]);
1855 fprintf(fp,
"%lu %lu %lu %lu\n", vertices.size(),
edges.size(),
1856 faces.size(), regions.size());
1858 for(
auto it = vertices.begin(); it != vertices.end(); ++it) {
1859 fprintf(fp,
"%d ", (*it)->tag());
1862 int parentEntityDim = 0, parentEntityTag = 0;
1867 fprintf(fp,
"%d %d ", parentEntityDim, parentEntityTag);
1870 fprintf(fp,
"%lu ", partitions.size());
1871 for(std::size_t i = 0; i < partitions.size(); i++)
1872 fprintf(fp,
"%d ", partitions[i]);
1874 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1880 for(
auto it =
edges.begin(); it !=
edges.end(); ++it) {
1881 std::vector<GVertex *> vertices;
1882 std::vector<int> ori;
1883 if((*it)->getBeginVertex()) {
1884 vertices.push_back((*it)->getBeginVertex());
1887 if((*it)->getEndVertex()) {
1889 vertices.push_back((*it)->getEndVertex());
1892 fprintf(fp,
"%d ", (*it)->tag());
1895 int parentEntityDim = 0, parentEntityTag = 0;
1900 fprintf(fp,
"%d %d ", parentEntityDim, parentEntityTag);
1903 fprintf(fp,
"%lu ", partitions.size());
1904 for(std::size_t i = 0; i < partitions.size(); i++)
1905 fprintf(fp,
"%d ", partitions[i]);
1907 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1910 fprintf(fp,
"%lu ", vertices.size());
1912 for(
auto itv = vertices.begin(); itv != vertices.end(); itv++) {
1913 fprintf(fp,
"%d ", ori[oriI] * (*itv)->tag());
1919 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
1920 std::vector<GEdge *>
const &
edges = (*it)->edges();
1921 std::vector<int>
const &ori = (*it)->edgeOrientations();
1922 fprintf(fp,
"%d ", (*it)->tag());
1925 int parentEntityDim = 0, parentEntityTag = 0;
1930 fprintf(fp,
"%d %d ", parentEntityDim, parentEntityTag);
1933 fprintf(fp,
"%lu ", partitions.size());
1934 for(std::size_t i = 0; i < partitions.size(); i++)
1935 fprintf(fp,
"%d ", partitions[i]);
1937 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1940 fprintf(fp,
"%lu ",
edges.size());
1941 std::vector<int>
tags, signs;
1942 for(
auto ite =
edges.begin(); ite !=
edges.end(); ite++)
1943 tags.push_back((*ite)->tag());
1944 for(
auto ite = ori.begin(); ite != ori.end(); ite++)
1945 signs.push_back(*ite);
1946 if(
tags.size() == signs.size()) {
1947 for(std::size_t i = 0; i <
tags.size(); i++)
1948 tags[i] *= (signs[i] > 0 ? 1 : -1);
1950 for(std::size_t i = 0; i <
tags.size(); i++) fprintf(fp,
"%d ",
tags[i]);
1954 for(
auto it = regions.begin(); it != regions.end(); ++it) {
1955 std::vector<GFace *>
const &
faces = (*it)->faces();
1956 std::vector<int>
const &ori = (*it)->faceOrientations();
1957 fprintf(fp,
"%d ", (*it)->tag());
1960 int parentEntityDim = 0, parentEntityTag = 0;
1965 fprintf(fp,
"%d %d ", parentEntityDim, parentEntityTag);
1970 fprintf(fp,
"%d ", partition);
1973 SBoundingBox3d bb = entityBounds ? (*entityBounds)[*it] : (*it)->bounds();
1976 fprintf(fp,
"%lu ",
faces.size());
1980 [](
const GFace *
const face) {
return face->
tag(); });
1982 std::vector<int> signs(ori.begin(), ori.end());
1984 if(
tags.size() == signs.size()) {
1985 for(std::size_t i = 0; i <
tags.size(); i++)
1986 tags[i] *= (signs[i] > 0 ? 1 : -1);
1989 for(
auto const tag :
tags) { fprintf(fp,
"%d ", tag); }
1995 fprintf(fp,
"$EndPartitionedEntities\n");
1997 fprintf(fp,
"$EndEntities\n");
2001 int saveParametric,
double scalingFactor,
2004 int parametric = saveParametric;
2005 if(ge->
dim() != 1 && ge->
dim() != 2)
2009 int entityDim = ge->
dim();
2010 int entityTag = ge->
tag();
2012 fwrite(&entityDim,
sizeof(
int), 1, fp);
2013 fwrite(&entityTag,
sizeof(
int), 1, fp);
2014 fwrite(¶metric,
sizeof(
int), 1, fp);
2015 fwrite(&numVerts,
sizeof(std::size_t), 1, fp);
2018 fprintf(fp,
"%d %d %d %lu\n", (version >= 4.1) ? ge->
dim() : ge->
tag(),
2019 (version >= 4.1) ? ge->
tag() : ge->
dim(), parametric,
2025 if(parametric) n += ge->
dim();
2028 std::vector<size_t>
tags(N);
2030 fwrite(&
tags[0],
sizeof(std::size_t), N, fp);
2031 std::vector<double> coord(n * N);
2033 for(std::size_t i = 0; i < N; i++) {
2035 coord[j++] = mv->
x() * scalingFactor;
2036 coord[j++] = mv->
y() * scalingFactor;
2037 coord[j++] = mv->
z() * scalingFactor;
2041 fwrite(&coord[0],
sizeof(
double), n * N, fp);
2044 if(version >= 4.1) {
2045 for(std::size_t i = 0; i < N; i++)
2048 for(std::size_t i = 0; i < N; i++) {
2050 double x = mv->
x() * scalingFactor;
2051 double y = mv->
y() * scalingFactor;
2052 double z = mv->
z() * scalingFactor;
2053 if(version < 4.1) fprintf(fp,
"%lu ", mv->
getNum());
2058 fprintf(fp,
"%.16g %.16g %.16g %.16g %.16g\n", x, y,
z, u, v);
2063 fprintf(fp,
"%.16g %.16g %.16g %.16g\n", x, y,
z, u);
2066 fprintf(fp,
"%.16g %.16g %.16g\n", x, y,
z);
2074 std::set<GFace *, GEntityPtrLessThan> &
faces,
2075 std::set<GEdge *, GEntityPtrLessThan> &
edges,
2076 std::set<GVertex *, GEntityPtrLessThan> &vertices)
2078 std::size_t numVertices = 0;
2080 for(
auto it = vertices.begin(); it != vertices.end(); ++it) {
2081 numVertices += (*it)->getNumMeshVertices();
2084 for(
auto it =
edges.begin(); it !=
edges.end(); ++it) {
2085 numVertices += (*it)->getNumMeshVertices();
2086 for(std::size_t i = 0; i < (*it)->getNumMeshElements(); i++) {
2087 for(std::size_t j = 0; j < (*it)->getMeshElement(i)->
getNumVertices();
2089 if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)) {
2092 switch(entity->
dim()) {
2094 if(vertices.find(
static_cast<GVertex *
>(entity)) ==
2096 vertices.insert(
static_cast<GVertex *
>(entity));
2113 if(regions.find(
static_cast<GRegion *
>(entity)) == regions.end()) {
2114 regions.insert(
static_cast<GRegion *
>(entity));
2125 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
2126 numVertices += (*it)->getNumMeshVertices();
2127 for(std::size_t i = 0; i < (*it)->getNumMeshElements(); i++) {
2128 for(std::size_t j = 0; j < (*it)->getMeshElement(i)->
getNumVertices();
2130 if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)) {
2133 switch(entity->
dim()) {
2135 if(vertices.find(
static_cast<GVertex *
>(entity)) ==
2137 vertices.insert(
static_cast<GVertex *
>(entity));
2154 if(regions.find(
static_cast<GRegion *
>(entity)) == regions.end()) {
2155 regions.insert(
static_cast<GRegion *
>(entity));
2166 for(
auto it = regions.begin(); it != regions.end(); ++it) {
2167 numVertices += (*it)->getNumMeshVertices();
2168 for(std::size_t i = 0; i < (*it)->getNumMeshElements(); i++) {
2169 for(std::size_t j = 0; j < (*it)->getMeshElement(i)->
getNumVertices();
2171 if((*it)->getMeshElement(i)->getVertex(j)->onWhat() != (*it)) {
2174 switch(entity->
dim()) {
2176 if(vertices.find(
static_cast<GVertex *
>(entity)) ==
2178 vertices.insert(
static_cast<GVertex *
>(entity));
2195 if(regions.find(
static_cast<GRegion *
>(entity)) == regions.end()) {
2196 regions.insert(
static_cast<GRegion *
>(entity));
2212 int partitionToSave,
bool saveAll,
2213 std::set<GRegion *, GEntityPtrLessThan> ®ions,
2214 std::set<GFace *, GEntityPtrLessThan> &
faces,
2215 std::set<GEdge *, GEntityPtrLessThan> &
edges,
2216 std::set<GVertex *, GEntityPtrLessThan> &vertices)
2220 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
2224 if(!partitionToSave ||
2227 vertices.insert(pv);
2231 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
2235 if(!partitionToSave ||
2247 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
2251 if(!partitionToSave ||
2265 if(!partitionToSave ||
2279 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
2282 (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0)))
2283 vertices.insert(*it);
2286 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
2289 (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0) ||
2294 if(
CTX::instance()->mesh.saveWithoutOrphans && (*it)->isOrphan())
2297 (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0) ||
2303 (saveAll || (!saveAll && (*it)->getPhysicalEntities().size() != 0) ||
2305 regions.insert(*it);
2311 int partitionToSave,
bool binary,
int saveParametric,
2312 double scalingFactor,
bool saveAll,
double version)
2314 std::set<GRegion *, GEntityPtrLessThan> regions;
2315 std::set<GFace *, GEntityPtrLessThan>
faces;
2316 std::set<GEdge *, GEntityPtrLessThan>
edges;
2317 std::set<GVertex *, GEntityPtrLessThan> vertices;
2321 std::size_t numNodes = (saveAll && !partitioned &&
2326 if(!numNodes)
return;
2328 fprintf(fp,
"$Nodes\n");
2330 std::size_t minTag = std::numeric_limits<std::size_t>::max(), maxTag = 0;
2331 for(
auto it = vertices.begin(); it != vertices.end(); ++it) {
2332 for(std::size_t i = 0; i < (*it)->getNumMeshVertices(); i++) {
2333 minTag = std::min(minTag, (*it)->getMeshVertex(i)->getNum());
2334 maxTag = std::max(maxTag, (*it)->getMeshVertex(i)->getNum());
2337 for(
auto it =
edges.begin(); it !=
edges.end(); ++it) {
2338 for(std::size_t i = 0; i < (*it)->getNumMeshVertices(); i++) {
2339 minTag = std::min(minTag, (*it)->getMeshVertex(i)->getNum());
2340 maxTag = std::max(maxTag, (*it)->getMeshVertex(i)->getNum());
2343 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
2344 for(std::size_t i = 0; i < (*it)->getNumMeshVertices(); i++) {
2345 minTag = std::min(minTag, (*it)->getMeshVertex(i)->getNum());
2346 maxTag = std::max(maxTag, (*it)->getMeshVertex(i)->getNum());
2349 for(
auto it = regions.begin(); it != regions.end(); ++it) {
2350 for(std::size_t i = 0; i < (*it)->getNumMeshVertices(); i++) {
2351 minTag = std::min(minTag, (*it)->getMeshVertex(i)->getNum());
2352 maxTag = std::max(maxTag, (*it)->getMeshVertex(i)->getNum());
2357 std::size_t numSection =
2358 vertices.size() +
edges.size() +
faces.size() + regions.size();
2359 fwrite(&numSection,
sizeof(std::size_t), 1, fp);
2360 fwrite(&numNodes,
sizeof(std::size_t), 1, fp);
2361 fwrite(&minTag,
sizeof(std::size_t), 1, fp);
2362 fwrite(&maxTag,
sizeof(std::size_t), 1, fp);
2365 if(version >= 4.1) {
2366 fprintf(fp,
"%lu %lu %lu %lu\n",
2367 vertices.size() +
edges.size() +
faces.size() + regions.size(),
2368 numNodes, minTag, maxTag);
2371 fprintf(fp,
"%lu %lu\n",
2372 vertices.size() +
edges.size() +
faces.size() + regions.size(),
2377 for(
auto it = vertices.begin(); it != vertices.end(); ++it) {
2381 for(
auto it =
edges.begin(); it !=
edges.end(); ++it) {
2385 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
2389 for(
auto it = regions.begin(); it != regions.end(); ++it) {
2394 if(binary) fprintf(fp,
"\n");
2396 fprintf(fp,
"$EndNodes\n");
2400 int partitionToSave,
bool binary,
bool saveAll,
2403 std::set<GRegion *, GEntityPtrLessThan> regions;
2404 std::set<GFace *, GEntityPtrLessThan>
faces;
2405 std::set<GEdge *, GEntityPtrLessThan>
edges;
2406 std::set<GVertex *, GEntityPtrLessThan> vertices;
2410 std::map<std::pair<int, int>, std::vector<MElement *> > elementsByType[4];
2411 std::size_t numElements = 0;
2413 for(
auto it = vertices.begin(); it != vertices.end(); ++it) {
2414 if(!saveAll && (*it)->physicals.size() == 0)
continue;
2416 numElements += (*it)->points.size();
2417 for(std::size_t i = 0; i < (*it)->points.size(); i++) {
2418 std::pair<int, int> p((*it)->tag(), (*it)->points[i]->getTypeForMSH());
2419 elementsByType[0][p].push_back((*it)->points[i]);
2423 for(
auto it =
edges.begin(); it !=
edges.end(); ++it) {
2424 if(!saveAll && (*it)->physicals.size() == 0 &&
2428 numElements += (*it)->lines.size();
2429 for(std::size_t i = 0; i < (*it)->lines.size(); i++) {
2430 std::pair<int, int> p((*it)->tag(), (*it)->lines[i]->getTypeForMSH());
2431 elementsByType[1][p].push_back((*it)->lines[i]);
2435 for(
auto it =
faces.begin(); it !=
faces.end(); ++it) {
2436 if(!saveAll && (*it)->physicals.size() == 0 &&
2440 numElements += (*it)->triangles.size();
2441 for(std::size_t i = 0; i < (*it)->triangles.size(); i++) {
2442 std::pair<int, int> p((*it)->tag(), (*it)->triangles[i]->getTypeForMSH());
2443 elementsByType[2][p].push_back((*it)->triangles[i]);
2445 numElements += (*it)->quadrangles.size();
2446 for(std::size_t i = 0; i < (*it)->quadrangles.size(); i++) {
2447 std::pair<int, int> p((*it)->tag(),
2448 (*it)->quadrangles[i]->getTypeForMSH());
2449 elementsByType[2][p].push_back((*it)->quadrangles[i]);
2453 for(
auto it = regions.begin(); it != regions.end(); ++it) {
2454 if(!saveAll && (*it)->physicals.size() == 0 &&
2458 numElements += (*it)->tetrahedra.size();
2459 for(std::size_t i = 0; i < (*it)->tetrahedra.size(); i++) {
2460 std::pair<int, int> p((*it)->tag(),
2461 (*it)->tetrahedra[i]->getTypeForMSH());
2462 elementsByType[3][p].push_back((*it)->tetrahedra[i]);
2464 numElements += (*it)->hexahedra.size();
2465 for(std::size_t i = 0; i < (*it)->hexahedra.size(); i++) {
2466 std::pair<int, int> p((*it)->tag(), (*it)->hexahedra[i]->getTypeForMSH());
2467 elementsByType[3][p].push_back((*it)->hexahedra[i]);
2469 numElements += (*it)->prisms.size();
2470 for(std::size_t i = 0; i < (*it)->prisms.size(); i++) {
2471 std::pair<int, int> p((*it)->tag(), (*it)->prisms[i]->getTypeForMSH());
2472 elementsByType[3][p].push_back((*it)->prisms[i]);
2474 numElements += (*it)->pyramids.size();
2475 for(std::size_t i = 0; i < (*it)->pyramids.size(); i++) {
2476 std::pair<int, int> p((*it)->tag(), (*it)->pyramids[i]->getTypeForMSH());
2477 elementsByType[3][p].push_back((*it)->pyramids[i]);
2479 numElements += (*it)->trihedra.size();
2480 for(std::size_t i = 0; i < (*it)->trihedra.size(); i++) {
2481 std::pair<int, int> p((*it)->tag(), (*it)->trihedra[i]->getTypeForMSH());
2482 elementsByType[3][p].push_back((*it)->trihedra[i]);
2486 if(!numElements)
return;
2488 fprintf(fp,
"$Elements\n");
2490 std::size_t numSection = 0;
2491 for(
int dim = 0; dim <= 3; dim++) numSection += elementsByType[dim].size();
2493 std::size_t minTag = std::numeric_limits<std::size_t>::max(), maxTag = 0;
2494 for(
int dim = 0; dim <= 3; dim++) {
2495 for(
auto it = elementsByType[dim].begin(); it != elementsByType[dim].end();
2497 for(std::size_t i = 0; i < it->second.size(); i++) {
2498 minTag = std::min(minTag, it->second[i]->getNum());
2499 maxTag = std::max(maxTag, it->second[i]->getNum());
2505 fwrite(&numSection,
sizeof(std::size_t), 1, fp);
2506 fwrite(&numElements,
sizeof(std::size_t), 1, fp);
2507 fwrite(&minTag,
sizeof(std::size_t), 1, fp);
2508 fwrite(&maxTag,
sizeof(std::size_t), 1, fp);
2512 fprintf(fp,
"%lu %lu %lu %lu\n", numSection, numElements, minTag, maxTag);
2514 fprintf(fp,
"%lu %lu\n", numSection, numElements);
2517 for(
int dim = 0; dim <= 3; dim++) {
2518 for(
auto it = elementsByType[dim].begin(); it != elementsByType[dim].end();
2520 int entityTag = it->first.first;
2521 int elmType = it->first.second;
2522 std::size_t numElm = it->second.size();
2524 fwrite(&dim,
sizeof(
int), 1, fp);
2525 fwrite(&entityTag,
sizeof(
int), 1, fp);
2526 fwrite(&elmType,
sizeof(
int), 1, fp);
2527 fwrite(&numElm,
sizeof(std::size_t), 1, fp);
2530 fprintf(fp,
"%d %d %d %lu\n", (version >= 4.1) ? dim : entityTag,
2531 (version >= 4.1) ? entityTag : dim, elmType, numElm);
2534 std::size_t N = it->second.size();
2537 std::size_t n = 1 + numVertPerElm;
2538 std::vector<std::size_t>
tags(N * n);
2540 for(std::size_t i = 0; i < N; i++) {
2543 for(
int j = 0; j < numVertPerElm; j++) {
2548 fwrite(&
tags[0],
sizeof(std::size_t), N * n, fp);
2551 for(std::size_t i = 0; i < N; i++) {
2553 fprintf(fp,
"%lu ", e->
getNum());
2563 if(binary) fprintf(fp,
"\n");
2565 fprintf(fp,
"$EndElements\n");
2569 bool binary,
double version)
2579 std::size_t count = 0;
2580 std::vector<GEntity *> entities;
2582 for(std::size_t i = 0; i < entities.size(); i++)
2583 if(entities[i]->getMeshMaster() != entities[i]) count++;
2587 fprintf(fp,
"$Periodic\n");
2589 if(binary) { fwrite(&count,
sizeof(std::size_t), 1, fp); }
2591 fprintf(fp,
"%lu\n", count);
2594 for(std::size_t i = 0; i < entities.size(); i++) {
2595 GEntity *g_slave = entities[i];
2598 if(g_slave != g_master) {
2599 std::map<MVertex *, MVertex *, MVertexPtrLessThan> corrVert;
2607 int gSlaveDim = g_slave->
dim();
2608 int gSlaveTag = g_slave->
tag();
2609 int gMasterTag = g_master->
tag();
2610 fwrite(&gSlaveDim,
sizeof(
int), 1, fp);
2611 fwrite(&gSlaveTag,
sizeof(
int), 1, fp);
2612 fwrite(&gMasterTag,
sizeof(
int), 1, fp);
2615 std::size_t numAffine = 16;
2616 fwrite(&numAffine,
sizeof(std::size_t), 1, fp);
2617 for(
int j = 0; j < 16; j++) {
2619 fwrite(&value,
sizeof(
double), 1, fp);
2623 std::size_t numAffine = 0;
2624 fwrite(&numAffine,
sizeof(std::size_t), 1, fp);
2627 std::size_t corrVertSize = corrVert.size();
2628 fwrite(&corrVertSize,
sizeof(std::size_t), 1, fp);
2630 for(
auto it = corrVert.begin(); it != corrVert.end(); ++it) {
2631 std::size_t numFirst = it->first->getNum();
2632 std::size_t numSecond = it->second->getNum();
2633 fwrite(&numFirst,
sizeof(std::size_t), 1, fp);
2634 fwrite(&numSecond,
sizeof(std::size_t), 1, fp);
2638 fprintf(fp,
"%d %d %d\n", g_slave->
dim(), g_slave->
tag(),
2641 if(version >= 4.1) {
2644 for(
int j = 0; j < 16; j++)
2654 fprintf(fp,
"Affine");
2655 for(
int j = 0; j < 16; j++)
2661 fprintf(fp,
"%lu\n", corrVert.size());
2663 for(
auto it = corrVert.begin(); it != corrVert.end(); ++it) {
2664 fprintf(fp,
"%lu %lu\n", it->first->getNum(), it->second->getNum());
2670 if(binary) fprintf(fp,
"\n");
2671 fprintf(fp,
"$EndPeriodic\n");
2675 int partitionToSave,
bool binary)
2677 std::vector<GEntity *> entities;
2679 std::map<MElement *, std::vector<int> > ghostCells;
2681 for(std::size_t i = 0; i < entities.size(); i++) {
2682 std::map<MElement *, int> ghostElements;
2686 ghostElements =
static_cast<ghostEdge *
>(entities[i])->getGhostCells();
2687 partition =
static_cast<ghostEdge *
>(entities[i])->getPartition();
2690 ghostElements =
static_cast<ghostFace *
>(entities[i])->getGhostCells();
2691 partition =
static_cast<ghostFace *
>(entities[i])->getPartition();
2694 ghostElements =
static_cast<ghostRegion *
>(entities[i])->getGhostCells();
2695 partition =
static_cast<ghostRegion *
>(entities[i])->getPartition();
2698 if(!partitionToSave || partitionToSave == partition) {
2699 for(
auto it = ghostElements.begin(); it != ghostElements.end(); ++it) {
2700 if(ghostCells[it->first].size() == 0)
2701 ghostCells[it->first].push_back(it->second);
2702 ghostCells[it->first].push_back(partition);
2707 if(ghostCells.size() != 0) {
2708 fprintf(fp,
"$GhostElements\n");
2710 std::size_t ghostCellsSize = ghostCells.size();
2711 fwrite(&ghostCellsSize,
sizeof(std::size_t), 1, fp);
2713 for(
auto it = ghostCells.begin(); it != ghostCells.end(); ++it) {
2714 std::size_t elmTag = it->first->getNum();
2715 int partNum = it->second[0];
2716 std::size_t numGhostPartitions = it->second.size() - 1;
2717 fwrite(&elmTag,
sizeof(std::size_t), 1, fp);
2718 fwrite(&partNum,
sizeof(
int), 1, fp);
2719 fwrite(&numGhostPartitions,
sizeof(std::size_t), 1, fp);
2720 for(std::size_t i = 1; i < it->second.size(); i++) {
2721 fwrite(&it->second[i],
sizeof(
int), 1, fp);
2727 fprintf(fp,
"%ld\n", ghostCells.size());
2729 for(
auto it = ghostCells.begin(); it != ghostCells.end(); ++it) {
2730 fprintf(fp,
"%lu %d %ld", it->first->getNum(), it->second[0],
2731 it->second.size() - 1);
2732 for(std::size_t i = 1; i < it->second.size(); i++) {
2733 fprintf(fp,
" %d", it->second[i]);
2738 fprintf(fp,
"$EndGhostElements\n");
2745 std::size_t nParamE = 0, nParamF = 0;
2753 if(
df &&
df->haveParametrization()) { nParamF++; }
2756 if(!nParamE && !nParamF)
return;
2758 fprintf(fp,
"$Parametrizations\n");
2761 fwrite(&nParamE,
sizeof(std::size_t), 1, fp);
2762 fwrite(&nParamF,
sizeof(std::size_t), 1, fp);
2765 fprintf(fp,
"%lu %lu\n", nParamE, nParamF);
2773 fwrite(&t,
sizeof(
int), 1, fp);
2775 fprintf(fp,
"%d\n", t);
2781 if(
df &&
df->haveParametrization()) {
2784 fwrite(&t,
sizeof(
int), 1, fp);
2786 fprintf(fp,
"%d\n", t);
2787 df->writeParametrization(fp, binary);
2791 if(binary) fprintf(fp,
"\n");
2793 fprintf(fp,
"$EndParametrizations\n");
2797 bool saveAll,
bool saveParametric,
double scalingFactor,
2798 bool append,
int partitionToSave,
2799 std::map<GEntity*, SBoundingBox3d> *entityBounds)
2803 fp =
Fopen(name.c_str(), binary ?
"ab" :
"a");
2805 fp =
Fopen(name.c_str(), binary ?
"wb" :
"w");
2808 Msg::Error(
"Unable to open file '%s'", name.c_str());
2812 if(version < 4.1 && binary) {
2813 Msg::Error(
"Can only write MSH 4.0 format in ASCII mode");
2821 fprintf(fp,
"$MeshFormat\n");
2822 fprintf(fp,
"%g %d %lu\n", version, (binary ? 1 : 0),
sizeof(std::size_t));
2825 fwrite(&one,
sizeof(
int), 1, fp);
2828 fprintf(fp,
"$EndMeshFormat\n");
2832 fprintf(fp,
"$PhysicalNames\n");
2835 std::string name = it->second;
2836 if(name.size() > 128) name.resize(128);
2837 fprintf(fp,
"%d %d \"%s\"\n", it->first.first, it->first.second,
2840 fprintf(fp,
"$EndPhysicalNames\n");
2851 std::vector<GEntity *> entities;
2853 std::size_t partEnt = 0;
2854 for(
auto &ge : entities) {
2867 Msg::Warning(
"No partition entities found, saving mesh as unpartitioned");
2868 partitioned =
false;
2879 saveParametric ? 1 : 0, scalingFactor, saveAll, version);
2896 fprintf(fp,
"$%s\n", a.first.c_str());
2897 for(
auto &s : a.second) fprintf(fp,
"%s\n", s.c_str());
2898 fprintf(fp,
"$End%s\n", a.first.c_str());
2907 bool binary,
bool saveAll,
2908 bool saveParametric,
double scalingFactor)
2916 std::vector<GEntity*> entities;
2918 std::vector<SBoundingBox3d>
bounds(entities.size());
2919 #pragma omp parallel for num_threads(nthreads)
2920 for(std::size_t i = 0; i < entities.size(); i++) {
2921 bounds[i] = entities[i]->bounds();
2923 std::map<GEntity*, SBoundingBox3d> entityBounds;
2924 for(std::size_t i = 0; i < entities.size(); i++) {
2925 entityBounds[entities[i]] =
bounds[i];
2928 bool exceptions =
false;
2929 #pragma omp parallel for num_threads(nthreads)
2931 if(exceptions)
continue;
2932 std::ostringstream sstream;
2933 sstream << baseName <<
"_" << part <<
".msh";
2935 if(part % 100 == 1) {
2937 sstream.str().c_str());
2941 Msg::Info(
"Writing partition %d in file '%s'", part, sstream.str().c_str());
2944 _writeMSH4(sstream.str(), version, binary, saveAll, saveParametric,
2945 scalingFactor,
false, part, &entityBounds);
2958 std::vector<int> &partitions)
2960 if(name[0] !=
'_')
return false;
2962 const std::string part =
"_part{";
2963 const std::string physical =
"_physical{";
2965 size_t firstPart = name.find(part) + part.size();
2966 size_t lastPart = name.find_first_of(
'}', firstPart);
2967 const std::string partString = name.substr(firstPart, lastPart - firstPart);
2969 size_t firstPhysical = name.find(physical) + physical.size();
2970 size_t lastPhysical = name.find_first_of(
'}', firstPhysical);
2971 const std::string physicalString =
2972 name.substr(firstPhysical, lastPhysical - firstPhysical);
2975 for(
size_t i = 0; i < partString.size(); ++i) {
2976 if(partString[i] ==
',') {
2977 partitions.push_back(atoi(number.c_str()));
2981 number += partString[i];
2984 partitions.push_back(atoi(number.c_str()));
2986 parentPhysicalTag = atoi(physicalString.c_str());
2993 Msg::Info(
"Writing '%s'", name.c_str());
2995 std::vector<std::map<int, std::pair<int, std::vector<int> > > > allParts(4);
2996 std::vector<GEntity *> entities;
2998 for(
size_t i = 0; i < entities.size(); i++) {
2999 std::vector<int> physicals = entities[i]->getPhysicalEntities();
3000 for(
size_t j = 0; j < physicals.size(); ++j) {
3001 const std::string phyName =
3003 int parentPhysicalTag;
3004 std::vector<int> partitions;
3006 allParts[entities[i]->dim()].insert
3007 (std::make_pair(physicals[j],
3008 std::make_pair(parentPhysicalTag, partitions)));
3013 FILE *fp =
Fopen(name.c_str(),
"w");
3015 Msg::Error(
"Could not open file '%s'", name.c_str());
3019 fprintf(fp,
"Group{\n");
3020 fprintf(fp,
" // Part~{dim}~{parentPhysicalTag}~{part1}~{part2}~...\n\n");
3021 std::vector<std::map<int, std::string> > tagToString(4);
3022 for(
size_t i = 4; i > 0; --i) {
3023 fprintf(fp,
" // Dim %lu\n", i - 1);
3024 for(
auto it = allParts[i - 1].begin(); it != allParts[i - 1].end(); ++it) {
3025 std::string partName =
"Part~{" + std::to_string(i - 1) +
"}~{" +
3026 std::to_string(it->second.first) +
"}";
3027 fprintf(fp,
" Part~{%lu}~{%d}", i - 1, it->second.first);
3028 for(
size_t j = 0; j < it->second.second.size(); ++j) {
3029 partName +=
"~{" + std::to_string(it->second.second[j]) +
"}";
3030 fprintf(fp,
"~{%d}", it->second.second[j]);
3032 tagToString[i - 1].insert(std::make_pair(it->first, partName));
3033 fprintf(fp,
" = Region[{%d}];\n", it->first);
3038 fprintf(fp,
" // Global names\n\n");
3039 std::map<int, std::vector<int> > omegas;
3040 std::map<std::pair<int, int>, std::vector<int> > sigmasij;
3041 std::map<int, std::vector<int> > sigmas;
3042 std::map<int, std::set<int> > neighbors;
3043 std::size_t omegaDim = 0;
3044 for(
size_t i = 4; i > 0; --i) {
3045 if(allParts[i - 1].size() != 0) {
3052 for(
auto it = allParts[omegaDim].begin(); it != allParts[omegaDim].end();
3054 if(it->second.second.size() == 1) {
3055 omegas[it->second.second[0]].push_back(it->first);
3058 fprintf(fp,
" // Omega\n");
3059 for(
auto it = omegas.begin(); it != omegas.end(); ++it) {
3060 fprintf(fp,
" Omega~{%d} = Region[{", it->first);
3061 for(
size_t j = 0; j < it->second.size(); ++j) {
3063 fprintf(fp,
"%s", tagToString[omegaDim][it->second[j]].c_str());
3065 fprintf(fp,
", %s", tagToString[omegaDim][it->second[j]].c_str());
3067 fprintf(fp,
"}];\n");
3073 for(
auto it = allParts[omegaDim - 1].begin();
3074 it != allParts[omegaDim - 1].end(); ++it) {
3075 if(it->second.second.size() == 2) {
3076 sigmasij[std::make_pair(it->second.second[0],
3077 it->second.second[1])]
3078 .push_back(it->first);
3079 sigmasij[std::make_pair(it->second.second[1],
3080 it->second.second[0])]
3081 .push_back(it->first);
3082 sigmas[it->second.second[0]].push_back(it->first);
3083 sigmas[it->second.second[1]].push_back(it->first);
3086 fprintf(fp,
" // Sigma\n");
3087 for(
auto it = sigmasij.begin(); it != sigmasij.end(); ++it) {
3088 fprintf(fp,
" Sigma~{%d}~{%d} = Region[{", it->first.first,
3090 for(
size_t j = 0; j < it->second.size(); ++j) {
3092 fprintf(fp,
"%s", tagToString[omegaDim - 1][it->second[j]].c_str());
3094 fprintf(fp,
", %s", tagToString[omegaDim - 1][it->second[j]].c_str());
3096 fprintf(fp,
"}];\n");
3100 for(
auto it = sigmas.begin(); it != sigmas.end(); ++it) {
3101 fprintf(fp,
" Sigma~{%d} = Region[{", it->first);
3102 for(
size_t j = 0; j < it->second.size(); ++j) {
3104 fprintf(fp,
"%s", tagToString[omegaDim - 1][it->second[j]].c_str());
3106 fprintf(fp,
", %s", tagToString[omegaDim - 1][it->second[j]].c_str());
3108 fprintf(fp,
"}];\n");
3114 fprintf(fp,
" D() = {");
3116 if(i != 1) fprintf(fp,
", ");
3117 fprintf(fp,
"%lu", i);
3119 fprintf(fp,
"};\n");
3123 for(
auto it = allParts[omegaDim - 1].begin();
3124 it != allParts[omegaDim - 1].end(); ++it) {
3125 if(it->second.second.size() == 2) {
3126 neighbors[it->second.second[0]].insert(it->second.second[1]);
3127 neighbors[it->second.second[1]].insert(it->second.second[0]);
3131 fprintf(fp,
" D~{%lu}() = {", i);
3132 for(
auto it = neighbors[i].begin(); it != neighbors[i].end(); ++it) {
3133 if(it != neighbors[i].begin()) fprintf(fp,
", ");
3134 fprintf(fp,
"%d", *it);
3136 fprintf(fp,
"};\n");
3140 fprintf(fp,
"}\n\n");
3144 Msg::Info(
"Done writing '%s'", name.c_str());