surfaceToPoint.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "surfaceToPoint.H"
27 #include "polyMesh.H"
28 #include "triSurfaceSearch.H"
29 #include "triSurface.H"
30 #include "cpuTime.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(surfaceToPoint, 0);
38  addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
39  addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
40 }
41 
42 
44 (
45  surfaceToPoint::typeName,
46  "\n Usage: surfaceToPoint <surface> <near> <inside> <outside>\n\n"
47  " <surface> name of triSurface\n"
48  " <near> scalar; include points with coordinate <= near to surface\n"
49  " <inside> boolean; whether to include points on opposite side of"
50  " surface normal\n"
51  " <outside> boolean; whether to include points on this side of"
52  " surface normal\n\n"
53 );
54 
55 
56 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
57 
58 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
59 {
60  cpuTime timer;
61 
62  triSurface surf(surfName_);
63 
64  Info<< " Read surface from " << surfName_
65  << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
66 
67  // Construct search engine on surface
68  triSurfaceSearch querySurf(surf);
69 
71  {
72  boolList pointInside(querySurf.calcInside(mesh_.points()));
73 
74  forAll(pointInside, pointI)
75  {
76  bool isInside = pointInside[pointI];
77 
78  if ((isInside && includeInside_) || (!isInside && includeOutside_))
79  {
80  addOrDelete(set, pointI, add);
81  }
82  }
83  }
84 
85  if (nearDist_ > 0)
86  {
87  const pointField& meshPoints = mesh_.points();
88 
89  // Box dimensions to search in octree.
90  const vector span(nearDist_, nearDist_, nearDist_);
91 
92  forAll(meshPoints, pointI)
93  {
94  const point& pt = meshPoints[pointI];
95 
96  pointIndexHit inter = querySurf.nearest(pt, span);
97 
98  if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
99  {
100  addOrDelete(set, pointI, add);
101  }
102  }
103  }
104 }
105 
106 
108 {
109  if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
110  {
112  << "Illegal point selection specification."
113  << " Result would be either all or no points." << endl
114  << "Please set one of includeInside or includeOutside"
115  << " to true, set nearDistance to a value > 0"
116  << exit(FatalError);
117  }
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
122 
124 (
125  const polyMesh& mesh,
126  const fileName& surfName,
127  const scalar nearDist,
128  const bool includeInside,
129  const bool includeOutside
130 )
131 :
133  surfName_(surfName),
134  nearDist_(nearDist),
135  includeInside_(includeInside),
136  includeOutside_(includeOutside)
137 {
138  checkSettings();
139 }
140 
141 
143 (
144  const polyMesh& mesh,
145  const dictionary& dict
146 )
147 :
149  surfName_(fileName(dict.lookup("file")).expand()),
150  nearDist_(readScalar(dict.lookup("nearDistance"))),
151  includeInside_(readBool(dict.lookup("includeInside"))),
152  includeOutside_(readBool(dict.lookup("includeOutside")))
153 {
154  checkSettings();
155 }
156 
157 
159 (
160  const polyMesh& mesh,
161  Istream& is
162 )
163 :
165  surfName_(checkIs(is)),
166  nearDist_(readScalar(checkIs(is))),
167  includeInside_(readBool(checkIs(is))),
168  includeOutside_(readBool(checkIs(is)))
169 {
170  checkSettings();
171 }
172 
173 
174 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
175 
177 {}
178 
179 
180 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181 
183 (
184  const topoSetSource::setAction action,
185  topoSet& set
186 ) const
187 {
188  if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
189  {
190  Info<< " Adding points in relation to surface " << surfName_
191  << " ..." << endl;
192 
193  combine(set, true);
194  }
195  else if (action == topoSetSource::DELETE)
196  {
197  Info<< " Removing points in relation to surface " << surfName_
198  << " ..." << endl;
199 
200  combine(set, false);
201  }
202 }
203 
204 
205 // ************************************************************************* //
Foam::cpuTime
Starts timing CPU usage and return elapsed time from start.
Definition: cpuTime.H:52
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:979
Foam::surfaceToPoint::includeInside_
const bool includeInside_
Include all points on opposite sign of normal on nearest surface.
Definition: surfaceToPoint.H:73
Foam::topoSetSource::ADD
@ ADD
Definition: topoSetSource.H:87
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::triSurfaceSearch::nearest
pointIndexHit nearest(const point &, const vector &span) const
Calculate nearest point on surface for single searchPoint. Returns.
Definition: triSurfaceSearch.C:312
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::ListListOps::combine
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:100
Foam::surfaceToPoint::combine
void combine(topoSet &set, const bool add) const
Depending on surface add to or delete from pointSet.
Definition: surfaceToPoint.C:58
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::PointIndexHit::hit
bool hit() const
Is there a hit.
Definition: PointIndexHit.H:105
Foam::surfaceToPoint::usage_
static addToUsageTable usage_
Add usage string.
Definition: surfaceToPoint.H:64
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
Foam::topoSetSource::NEW
@ NEW
Definition: topoSetSource.H:85
Foam::surfaceToPoint::surfName_
const fileName surfName_
Name of surface file.
Definition: surfaceToPoint.H:67
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
polyMesh.H
Foam::triSurfaceSearch
Helper class to search on triSurface.
Definition: triSurfaceSearch.H:55
Foam::surfaceToPoint::checkSettings
void checkSettings() const
Check settings at construction time.
Definition: surfaceToPoint.C:107
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::surfaceToPoint::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
Definition: surfaceToPoint.C:183
Foam::PointIndexHit
This class describes the interaction of (usually) a face and a point. It carries the info of a succes...
Definition: PointIndexHit.H:53
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
surfaceToPoint.H
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Info
messageStream Info
Foam::PointIndexHit::hitPoint
const Point & hitPoint() const
Return hit point.
Definition: PointIndexHit.H:117
Foam::topoSetSource::DELETE
@ DELETE
Definition: topoSetSource.H:88
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::surfaceToPoint::nearDist_
const scalar nearDist_
If > 0 : include points with distance to surface less than nearDist.
Definition: surfaceToPoint.H:70
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::add
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Definition: FieldFieldFunctions.C:870
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::surfaceToPoint::~surfaceToPoint
virtual ~surfaceToPoint()
Destructor.
Definition: surfaceToPoint.C:176
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::topoSetSource
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
cpuTime.H
Foam::surfaceToPoint::surfaceToPoint
surfaceToPoint(const polyMesh &mesh, const fileName &surfName, const scalar nearDist, const bool includeInside, const bool includeOutside)
Construct from components.
Definition: surfaceToPoint.C:124
Foam::triSurfaceSearch::calcInside
boolList calcInside(const pointField &searchPoints) const
Calculate for each searchPoint inside/outside status.
Definition: triSurfaceSearch.C:254
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
Foam::surfaceToPoint::includeOutside_
const bool includeOutside_
Include all points on this sign of normal on nearest surface.
Definition: surfaceToPoint.H:76
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::string::expand
string & expand(const bool allowEmpty=false)
Expand initial tildes and all occurences of environment variables.
Definition: string.C:98
Foam::timer
Implements a timeout mechanism via sigalarm.
Definition: timer.H:81
triSurfaceSearch.H
Foam::readBool
bool readBool(Istream &)
Definition: boolIO.C:60
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Definition: topoSetSource.H:126
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label cellI, const bool) const
Add (if bool) cellI to set or delete cellI from set.
Definition: topoSetSource.C:140