70 int main(
int argc,
char *argv[])
83 scalar scaleFactor = 1.0;
93 label nblock, npatch, nglue, nelem, npoint;
95 cfxFile >> nblock >> npatch >> nglue >> nelem >> npoint;
107 cfxFile >> blockName;
108 cfxFile >> nx >> ny >> nz;
110 blocks.set(blockI,
new hexBlock(nx, ny, nz));
114 Info <<
"Reading patch definitions" <<
endl;
123 label no, blkNo, patchLabel;
125 forAll (cfxPatchTypes, patchI)
128 cfxFile >> cfxPatchTypes[patchI] >> cfxPatchNames[patchI] >> no;
131 patchRanges[patchI].setSize(6);
132 labelList& curRange = patchRanges[patchI];
136 cfxFile >> curRange[rI];
144 cfxFile >> patchDirections[patchI] >> blkNo >> patchLabel;
146 patchMasterBlocks[patchI] = blkNo - 1;
150 Info <<
"Reading block glueing information" <<
endl;
156 label masterPatch, slavePatch;
157 label dirIndex1, dirIndex2, dirIndex3, joinNumber;
159 for (label glueI = 0; glueI < nglue; glueI++)
161 cfxFile >> masterPatch >> slavePatch;
162 cfxFile >> dirIndex1 >> dirIndex2 >> dirIndex3 >> joinNumber;
164 glueMasterPatches[glueI] = masterPatch - 1;
165 glueSlavePatches[glueI] = slavePatch - 1;
169 Info <<
"Reading block points" <<
endl;
173 Info <<
"block " << blockI <<
" is a ";
174 blocks[blockI].readPoints(cfxFile);
177 Info <<
"Calculating block offsets" <<
endl;
183 label nMeshPoints = blocks[0].nBlockPoints();
184 label nMeshCells = blocks[0].nBlockCells();
186 for (label blockI = 1; blockI < nblock; blockI++)
188 nMeshPoints += blocks[blockI].nBlockPoints();
189 nMeshCells += blocks[blockI].nBlockCells();
191 blockOffsets[blockI] =
192 blockOffsets[blockI - 1]
193 + blocks[blockI - 1].nBlockPoints();
196 Info <<
"Assembling patches" <<
endl;
200 forAll (rawPatches, patchI)
202 const word& patchType = cfxPatchTypes[patchI];
207 patchType ==
"POROUS" || patchType ==
"SOLID"
208 || patchType ==
"SOLCON" || patchType ==
"USER3D"
211 patchMasterBlocks[patchI] = -1;
212 rawPatches[patchI].setSize(0);
218 blocks[patchMasterBlocks[patchI]].patchFaces
220 patchDirections[patchI],
227 Info <<
"Merging points ";
229 labelList pointMergeList(nMeshPoints, -1);
238 forAll (glueMasterPatches, glueI)
240 const label masterPatch = glueMasterPatches[glueI];
241 const label slavePatch = glueSlavePatches[glueI];
243 const label blockPlabel = patchMasterBlocks[masterPatch];
244 const label blockNlabel = patchMasterBlocks[slavePatch];
246 const pointField& blockPpoints = blocks[blockPlabel].points();
247 const pointField& blockNpoints = blocks[blockNlabel].points();
249 const faceList& blockPFaces = rawPatches[masterPatch];
250 const faceList& blockNFaces = rawPatches[slavePatch];
255 if (blockPFaces.
size() != blockNFaces.
size())
258 <<
"Inconsistent number of faces for glue pair "
259 << glueI <<
" between blocks " << blockPlabel + 1
260 <<
" and " << blockNlabel + 1
269 scalar sqrMergeTol = GREAT;
271 forAll (blockPFaces, blockPFaceLabel)
274 blockPFaces[blockPFaceLabel];
276 forAll (blockPFacePoints, blockPFacePointI)
278 forAll (blockPFacePoints, blockPFacePointI2)
280 if (blockPFacePointI != blockPFacePointI2)
289 [blockPFacePoints[blockPFacePointI]]
291 [blockPFacePoints[blockPFacePointI2]]
301 register bool found =
false;
305 forAll (blockPFaces, blockPFaceLabel)
308 blockPFaces[blockPFaceLabel];
313 forAll (blockPFacePoints, blockPFacePointI)
317 forAll (blockNFaces, blockNFaceLabel)
320 blockNFaces[blockNFaceLabel];
322 forAll (blockNFacePoints, blockNFacePointI)
329 [blockPFacePoints[blockPFacePointI]]
331 [blockNFacePoints[blockNFacePointI]]
339 cp[blockPFacePointI] =
340 blockNFacePoints[blockNFacePointI];
343 blockPFacePoints[blockPFacePointI]
344 + blockOffsets[blockPlabel];
347 blockNFacePoints[blockNFacePointI]
348 + blockOffsets[blockNlabel];
350 label minPN =
min(PpointLabel, NpointLabel);
352 if (pointMergeList[PpointLabel] != -1)
354 minPN =
min(minPN, pointMergeList[PpointLabel]);
357 if (pointMergeList[NpointLabel] != -1)
359 minPN =
min(minPN, pointMergeList[NpointLabel]);
362 pointMergeList[PpointLabel]
363 = pointMergeList[NpointLabel]
376 register bool changedPointMerge =
false;
381 changedPointMerge =
false;
384 forAll (glueMasterPatches, glueI)
386 const label masterPatch = glueMasterPatches[glueI];
387 const label slavePatch = glueSlavePatches[glueI];
389 const label blockPlabel = patchMasterBlocks[masterPatch];
390 const label blockNlabel = patchMasterBlocks[slavePatch];
392 const faceList& blockPFaces = rawPatches[masterPatch];
396 forAll (blockPFaces, blockPFaceLabel)
399 blockPFaces[blockPFaceLabel];
401 const labelList& cp = curPairs[blockPFaceLabel];
403 forAll (cp, blockPFacePointI)
406 blockPFacePoints[blockPFacePointI]
407 + blockOffsets[blockPlabel];
411 + blockOffsets[blockNlabel];
415 pointMergeList[PpointLabel]
416 != pointMergeList[NpointLabel]
419 changedPointMerge =
true;
421 pointMergeList[PpointLabel]
422 = pointMergeList[NpointLabel]
425 pointMergeList[PpointLabel],
426 pointMergeList[NpointLabel]
434 while (changedPointMerge && nPasses < 8);
437 if (changedPointMerge ==
true)
440 <<
"Point merging failed after max number of passes."
445 forAll (glueMasterPatches, glueI)
447 const label masterPatch = glueMasterPatches[glueI];
448 const label slavePatch = glueSlavePatches[glueI];
450 const label blockPlabel = patchMasterBlocks[masterPatch];
451 const label blockNlabel = patchMasterBlocks[slavePatch];
453 const faceList& blockPFaces = rawPatches[masterPatch];
454 const faceList& blockNFaces = rawPatches[slavePatch];
457 forAll (blockPFaces, blockPFaceLabel)
460 = blockPFaces[blockPFaceLabel];
462 forAll (blockPFacePoints, blockPFacePointI)
465 blockPFacePoints[blockPFacePointI]
466 + blockOffsets[blockPlabel];
468 if (pointMergeList[PpointLabel] == -1)
471 <<
"Unable to merge point " << blockPFacePointI
472 <<
" of face " << blockPFaceLabel
473 <<
" of block " << blockPlabel
479 forAll (blockNFaces, blockNFaceLabel)
482 = blockNFaces[blockNFaceLabel];
484 forAll (blockNFacePoints, blockNFacePointI)
487 blockNFacePoints[blockNFacePointI]
488 + blockOffsets[blockNlabel];
490 if (pointMergeList[NpointLabel] == -1)
493 <<
"Unable to merge point " << blockNFacePointI
494 <<
" of face " << blockNFaceLabel
495 <<
" of block " << blockNlabel
505 label nNewPoints = 0;
507 forAll (pointMergeList, pointLabel)
509 if (pointMergeList[pointLabel] > pointLabel)
517 (pointMergeList[pointLabel] == -1)
518 || pointMergeList[pointLabel] == pointLabel
521 pointMergeList[pointLabel] = nNewPoints;
526 pointMergeList[pointLabel] =
527 pointMergeList[pointMergeList[pointLabel]];
531 nMeshPoints = nNewPoints;
539 const pointField& blockPoints = blocks[blockI].points();
541 forAll (blockPoints, blockPointLabel)
548 + blockOffsets[blockI]
550 ] = blockPoints[blockPointLabel];
555 if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
566 label nCreatedCells = 0;
572 forAll (curBlockCells, blockCellI)
574 labelList cellPoints(curBlockCells[blockCellI].size());
576 forAll (cellPoints, pointI)
581 curBlockCells[blockCellI][pointI]
582 + blockOffsets[blockI]
592 Info <<
"Creating boundary patches" <<
endl;
601 label nCreatedPatches = 0;
603 forAll (rawPatches, patchI)
605 if (rawPatches[patchI].size() && cfxPatchTypes[patchI] !=
"BLKBDY")
608 label existingPatch = -1;
610 for (label oldPatchI = 0; oldPatchI < nCreatedPatches; oldPatchI++)
612 if (
patchNames[oldPatchI] == cfxPatchNames[patchI])
614 existingPatch = oldPatchI;
619 const faceList& curRawPatch = rawPatches[patchI];
620 label curBlock = patchMasterBlocks[patchI];
622 if (existingPatch >= 0)
624 Info <<
"CFX patch " << patchI
625 <<
", of type " << cfxPatchTypes[patchI]
626 <<
", name " << cfxPatchNames[patchI]
627 <<
" already exists as FOAM patch " << existingPatch
628 <<
". Adding faces." <<
endl;
631 label oldSize = renumberedPatch.
size();
632 renumberedPatch.
setSize(oldSize + curRawPatch.
size());
634 forAll (curRawPatch, faceI)
636 const face& oldFace = curRawPatch[faceI];
638 face& newFace = renumberedPatch[oldSize + faceI];
647 + blockOffsets[curBlock]
658 forAll (curRawPatch, faceI)
660 const face& oldFace = curRawPatch[faceI];
662 face& newFace = renumberedPatch[faceI];
671 + blockOffsets[curBlock]
676 Info <<
"CFX patch " << patchI
677 <<
", of type " << cfxPatchTypes[patchI]
678 <<
", name " << cfxPatchNames[patchI]
679 <<
" converted into FOAM patch " << nCreatedPatches
682 if (cfxPatchTypes[patchI] ==
"WALL")
686 patchTypes[nCreatedPatches] = wallPolyPatch::typeName;
687 patchNames[nCreatedPatches] = cfxPatchNames[patchI];
690 else if (cfxPatchTypes[patchI] ==
"SYMMET")
694 patchTypes[nCreatedPatches] = symmetryPolyPatch::typeName;
695 patchNames[nCreatedPatches] = cfxPatchNames[patchI];
700 cfxPatchTypes[patchI] ==
"INLET"
701 || cfxPatchTypes[patchI] ==
"OUTLET"
702 || cfxPatchTypes[patchI] ==
"PRESS"
703 || cfxPatchTypes[patchI] ==
"CNDBDY"
704 || cfxPatchTypes[patchI] ==
"USER2D"
709 patchTypes[nCreatedPatches] = polyPatch::typeName;
710 patchNames[nCreatedPatches] = cfxPatchNames[patchI];
716 <<
"Unrecognised CFX patch type "
717 << cfxPatchTypes[patchI]