Fix tutorials: coupled/conjugateHeatFoam/conjugateCavity: fix Allrun file
[OpenFOAM-1.6-ext.git] / src / meshTools / sets / pointSources / surfaceToPoint / surfaceToPoint.C
blob5131fae796db5afc494767fbc68501fc1dacce4f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 \*---------------------------------------------------------------------------*/
27 #include "surfaceToPoint.H"
28 #include "polyMesh.H"
29 #include "meshSearch.H"
30 #include "triSurfaceSearch.H"
32 #include "addToRunTimeSelectionTable.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 namespace Foam
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"
55     " surface normal\n"
56     "    <outside> boolean; whether to include points on this side of"
57     " surface normal\n\n"
61 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
63 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
65     cpuTime timer;
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_)
76     {
77         boolList pointInside(querySurf.calcInside(mesh_.points()));
79         forAll(pointInside, pointI)
80         {
81             bool isInside = pointInside[pointI];
83             if ((isInside && includeInside_) || (!isInside && includeOutside_))
84             {
85                 addOrDelete(set, pointI, add);
86             }
87         }
88     }
90     if (nearDist_ > 0)
91     {
92         const pointField& meshPoints = mesh_.points();
94         // Box dimensions to search in octree.
95         const vector span(nearDist_, nearDist_, nearDist_);
97         forAll(meshPoints, pointI)
98         {
99             const point& pt = meshPoints[pointI];
101             pointIndexHit inter = querySurf.nearest(pt, span);
103             if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
104             {
105                 addOrDelete(set, pointI, add);
106             }
107         }
108     }
112 void Foam::surfaceToPoint::checkSettings() const
114     if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
115     {
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"
121             << exit(FatalError);
122     }
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
138     topoSetSource(mesh),
139     surfName_(surfName),
140     nearDist_(nearDist),
141     includeInside_(includeInside),
142     includeOutside_(includeOutside)
144     checkSettings();
148 // Construct from dictionary
149 Foam::surfaceToPoint::surfaceToPoint
151     const polyMesh& mesh,
152     const dictionary& dict
155     topoSetSource(mesh),
156     surfName_(dict.lookup("file")),
157     nearDist_(readScalar(dict.lookup("nearDistance"))),
158     includeInside_(readBool(dict.lookup("includeInside"))),
159     includeOutside_(readBool(dict.lookup("includeOutside")))
161     checkSettings();
165 // Construct from Istream
166 Foam::surfaceToPoint::surfaceToPoint
168     const polyMesh& mesh,
169     Istream& is
172     topoSetSource(mesh),
173     surfName_(checkIs(is)),
174     nearDist_(readScalar(checkIs(is))),
175     includeInside_(readBool(checkIs(is))),
176     includeOutside_(readBool(checkIs(is)))
178     checkSettings();
182 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
184 Foam::surfaceToPoint::~surfaceToPoint()
188 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
190 void Foam::surfaceToPoint::applyToSet
192     const topoSetSource::setAction action,
193     topoSet& set
194 ) const
196     if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
197     {
198         Info<< "    Adding points in relation to surface " << surfName_
199             << " ..." << endl;
201         combine(set, true);
202     }
203     else if (action == topoSetSource::DELETE)
204     {
205         Info<< "    Removing points in relation to surface " << surfName_
206             << " ..." << endl;
208         combine(set, false);
209     }
213 // ************************************************************************* //