boxToCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(boxToCell, 0);
35  addToRunTimeSelectionTable(topoSetSource, boxToCell, word);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::boxToCell::combine(topoSet& set, const bool add) const
42 {
43  const pointField& ctrs = mesh_.cellCentres();
44 
45  forAll(ctrs, celli)
46  {
47  forAll(bbs_, i)
48  {
49  if (bbs_[i].contains(ctrs[celli]))
50  {
51  addOrDelete(set, celli, add);
52  break;
53  }
54  }
55  }
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
60 
62 (
63  const polyMesh& mesh,
64  const treeBoundBoxList& bbs
65 )
66 :
67  topoSetSource(mesh),
68  bbs_(bbs)
69 {}
70 
71 
73 (
74  const polyMesh& mesh,
75  const dictionary& dict
76 )
77 :
78  topoSetSource(mesh),
79  bbs_
80  (
81  dict.found("box")
82  ? treeBoundBoxList(1, treeBoundBox(dict.lookup("box")))
83  : dict.lookup("boxes")
84  )
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
89 
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
97 (
98  const topoSetSource::setAction action,
99  topoSet& set
100 ) const
101 {
102  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
103  {
104  Info<< " Adding cells with center within boxes " << bbs_ << endl;
105 
106  combine(set, true);
107  }
108  else if (action == topoSetSource::DELETE)
109  {
110  Info<< " Removing cells with center within boxes " << bbs_ << endl;
111 
112  combine(set, false);
113  }
114 }
115 
116 
117 // ************************************************************************* //
bool found
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
boxToCell(const polyMesh &mesh, const treeBoundBoxList &bbs)
Construct from components.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
virtual ~boxToCell()
Destructor.
const vectorField & cellCentres() const
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
Namespace for OpenFOAM.
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
void add(GeometricField< typename typeOfSum< Type1, Type2 >::type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type1, GeoMesh, PrimitiveField2 > &gf1, const GeometricField< Type2, GeoMesh, PrimitiveField3 > &gf2)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< treeBoundBox > treeBoundBoxList
List of bounding boxes.
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict