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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "surfaceToPoint.H"
30 #include "polyMesh.H"
31 #include "triSurfaceSearch.H"
32 #include "triSurface.H"
33 #include "cpuTime.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(surfaceToPoint, 0);
41  addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, word);
42  addToRunTimeSelectionTable(topoSetSource, surfaceToPoint, istream);
43  addToRunTimeSelectionTable(topoSetPointSource, surfaceToPoint, word);
44  addToRunTimeSelectionTable(topoSetPointSource, surfaceToPoint, istream);
45 }
46 
47 
48 Foam::topoSetSource::addToUsageTable Foam::surfaceToPoint::usage_
49 (
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"
58 );
59 
60 
61 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
62 
63 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
64 {
65  cpuTime timer;
66 
67  triSurface surf(surfName_, surfType_, scale_);
68 
69  if (verbose_)
70  {
71  Info<< " Read surface from " << surfName_
72  << " in = "<< timer.cpuTimeIncrement() << " s" << nl << endl;
73  }
74 
75  // Construct search engine on surface
76  triSurfaceSearch querySurf(surf);
77 
78  if (includeInside_ || includeOutside_)
79  {
80  boolList pointInside(querySurf.calcInside(mesh_.points()));
81 
82  forAll(pointInside, pointi)
83  {
84  if (pointInside[pointi] ? includeInside_ : includeOutside_)
85  {
86  addOrDelete(set, pointi, add);
87  }
88  }
89  }
90 
91  if (nearDist_ > 0)
92  {
93  const pointField& meshPoints = mesh_.points();
94 
95  // Box dimensions to search in octree.
96  const vector span(nearDist_, nearDist_, nearDist_);
97 
98  forAll(meshPoints, pointi)
99  {
100  const point& pt = meshPoints[pointi];
101 
102  pointIndexHit inter = querySurf.nearest(pt, span);
103 
104  if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
105  {
106  addOrDelete(set, pointi, add);
107  }
108  }
109  }
110 }
111 
112 
113 void Foam::surfaceToPoint::checkSettings() const
114 {
115  if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
116  {
118  << "Illegal point selection specification."
119  << " Result would be either all or no points." << endl
120  << "Please set one of includeInside or includeOutside"
121  << " to true, set nearDistance to a value > 0"
122  << exit(FatalError);
123  }
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 
130 (
131  const polyMesh& mesh,
132  const fileName& surfName,
133  const scalar nearDist,
134  const bool includeInside,
135  const bool includeOutside
136 )
137 :
139  surfName_(surfName),
140  surfType_(),
141  scale_(-1),
142  nearDist_(nearDist),
143  includeInside_(includeInside),
144  includeOutside_(includeOutside)
145 {
146  checkSettings();
147 }
148 
149 
151 (
152  const polyMesh& mesh,
153  const dictionary& dict
154 )
155 :
157  surfName_(dict.get<fileName>("file").expand()),
158  surfType_(dict.getOrDefault<word>("fileType", word::null)),
159  scale_(dict.getOrDefault<scalar>("scale", -1)),
160  nearDist_(dict.get<scalar>("nearDistance")),
161  includeInside_(dict.get<bool>("includeInside")),
162  includeOutside_(dict.get<bool>("includeOutside"))
163 {
164  checkSettings();
165 }
166 
167 
169 (
170  const polyMesh& mesh,
171  Istream& is
172 )
173 :
175  surfName_(checkIs(is)),
176  surfType_(),
177  scale_(-1),
178  nearDist_(readScalar(checkIs(is))),
179  includeInside_(readBool(checkIs(is))),
180  includeOutside_(readBool(checkIs(is)))
181 {
182  checkSettings();
183 }
184 
185 
186 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
187 
189 (
190  const topoSetSource::setAction action,
191  topoSet& set
192 ) const
193 {
194  if (action == topoSetSource::ADD || action == topoSetSource::NEW)
195  {
196  if (verbose_)
197  {
198  Info<< " Adding points in relation to surface " << surfName_
199  << " ..." << endl;
200  }
201 
202  combine(set, true);
203  }
204  else if (action == topoSetSource::SUBTRACT)
205  {
206  if (verbose_)
207  {
208  Info<< " Removing points in relation to surface " << surfName_
209  << " ..." << endl;
210  }
211 
212  combine(set, false);
213  }
214 }
215 
216 
217 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1069
Foam::topoSetSource::ADD
Add elements to current set.
Definition: topoSetSource.H:103
Foam::BitOps::set
void set(List< bool > &bools, const labelRange &range)
Set the specified range 'on' in a boolList.
Definition: BitOps.C:37
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::topoSetSource::addToUsageTable
Class with constructor to add usage string to table.
Definition: topoSetSource.H:129
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::topoSetSource::setAction
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:100
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::topoSetSource::NEW
Create a new set and ADD elements to it.
Definition: topoSetSource.H:104
triSurface.H
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::cpuTime
cpuTimeCxx cpuTime
Selection of preferred clock mechanism for the elapsed cpu time.
Definition: cpuTimeFwd.H:41
Foam::topoSetSource::verbose_
bool verbose_
Output verbosity (default: true)
Definition: topoSetSource.H:159
surfaceToPoint.H
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::readBool
bool readBool(Istream &is)
Read bool from stream using Foam::Switch(Istream&)
Definition: bool.C:75
Foam::ListListOps::combine
AccessType combine(const UList< T > &lists, AccessOp aop=accessOp< T >())
Combines sub-lists into a single list.
Definition: ListListOps.C:69
Foam::topoSet
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:63
Foam::topoSetPointSource
The topoSetPointSource is a intermediate class for handling topoSet sources for selecting points.
Definition: topoSetPointSource.H:54
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
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:939
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::topoSetSource::SUBTRACT
Subtract elements from current set.
Definition: topoSetSource.H:105
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:51
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:130
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::pointIndexHit
PointIndexHit< point > pointIndexHit
A PointIndexHit for 3D points.
Definition: pointIndexHit.H:46
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::string::expand
string & expand(const bool allowEmpty=false)
Definition: string.C:173
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
triSurfaceSearch.H
Foam::topoSetSource::addOrDelete
void addOrDelete(topoSet &set, const label id, const bool add) const
Add or delete id from set. Add when 'add' is true.
Definition: topoSetSource.C:171
Foam::surfaceToPoint::applyToSet
virtual void applyToSet(const topoSetSource::setAction action, topoSet &set) const
Apply specified action to the topoSet.
Definition: surfaceToPoint.C:189
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::topoSetSource::mesh_
const polyMesh & mesh_
Reference to the mesh.
Definition: topoSetSource.H:156
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)