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;
109 cfxFile >> cfxPatchTypes[
patchi] >> cfxPatchNames[
patchi] >> no;
112 patchRanges[
patchi].setSize(6);
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;
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
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;
585 if (rawPatches[
patchi].size() && cfxPatchTypes[
patchi] !=
"BLKBDY")
588 label existingPatch = -1;
590 for (
label oldPatchi = 0; oldPatchi < nCreatedPatches; oldPatchi++)
594 existingPatch = oldPatchi;
602 if (existingPatch >= 0)
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]
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;
670 else if (cfxPatchTypes[
patchi] ==
"SYMMET")
674 patchTypes[nCreatedPatches] = symmetryPolyPatch::typeName;
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;
696 <<
"Unrecognised CFX patch type "
#define forAll(list, i)
Loop across all elements in list.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
static unsigned int defaultPrecision()
Return the default precision.
void size(const label)
Override size to be inconsistent with allocated storage.
void setSize(const label)
Reset size of List.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Extract command arguments and options from the supplied argc and argv parameters.
static void addOption(const word &opt, const string ¶m="", const string &usage="")
Add to an option to validOptions with usage information.
static void noParallel()
Remove the parallel options.
static SLList< string > validArgs
A list of valid (mandatory) arguments.
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
bool check(bool checkArgs=true, bool checkOpts=true) const
Check argument list.
Maps a geometry to a set of cell primitives, which enables geometric cell data to be calculated witho...
static const cellModel * lookup(const word &)
Look up a model by name and return a pointer to the model or nullptr.
An analytical geometric cellShape.
A list of keyword definitions, which are a keyword followed by any number of values (e....
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
A face is a list of labels corresponding to mesh vertices.
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")
virtual bool write(const bool write=true) const
Write using setting from DB.
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
int main(int argc, char *argv[])
const cellShapeList & cellShapes
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.
errorManip< error > abort(error &err)
IOstream & hex(IOstream &io)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
void preservePatchTypes(const objectRegistry &obr, const word &meshInstance, const fileName &meshDir, const wordList &patchNames, PtrList< dictionary > &patchDicts, const word &defaultFacesName, word &defaultFacesType)
Preserve patch types.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy, recursively if necessary, the source to the destination.
Ostream & flush(Ostream &os)
Flush stream.
dimensioned< scalar > magSqr(const dimensioned< Type > &)
wordList patchTypes(nPatches)
wordList patchNames(nPatches)
PtrList< dictionary > patchDicts
faceListList boundary(nPatches)
polyMesh pShapeMesh(IOobject(polyMesh::defaultRegion, runTime.constant(), runTime), move(points), cellShapes, boundary, patchNames, patchDicts, defaultFacesName, defaultFacesType)
Foam::argList args(argc, argv)