Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / mesh / manipulation / insideCells / insideCells.C
blob27ccb1f7a5b70d482eb6d892861476ae061bb7b3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Description
25     Picks up cells with cell centre 'inside' of surface. Requires surface
26     to be closed and singly connected.
28 \*---------------------------------------------------------------------------*/
30 #include "argList.H"
31 #include "objectRegistry.H"
32 #include "foamTime.H"
33 #include "polyMesh.H"
34 #include "triSurface.H"
35 #include "triSurfaceSearch.H"
36 #include "cellSet.H"
38 using namespace Foam;
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // Main program:
44 int main(int argc, char *argv[])
46     Foam::argList::noParallel();
47     Foam::argList::validArgs.append("surface file");
48     Foam::argList::validArgs.append("destination cellSet");
50 #   include "setRootCase.H"
51 #   include "createTime.H"
52 #   include "createPolyMesh.H"
54     fileName surfName(args.additionalArgs()[0]);
56     fileName setName(args.additionalArgs()[1]);
59     // Read surface
60     Info<< "Reading surface from " << surfName << endl;
61     triSurface surf(surfName);
63     // Destination cellSet.
64     cellSet insideCells(mesh, setName, IOobject::NO_READ);
67     // Construct search engine on surface
68     triSurfaceSearch querySurf(surf);
70     boolList inside(querySurf.calcInside(mesh.cellCentres()));
72     forAll(inside, cellI)
73     {
74         if (inside[cellI])
75         {
76             insideCells.insert(cellI);
77         }
78     }
81     Info<< "Selected " << insideCells.size()
82         << " cells out of " << mesh.nCells() << endl
83         << endl
84         << "Writing selected cells to cellSet " << insideCells.name()
85         << endl << endl
86         << "Use this cellSet e.g. with subsetMesh : " << endl << endl
87         << "    subsetMesh <root> <case> " << insideCells.name()
88         << endl << endl;
90     insideCells.write();
92     Info << "End\n" << endl;
94     return 0;
98 // ************************************************************************* //