1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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"
30 #include <OpenFOAM/polyMesh.H>
31 #include <meshTools/meshSearch.H>
32 #include <meshTools/triSurfaceSearch.H>
34 #include <OpenFOAM/addToRunTimeSelectionTable.H>
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
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"
58 " <outside> boolean; whether to include points on this side of"
63 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
65 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
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_)
79 boolList pointInside(querySurf.calcInside(mesh_.points()));
81 forAll(pointInside, pointI)
83 bool isInside = pointInside[pointI];
85 if ((isInside && includeInside_) || (!isInside && includeOutside_))
87 addOrDelete(set, pointI, add);
94 const pointField& meshPoints = mesh_.points();
96 // Box dimensions to search in octree.
97 const vector span(nearDist_, nearDist_, nearDist_);
99 forAll(meshPoints, pointI)
101 const point& pt = meshPoints[pointI];
103 pointIndexHit inter = querySurf.nearest(pt, span);
105 if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
107 addOrDelete(set, pointI, add);
114 void Foam::surfaceToPoint::checkSettings() const
116 if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
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"
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
143 includeInside_(includeInside),
144 includeOutside_(includeOutside)
150 // Construct from dictionary
151 Foam::surfaceToPoint::surfaceToPoint
153 const polyMesh& mesh,
154 const dictionary& dict
158 surfName_(dict.lookup("file")),
159 nearDist_(readScalar(dict.lookup("nearDistance"))),
160 includeInside_(readBool(dict.lookup("includeInside"))),
161 includeOutside_(readBool(dict.lookup("includeOutside")))
167 // Construct from Istream
168 Foam::surfaceToPoint::surfaceToPoint
170 const polyMesh& mesh,
175 surfName_(checkIs(is)),
176 nearDist_(readScalar(checkIs(is))),
177 includeInside_(readBool(checkIs(is))),
178 includeOutside_(readBool(checkIs(is)))
184 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
186 Foam::surfaceToPoint::~surfaceToPoint()
190 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
192 void Foam::surfaceToPoint::applyToSet
194 const topoSetSource::setAction action,
198 if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
200 Info<< " Adding points in relation to surface " << surfName_
205 else if (action == topoSetSource::DELETE)
207 Info<< " Removing points in relation to surface " << surfName_
215 // ************************ vim: set sw=4 sts=4 et: ************************ //