This repository has been archived on 2023-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
foam-extend4.1-coherent-io/applications/utilities/mesh/generation/cfMesh/FPMAToMesh/FPMAToMesh.C

218 lines
5 KiB
C
Raw Normal View History

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 3.2
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
foam-extend is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Description
Writes the mesh in fpma format readable by AVL's CfdWM
\*---------------------------------------------------------------------------*/
#include "argList.H"
2014-06-17 10:42:41 +00:00
#include "objectRegistry.H"
#include "Time.H"
#include "polyMeshGenModifier.H"
#include "IFstream.H"
#include "Map.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
2015-05-15 13:57:39 +00:00
{
# include "setRootCase.H"
# include "createTime.H"
fileName inFileName;
2015-05-15 13:57:39 +00:00
Info << "Reading mesh from file " << endl;
cin >> inFileName;
2015-05-15 13:57:39 +00:00
IFstream file(inFileName);
polyMeshGen pmg(runTime);
polyMeshGenModifier meshModifier(pmg);
2015-05-15 13:57:39 +00:00
label counter;
2015-05-15 13:57:39 +00:00
//- read the number of vertices
pointFieldPMG& points = meshModifier.pointsAccess();
file >> counter;
2015-05-15 13:57:39 +00:00
//- read points from file
points.setSize(counter);
forAll(points, pointI)
{
point p;
file >> p.x();
file >> p.y();
file >> p.z();
2015-05-15 13:57:39 +00:00
points[pointI] = p;
}
2015-05-15 13:57:39 +00:00
//- read the number of faces
file >> counter;
2015-05-15 13:57:39 +00:00
faceListPMG& faces = meshModifier.facesAccess();
2015-05-15 13:57:39 +00:00
//- read faces from file
faces.setSize(counter);
forAll(faces, faceI)
{
file >> counter;
2015-05-15 13:57:39 +00:00
face f;
f.setSize(counter);
2015-05-15 13:57:39 +00:00
forAll(f, pI)
file >> f[pI];
2015-05-15 13:57:39 +00:00
faces[faceI] = f.reverseFace();
}
2015-05-15 13:57:39 +00:00
//- read the number of cells
file >> counter;
2015-05-15 13:57:39 +00:00
//- read cells from file
cellListPMG& cells = meshModifier.cellsAccess();
cells.setSize(counter);
2015-05-15 13:57:39 +00:00
forAll(cells, cellI)
{
file >> counter;
2015-05-15 13:57:39 +00:00
cell& c = cells[cellI];
2015-05-15 13:57:39 +00:00
c.setSize(counter);
2015-05-15 13:57:39 +00:00
forAll(c, fI)
file >> c[fI];
}
2015-05-15 13:57:39 +00:00
//- read selections
file >> counter;
2015-05-15 13:57:39 +00:00
wordList patchNames;
Map<label> subsetToPatch;
2015-05-15 13:57:39 +00:00
for(label setI=0;setI<counter;++setI)
{
word sName;
file >> sName;
2015-05-15 13:57:39 +00:00
label type;
file >> type;
2015-05-15 13:57:39 +00:00
label nEntries;
file >> nEntries;
2015-05-15 13:57:39 +00:00
switch( type )
{
case 3:
{
//- face selection
const label id = pmg.addFaceSubset(sName);
2015-05-15 13:57:39 +00:00
patchNames.setSize(patchNames.size()+1);
patchNames[patchNames.size()-1] = sName;
subsetToPatch.insert(id, patchNames.size()-1);
2015-05-15 13:57:39 +00:00
Info << "Reading face selection " << sName << endl;
2015-05-15 13:57:39 +00:00
for(label i=0;i<nEntries;++i)
{
label entryI;
file >> entryI;
pmg.addFaceToSubset(id, entryI);
}
} break;
case 2:
{
//- cell selection
const label id = pmg.addCellSubset(sName);
2015-05-15 13:57:39 +00:00
for(label i=0;i<nEntries;++i)
{
label entryI;
file >> entryI;
pmg.addCellToSubset(id, entryI);
}
} break;
case 1:
{
//- node selection
const label id = pmg.addPointSubset(sName);
2015-05-15 13:57:39 +00:00
for(label i=0;i<nEntries;++i)
{
label entryI;
file >> entryI;
pmg.addPointToSubset(id, entryI);
}
} break;
};
}
2015-05-15 13:57:39 +00:00
//- create patches from face selections
VRWGraph boundaryFaces;
labelLongList boundaryOwner;
labelLongList boundaryPatches;
2015-05-15 13:57:39 +00:00
const labelList& owner = pmg.owner();
DynList<label> faceSubsets;
pmg.faceSubsetIndices(faceSubsets);
2015-05-15 13:57:39 +00:00
forAll(faceSubsets, setI)
{
labelLongList setFaces;
pmg.facesInSubset(faceSubsets[setI], setFaces);
2015-05-15 13:57:39 +00:00
forAll(setFaces, i)
{
boundaryFaces.appendList(faces[setFaces[i]]);
boundaryOwner.append(owner[setFaces[i]]);
boundaryPatches.append(subsetToPatch[faceSubsets[setI]]);
}
2015-05-15 13:57:39 +00:00
pmg.removeFaceSubset(faceSubsets[setI]);
}
2015-05-15 13:57:39 +00:00
meshModifier.reorderBoundaryFaces();
meshModifier.replaceBoundary
(
patchNames,
boundaryFaces,
boundaryOwner,
boundaryPatches
);
2015-05-15 13:57:39 +00:00
pmg.write();
2015-05-15 13:57:39 +00:00
Info << "End\n" << endl;
return 0;
}
// ************************************************************************* //