All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
surfaceToPoint.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 
43 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
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 
70  if (includeInside_ || includeOutside_)
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 
107 void Foam::surfaceToPoint::checkSettings() const
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 :
132  topoSetSource(mesh),
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 :
148  topoSetSource(mesh),
149  surfName_(fileName(dict.lookup("file")).expand()),
150  nearDist_(dict.lookup<scalar>("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 :
164  topoSetSource(mesh),
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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Expand occurrences of variables according to the mapping.
Definition: stringOps.C:69
A class for handling file names.
Definition: fileName.H:79
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual ~surfaceToPoint()
Destructor.
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
bool readBool(Istream &)
Definition: boolIO.C:60
surfaceToPoint(const polyMesh &mesh, const fileName &surfName, const scalar nearDist, const bool includeInside, const bool includeOutside)
Construct from components.
AccessType combine(const List< T > &, AccessOp aop=accessOp< T >())
Combines sublists into one big list.
Definition: ListListOps.C:34
Macros for easy insertion into run-time selection tables.
Base class of a source for a topoSet.
Definition: topoSetSource.H:63
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:82
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
defineTypeNameAndDebug(combustionModel, 0)
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:61
vector point
Point is a vector.
Definition: point.H:41
Class with constructor to add usage string to table.
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812