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].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];
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];
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];
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]
static void addNote(const string ¬e)
Add extra notes for the usage information.
void size(const label n)
Older name for setAddressableSize.
A class for handling file names.
A face is a list of labels corresponding to mesh vertices.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
IOstream & hex(IOstream &io)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
wordList patchTypes(nPatches)
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Ostream & endl(Ostream &os)
Add newline and flush stream.
bool cp(const fileName &src, const fileName &dst, const bool followLink=true)
Copy the source to the destination (recursively if necessary).
static unsigned int defaultPrecision() noexcept
Return the default precision.
static void noParallel()
Remove the parallel options.
polyMesh pShapeMesh(IOobject(polyMesh::defaultRegion, runTime.constant(), runTime), std::move(points), cellShapes, boundary, patchNames, patchDicts, defaultFacesName, defaultFacesType)
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
void exit(const int errNo=1)
Exit : can be called for any error to exit program.
#define forAll(list, i)
Loop across all elements in list.
static const cellModel & ref(const modelType model)
Look up reference to cellModel by enumeration. Fatal on failure.
void setSize(const label n)
Alias for resize()
void removeFiles(const fileName &instanceDir) const
Remove all files from mesh instance.
A class for handling words, derived from Foam::string.
static word defaultRegion
Return the default region name.
Extract command arguments and options from the supplied argc and argv parameters. ...
wordList patchNames(nPatches)
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
static void addOption(const word &optName, const string ¶m="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
const word & constant() const noexcept
Return constant name.
Input from file stream, using an ISstream.
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.
Ostream & flush(Ostream &os)
Flush stream.
T get(const label index) const
Get a value from the argument at index.
Hex block definition used in the cfx converter.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Maps a geometry to a set of cell primitives.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
PtrList< dictionary > patchDicts
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
bool check(bool checkArgs=argList::argsMandatory(), bool checkOpts=true) const
Check the parsed command-line for mandatory arguments and that all the options are correct...
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)