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,
nullptr);
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(
nullptr, problem, kCCMIOCellType, &i, &next)
261 CCMIOReadOptstr(
nullptr, next,
"MaterialType", &size,
nullptr)
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(
nullptr, problem, kCCMIOBoundaryRegion, &k, &boundary)
288 label foamPatchi = -1;
295 CCMIOReadOpti(
nullptr, 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];
331 char*
s =
new char[size + 1];
332 CCMIOReadOptstr(
nullptr, boundary,
"BoundaryType", &size, s);
334 foamPatchTypes[foamPatchi] = string::validate<word>(
string(s));
359 char* name =
new char[size + 1];
360 CCMIOReadOptstr(
nullptr, boundary,
"BoundaryName", &size, name);
362 foamPatchNames[foamPatchi] =
363 string::validate<word>(
string(name));
368 CCMIOReadOptstr(
nullptr, boundary,
"Label", &size,
nullptr)
372 char* name =
new char[size + 1];
373 CCMIOReadOptstr(
nullptr, boundary,
"Label", &size, name);
375 foamPatchNames[foamPatchi] =
376 string::validate<word>(
string(name));
381 foamPatchNames[foamPatchi] =
382 foamPatchTypes[foamPatchi]
384 Pout<<
"Made up name:" << foamPatchNames[foamPatchi]
388 Pout<<
"Read patch:" << foamPatchi
389 <<
" name:" << foamPatchNames[foamPatchi]
390 <<
" foamPatchTypes:" << foamPatchTypes[foamPatchi]
420 CCMIOGetEntity(&err, topology, kCCMIOCells, 0, &
id);
422 CCMIOEntitySize(&err,
id, &nCells,
nullptr);
424 std::vector<int> mapData(nCells);
425 std::vector<int> cellType(nCells);
428 CCMIOReadCells(&err,
id, &mapID, &cellType[0], 0, nCells);
429 CCMIOReadMap(&err, mapID, &mapData[0], 0, nCells);
430 CheckError(err,
"Error reading cells");
436 foamCellMap[i] = mapData[i];
437 foamCellType[i] = cellType[i];
444 CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &
id);
445 CCMIOSize nInternalFaces;
446 CCMIOEntitySize(&err,
id, &nInternalFaces,
nullptr);
447 Pout<<
"nInternalFaces:" << nInternalFaces <<
endl;
450 label foamNFaces = nInternalFaces;
454 CCMIONextEntity(
nullptr, topology, kCCMIOBoundaryFaces, &index, &
id)
459 CCMIOEntitySize(&err,
id, &size,
nullptr);
461 Pout<<
"Read kCCMIOBoundaryFaces entry with " << size
462 <<
" faces." <<
endl;
464 foamPatchStarts.
append(foamNFaces);
465 foamPatchSizes.
append(size);
471 Pout<<
"patchSizes:" << foamPatchSizes <<
endl;
472 Pout<<
"patchStarts:" << foamPatchStarts <<
endl;
473 Pout<<
"nFaces:" << foamNFaces <<
endl;
475 mapData.resize(nInternalFaces);
476 CCMIOGetEntity(&err, topology, kCCMIOInternalFaces, 0, &
id);
478 CCMIOReadFaces(&err,
id, kCCMIOInternalFaces,
nullptr, &size,
nullptr,
479 kCCMIOStart, kCCMIOEnd);
480 std::vector<int> faces(size);
481 CCMIOReadFaces(&err,
id, kCCMIOInternalFaces, &mapID,
nullptr, &faces[0],
482 kCCMIOStart, kCCMIOEnd);
483 std::vector<int> faceCells(2*nInternalFaces);
484 CCMIOReadFaceCells(&err,
id, kCCMIOInternalFaces, &faceCells[0],
485 kCCMIOStart, kCCMIOEnd);
486 CCMIOReadMap(&err, mapID, &mapData[0], kCCMIOStart, kCCMIOEnd);
487 CheckError(err,
"Error reading internal faces");
490 foamFaceMap.
setSize(foamNFaces);
493 foamNeighbour.
setSize(foamNFaces);
495 unsigned int pos = 0;
497 for (
unsigned int facei = 0; facei < nInternalFaces; facei++)
499 foamFaceMap[facei] = mapData[facei];
500 foamOwner[facei] = faceCells[2*facei];
501 foamNeighbour[facei] = faceCells[2*facei+1];
502 face& f = foamFaces[facei];
507 f[fp] = faces[pos++];
518 CCMIONextEntity(
nullptr, topology, kCCMIOBoundaryFaces, &index, &
id)
523 CCMIOEntitySize(&err,
id, &nFaces,
nullptr);
525 mapData.resize(nFaces);
526 faceCells.resize(nFaces);
527 CCMIOReadFaces(&err,
id, kCCMIOBoundaryFaces,
nullptr, &size,
nullptr,
528 kCCMIOStart, kCCMIOEnd);
550 CCMIOReadMap(&err, mapID, &mapData[0], kCCMIOStart, kCCMIOEnd);
551 CheckError(err,
"Error reading boundary faces");
557 CCMIOReadOpti(
nullptr,
id,
"ProstarRegionNumber", &prostarI)
561 Pout<<
"For region:" << regionI
562 <<
" found ProstarRegionNumber:" << prostarI <<
endl;
568 Pout<<
"For region:" << regionI
569 <<
" did not find ProstarRegionNumber entry. Assuming " 572 prostarToFoamPatch.
insert(prostarI, regionI);
575 Pout<<
"region:" << regionI
576 <<
" ProstarRegionNumber:" << prostarI
577 <<
" foamPatchStart:" 578 << foamPatchStarts[regionI]
580 << foamPatchSizes[regionI]
584 unsigned int pos = 0;
586 for (
unsigned int i = 0; i < nFaces; i++)
588 label foamFacei = foamPatchStarts[regionI] + i;
590 foamFaceMap[foamFacei] = mapData[i];
591 foamOwner[foamFacei] = faceCells[i];
592 foamNeighbour[foamFacei] = -1;
593 face& f = foamFaces[foamFacei];
598 f[fp] = faces[pos++];
609 int main(
int argc,
char *argv[])
613 "read CCM files as written by proSTAR/ccm\n" 614 " - does not handle 'interfaces' (couples), cyclics or data\n" 615 " - does not handle mesh regions (porosity, solids, ...)\n" 652 const word ccmExt = ccmFile.
ext();
657 <<
"Cannot read file " << ccmFile
661 if (ccmExt !=
"ccm" && ccmExt !=
"ccmg")
664 <<
"Illegal extension " << ccmExt <<
" for file " << ccmFile
665 <<
nl <<
"Allowed extensions are '.ccm', '.ccmg'" 673 CCMIOError err = CCMIOOpenFile
686 CCMIONextEntity(&err, root, kCCMIOState, &stateI, &state);
687 CheckError(err,
"Error opening state");
690 CCMIOEntityDescription(&err, state, &size,
nullptr);
691 char *desc =
new char[size + 1];
692 CCMIOEntityDescription(&err, state,
nullptr, desc);
693 Pout<<
"Reading state '" << kDefaultState <<
"' (" << desc <<
")" 701 CCMIONextEntity(&err, state, kCCMIOProcessor, &i, &processor);
702 CCMIOID solution,
vertices, topology;
713 if (err != kCCMIONoErr)
726 if (err != kCCMIONoErr)
729 <<
"Could not read the file." 734 ReadVertices(err, vertices, foamPointMap, foamPoints);
736 Pout<<
"nPoints:" << foamPoints.
size() << endl
737 <<
"bounding box:" <<
boundBox(foamPoints) << endl
755 Pout<<
"nCells:" << foamCellMap.
size() << endl
756 <<
"nFaces:" << foamOwner.
size() << endl
757 <<
"nPatches:" << foamPatchStarts.
size() << endl
758 <<
"nInternalFaces:" << foamPatchStarts[0] << endl
769 foamPatchTypes[i] =
"patch";
780 kCCMIOProblemDescription,
784 CheckError(err,
"Error stepping to first problem description");
786 if (CCMIOIsValidEntity(problem))
801 CCMIOCloseFile(&err, vertices);
802 CCMIOCloseFile(&err, topology);
803 CCMIOCloseFile(&err, solution);
804 CCMIOCloseFile(&err, root);
808 Pout<<
"foamPatchNames:" << foamPatchNames <<
endl;
811 Pout<<
"foamOwner : min:" <<
min(foamOwner)
812 <<
" max:" <<
max(foamOwner)
814 <<
"foamNeighbour : min:" <<
min(foamNeighbour)
815 <<
" max:" <<
max(foamNeighbour)
817 <<
"foamCellType : min:" <<
min(foamCellType)
818 <<
" max:" <<
max(foamCellType)
832 label maxCCMPointi =
max(foamPointMap);
843 label maxCCMCelli =
max(foamCellMap);
862 forAll(foamNeighbour, facei)
864 label nbr = foamNeighbour[facei];
865 label own = foamOwner[facei];
867 if (nbr >= foamCellType.
size() || own >= foamCellType.
size())
873 <<
" nCells:" << foamCellType.
size()
881 foamOwner[facei] = foamNeighbour[facei];
882 foamNeighbour[facei] = own;
883 foamFaces[facei].flip();
889 const face& f = foamFaces[facei];
893 if (f[fp] < 0 || f[fp] >= foamPoints.
size())
908 primitiveMesh::calcCells
960 label meshFacei = foamPatchStarts[0];
964 const word& patchName = foamPatchNames[
patchi];
965 const word& patchType = foamPatchTypes[
patchi];
967 Pout<<
"Patch:" << patchName <<
" start at:" << meshFacei
968 <<
" size:" << foamPatchSizes[
patchi]
969 <<
" end at:" << meshFacei+foamPatchSizes[
patchi]
972 if (patchType ==
"wall")
985 else if (patchType ==
"symmetryplane")
998 else if (patchType ==
"empty")
1028 meshFacei += foamPatchSizes[
patchi];
1031 if (meshFacei != foamOwner.
size())
1034 <<
"meshFacei:" << meshFacei
1035 <<
" nFaces:" << foamOwner.
size()
1048 if (maxType > minType)
1055 forAll(foamCellType, celli)
1060 foamCellType[celli],
1069 label nValidCellZones = 0;
1073 label type = iter.key();
1074 label zoneI = iter();
1076 zoneCells[zoneI].shrink();
1078 word zoneName =
"cellZone_" +
name(type);
1080 Info<<
"Writing zone " << type
1081 <<
" size " << zoneCells[zoneI].size()
1083 << zoneName <<
" and cellSet " << zoneName
1106 Info<<
"Writing mesh to " <<
mesh.objectRegistry::relativeObjectPath()
1125 forAll(foamCellMap, celli)
1127 cellIdField[celli] = foamCellMap[celli];
1145 forAll(foamCellType, celli)
1147 cellTypeField[celli] = foamCellType[celli];
1150 Info<<
"Writing cellIds as volScalarField to " 1151 << cellIdField.relativeObjectPath() <<
"..." <<
nl <<
endl;
Symmetry patch for non-planar or multi-plane patches.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
A class for handling file names.
bool set(const label) const
Is element set.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
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
const meshCellZones & cellZones() const
Return cell zones.
void addFvPatches(const List< polyPatch *> &, const bool validBoundary=true)
Add boundary patches. Constructor helper.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
A list that is sorted upon construction or when explicitly requested with the sort() method...
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
void size(const label)
Override size to be inconsistent with allocated storage.
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.
const dimensionSet dimless
void clear()
Clear the zones.
virtual bool write(const bool write=true) const
Write mesh using IO settings from time.
word ext() const
Return file name extension (part after last .)
label size() const
Return number of elements in table.
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.
pointField vertices(const blockVertexList &bvl)
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 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
bool found(const Key &) const
Return true if hashedEntry is found in table.
A class for handling words, derived from string.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
static const word null
An empty word.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
faceListList boundary(nPatches)
errorManip< error > abort(error &err)
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
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.
word name(const complex &)
Return a string representation of a complex.
void setSize(const label)
Reset size of List.
writeOption writeOpt() const
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A collection of cell labels.
prefixOSstream Pout(cout, "Pout")
Mesh data needed to do the Finite Volume discretisation.
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.