insideCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  insideCells
29 
30 Group
31  grpMeshManipulationUtilities
32 
33 Description
34  Create a cellSet for cells with their centres 'inside' the defined
35  surface.
36  Requires surface to be closed and singly connected.
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #include "argList.H"
41 #include "Time.H"
42 #include "polyMesh.H"
43 #include "triSurface.H"
44 #include "triSurfaceSearch.H"
45 #include "cellSet.H"
46 #include "globalMeshData.H"
47 
48 using namespace Foam;
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 
53 int main(int argc, char *argv[])
54 {
56  (
57  "Create a cellSet for cells with their centres 'inside' the defined"
58  " surface.\n"
59  "Surface must be closed and singly connected."
60  );
61 
62  argList::addArgument("surfaceFile");
63  argList::addArgument("cellSet");
64 
65  #include "setRootCase.H"
66  #include "createTime.H"
67  #include "createPolyMesh.H"
68 
69  const auto surfName = args.get<fileName>(1);
70  const auto setName = args.get<fileName>(2);
71 
72  // Read surface
73  Info<< "Reading surface from " << surfName << endl;
74  triSurface surf(surfName);
75 
76  // Destination cellSet.
77  cellSet insideCells(mesh, setName, IOobject::NO_READ);
78 
79 
80  // Construct search engine on surface
81  triSurfaceSearch querySurf(surf);
82 
83  boolList inside(querySurf.calcInside(mesh.cellCentres()));
84 
85  forAll(inside, celli)
86  {
87  if (inside[celli])
88  {
89  insideCells.insert(celli);
90  }
91  }
92 
93 
94  Info<< "Selected " << returnReduce(insideCells.size(), sumOp<label>())
95  << " of " << mesh.globalData().nTotalCells()
96  << " cells" << nl << nl
97  << "Writing selected cells to cellSet " << insideCells.name()
98  << nl << nl
99  << "Use this cellSet e.g. with subsetMesh : " << nl << nl
100  << " subsetMesh " << insideCells.name()
101  << nl << endl;
102 
103  insideCells.write();
104 
105  Info<< "End\n" << endl;
106 
107  return 0;
108 }
109 
110 
111 // ************************************************************************* //
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
Required Variables.
A class for handling file names.
Definition: fileName.H:71
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:414
Helper class to search on triSurface.
dynamicFvMesh & mesh
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1300
const vectorField & cellCentres() const
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
A collection of cell labels.
Definition: cellSet.H:47
Nothing to be read.
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
messageStream Info
Information stream (stdout output on master, null elsewhere)
Triangulated surface description with patch information.
Definition: triSurface.H:71
Foam::argList args(argc, argv)
Namespace for OpenFOAM.