initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / meshTools / sets / pointSources / surfaceToPoint / surfaceToPoint.C
blobd38de31a1de23e3d7acd3a6430bcb552ac583f53
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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 "surfaceToPoint.H"
30 #include "polyMesh.H"
31 #include "meshSearch.H"
32 #include "triSurfaceSearch.H"
33 #include "octree.H"
34 #include "octreeDataTriSurface.H"
36 #include "addToRunTimeSelectionTable.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
40 namespace Foam
43 defineTypeNameAndDebug(surfaceToPoint, 0);
45 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
47 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
52 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
54     surfaceToPoint::typeName,
55     "\n    Usage: surfaceToPoint <surface> <near> <inside> <outside>\n\n"
56     "    <surface> name of triSurface\n"
57     "    <near> scalar; include points with coordinate <= near to surface\n"
58     "    <inside> boolean; whether to include points on opposite side of"
59     " surface normal\n"
60     "    <outside> boolean; whether to include points on this side of"
61     " surface normal\n\n"
65 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
67 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
69     cpuTime timer;
71     triSurface surf(surfName_);
73     Info<< "    Read surface from " << surfName_
74         << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
76     // Construct search engine on surface
77     triSurfaceSearch querySurf(surf);
79     if (includeInside_ || includeOutside_)
80     {
81         boolList pointInside(querySurf.calcInside(mesh_.points()));
83         forAll(pointInside, pointI)
84         {
85             bool isInside = pointInside[pointI];
87             if ((isInside && includeInside_) || (!isInside && includeOutside_))
88             {
89                 addOrDelete(set, pointI, add);
90             }   
91         }
92     }
94     if (nearDist_ > 0)
95     {
96         const pointField& meshPoints = mesh_.points();
98         // Box dimensions to search in octree.
99         const vector span(nearDist_, nearDist_, nearDist_);
101         forAll(meshPoints, pointI)
102         {
103             const point& pt = meshPoints[pointI];
105             pointIndexHit inter = querySurf.nearest(pt, span);
107             if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
108             {
109                 addOrDelete(set, pointI, add);
110             }
111         }
112     }
116 void Foam::surfaceToPoint::checkSettings() const
118     if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
119     {
120         FatalErrorIn("surfaceToPoint:checkSettings()")
121             << "Illegal point selection specification."
122             << " Result would be either all or no points." << endl
123             << "Please set one of includeInside or includeOutside"
124             << " to true, set nearDistance to a value > 0"
125             << exit(FatalError);
126     }
130 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
132 // Construct from components
133 Foam::surfaceToPoint::surfaceToPoint
135     const polyMesh& mesh,
136     const fileName& surfName,
137     const scalar nearDist,
138     const bool includeInside,
139     const bool includeOutside
142     topoSetSource(mesh),
143     surfName_(surfName),
144     nearDist_(nearDist),
145     includeInside_(includeInside),
146     includeOutside_(includeOutside)
148     checkSettings();
152 // Construct from dictionary
153 Foam::surfaceToPoint::surfaceToPoint
155     const polyMesh& mesh,
156     const dictionary& dict          
159     topoSetSource(mesh),
160     surfName_(dict.lookup("file")),
161     nearDist_(readScalar(dict.lookup("nearDistance"))),
162     includeInside_(readBool(dict.lookup("includeInside"))),
163     includeOutside_(readBool(dict.lookup("includeOutside")))
165     checkSettings();
169 // Construct from Istream
170 Foam::surfaceToPoint::surfaceToPoint
172     const polyMesh& mesh,
173     Istream& is
176     topoSetSource(mesh),
177     surfName_(checkIs(is)),
178     nearDist_(readScalar(checkIs(is))),
179     includeInside_(readBool(checkIs(is))),
180     includeOutside_(readBool(checkIs(is)))
182     checkSettings();
186 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
188 Foam::surfaceToPoint::~surfaceToPoint()
192 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
194 void Foam::surfaceToPoint::applyToSet
196     const topoSetSource::setAction action,
197     topoSet& set
198 ) const
200     if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
201     {
202         Info<< "    Adding points in relation to surface " << surfName_
203             << " ..." << endl;
205         combine(set, true);
206     }
207     else if (action == topoSetSource::DELETE)
208     {
209         Info<< "    Removing points in relation to surface " << surfName_
210             << " ..." << endl;
212         combine(set, false);
213     }
217 // ************************************************************************* //