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);
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];
361 CCMIOReadOptstr(NULL, boundary,
"Label", &size, name);
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
709 <<
"bounding box:" <<
boundBox(foamPoints) << endl
727 Pout<<
"nCells:" << foamCellMap.
size() << endl
728 <<
"nFaces:" << foamOwner.
size() << endl
729 <<
"nPatches:" << foamPatchStarts.
size() << endl
730 <<
"nInternalFaces:" << foamPatchStarts[0] << endl
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);
775 CCMIOCloseFile(&err, solution);
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())
880 primitiveMesh::calcCells
923 xferMove<pointField>(foamPoints),
924 xferMove<faceList>(foamFaces),
925 xferCopy<labelList>(foamOwner),
926 xferMove<labelList>(foamNeighbour)
932 label meshFacei = foamPatchStarts[0];
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")
957 else if (patchType ==
"symmetryplane")
970 else if (patchType ==
"empty")
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;
1045 label type = iter.key();
1046 label zoneI = iter();
1048 zoneCells[zoneI].shrink();
1050 word zoneName =
"cellZone_" +
name(type);
1052 Info<<
"Writing zone " << type
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()
Symmetry patch for non-planar or multi-plane patches.
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
A class for handling file names.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
void clear()
Clear the zones.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A list that is sorted upon construction or when explicitly requested with the sort() method...
void size(const label)
Override size to be inconsistent with allocated storage.
bool isFile(const fileName &, const bool checkGzip=true)
Does the name exist as a FILE in the file system?
static word defaultRegion
Return the default region name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static void noParallel()
Remove the parallel options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
A bounding box defined in terms of the points at its extremities.
label size() const
Return number of elements in table.
writeOption writeOpt() const
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
void addFvPatches(const List< polyPatch * > &, const bool validBoundary=true)
Add boundary patches. Constructor helper.
Various functions to operate on Lists.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
A class for handling words, derived from string.
bool set(const label) const
Is element set.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
static const word null
An empty word.
faceListList boundary(nPatches)
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
bool found(const Key &) const
Return true if hashedEntry is found in table.
prefixOSstream Pout(cout,"Pout")
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Empty front and back plane patch. Used for 2-D geometries.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
void setSize(const label)
Reset size of List.
const cellZoneMesh & cellZones() const
Return cell zone mesh.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A collection of cell labels.
Mesh data needed to do the Finite Volume discretisation.
word ext() const
Return file name extension (part after last .)
static void addNote(const string &)
Add extra notes for the usage information.
A patch is a list of labels that address the faces in the global face list.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
A class for handling character strings derived from std::string.
virtual bool write() const
Write mesh using IO settings from time.