initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / meshTools / sets / pointSources / surfaceToPoint / surfaceToPoint.C
blob25601a213424c2dadc6de6528e261a4bbace61d7
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 "surfaceToPoint.H"
30 #include "polyMesh.H"
31 #include "meshSearch.H"
32 #include "triSurfaceSearch.H"
34 #include "addToRunTimeSelectionTable.H"
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 namespace Foam
41 defineTypeNameAndDebug(surfaceToPoint, 0);
43 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
45 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
50 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
52     surfaceToPoint::typeName,
53     "\n    Usage: surfaceToPoint <surface> <near> <inside> <outside>\n\n"
54     "    <surface> name of triSurface\n"
55     "    <near> scalar; include points with coordinate <= near to surface\n"
56     "    <inside> boolean; whether to include points on opposite side of"
57     " surface normal\n"
58     "    <outside> boolean; whether to include points on this side of"
59     " surface normal\n\n"
63 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
65 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
67     cpuTime timer;
69     triSurface surf(surfName_);
71     Info<< "    Read surface from " << surfName_
72         << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
74     // Construct search engine on surface
75     triSurfaceSearch querySurf(surf);
77     if (includeInside_ || includeOutside_)
78     {
79         boolList pointInside(querySurf.calcInside(mesh_.points()));
81         forAll(pointInside, pointI)
82         {
83             bool isInside = pointInside[pointI];
85             if ((isInside && includeInside_) || (!isInside && includeOutside_))
86             {
87                 addOrDelete(set, pointI, add);
88             }   
89         }
90     }
92     if (nearDist_ > 0)
93     {
94         const pointField& meshPoints = mesh_.points();
96         // Box dimensions to search in octree.
97         const vector span(nearDist_, nearDist_, nearDist_);
99         forAll(meshPoints, pointI)
100         {
101             const point& pt = meshPoints[pointI];
103             pointIndexHit inter = querySurf.nearest(pt, span);
105             if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
106             {
107                 addOrDelete(set, pointI, add);
108             }
109         }
110     }
114 void Foam::surfaceToPoint::checkSettings() const
116     if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
117     {
118         FatalErrorIn("surfaceToPoint:checkSettings()")
119             << "Illegal point selection specification."
120             << " Result would be either all or no points." << endl
121             << "Please set one of includeInside or includeOutside"
122             << " to true, set nearDistance to a value > 0"
123             << exit(FatalError);
124     }
128 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
130 // Construct from components
131 Foam::surfaceToPoint::surfaceToPoint
133     const polyMesh& mesh,
134     const fileName& surfName,
135     const scalar nearDist,
136     const bool includeInside,
137     const bool includeOutside
140     topoSetSource(mesh),
141     surfName_(surfName),
142     nearDist_(nearDist),
143     includeInside_(includeInside),
144     includeOutside_(includeOutside)
146     checkSettings();
150 // Construct from dictionary
151 Foam::surfaceToPoint::surfaceToPoint
153     const polyMesh& mesh,
154     const dictionary& dict          
157     topoSetSource(mesh),
158     surfName_(dict.lookup("file")),
159     nearDist_(readScalar(dict.lookup("nearDistance"))),
160     includeInside_(readBool(dict.lookup("includeInside"))),
161     includeOutside_(readBool(dict.lookup("includeOutside")))
163     checkSettings();
167 // Construct from Istream
168 Foam::surfaceToPoint::surfaceToPoint
170     const polyMesh& mesh,
171     Istream& is
174     topoSetSource(mesh),
175     surfName_(checkIs(is)),
176     nearDist_(readScalar(checkIs(is))),
177     includeInside_(readBool(checkIs(is))),
178     includeOutside_(readBool(checkIs(is)))
180     checkSettings();
184 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
186 Foam::surfaceToPoint::~surfaceToPoint()
190 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
192 void Foam::surfaceToPoint::applyToSet
194     const topoSetSource::setAction action,
195     topoSet& set
196 ) const
198     if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
199     {
200         Info<< "    Adding points in relation to surface " << surfName_
201             << " ..." << endl;
203         combine(set, true);
204     }
205     else if (action == topoSetSource::DELETE)
206     {
207         Info<< "    Removing points in relation to surface " << surfName_
208             << " ..." << endl;
210         combine(set, false);
211     }
215 // ************************************************************************* //