insideCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  insideCells
26 
27 Description
28  Picks up cells with cell centre 'inside' of surface.
29  Requires surface to be closed and singly connected.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "Time.H"
35 #include "polyMesh.H"
36 #include "triSurface.H"
37 #include "triSurfaceSearch.H"
38 #include "cellSet.H"
39 
40 using namespace Foam;
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 
45 int main(int argc, char *argv[])
46 {
48  (
49  "Create a cellSet for cells with their centres inside the defined "
50  "surface.\n"
51  "Surface must be closed and singly connected."
52  );
53 
55  argList::validArgs.append("surface file");
56  argList::validArgs.append("cellSet");
57 
58  #include "setRootCase.H"
59  #include "createTime.H"
60  #include "createPolyMesh.H"
61 
62  const fileName surfName = args[1];
63  const fileName setName = args[2];
64 
65  // Read surface
66  Info<< "Reading surface from " << surfName << endl;
67  triSurface surf(surfName);
68 
69  // Destination cellSet.
70  cellSet insideCells(mesh, setName, IOobject::NO_READ);
71 
72 
73  // Construct search engine on surface
74  triSurfaceSearch querySurf(surf);
75 
76  boolList inside(querySurf.calcInside(mesh.cellCentres()));
77 
78  forAll(inside, celli)
79  {
80  if (inside[celli])
81  {
82  insideCells.insert(celli);
83  }
84  }
85 
86 
87  Info<< "Selected " << insideCells.size() << " of " << mesh.nCells()
88  << " cells" << nl << nl
89  << "Writing selected cells to cellSet " << insideCells.name()
90  << nl << nl
91  << "Use this cellSet e.g. with subsetMesh : " << nl << nl
92  << " subsetMesh " << insideCells.name()
93  << nl << endl;
94 
95  insideCells.write();
96 
97  Info<< "End\n" << endl;
98 
99  return 0;
100 }
101 
102 
103 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for handling file names.
Definition: fileName.H:79
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static void noParallel()
Remove the parallel options.
Definition: argList.C:174
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
Helper class to search on triSurface.
dynamicFvMesh & mesh
const vectorField & cellCentres() const
static const char nl
Definition: Ostream.H:265
A collection of cell labels.
Definition: cellSet.H:48
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:158
Triangulated surface description with patch information.
Definition: triSurface.H:66
Foam::argList args(argc, argv)
Namespace for OpenFOAM.