boxToFace.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-2017 OpenFOAM Foundation
9  Copyright (C) 2018 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 \*---------------------------------------------------------------------------*/
28 
29 #include "boxToFace.H"
30 #include "polyMesh.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(boxToFace, 0);
38  addToRunTimeSelectionTable(topoSetSource, boxToFace, word);
39  addToRunTimeSelectionTable(topoSetSource, boxToFace, istream);
40  addToRunTimeSelectionTable(topoSetFaceSource, boxToFace, word);
41  addToRunTimeSelectionTable(topoSetFaceSource, boxToFace, istream);
43  (
44  topoSetFaceSource,
45  boxToFace,
46  word,
47  box
48  );
50  (
51  topoSetFaceSource,
52  boxToFace,
53  istream,
54  box
55  );
56 }
57 
58 
59 Foam::topoSetSource::addToUsageTable Foam::boxToFace::usage_
60 (
61  boxToFace::typeName,
62  "\n Usage: boxToFace ((minx miny minz) (maxx maxy maxz))\n\n"
63  " Select all face with faceCentre within bounding box\n\n"
64 );
65 
66 
67 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
68 
69 void Foam::boxToFace::combine(topoSet& set, const bool add) const
70 {
71  const pointField& ctrs = mesh_.faceCentres();
72 
73  forAll(ctrs, elemi)
74  {
75  for (const auto& bb : bbs_)
76  {
77  if (bb.contains(ctrs[elemi]))
78  {
79  addOrDelete(set, elemi, add);
80  break;
81  }
82  }
83  }
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
89 Foam::boxToFace::boxToFace
90 (
91  const polyMesh& mesh,
92  const treeBoundBoxList& bbs
93 )
94 :
95  topoSetFaceSource(mesh),
96  bbs_(bbs)
97 {}
98 
99 
100 Foam::boxToFace::boxToFace
101 (
102  const polyMesh& mesh,
103  treeBoundBoxList&& bbs
104 )
105 :
106  topoSetFaceSource(mesh),
107  bbs_(std::move(bbs))
108 {}
109 
110 
111 Foam::boxToFace::boxToFace
112 (
113  const polyMesh& mesh,
114  const dictionary& dict
115 )
116 :
117  topoSetFaceSource(mesh),
118  bbs_()
119 {
120  // Accept 'boxes', 'box' or 'min/max'
121  if (!dict.readIfPresent("boxes", bbs_))
122  {
123  bbs_.resize(1);
124  if (!dict.readIfPresent("box", bbs_.first()))
125  {
126  dict.readEntry<point>("min", bbs_.first().min());
127  dict.readEntry<point>("max", bbs_.first().max());
128  }
129  }
130 }
131 
132 
133 Foam::boxToFace::boxToFace
134 (
135  const polyMesh& mesh,
136  Istream& is
137 )
138 :
139  topoSetFaceSource(mesh),
140  bbs_(one(), treeBoundBox(checkIs(is)))
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
146 void Foam::boxToFace::applyToSet
147 (
148  const topoSetSource::setAction action,
149  topoSet& set
150 ) const
151 {
152  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
153  {
154  if (verbose_)
155  {
156  Info<< " Adding faces with centre within boxes "
157  << bbs_ << endl;
158  }
159 
160  combine(set, true);
161  }
162  else if (action == topoSetSource::SUBTRACT)
163  {
164  if (verbose_)
165  {
166  Info<< " Removing faces with centre within boxes "
167  << bbs_ << endl;
168  }
169 
170  combine(set, false);
171  }
172 }
173 
174 
175 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::topoSetSource::ADD
Add elements to the set.
Definition: topoSetSource.H:101
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:124
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::addNamedToRunTimeSelectionTable
addNamedToRunTimeSelectionTable(topoSetCellSource, badQualityToCell, word, badQuality)
boxToFace.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from the set.
Definition: topoSetSource.H:102
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::treeBoundBoxList
List< treeBoundBox > treeBoundBoxList
List of bounding boxes.
Definition: treeBoundBoxList.H:46
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)