boxToCell.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 | Copyright (C) 2011-2016 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 \*---------------------------------------------------------------------------*/
25 
26 #include "boxToCell.H"
27 #include "polyMesh.H"
28 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 
36 defineTypeNameAndDebug(boxToCell, 0);
37 
38 addToRunTimeSelectionTable(topoSetSource, boxToCell, word);
39 
40 addToRunTimeSelectionTable(topoSetSource, boxToCell, istream);
41 
42 }
43 
44 
45 Foam::topoSetSource::addToUsageTable Foam::boxToCell::usage_
46 (
47  boxToCell::typeName,
48  "\n Usage: boxToCell (minx miny minz) (maxx maxy maxz)\n\n"
49  " Select all cells with cellCentre within bounding box\n\n"
50 );
51 
52 
53 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
54 
55 void Foam::boxToCell::combine(topoSet& set, const bool add) const
56 {
57  const pointField& ctrs = mesh_.cellCentres();
58 
59  forAll(ctrs, celli)
60  {
61  forAll(bbs_, i)
62  {
63  if (bbs_[i].contains(ctrs[celli]))
64  {
65  addOrDelete(set, celli, add);
66  break;
67  }
68  }
69  }
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
75 // Construct from components
77 (
78  const polyMesh& mesh,
79  const treeBoundBoxList& bbs
80 )
81 :
82  topoSetSource(mesh),
83  bbs_(bbs)
84 {}
85 
86 
87 // Construct from dictionary
89 (
90  const polyMesh& mesh,
91  const dictionary& dict
92 )
93 :
94  topoSetSource(mesh),
95  bbs_
96  (
97  dict.found("box")
98  ? treeBoundBoxList(1, treeBoundBox(dict.lookup("box")))
99  : dict.lookup("boxes")
100  )
101 {}
102 
103 
104 // Construct from Istream
106 (
107  const polyMesh& mesh,
108  Istream& is
109 )
110 :
111  topoSetSource(mesh),
112  bbs_(1, treeBoundBox(checkIs(is)))
113 {}
114 
115 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
116 
118 {}
119 
120 
121 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
122 
124 (
125  const topoSetSource::setAction action,
126  topoSet& set
127 ) const
128 {
129  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
130  {
131  Info<< " Adding cells with center within boxes " << bbs_ << endl;
132 
133  combine(set, true);
134  }
135  else if (action == topoSetSource::DELETE)
136  {
137  Info<< " Removing cells with center within boxes " << bbs_ << endl;
138 
139  combine(set, false);
140  }
141 }
142 
143 
144 // ************************************************************************* //
List< treeBoundBox > treeBoundBoxList
List of bounding boxes.
boxToCell(const polyMesh &mesh, const treeBoundBoxList &bbs)
Construct from components.
Definition: boxToCell.C:77
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
stressControl lookup("compactNormalStress") >> compactNormalStress
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
virtual ~boxToCell()
Destructor.
Definition: boxToCell.C:117
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: boxToCell.C:124
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
Class with constructor to add usage string to table.
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576