47 int main(
int argc,
char *argv[])
55 "geometry scaling factor - default is 1"
74 label nblock, npatch, nglue, nelem, npoint;
76 cfxFile >> nblock >> npatch >> nglue >> nelem >> npoint;
89 cfxFile >> nx >> ny >> nz;
91 blocks.set(blockI,
new hexBlock(nx, ny, nz));
95 Info<<
"Reading patch definitions" <<
endl;
104 label no, blkNo, patchLabel;
106 forAll(cfxPatchTypes, patchI)
109 cfxFile >> cfxPatchTypes[patchI] >> cfxPatchNames[patchI] >> no;
112 patchRanges[patchI].setSize(6);
113 labelList& curRange = patchRanges[patchI];
117 cfxFile >> curRange[rI];
125 cfxFile >> patchDirections[patchI] >> blkNo >> patchLabel;
127 patchMasterBlocks[patchI] = blkNo - 1;
131 Info<<
"Reading block glueing information" <<
endl;
137 label masterPatch, slavePatch;
138 label dirIndex1, dirIndex2, dirIndex3, joinNumber;
140 for (
label glueI = 0; glueI < nglue; glueI++)
142 cfxFile >> masterPatch >> slavePatch;
143 cfxFile >> dirIndex1 >> dirIndex2 >> dirIndex3 >> joinNumber;
145 glueMasterPatches[glueI] = masterPatch - 1;
146 glueSlavePatches[glueI] = slavePatch - 1;
150 Info<<
"Reading block points" <<
endl;
154 Info<<
"block " << blockI <<
" is a ";
155 blocks[blockI].readPoints(cfxFile);
158 Info<<
"Calculating block offsets" <<
endl;
164 label nMeshPoints = blocks[0].nBlockPoints();
165 label nMeshCells = blocks[0].nBlockCells();
167 for (
label blockI = 1; blockI < nblock; blockI++)
169 nMeshPoints += blocks[blockI].nBlockPoints();
170 nMeshCells += blocks[blockI].nBlockCells();
172 blockOffsets[blockI] =
173 blockOffsets[blockI - 1]
174 + blocks[blockI - 1].nBlockPoints();
177 Info<<
"Assembling patches" <<
endl;
181 forAll(rawPatches, patchI)
183 const word& patchType = cfxPatchTypes[patchI];
188 patchType ==
"POROUS" || patchType ==
"SOLID"
189 || patchType ==
"SOLCON" || patchType ==
"USER3D"
192 patchMasterBlocks[patchI] = -1;
193 rawPatches[patchI].setSize(0);
199 blocks[patchMasterBlocks[patchI]].patchFaces
201 patchDirections[patchI],
208 Info<<
"Merging points ";
210 labelList pointMergeList(nMeshPoints, -1);
219 forAll(glueMasterPatches, glueI)
221 const label masterPatch = glueMasterPatches[glueI];
222 const label slavePatch = glueSlavePatches[glueI];
224 const label blockPlabel = patchMasterBlocks[masterPatch];
225 const label blockNlabel = patchMasterBlocks[slavePatch];
227 const pointField& blockPpoints = blocks[blockPlabel].points();
228 const pointField& blockNpoints = blocks[blockNlabel].points();
230 const faceList& blockPFaces = rawPatches[masterPatch];
231 const faceList& blockNFaces = rawPatches[slavePatch];
236 if (blockPFaces.
size() != blockNFaces.
size())
239 <<
"Inconsistent number of faces for glue pair "
240 << glueI <<
" between blocks " << blockPlabel + 1
241 <<
" and " << blockNlabel + 1
250 scalar sqrMergeTol = GREAT;
252 forAll(blockPFaces, blockPFaceLabel)
255 blockPFaces[blockPFaceLabel];
257 forAll(blockPFacePoints, blockPFacePointI)
259 forAll(blockPFacePoints, blockPFacePointI2)
261 if (blockPFacePointI != blockPFacePointI2)
270 [blockPFacePoints[blockPFacePointI]]
272 [blockPFacePoints[blockPFacePointI2]]
286 forAll(blockPFaces, blockPFaceLabel)
289 blockPFaces[blockPFaceLabel];
292 cp.setSize(blockPFacePoints.
size());
294 forAll(blockPFacePoints, blockPFacePointI)
298 forAll(blockNFaces, blockNFaceLabel)
301 blockNFaces[blockNFaceLabel];
303 forAll(blockNFacePoints, blockNFacePointI)
310 [blockPFacePoints[blockPFacePointI]]
312 [blockNFacePoints[blockNFacePointI]]
320 cp[blockPFacePointI] =
321 blockNFacePoints[blockNFacePointI];
324 blockPFacePoints[blockPFacePointI]
325 + blockOffsets[blockPlabel];
328 blockNFacePoints[blockNFacePointI]
329 + blockOffsets[blockNlabel];
331 label minPN =
min(PpointLabel, NpointLabel);
333 if (pointMergeList[PpointLabel] != -1)
335 minPN =
min(minPN, pointMergeList[PpointLabel]);
338 if (pointMergeList[NpointLabel] != -1)
340 minPN =
min(minPN, pointMergeList[NpointLabel]);
343 pointMergeList[PpointLabel]
344 = pointMergeList[NpointLabel]
357 bool changedPointMerge =
false;
362 changedPointMerge =
false;
365 forAll(glueMasterPatches, glueI)
367 const label masterPatch = glueMasterPatches[glueI];
368 const label slavePatch = glueSlavePatches[glueI];
370 const label blockPlabel = patchMasterBlocks[masterPatch];
371 const label blockNlabel = patchMasterBlocks[slavePatch];
373 const faceList& blockPFaces = rawPatches[masterPatch];
377 forAll(blockPFaces, blockPFaceLabel)
380 blockPFaces[blockPFaceLabel];
387 blockPFacePoints[blockPFacePointI]
388 + blockOffsets[blockPlabel];
392 + blockOffsets[blockNlabel];
396 pointMergeList[PpointLabel]
397 != pointMergeList[NpointLabel]
400 changedPointMerge =
true;
402 pointMergeList[PpointLabel]
403 = pointMergeList[NpointLabel]
406 pointMergeList[PpointLabel],
407 pointMergeList[NpointLabel]
415 while (changedPointMerge && nPasses < 8);
418 if (changedPointMerge ==
true)
421 <<
"Point merging failed after max number of passes."
426 forAll(glueMasterPatches, glueI)
428 const label masterPatch = glueMasterPatches[glueI];
429 const label slavePatch = glueSlavePatches[glueI];
431 const label blockPlabel = patchMasterBlocks[masterPatch];
432 const label blockNlabel = patchMasterBlocks[slavePatch];
434 const faceList& blockPFaces = rawPatches[masterPatch];
435 const faceList& blockNFaces = rawPatches[slavePatch];
438 forAll(blockPFaces, blockPFaceLabel)
441 = blockPFaces[blockPFaceLabel];
443 forAll(blockPFacePoints, blockPFacePointI)
446 blockPFacePoints[blockPFacePointI]
447 + blockOffsets[blockPlabel];
449 if (pointMergeList[PpointLabel] == -1)
452 <<
"Unable to merge point " << blockPFacePointI
453 <<
" of face " << blockPFaceLabel
454 <<
" of block " << blockPlabel
460 forAll(blockNFaces, blockNFaceLabel)
463 = blockNFaces[blockNFaceLabel];
465 forAll(blockNFacePoints, blockNFacePointI)
468 blockNFacePoints[blockNFacePointI]
469 + blockOffsets[blockNlabel];
471 if (pointMergeList[NpointLabel] == -1)
474 <<
"Unable to merge point " << blockNFacePointI
475 <<
" of face " << blockNFaceLabel
476 <<
" of block " << blockNlabel
486 label nNewPoints = 0;
488 forAll(pointMergeList, pointLabel)
490 if (pointMergeList[pointLabel] > pointLabel)
498 (pointMergeList[pointLabel] == -1)
499 || pointMergeList[pointLabel] == pointLabel
502 pointMergeList[pointLabel] = nNewPoints;
507 pointMergeList[pointLabel] =
508 pointMergeList[pointMergeList[pointLabel]];
512 nMeshPoints = nNewPoints;
520 const pointField& blockPoints = blocks[blockI].points();
522 forAll(blockPoints, blockPointLabel)
529 + blockOffsets[blockI]
531 ] = blockPoints[blockPointLabel];
536 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
547 label nCreatedCells = 0;
553 forAll(curBlockCells, blockCellI)
555 labelList cellPoints(curBlockCells[blockCellI].size());
557 forAll(cellPoints, pointI)
562 curBlockCells[blockCellI][pointI]
563 + blockOffsets[blockI]
573 Info<<
"Creating boundary patches" <<
endl;
581 label nCreatedPatches = 0;
583 forAll(rawPatches, patchI)
585 if (rawPatches[patchI].size() && cfxPatchTypes[patchI] !=
"BLKBDY")
588 label existingPatch = -1;
590 for (
label oldPatchI = 0; oldPatchI < nCreatedPatches; oldPatchI++)
592 if (
patchNames[oldPatchI] == cfxPatchNames[patchI])
594 existingPatch = oldPatchI;
599 const faceList& curRawPatch = rawPatches[patchI];
600 label curBlock = patchMasterBlocks[patchI];
602 if (existingPatch >= 0)
604 Info<<
"CFX patch " << patchI
605 <<
", of type " << cfxPatchTypes[patchI]
606 <<
", name " << cfxPatchNames[patchI]
607 <<
" already exists as OpenFOAM patch " << existingPatch
608 <<
". Adding faces." <<
endl;
612 renumberedPatch.
setSize(oldSize + curRawPatch.
size());
614 forAll(curRawPatch, faceI)
616 const face& oldFace = curRawPatch[faceI];
618 face& newFace = renumberedPatch[oldSize + faceI];
627 + blockOffsets[curBlock]
638 forAll(curRawPatch, faceI)
640 const face& oldFace = curRawPatch[faceI];
642 face& newFace = renumberedPatch[faceI];
651 + blockOffsets[curBlock]
656 Info<<
"CFX patch " << patchI
657 <<
", of type " << cfxPatchTypes[patchI]
658 <<
", name " << cfxPatchNames[patchI]
659 <<
" converted into OpenFOAM patch " << nCreatedPatches
662 if (cfxPatchTypes[patchI] ==
"WALL")
666 patchTypes[nCreatedPatches] = wallPolyPatch::typeName;
667 patchNames[nCreatedPatches] = cfxPatchNames[patchI];
670 else if (cfxPatchTypes[patchI] ==
"SYMMET")
674 patchTypes[nCreatedPatches] = symmetryPolyPatch::typeName;
675 patchNames[nCreatedPatches] = cfxPatchNames[patchI];
680 cfxPatchTypes[patchI] ==
"INLET"
681 || cfxPatchTypes[patchI] ==
"OUTLET"
682 || cfxPatchTypes[patchI] ==
"PRESS"
683 || cfxPatchTypes[patchI] ==
"CNDBDY"
684 || cfxPatchTypes[patchI] ==
"USER2D"
689 patchTypes[nCreatedPatches] = polyPatch::typeName;
690 patchNames[nCreatedPatches] = cfxPatchNames[patchI];
696 <<
"Unrecognised CFX patch type "
697 << cfxPatchTypes[patchI]