1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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
27 \*---------------------------------------------------------------------------*/
29 #include "surfaceToPoint.H"
31 #include "meshSearch.H"
32 #include "triSurfaceSearch.H"
34 #include "octreeDataTriSurface.H"
36 #include "addToRunTimeSelectionTable.H"
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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"
60 " <outside> boolean; whether to include points on this side of"
65 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
67 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
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_)
81 boolList pointInside(querySurf.calcInside(mesh_.points()));
83 forAll(pointInside, pointI)
85 bool isInside = pointInside[pointI];
87 if ((isInside && includeInside_) || (!isInside && includeOutside_))
89 addOrDelete(set, pointI, add);
96 const pointField& meshPoints = mesh_.points();
98 // Box dimensions to search in octree.
99 const vector span(nearDist_, nearDist_, nearDist_);
101 forAll(meshPoints, pointI)
103 const point& pt = meshPoints[pointI];
105 pointIndexHit inter = querySurf.nearest(pt, span);
107 if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
109 addOrDelete(set, pointI, add);
116 void Foam::surfaceToPoint::checkSettings() const
118 if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
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"
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
145 includeInside_(includeInside),
146 includeOutside_(includeOutside)
152 // Construct from dictionary
153 Foam::surfaceToPoint::surfaceToPoint
155 const polyMesh& mesh,
156 const dictionary& dict
160 surfName_(dict.lookup("file")),
161 nearDist_(readScalar(dict.lookup("nearDistance"))),
162 includeInside_(readBool(dict.lookup("includeInside"))),
163 includeOutside_(readBool(dict.lookup("includeOutside")))
169 // Construct from Istream
170 Foam::surfaceToPoint::surfaceToPoint
172 const polyMesh& mesh,
177 surfName_(checkIs(is)),
178 nearDist_(readScalar(checkIs(is))),
179 includeInside_(readBool(checkIs(is))),
180 includeOutside_(readBool(checkIs(is)))
186 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
188 Foam::surfaceToPoint::~surfaceToPoint()
192 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 void Foam::surfaceToPoint::applyToSet
196 const topoSetSource::setAction action,
200 if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
202 Info<< " Adding points in relation to surface " << surfName_
207 else if (action == topoSetSource::DELETE)
209 Info<< " Removing points in relation to surface " << surfName_
217 // ************************************************************************* //