52 int main(
int argc,
char *argv[])
56 "Convert a CFX 4 mesh to OpenFOAM format"
65 "Geometry scaling factor - default is 1"
84 label nblock, npatch, nglue, nelem, npoint;
86 cfxFile >> nblock >> npatch >> nglue >> nelem >> npoint;
99 cfxFile >> nx >> ny >> nz;
101 blocks.set(blockI,
new hexBlock(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].setSize(0);
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];
237 const pointField& blockPpoints = blocks[blockPlabel].points();
238 const pointField& blockNpoints = blocks[blockNlabel].points();
240 const faceList& blockPFaces = rawPatches[masterPatch];
241 const faceList& blockNFaces = rawPatches[slavePatch];
244 curPairs.
setSize(blockPFaces.size());
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 =
min(PpointLabel, NpointLabel);
343 if (pointMergeList[PpointLabel] != -1)
345 minPN =
min(minPN, pointMergeList[PpointLabel]);
348 if (pointMergeList[NpointLabel] != -1)
350 minPN =
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;
530 const pointField& blockPoints = blocks[blockI].points();
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];
629 newFace.
setSize(oldFace.size());
637 + blockOffsets[curBlock]
646 renumberedPatch.
setSize(curRawPatch.size());
648 forAll(curRawPatch, facei)
650 const face& oldFace = curRawPatch[facei];
652 face& newFace = renumberedPatch[facei];
653 newFace.
setSize(oldFace.size());
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]