52int main(
int argc,
char *argv[])
56 "Convert a CFX 4 mesh to OpenFOAM format"
65 "Geometry scaling factor - default is 1"
75 const scalar scaleFactor =
args.getOrDefault<scalar>(
"scale", 1);
84 label nblock, npatch, nglue, nelem, npoint;
86 cfxFile >> nblock >> npatch >> nglue >> nelem >> npoint;
99 cfxFile >> nx >> ny >> nz;
105 Info<<
"Reading patch definitions" <<
endl;
114 label no, blkNo, patchLabel;
116 forAll(cfxPatchTypes, patchi)
119 cfxFile >> cfxPatchTypes[patchi] >> cfxPatchNames[patchi] >> no;
122 patchRanges[patchi].setSize(6);
123 labelList& curRange = patchRanges[patchi];
127 cfxFile >> curRange[rI];
135 cfxFile >> patchDirections[patchi] >> blkNo >> patchLabel;
137 patchMasterBlocks[patchi] = blkNo - 1;
141 Info<<
"Reading block glueing information" <<
endl;
147 label masterPatch, slavePatch;
148 label dirIndex1, dirIndex2, dirIndex3, joinNumber;
150 for (label glueI = 0; glueI < nglue; glueI++)
152 cfxFile >> masterPatch >> slavePatch;
153 cfxFile >> dirIndex1 >> dirIndex2 >> dirIndex3 >> joinNumber;
155 glueMasterPatches[glueI] = masterPatch - 1;
156 glueSlavePatches[glueI] = slavePatch - 1;
160 Info<<
"Reading block points" <<
endl;
164 Info<<
"block " << blockI <<
" is a ";
165 blocks[blockI].readPoints(cfxFile);
168 Info<<
"Calculating block offsets" <<
endl;
174 label nMeshPoints =
blocks[0].nBlockPoints();
175 label nMeshCells =
blocks[0].nBlockCells();
177 for (label blockI = 1; blockI < nblock; blockI++)
179 nMeshPoints +=
blocks[blockI].nBlockPoints();
180 nMeshCells +=
blocks[blockI].nBlockCells();
182 blockOffsets[blockI] =
183 blockOffsets[blockI - 1]
184 +
blocks[blockI - 1].nBlockPoints();
187 Info<<
"Assembling patches" <<
endl;
191 forAll(rawPatches, patchi)
193 const word& patchType = cfxPatchTypes[patchi];
198 patchType ==
"POROUS" || patchType ==
"SOLID"
199 || patchType ==
"SOLCON" || patchType ==
"USER3D"
202 patchMasterBlocks[patchi] = -1;
203 rawPatches[patchi].clear();
209 blocks[patchMasterBlocks[patchi]].patchFaces
211 patchDirections[patchi],
218 Info<<
"Merging points ";
220 labelList pointMergeList(nMeshPoints, -1);
229 forAll(glueMasterPatches, glueI)
231 const label masterPatch = glueMasterPatches[glueI];
232 const label slavePatch = glueSlavePatches[glueI];
234 const label blockPlabel = patchMasterBlocks[masterPatch];
235 const label blockNlabel = patchMasterBlocks[slavePatch];
240 const faceList& blockPFaces = rawPatches[masterPatch];
241 const faceList& blockNFaces = rawPatches[slavePatch];
246 if (blockPFaces.
size() != blockNFaces.
size())
249 <<
"Inconsistent number of faces for glue pair "
250 << glueI <<
" between blocks " << blockPlabel + 1
251 <<
" and " << blockNlabel + 1
260 scalar sqrMergeTol = GREAT;
262 forAll(blockPFaces, blockPFaceLabel)
265 blockPFaces[blockPFaceLabel];
267 forAll(blockPFacePoints, blockPFacePointi)
269 forAll(blockPFacePoints, blockPFacePointi2)
271 if (blockPFacePointi != blockPFacePointi2)
280 [blockPFacePoints[blockPFacePointi]]
282 [blockPFacePoints[blockPFacePointi2]]
296 forAll(blockPFaces, blockPFaceLabel)
299 blockPFaces[blockPFaceLabel];
302 cp.setSize(blockPFacePoints.
size());
304 forAll(blockPFacePoints, blockPFacePointi)
308 forAll(blockNFaces, blockNFaceLabel)
311 blockNFaces[blockNFaceLabel];
313 forAll(blockNFacePoints, blockNFacePointi)
320 [blockPFacePoints[blockPFacePointi]]
322 [blockNFacePoints[blockNFacePointi]]
330 cp[blockPFacePointi] =
331 blockNFacePoints[blockNFacePointi];
334 blockPFacePoints[blockPFacePointi]
335 + blockOffsets[blockPlabel];
338 blockNFacePoints[blockNFacePointi]
339 + blockOffsets[blockNlabel];
341 label minPN =
Foam::min(PpointLabel, NpointLabel);
343 if (pointMergeList[PpointLabel] != -1)
345 minPN =
Foam::min(minPN, pointMergeList[PpointLabel]);
348 if (pointMergeList[NpointLabel] != -1)
350 minPN =
Foam::min(minPN, pointMergeList[NpointLabel]);
353 pointMergeList[PpointLabel]
354 = pointMergeList[NpointLabel]
367 bool changedPointMerge =
false;
372 changedPointMerge =
false;
375 forAll(glueMasterPatches, glueI)
377 const label masterPatch = glueMasterPatches[glueI];
378 const label slavePatch = glueSlavePatches[glueI];
380 const label blockPlabel = patchMasterBlocks[masterPatch];
381 const label blockNlabel = patchMasterBlocks[slavePatch];
383 const faceList& blockPFaces = rawPatches[masterPatch];
387 forAll(blockPFaces, blockPFaceLabel)
390 blockPFaces[blockPFaceLabel];
397 blockPFacePoints[blockPFacePointi]
398 + blockOffsets[blockPlabel];
402 + blockOffsets[blockNlabel];
406 pointMergeList[PpointLabel]
407 != pointMergeList[NpointLabel]
410 changedPointMerge =
true;
412 pointMergeList[PpointLabel]
413 = pointMergeList[NpointLabel]
416 pointMergeList[PpointLabel],
417 pointMergeList[NpointLabel]
425 while (changedPointMerge && nPasses < 8);
428 if (changedPointMerge ==
true)
431 <<
"Point merging failed after max number of passes."
436 forAll(glueMasterPatches, glueI)
438 const label masterPatch = glueMasterPatches[glueI];
439 const label slavePatch = glueSlavePatches[glueI];
441 const label blockPlabel = patchMasterBlocks[masterPatch];
442 const label blockNlabel = patchMasterBlocks[slavePatch];
444 const faceList& blockPFaces = rawPatches[masterPatch];
445 const faceList& blockNFaces = rawPatches[slavePatch];
448 forAll(blockPFaces, blockPFaceLabel)
451 = blockPFaces[blockPFaceLabel];
453 forAll(blockPFacePoints, blockPFacePointi)
456 blockPFacePoints[blockPFacePointi]
457 + blockOffsets[blockPlabel];
459 if (pointMergeList[PpointLabel] == -1)
462 <<
"Unable to merge point " << blockPFacePointi
463 <<
" of face " << blockPFaceLabel
464 <<
" of block " << blockPlabel
470 forAll(blockNFaces, blockNFaceLabel)
473 = blockNFaces[blockNFaceLabel];
475 forAll(blockNFacePoints, blockNFacePointi)
478 blockNFacePoints[blockNFacePointi]
479 + blockOffsets[blockNlabel];
481 if (pointMergeList[NpointLabel] == -1)
484 <<
"Unable to merge point " << blockNFacePointi
485 <<
" of face " << blockNFaceLabel
486 <<
" of block " << blockNlabel
496 label nNewPoints = 0;
498 forAll(pointMergeList, pointLabel)
500 if (pointMergeList[pointLabel] > pointLabel)
508 (pointMergeList[pointLabel] == -1)
509 || pointMergeList[pointLabel] == pointLabel
512 pointMergeList[pointLabel] = nNewPoints;
517 pointMergeList[pointLabel] =
518 pointMergeList[pointMergeList[pointLabel]];
522 nMeshPoints = nNewPoints;
532 forAll(blockPoints, blockPointLabel)
539 + blockOffsets[blockI]
541 ] = blockPoints[blockPointLabel];
546 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
557 label nCreatedCells = 0;
563 forAll(curBlockCells, blockCelli)
565 labelList cellPoints(curBlockCells[blockCelli].size());
567 forAll(cellPoints, pointi)
572 curBlockCells[blockCelli][pointi]
573 + blockOffsets[blockI]
583 Info<<
"Creating boundary patches" <<
endl;
591 label nCreatedPatches = 0;
593 forAll(rawPatches, patchi)
595 if (rawPatches[patchi].size() && cfxPatchTypes[patchi] !=
"BLKBDY")
598 label existingPatch = -1;
600 for (label oldPatchi = 0; oldPatchi < nCreatedPatches; oldPatchi++)
602 if (
patchNames[oldPatchi] == cfxPatchNames[patchi])
604 existingPatch = oldPatchi;
609 const faceList& curRawPatch = rawPatches[patchi];
610 label curBlock = patchMasterBlocks[patchi];
612 if (existingPatch >= 0)
614 Info<<
"CFX patch " << patchi
615 <<
", of type " << cfxPatchTypes[patchi]
616 <<
", name " << cfxPatchNames[patchi]
617 <<
" already exists as OpenFOAM patch " << existingPatch
618 <<
". Adding faces." <<
endl;
621 label oldSize = renumberedPatch.
size();
622 renumberedPatch.
setSize(oldSize + curRawPatch.
size());
624 forAll(curRawPatch, facei)
626 const face& oldFace = curRawPatch[facei];
628 face& newFace = renumberedPatch[oldSize + facei];
637 + blockOffsets[curBlock]
648 forAll(curRawPatch, facei)
650 const face& oldFace = curRawPatch[facei];
652 face& newFace = renumberedPatch[facei];
661 + blockOffsets[curBlock]
666 Info<<
"CFX patch " << patchi
667 <<
", of type " << cfxPatchTypes[patchi]
668 <<
", name " << cfxPatchNames[patchi]
669 <<
" converted into OpenFOAM patch " << nCreatedPatches
672 if (cfxPatchTypes[patchi] ==
"WALL")
676 patchTypes[nCreatedPatches] = wallPolyPatch::typeName;
677 patchNames[nCreatedPatches] = cfxPatchNames[patchi];
680 else if (cfxPatchTypes[patchi] ==
"SYMMET")
684 patchTypes[nCreatedPatches] = symmetryPolyPatch::typeName;
685 patchNames[nCreatedPatches] = cfxPatchNames[patchi];
690 cfxPatchTypes[patchi] ==
"INLET"
691 || cfxPatchTypes[patchi] ==
"OUTLET"
692 || cfxPatchTypes[patchi] ==
"PRESS"
693 || cfxPatchTypes[patchi] ==
"CNDBDY"
694 || cfxPatchTypes[patchi] ==
"USER2D"
699 patchTypes[nCreatedPatches] = polyPatch::typeName;
700 patchNames[nCreatedPatches] = cfxPatchNames[patchi];
706 <<
"Unrecognised CFX patch type "
707 << cfxPatchTypes[patchi]
Input from file stream as an ISstream, normally using std::ifstream for the actual input.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
void setSize(label n)
Alias for resize().
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
void size(const label n)
Older name for setAddressableSize.
Extract command arguments and options from the supplied argc and argv parameters.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
static void noParallel()
Remove the parallel options.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
static void addNote(const string ¬e)
Add extra notes for the usage information.
Maps a geometry to a set of cell primitives.
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
A face is a list of labels corresponding to mesh vertices.
A class for handling file names.
Hex block definition used in the cfx converter.
Mesh consisting of general polyhedral cells.
static word defaultRegion
Return the default region name.
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh").
A class for handling words, derived from Foam::string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
List< word > wordList
List of word.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
List< labelListList > labelListListList
List of labelListList.
messageStream Info
Information stream (stdout output on master, null elsewhere).
List< face > faceList
List of faces.
IOstream & hex(IOstream &io)
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< faceList > faceListList
List of faceList.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Ostream & flush(Ostream &os)
Flush stream.
List< cellShape > cellShapeList
List of cellShape.
wordList patchTypes(nPatches)
wordList patchNames(nPatches)
PtrList< dictionary > patchDicts
polyMesh pShapeMesh(IOobject(polyMesh::defaultRegion, runTime.constant(), runTime), std::move(points), cellShapes, boundary, patchNames, patchDicts, defaultFacesName, defaultFacesType)
preservePatchTypes(runTime, runTime.constant(), polyMesh::meshSubDir, patchNames, patchDicts, defaultFacesName, defaultFacesType)
const volScalarField & cp
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.