53 static char const kDefaultState[] =
"default";
54 static int const kVertOffset = 2;
78 label faceI = cFaces[i];
80 label nbrCellI = neighbour[faceI];
85 if (nbrCellI == cellI)
87 nbrCellI = owner[faceI];
114 oldToNew[cFaces[nbr.indices()[i]]] = newFaceI++;
120 for (
label faceI = newFaceI; faceI < owner.
size(); faceI++)
122 oldToNew[faceI] = faceI;
132 const label cellType,
141 if (zoneFnd == typeToZone.end())
144 zoneCells.setSize(zoneCells.size() + 1);
146 label zoneI = zoneCells.size()-1;
148 Info<<
"Mapping type " << cellType <<
" to Foam cellZone "
150 typeToZone.insert(cellType, zoneI);
152 zoneCells[zoneI].append(cellI);
157 zoneCells[zoneFnd()].append(cellI);
163 void CheckError(CCMIOError
const &err,
const Foam::string& str)
165 if (err != kCCMIONoErr)
189 CCMIOEntitySize(&err, vertices, &nVertices, NULL);
195 int offsetPlusSize = offset+nVertices;
202 &err, vertices, &dims, &scale, &mapID, verts.begin(),
203 offset, offsetPlusSize
205 CCMIOReadMap(&err, mapID, mapData.begin(), offset, offsetPlusSize);
215 foamPoints.setSize(nVertices);
217 foamPointMap.
setSize(nVertices);
221 foamPointMap[i] = mapData[i];
222 for (
direction cmpt = 0; cmpt < dims; cmpt++)
224 foamPoints[i][cmpt] = verts[dims*i + cmpt]*scale;
246 CCMIONextEntity(NULL, problem, kCCMIOCellType, &i, &next)
261 CCMIOReadOptstr(NULL, next,
"MaterialType", &size, NULL)
265 name =
new char[size + 1];
266 CCMIOReadOptstr(&err, next,
"MaterialType", &size,
name);
267 CCMIOGetEntityIndex(&err, next, &cellType);
269 foamCellTypeNames.insert(cellType,
name);
270 Pout<<
"Celltype:" << cellType <<
" name:" <<
name <<
endl;
283 CCMIONextEntity(NULL, problem, kCCMIOBoundaryRegion, &
k, &
boundary)
288 label foamPatchI = -1;
295 CCMIOReadOpti(NULL,
boundary,
"ProstarRegionNumber", &prostarI)
299 Pout<<
"For region:" << regionI
300 <<
" found ProstarRegionNumber:" << prostarI <<
endl;
306 Pout<<
"For region:" << regionI
307 <<
"did not find ProstarRegionNumber entry. Assuming "
312 if (prostarToFoamPatch.found(prostarI))
314 foamPatchI = prostarToFoamPatch[prostarI];
321 CCMIOReadOptstr(NULL,
boundary,
"BoundaryType", &size, NULL)
325 char*
s =
new char[size + 1];
326 CCMIOReadOptstr(NULL,
boundary,
"BoundaryType", &size,
s);
328 foamPatchTypes[foamPatchI] = string::validate<word>(
string(
s));
343 CCMIOReadOptstr(NULL,
boundary,
"BoundaryName", &size, NULL)
347 char*
name =
new char[size + 1];
348 CCMIOReadOptstr(NULL,
boundary,
"BoundaryName", &size,
name);
350 foamPatchNames[foamPatchI] =
351 string::validate<word>(
string(
name));
356 CCMIOReadOptstr(NULL,
boundary,
"Label", &size, NULL)
360 char*
name =
new char[size + 1];
363 foamPatchNames[foamPatchI] =
364 string::validate<word>(
string(
name));
369 foamPatchNames[foamPatchI] =
370 foamPatchTypes[foamPatchI]
372 Pout<<
"Made up name:" << foamPatchNames[foamPatchI]
376 Pout<<
"Read patch:" << foamPatchI
377 <<
" name:" << foamPatchNames[foamPatchI]
378 <<
" foamPatchTypes:" << foamPatchTypes[foamPatchI]
408 CCMIOGetEntity(&err, topology, kCCMIOCells, 0, &
id);
410 CCMIOEntitySize(&err,
id, &nCells, NULL);
412 std::vector<int> mapData(nCells);
413 std::vector<int> cellType(nCells);
416 CCMIOReadCells(&err,
id, &mapID, &cellType[0], 0, nCells);
417 CCMIOReadMap(&err, mapID, &mapData[0], 0, nCells);
418 CheckError(err,
"Error reading cells");
424 foamCellMap[i] = mapData[i];
425 foamCellType[i] = cellType[i];
432 CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &
id);
433 CCMIOSize nInternalFaces;
434 CCMIOEntitySize(&err,
id, &nInternalFaces, NULL);
435 Pout<<
"nInternalFaces:" << nInternalFaces <<
endl;
438 label foamNFaces = nInternalFaces;
442 CCMIONextEntity(NULL, topology, kCCMIOBoundaryFaces, &index, &
id)
447 CCMIOEntitySize(&err,
id, &size, NULL);
449 Pout<<
"Read kCCMIOBoundaryFaces entry with " << size
450 <<
" faces." <<
endl;
452 foamPatchStarts.
append(foamNFaces);
453 foamPatchSizes.
append(size);
459 Pout<<
"patchSizes:" << foamPatchSizes <<
endl;
460 Pout<<
"patchStarts:" << foamPatchStarts <<
endl;
461 Pout<<
"nFaces:" << foamNFaces <<
endl;
463 mapData.resize(nInternalFaces);
464 CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &
id);
466 CCMIOReadFaces(&err,
id, kCCMIOInternalFaces, NULL, &size, NULL,
467 kCCMIOStart, kCCMIOEnd);
468 std::vector<int> faces(size);
469 CCMIOReadFaces(&err,
id, kCCMIOInternalFaces, &mapID, NULL, &faces[0],
470 kCCMIOStart, kCCMIOEnd);
471 std::vector<int> faceCells(2*nInternalFaces);
472 CCMIOReadFaceCells(&err,
id, kCCMIOInternalFaces, &faceCells[0],
473 kCCMIOStart, kCCMIOEnd);
474 CCMIOReadMap(&err, mapID, &mapData[0], kCCMIOStart, kCCMIOEnd);
475 CheckError(err,
"Error reading internal faces");
478 foamFaceMap.
setSize(foamNFaces);
481 foamNeighbour.
setSize(foamNFaces);
483 unsigned int pos = 0;
485 for (
unsigned int faceI = 0; faceI < nInternalFaces; faceI++)
487 foamFaceMap[faceI] = mapData[faceI];
488 foamOwner[faceI] = faceCells[2*faceI];
489 foamNeighbour[faceI] = faceCells[2*faceI+1];
490 face&
f = foamFaces[faceI];
495 f[fp] = faces[
pos++];
506 CCMIONextEntity(NULL, topology, kCCMIOBoundaryFaces, &index, &
id)
511 CCMIOEntitySize(&err,
id, &nFaces, NULL);
513 mapData.resize(nFaces);
514 faceCells.resize(nFaces);
515 CCMIOReadFaces(&err,
id, kCCMIOBoundaryFaces, NULL, &size, NULL,
516 kCCMIOStart, kCCMIOEnd);
518 CCMIOReadFaces(&err,
id, kCCMIOBoundaryFaces, &mapID, NULL, &faces[0],
519 kCCMIOStart, kCCMIOEnd);
520 CCMIOReadFaceCells(&err,
id, kCCMIOBoundaryFaces, &faceCells[0],
521 kCCMIOStart, kCCMIOEnd);
522 CCMIOReadMap(&err, mapID, &mapData[0], kCCMIOStart, kCCMIOEnd);
523 CheckError(err,
"Error reading boundary faces");
529 CCMIOReadOpti(NULL,
id,
"ProstarRegionNumber", &prostarI)
533 Pout<<
"For region:" << regionI
534 <<
" found ProstarRegionNumber:" << prostarI <<
endl;
540 Pout<<
"For region:" << regionI
541 <<
" did not find ProstarRegionNumber entry. Assuming "
544 prostarToFoamPatch.insert(prostarI, regionI);
547 Pout<<
"region:" << regionI
548 <<
" ProstarRegionNumber:" << prostarI
549 <<
" foamPatchStart:"
550 << foamPatchStarts[regionI]
552 << foamPatchSizes[regionI]
556 unsigned int pos = 0;
558 for (
unsigned int i = 0; i < nFaces; i++)
560 label foamFaceI = foamPatchStarts[regionI] + i;
562 foamFaceMap[foamFaceI] = mapData[i];
563 foamOwner[foamFaceI] = faceCells[i];
564 foamNeighbour[foamFaceI] = -1;
565 face&
f = foamFaces[foamFaceI];
570 f[fp] = faces[
pos++];
581 int main(
int argc,
char *argv[])
585 "read CCM files as written by proSTAR/ccm\n"
586 " - does not handle 'interfaces' (couples), cyclics or data\n"
587 " - does not handle mesh regions (porosity, solids, ...)\n"
624 const word ccmExt = ccmFile.
ext();
629 <<
"Cannot read file " << ccmFile
633 if (ccmExt !=
"ccm" && ccmExt !=
"ccmg")
636 <<
"Illegal extension " << ccmExt <<
" for file " << ccmFile
637 <<
nl <<
"Allowed extensions are '.ccm', '.ccmg'"
645 CCMIOError err = CCMIOOpenFile
658 CCMIONextEntity(&err, root, kCCMIOState, &stateI, &state);
659 CheckError(err,
"Error opening state");
662 CCMIOEntityDescription(&err, state, &size, NULL);
663 char *desc =
new char[size + 1];
664 CCMIOEntityDescription(&err, state, NULL, desc);
665 Pout<<
"Reading state '" << kDefaultState <<
"' (" << desc <<
")"
673 CCMIONextEntity(&err, state, kCCMIOProcessor, &i, &processor);
674 CCMIOID
solution, vertices, topology;
685 if (err != kCCMIONoErr)
698 if (err != kCCMIONoErr)
701 <<
"Could not read the file."
706 ReadVertices(err, vertices, foamPointMap, foamPoints);
708 Pout<<
"nPoints:" << foamPoints.size() <<
endl
728 <<
"nFaces:" << foamOwner.
size() <<
endl
729 <<
"nPatches:" << foamPatchStarts.size() <<
endl
730 <<
"nInternalFaces:" << foamPatchStarts[0] <<
endl
735 foamPatchTypes.
setSize(foamPatchStarts.size());
736 foamPatchNames.
setSize(foamPatchStarts.size());
741 foamPatchTypes[i] =
"patch";
752 kCCMIOProblemDescription,
756 CheckError(err,
"Error stepping to first problem description");
758 if (CCMIOIsValidEntity(problem))
773 CCMIOCloseFile(&err, vertices);
774 CCMIOCloseFile(&err, topology);
776 CCMIOCloseFile(&err, root);
780 Pout<<
"foamPatchNames:" << foamPatchNames <<
endl;
783 Pout<<
"foamOwner : min:" <<
min(foamOwner)
784 <<
" max:" <<
max(foamOwner)
786 <<
"foamNeighbour : min:" <<
min(foamNeighbour)
787 <<
" max:" <<
max(foamNeighbour)
789 <<
"foamCellType : min:" <<
min(foamCellType)
790 <<
" max:" <<
max(foamCellType)
804 label maxCCMPointI =
max(foamPointMap);
815 label maxCCMCellI =
max(foamCellMap);
834 forAll(foamNeighbour, faceI)
836 label nbr = foamNeighbour[faceI];
837 label own = foamOwner[faceI];
839 if (nbr >= foamCellType.
size() || own >= foamCellType.
size())
845 <<
" nCells:" << foamCellType.
size()
853 foamOwner[faceI] = foamNeighbour[faceI];
854 foamNeighbour[faceI] = own;
855 foamFaces[faceI].flip();
861 const face&
f = foamFaces[faceI];
865 if (
f[fp] < 0 ||
f[fp] >= foamPoints.size())
923 xferMove<pointField>(foamPoints),
924 xferMove<faceList>(foamFaces),
925 xferCopy<labelList>(foamOwner),
926 xferMove<labelList>(foamNeighbour)
932 label meshFaceI = foamPatchStarts[0];
934 forAll(newPatches, patchI)
936 const word& patchName = foamPatchNames[patchI];
937 const word& patchType = foamPatchTypes[patchI];
939 Pout<<
"Patch:" << patchName <<
" start at:" << meshFaceI
940 <<
" size:" << foamPatchSizes[patchI]
941 <<
" end at:" << meshFaceI+foamPatchSizes[patchI]
944 if (patchType ==
"wall")
950 foamPatchSizes[patchI],
957 else if (patchType ==
"symmetryplane")
963 foamPatchSizes[patchI],
970 else if (patchType ==
"empty")
977 foamPatchSizes[patchI],
992 foamPatchSizes[patchI],
1000 meshFaceI += foamPatchSizes[patchI];
1003 if (meshFaceI != foamOwner.
size())
1006 <<
"meshFaceI:" << meshFaceI
1007 <<
" nFaces:" << foamOwner.
size()
1020 if (maxType > minType)
1027 forAll(foamCellType, cellI)
1032 foamCellType[cellI],
1041 label nValidCellZones = 0;
1046 label zoneI = iter();
1048 zoneCells[zoneI].shrink();
1053 <<
" size " << zoneCells[zoneI].size()
1055 << zoneName <<
" and cellSet " << zoneName
1078 Info<<
"Writing mesh to " <<
mesh.objectRegistry::objectPath()
1097 forAll(foamCellMap, cellI)
1099 cellIdField[cellI] = foamCellMap[cellI];
1117 forAll(foamCellType, cellI)
1119 cellTypeField[cellI] = foamCellType[cellI];
1122 Info<<
"Writing cellIds as volScalarField to " << cellIdField.objectPath()