patchesToSubsets.C 2.62 KB
Newer Older
Franjo's avatar
Franjo committed
1 2 3 4 5 6 7 8
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | cfMesh: A library for mesh generation
   \\    /   O peration     |
    \\  /    A nd           | Author: Franjo Juretic (franjo.juretic@c-fields.com)
     \\/     M anipulation  | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
Andrew Heather's avatar
Andrew Heather committed
9
    This file is part of OpenFOAM.
Franjo's avatar
Franjo committed
10

Andrew Heather's avatar
Andrew Heather committed
11 12 13 14
    OpenFOAM 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.
Franjo's avatar
Franjo committed
15

Andrew Heather's avatar
Andrew Heather committed
16
    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
Franjo's avatar
Franjo committed
17 18 19 20 21
    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
Andrew Heather's avatar
Andrew Heather committed
22
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
Franjo's avatar
Franjo committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

Description
    Converts specified patches into subsets

\*---------------------------------------------------------------------------*/

#include "argList.H"
#include "triSurf.H"
#include "triFaceList.H"
#include "labelLongList.H"
#include "IFstream.H"
#include "OFstream.H"

using namespace Foam;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    argList::noParallel();
    argList::validArgs.clear();

    argList::validArgs.append("input surface file");
    argList::validArgs.append("output surface file");
    argList args(argc, argv);

Mark Olesen's avatar
Mark Olesen committed
49 50
    fileName inFileName(args[1]);
    fileName outFileName(args[2]);
Franjo's avatar
Franjo committed
51

Andrew Heather's avatar
Andrew Heather committed
52
    if (outFileName.ext() != "fms")
Franjo's avatar
Franjo committed
53 54 55 56 57 58 59 60 61 62 63 64 65
        Warning << "The subsets cann only be saved in the .fms format" << endl;

    triSurf origSurf(inFileName);

    wordList patchNames(origSurf.patches().size());
    forAll(origSurf.patches(), patchI)
        patchNames[patchI] = origSurf.patches()[patchI].name();

    forAll(patchNames, patchI)
    {
        labelLongList subsetFacets;
        forAll(origSurf, triI)
        {
Andrew Heather's avatar
Andrew Heather committed
66
            if (origSurf[triI].region() == patchI)
Franjo's avatar
Franjo committed
67 68 69 70 71 72 73 74 75 76 77
                subsetFacets.append(triI);
        }

        const label subsetId = origSurf.addFacetSubset(patchNames[patchI]);

        forAll(subsetFacets, i)
            origSurf.addFacetToSubset(subsetId, subsetFacets[i]);
    }

    origSurf.writeSurface(outFileName);

Andrew Heather's avatar
Andrew Heather committed
78
    Info<< "End\n" << endl;
Franjo's avatar
Franjo committed
79 80 81 82

    return 0;
}

Andrew Heather's avatar
Andrew Heather committed
83

Franjo's avatar
Franjo committed
84
// ************************************************************************* //