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 
90 (
91  const polyMesh& mesh,
92  const treeBoundBoxList& bbs
93 )
94 :
96  bbs_(bbs)
97 {}
98 
99 
101 (
102  const polyMesh& mesh,
103  treeBoundBoxList&& bbs
104 )
105 :
107  bbs_(std::move(bbs))
108 {}
109 
110 
112 (
113  const polyMesh& mesh,
114  const dictionary& dict
115 )
116 :
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 
134 (
135  const polyMesh& mesh,
136  Istream& is
137 )
138 :
140  bbs_(one(), treeBoundBox(checkIs(is)))
141 {}
142 
143 
144 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
145 
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::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::one
A class representing the concept of 1 (one), which can be used to avoid manipulating objects that are...
Definition: one.H:60
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:99
Foam::topoSetFaceSource
Base class of a topoSet source for selecting faces.
Definition: topoSetFaceSource.H:50
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:106
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
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)
Foam::dictionary::readEntry
bool readEntry(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX, bool mandatory=true) const
Definition: dictionaryTemplates.C:314
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:66
boxToFace.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::boxToFace::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: boxToFace.C:147
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
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::boxToFace::boxToFace
boxToFace(const polyMesh &mesh, const treeBoundBoxList &bbs)
Construct from components, copying bounding boxes.
Definition: boxToFace.C:90
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Vector< scalar >
Foam::List< treeBoundBox >
Foam::primitiveMesh::faceCentres
const vectorField & faceCentres() const
Definition: primitiveMeshFaceCentresAndAreas.C:145
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:170
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:151
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:417