OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceToPoint.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "surfaceToPoint.H"
00030 #include "polyMesh.H"
00031 #include "meshSearch.H"
00032 #include "triSurfaceSearch.H"
00033 
00034 #include "addToRunTimeSelectionTable.H"
00035 
00036 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 defineTypeNameAndDebug(surfaceToPoint, 0);
00042 
00043 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
00044 
00045 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
00046 
00047 }
00048 
00049 
00050 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
00051 (
00052     surfaceToPoint::typeName,
00053     "\n    Usage: surfaceToPoint <surface> <near> <inside> <outside>\n\n"
00054     "    <surface> name of triSurface\n"
00055     "    <near> scalar; include points with coordinate <= near to surface\n"
00056     "    <inside> boolean; whether to include points on opposite side of"
00057     " surface normal\n"
00058     "    <outside> boolean; whether to include points on this side of"
00059     " surface normal\n\n"
00060 );
00061 
00062 
00063 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00064 
00065 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
00066 {
00067     cpuTime timer;
00068 
00069     triSurface surf(surfName_);
00070 
00071     Info<< "    Read surface from " << surfName_
00072         << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
00073 
00074     // Construct search engine on surface
00075     triSurfaceSearch querySurf(surf);
00076 
00077     if (includeInside_ || includeOutside_)
00078     {
00079         boolList pointInside(querySurf.calcInside(mesh_.points()));
00080 
00081         forAll(pointInside, pointI)
00082         {
00083             bool isInside = pointInside[pointI];
00084 
00085             if ((isInside && includeInside_) || (!isInside && includeOutside_))
00086             {
00087                 addOrDelete(set, pointI, add);
00088             }   
00089         }
00090     }
00091 
00092     if (nearDist_ > 0)
00093     {
00094         const pointField& meshPoints = mesh_.points();
00095 
00096         // Box dimensions to search in octree.
00097         const vector span(nearDist_, nearDist_, nearDist_);
00098 
00099         forAll(meshPoints, pointI)
00100         {
00101             const point& pt = meshPoints[pointI];
00102 
00103             pointIndexHit inter = querySurf.nearest(pt, span);
00104 
00105             if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
00106             {
00107                 addOrDelete(set, pointI, add);
00108             }
00109         }
00110     }
00111 }
00112 
00113 
00114 void Foam::surfaceToPoint::checkSettings() const
00115 {
00116     if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
00117     {
00118         FatalErrorIn("surfaceToPoint:checkSettings()")
00119             << "Illegal point selection specification."
00120             << " Result would be either all or no points." << endl
00121             << "Please set one of includeInside or includeOutside"
00122             << " to true, set nearDistance to a value > 0"
00123             << exit(FatalError);
00124     }
00125 }
00126 
00127 
00128 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00129 
00130 // Construct from components
00131 Foam::surfaceToPoint::surfaceToPoint
00132 (
00133     const polyMesh& mesh,
00134     const fileName& surfName,
00135     const scalar nearDist,
00136     const bool includeInside,
00137     const bool includeOutside
00138 )
00139 :
00140     topoSetSource(mesh),
00141     surfName_(surfName),
00142     nearDist_(nearDist),
00143     includeInside_(includeInside),
00144     includeOutside_(includeOutside)
00145 {
00146     checkSettings();
00147 }
00148 
00149 
00150 // Construct from dictionary
00151 Foam::surfaceToPoint::surfaceToPoint
00152 (
00153     const polyMesh& mesh,
00154     const dictionary& dict          
00155 )
00156 :
00157     topoSetSource(mesh),
00158     surfName_(dict.lookup("file")),
00159     nearDist_(readScalar(dict.lookup("nearDistance"))),
00160     includeInside_(readBool(dict.lookup("includeInside"))),
00161     includeOutside_(readBool(dict.lookup("includeOutside")))
00162 {
00163     checkSettings();
00164 }
00165 
00166 
00167 // Construct from Istream
00168 Foam::surfaceToPoint::surfaceToPoint
00169 (
00170     const polyMesh& mesh,
00171     Istream& is
00172 )
00173 :
00174     topoSetSource(mesh),
00175     surfName_(checkIs(is)),
00176     nearDist_(readScalar(checkIs(is))),
00177     includeInside_(readBool(checkIs(is))),
00178     includeOutside_(readBool(checkIs(is)))
00179 {
00180     checkSettings();
00181 }
00182 
00183 
00184 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00185 
00186 Foam::surfaceToPoint::~surfaceToPoint()
00187 {}
00188 
00189 
00190 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00191 
00192 void Foam::surfaceToPoint::applyToSet
00193 (
00194     const topoSetSource::setAction action,
00195     topoSet& set
00196 ) const
00197 {
00198     if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00199     {
00200         Info<< "    Adding points in relation to surface " << surfName_
00201             << " ..." << endl;
00202 
00203         combine(set, true);
00204     }
00205     else if (action == topoSetSource::DELETE)
00206     {
00207         Info<< "    Removing points in relation to surface " << surfName_
00208             << " ..." << endl;
00209 
00210         combine(set, false);
00211     }
00212 }
00213 
00214 
00215 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd