FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "surfaceToPoint.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <meshTools/meshSearch.H>
00029 #include <meshTools/triSurfaceSearch.H>
00030 
00031 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00032 
00033 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 defineTypeNameAndDebug(surfaceToPoint, 0);
00039 
00040 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
00041 
00042 addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
00043 
00044 }
00045 
00046 
00047 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
00048 (
00049     surfaceToPoint::typeName,
00050     "\n    Usage: surfaceToPoint <surface> <near> <inside> <outside>\n\n"
00051     "    <surface> name of triSurface\n"
00052     "    <near> scalar; include points with coordinate <= near to surface\n"
00053     "    <inside> boolean; whether to include points on opposite side of"
00054     " surface normal\n"
00055     "    <outside> boolean; whether to include points on this side of"
00056     " surface normal\n\n"
00057 );
00058 
00059 
00060 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00061 
00062 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
00063 {
00064     cpuTime timer;
00065 
00066     triSurface surf(surfName_);
00067 
00068     Info<< "    Read surface from " << surfName_
00069         << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
00070 
00071     // Construct search engine on surface
00072     triSurfaceSearch querySurf(surf);
00073 
00074     if (includeInside_ || includeOutside_)
00075     {
00076         boolList pointInside(querySurf.calcInside(mesh_.points()));
00077 
00078         forAll(pointInside, pointI)
00079         {
00080             bool isInside = pointInside[pointI];
00081 
00082             if ((isInside && includeInside_) || (!isInside && includeOutside_))
00083             {
00084                 addOrDelete(set, pointI, add);
00085             }
00086         }
00087     }
00088 
00089     if (nearDist_ > 0)
00090     {
00091         const pointField& meshPoints = mesh_.points();
00092 
00093         // Box dimensions to search in octree.
00094         const vector span(nearDist_, nearDist_, nearDist_);
00095 
00096         forAll(meshPoints, pointI)
00097         {
00098             const point& pt = meshPoints[pointI];
00099 
00100             pointIndexHit inter = querySurf.nearest(pt, span);
00101 
00102             if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
00103             {
00104                 addOrDelete(set, pointI, add);
00105             }
00106         }
00107     }
00108 }
00109 
00110 
00111 void Foam::surfaceToPoint::checkSettings() const
00112 {
00113     if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
00114     {
00115         FatalErrorIn("surfaceToPoint:checkSettings()")
00116             << "Illegal point selection specification."
00117             << " Result would be either all or no points." << endl
00118             << "Please set one of includeInside or includeOutside"
00119             << " to true, set nearDistance to a value > 0"
00120             << exit(FatalError);
00121     }
00122 }
00123 
00124 
00125 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00126 
00127 // Construct from components
00128 Foam::surfaceToPoint::surfaceToPoint
00129 (
00130     const polyMesh& mesh,
00131     const fileName& surfName,
00132     const scalar nearDist,
00133     const bool includeInside,
00134     const bool includeOutside
00135 )
00136 :
00137     topoSetSource(mesh),
00138     surfName_(surfName),
00139     nearDist_(nearDist),
00140     includeInside_(includeInside),
00141     includeOutside_(includeOutside)
00142 {
00143     checkSettings();
00144 }
00145 
00146 
00147 // Construct from dictionary
00148 Foam::surfaceToPoint::surfaceToPoint
00149 (
00150     const polyMesh& mesh,
00151     const dictionary& dict
00152 )
00153 :
00154     topoSetSource(mesh),
00155     surfName_(dict.lookup("file")),
00156     nearDist_(readScalar(dict.lookup("nearDistance"))),
00157     includeInside_(readBool(dict.lookup("includeInside"))),
00158     includeOutside_(readBool(dict.lookup("includeOutside")))
00159 {
00160     checkSettings();
00161 }
00162 
00163 
00164 // Construct from Istream
00165 Foam::surfaceToPoint::surfaceToPoint
00166 (
00167     const polyMesh& mesh,
00168     Istream& is
00169 )
00170 :
00171     topoSetSource(mesh),
00172     surfName_(checkIs(is)),
00173     nearDist_(readScalar(checkIs(is))),
00174     includeInside_(readBool(checkIs(is))),
00175     includeOutside_(readBool(checkIs(is)))
00176 {
00177     checkSettings();
00178 }
00179 
00180 
00181 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00182 
00183 Foam::surfaceToPoint::~surfaceToPoint()
00184 {}
00185 
00186 
00187 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00188 
00189 void Foam::surfaceToPoint::applyToSet
00190 (
00191     const topoSetSource::setAction action,
00192     topoSet& set
00193 ) const
00194 {
00195     if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
00196     {
00197         Info<< "    Adding points in relation to surface " << surfName_
00198             << " ..." << endl;
00199 
00200         combine(set, true);
00201     }
00202     else if (action == topoSetSource::DELETE)
00203     {
00204         Info<< "    Removing points in relation to surface " << surfName_
00205             << " ..." << endl;
00206 
00207         combine(set, false);
00208     }
00209 }
00210 
00211 
00212 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines