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-------------------------------------------------------------------------------
11License
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
27Application
28 insideCells
29
30Group
31 grpMeshManipulationUtilities
32
33Description
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
48using namespace Foam;
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52
53int main(int argc, char *argv[])
54{
55 argList::addNote
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// ************************************************************************* //
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
A collection of cell labels.
Definition: cellSet.H:54
A class for handling file names.
Definition: fileName.H:76
Helper class to search on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:79
dynamicFvMesh & mesh
Required Variables.
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333