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-2021 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 {
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::surfaceToPoint::combine(topoSet& set, const bool add) const
45 {
46  cpuTime timer;
47 
48  triSurface surf(surfName_);
49 
50  Info<< " Read surface from " << surfName_
51  << " in = "<< timer.cpuTimeIncrement() << " s" << endl << endl;
52 
53  // Construct search engine on surface
54  triSurfaceSearch querySurf(surf);
55 
56  if (includeInside_ || includeOutside_)
57  {
58  boolList pointInside(querySurf.calcInside(mesh_.points()));
59 
60  forAll(pointInside, pointi)
61  {
62  bool isInside = pointInside[pointi];
63 
64  if ((isInside && includeInside_) || (!isInside && includeOutside_))
65  {
66  addOrDelete(set, pointi, add);
67  }
68  }
69  }
70 
71  if (nearDist_ > 0)
72  {
73  const pointField& meshPoints = mesh_.points();
74 
75  // Box dimensions to search in octree.
76  const vector span(nearDist_, nearDist_, nearDist_);
77 
78  forAll(meshPoints, pointi)
79  {
80  const point& pt = meshPoints[pointi];
81 
82  pointIndexHit inter = querySurf.nearest(pt, span);
83 
84  if (inter.hit() && (mag(inter.hitPoint() - pt) < nearDist_))
85  {
86  addOrDelete(set, pointi, add);
87  }
88  }
89  }
90 }
91 
92 
93 void Foam::surfaceToPoint::checkSettings() const
94 {
95  if (nearDist_ < 0 && !includeInside_ && !includeOutside_)
96  {
98  << "Illegal point selection specification."
99  << " Result would be either all or no points." << endl
100  << "Please set one of includeInside or includeOutside"
101  << " to true, set nearDistance to a value > 0"
102  << exit(FatalError);
103  }
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
108 
110 (
111  const polyMesh& mesh,
112  const fileName& surfName,
113  const scalar nearDist,
114  const bool includeInside,
115  const bool includeOutside
116 )
117 :
118  topoSetSource(mesh),
119  surfName_(surfName),
120  nearDist_(nearDist),
121  includeInside_(includeInside),
122  includeOutside_(includeOutside)
123 {
124  checkSettings();
125 }
126 
127 
129 (
130  const polyMesh& mesh,
131  const dictionary& dict
132 )
133 :
134  topoSetSource(mesh),
135  surfName_(fileName(dict.lookup("file")).expand()),
136  nearDist_(dict.lookup<scalar>("nearDistance")),
137  includeInside_(readBool(dict.lookup("includeInside"))),
138  includeOutside_(readBool(dict.lookup("includeOutside")))
139 {
140  checkSettings();
141 }
142 
143 
144 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
145 
147 {}
148 
149 
150 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
151 
153 (
154  const topoSetSource::setAction action,
155  topoSet& set
156 ) const
157 {
158  if ( (action == topoSetSource::NEW) || (action == topoSetSource::ADD))
159  {
160  Info<< " Adding points in relation to surface " << surfName_
161  << " ..." << endl;
162 
163  combine(set, true);
164  }
165  else if (action == topoSetSource::DELETE)
166  {
167  Info<< " Removing points in relation to surface " << surfName_
168  << " ..." << endl;
169 
170  combine(set, false);
171  }
172 }
173 
174 
175 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
A class for handling file names.
Definition: fileName.H:82
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1361
A topoSetSource to selects points based on relation to surface.
virtual void applyToSet(const topoSetSource::setAction action, topoSet &) const
surfaceToPoint(const polyMesh &mesh, const fileName &surfName, const scalar nearDist, const bool includeInside, const bool includeOutside)
Construct from components.
virtual ~surfaceToPoint()
Destructor.
Base class of a source for a topoSet.
Definition: topoSetSource.H:64
void addOrDelete(topoSet &set, const label celli, const bool) const
Add (if bool) celli to set or delete celli from set.
Definition: topoSetSource.C:96
setAction
Enumeration defining the valid actions.
Definition: topoSetSource.H:83
const polyMesh & mesh_
Definition: topoSetSource.H:99
General set of labels of mesh quantity (points, cells, faces).
Definition: topoSet.H:65
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
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
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
bool readBool(Istream &)
Definition: boolIO.C:60
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
vector point
Point is a vector.
Definition: point.H:41
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensioned< scalar > mag(const dimensioned< Type > &)
defineTypeNameAndDebug(combustionModel, 0)
error FatalError
treeBoundBox combine(const treeBoundBox &a, const treeBoundBox &b)
Definition: patchToPatch.C:78
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
dictionary dict