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;
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);
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);
713 if (err != kCCMIONoErr)
726 if (err != kCCMIONoErr)
729 <<
"Could not read the file."
734 ReadVertices(err,
vertices, foamPointMap, foamPoints);
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))
802 CCMIOCloseFile(&err, topology);
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")
1008 mesh.boundaryMesh(),
1023 mesh.boundaryMesh(),
1028 meshFacei += foamPatchSizes[
patchi];
1031 if (meshFacei != foamOwner.
size())
1034 <<
"meshFacei:" << meshFacei
1035 <<
" nFaces:" << foamOwner.
size()
1038 mesh.addFvPatches(newPatches);
1048 if (maxType > minType)
1055 forAll(foamCellType, celli)
1060 foamCellType[celli],
1066 mesh.cellZones().clear();
1067 mesh.cellZones().setSize(typeToZone.
size());
1069 label nValidCellZones = 0;
1074 label zoneI = iter();
1076 zoneCells[zoneI].shrink();
1081 <<
" size " << zoneCells[zoneI].size()
1083 << zoneName <<
" and cellSet " << zoneName
1086 cellSet cset(mesh, zoneName, zoneCells[zoneI]);
1089 mesh.cellZones().set
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;
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Generic GeometricField class.
label size() const
Return number of elements in table.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
bool found(const Key &) const
Return true if hashedEntry is found in table.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
virtual Ostream & write(const char)=0
Write character.
A list that is sorted upon construction or when explicitly requested with the sort() method.
iterator begin()
Return an iterator to begin traversing the UList.
static void addNote(const string &)
Add extra notes for the usage information.
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.
A collection of cell labels.
Empty front and back plane patch. Used for 2-D geometries.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
word ext() const
Return file name extension (part after last .)
Mesh data needed to do the Finite Volume discretisation.
static word defaultRegion
Return the default region name.
A patch is a list of labels that address the faces in the global face list.
Selector class for relaxation factors, solver type and solution.
A class for handling character strings derived from std::string.
Symmetry patch for non-planar or multi-plane patches.
A class for handling words, derived from string.
static const word null
An empty word.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
int main(int argc, char *argv[])
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.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
bool isFile(const fileName &, const bool checkVariants=true, const bool followLink=true)
Does the name exist as a file in the file system?
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensionedScalar pos(const dimensionedScalar &ds)
pointField vertices(const blockVertexList &bvl)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
errorManip< error > abort(error &err)
const dimensionSet dimless
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
prefixOSstream Pout(cout, "Pout")
void offset(label &lst, const label o)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
void inplaceReorder(const labelUList &oldToNew, ListType &)
Inplace reorder the elements of a list.
faceListList boundary(nPatches)
Foam::argList args(argc, argv)
static iteratorEnd end()
iteratorEnd set to beyond the end of any HashTable