1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
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
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 \*---------------------------------------------------------------------------*/
27 #include "surfaceToPoint.H"
29 #include "meshSearch.H"
30 #include "triSurfaceSearch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 defineTypeNameAndDebug(surfaceToPoint, 0);
41 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
43 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
48 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
50 surfaceToPoint::typeName,
51 "\n Usage: surfaceToPoint <surface> <near> <inside> <outside>\n\n"
52 " <surface> name of triSurface\n"
53 " <near> scalar; include points with coordinate <= near to surface\n"
54 " <inside> boolean; whether to include points on opposite side of"
56 " <outside> boolean; whether to include points on this side of"
61 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
63 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
67 triSurface surf(surfName_);
69 Info<< " Read surface from " << surfName_
70 << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
72 // Construct search engine on surface
73 triSurfaceSearch querySurf(surf);
75 if (includeInside_ || includeOutside_)
77 boolList pointInside(querySurf.calcInside(mesh_.points()));
79 forAll(pointInside, pointI)
81 bool isInside = pointInside[pointI];
83 if ((isInside && includeInside_) || (!isInside && includeOutside_))
85 addOrDelete(set, pointI, add);
92 const pointField& meshPoints = mesh_.points();
94 // Box dimensions to search in octree.
95 const vector span(nearDist_, nearDist_, nearDist_);
97 forAll(meshPoints, pointI)
99 const point& pt = meshPoints[pointI];
101 pointIndexHit inter = querySurf.nearest(pt, span);
103 if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
105 addOrDelete(set, pointI, add);
112 void Foam::surfaceToPoint::checkSettings() const
114 if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
116 FatalErrorIn("surfaceToPoint:checkSettings()")
117 << "Illegal point selection specification."
118 << " Result would be either all or no points." << endl
119 << "Please set one of includeInside or includeOutside"
120 << " to true, set nearDistance to a value > 0"
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 // Construct from components
129 Foam::surfaceToPoint::surfaceToPoint
131 const polyMesh& mesh,
132 const fileName& surfName,
133 const scalar nearDist,
134 const bool includeInside,
135 const bool includeOutside
141 includeInside_(includeInside),
142 includeOutside_(includeOutside)
148 // Construct from dictionary
149 Foam::surfaceToPoint::surfaceToPoint
151 const polyMesh& mesh,
152 const dictionary& dict
156 surfName_(dict.lookup("file")),
157 nearDist_(readScalar(dict.lookup("nearDistance"))),
158 includeInside_(readBool(dict.lookup("includeInside"))),
159 includeOutside_(readBool(dict.lookup("includeOutside")))
165 // Construct from Istream
166 Foam::surfaceToPoint::surfaceToPoint
168 const polyMesh& mesh,
173 surfName_(checkIs(is)),
174 nearDist_(readScalar(checkIs(is))),
175 includeInside_(readBool(checkIs(is))),
176 includeOutside_(readBool(checkIs(is)))
182 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
184 Foam::surfaceToPoint::~surfaceToPoint()
188 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
190 void Foam::surfaceToPoint::applyToSet
192 const topoSetSource::setAction action,
196 if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
198 Info<< " Adding points in relation to surface " << surfName_
203 else if (action == topoSetSource::DELETE)
205 Info<< " Removing points in relation to surface " << surfName_
213 // ************************************************************************* //