initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / cellSources / nearestToCell / nearestToCell.C
blob66e6734028d6b4642f22c16378f3cc07873d17fb
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
27 \*---------------------------------------------------------------------------*/
29 #include "nearestToCell.H"
30 #include "polyMesh.H"
31 #include "meshSearch.H"
33 #include "addToRunTimeSelectionTable.H"
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 namespace Foam
40 defineTypeNameAndDebug(nearestToCell, 0);
42 addToRunTimeSelectionTable(topoSetSource, nearestToCell, word);
44 addToRunTimeSelectionTable(topoSetSource, nearestToCell, istream);
49 Foam::topoSetSource::addToUsageTable Foam::nearestToCell::usage_
51     nearestToCell::typeName,
52     "\n    Usage: nearestToCell (pt0 .. ptn)\n\n"
53     "    Select the nearest cell for each of the points pt0 ..ptn\n\n"
57 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
59 void Foam::nearestToCell::combine(topoSet& set, const bool add) const
61     // Construct search engine withouth tet decomposition.
62     meshSearch queryMesh(mesh_, false);
64     forAll(points_, pointI)
65     {
66         addOrDelete(set, queryMesh.findNearestCell(points_[pointI]), add);
67     }
71 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
73 // Construct from components
74 Foam::nearestToCell::nearestToCell
76     const polyMesh& mesh,
77     const pointField& points
80     topoSetSource(mesh),
81     points_(points)
85 // Construct from dictionary
86 Foam::nearestToCell::nearestToCell
88     const polyMesh& mesh,
89     const dictionary& dict
92     topoSetSource(mesh),
93     points_(dict.lookup("points"))
97 // Construct from Istream
98 Foam::nearestToCell::nearestToCell
100     const polyMesh& mesh,
101     Istream& is
104     topoSetSource(mesh),
105     points_(checkIs(is))
109 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
111 Foam::nearestToCell::~nearestToCell()
115 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
117 void Foam::nearestToCell::applyToSet
119     const topoSetSource::setAction action,
120     topoSet& set
121 ) const
123     if ((action == topoSetSource::NEW) || (action == topoSetSource::ADD))
124     {
125         Info<< "    Adding cells nearest to " << points_ << endl;
127         combine(set, true);
128     }
129     else if (action == topoSetSource::DELETE)
130     {
131         Info<< "    Removing cells nearest to " << points_ << endl;
133         combine(set, false);
134     }
138 // ************************************************************************* //