FreeFOAM The Cross-Platform CFD Toolkit
nearestToCell.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) 1991-2010 OpenCFD Ltd.
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 "nearestToCell.H"
27 #include <OpenFOAM/polyMesh.H>
28 #include <meshTools/meshSearch.H>
29 
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 defineTypeNameAndDebug(nearestToCell, 0);
38 
39 addToRunTimeSelectionTable(topoSetSource, nearestToCell, word);
40 
41 addToRunTimeSelectionTable(topoSetSource, nearestToCell, istream);
42 
43 }
44 
45 
46 Foam::topoSetSource::addToUsageTable Foam::nearestToCell::usage_
47 (
48  nearestToCell::typeName,
49  "\n Usage: nearestToCell (pt0 .. ptn)\n\n"
50  " Select the nearest cell for each of the points pt0 ..ptn\n\n"
51 );
52 
53 
54 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
55 
56 void Foam::nearestToCell::combine(topoSet& set, const bool add) const
57 {
58  // Construct search engine withouth tet decomposition.
59  meshSearch queryMesh(mesh_, false);
60 
61  forAll(points_, pointI)
62  {
63  addOrDelete(set, queryMesh.findNearestCell(points_[pointI]), add);
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
70 // Construct from components
72 (
73  const polyMesh& mesh,
74  const pointField& points
75 )
76 :
77  topoSetSource(mesh),
78  points_(points)
79 {}
80 
81 
82 // Construct from dictionary
84 (
85  const polyMesh& mesh,
86  const dictionary& dict
87 )
88 :
89  topoSetSource(mesh),
90  points_(dict.lookup("points"))
91 {}
92 
93 
94 // Construct from Istream
96 (
97  const polyMesh& mesh,
98  Istream& is
99 )
100 :
101  topoSetSource(mesh),
102  points_(checkIs(is))
103 {}
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 (
116  const topoSetSource::setAction action,
117  topoSet& set
118 ) const
119 {
120  if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
121  {
122  Info<< " Adding cells nearest to " << points_ << endl;
123 
124  combine(set, true);
125  }
126  else if (action == topoSetSource::DELETE)
127  {
128  Info<< " Removing cells nearest to " << points_ << endl;
129 
130  combine(set, false);
131  }
132 }
133 
134 
135 // ************************ vim: set sw=4 sts=4 et: ************************ //