triSurfaceMeshPointSet.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) 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 "triSurfaceMeshPointSet.H"
30 #include "meshSearch.H"
31 #include "DynamicList.H"
32 #include "polyMesh.H"
34 #include "triSurfaceMesh.H"
35 #include "Time.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(triSurfaceMeshPointSet, 0);
42  addToRunTimeSelectionTable(sampledSet, triSurfaceMeshPointSet, word);
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::triSurfaceMeshPointSet::calcSamples
49 (
50  DynamicList<point>& samplingPts,
51  DynamicList<label>& samplingCells,
52  DynamicList<label>& samplingFaces,
53  DynamicList<label>& samplingSegments,
54  DynamicList<scalar>& samplingCurveDist
55 ) const
56 {
57  forAll(sampleCoords_, sampleI)
58  {
59  label celli = searchEngine().findCell(sampleCoords_[sampleI]);
60 
61  if (celli != -1)
62  {
63  samplingPts.append(sampleCoords_[sampleI]);
64  samplingCells.append(celli);
65  samplingFaces.append(-1);
66  samplingSegments.append(0);
67  samplingCurveDist.append(1.0 * sampleI);
68  }
69  }
70 }
71 
72 
73 void Foam::triSurfaceMeshPointSet::genSamples()
74 {
75  // Storage for sample points
76  DynamicList<point> samplingPts;
77  DynamicList<label> samplingCells;
78  DynamicList<label> samplingFaces;
79  DynamicList<label> samplingSegments;
80  DynamicList<scalar> samplingCurveDist;
81 
82  calcSamples
83  (
84  samplingPts,
85  samplingCells,
86  samplingFaces,
87  samplingSegments,
88  samplingCurveDist
89  );
90 
91  samplingPts.shrink();
92  samplingCells.shrink();
93  samplingFaces.shrink();
94  samplingSegments.shrink();
95  samplingCurveDist.shrink();
96 
97  // Move into *this
98  setSamples
99  (
100  std::move(samplingPts),
101  std::move(samplingCells),
102  std::move(samplingFaces),
103  std::move(samplingSegments),
104  std::move(samplingCurveDist)
105  );
106 
107  if (debug)
108  {
109  write(Info);
110  }
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
115 
117 (
118  const word& name,
119  const polyMesh& mesh,
120  const meshSearch& searchEngine,
121  const dictionary& dict
122 )
123 :
124  sampledSet(name, mesh, searchEngine, dict),
125  surfaceName_(dict.get<word>("surface"))
126 {
127  // Get or load surface
128 
129  const auto* surfPtr =
130  mesh.time().cfindObject<triSurfaceMesh>(surfaceName_);
131 
132  if (surfPtr)
133  {
134  // Note: should use localPoints() instead of points() but assume
135  // trisurface is compact.
136  sampleCoords_ = surfPtr->points();
137  }
138  else
139  {
140  sampleCoords_ = triSurface
141  (
142  IOobject
143  (
144  surfaceName_,
145  mesh.time().constant(), // instance
146  "triSurface", // local
147  mesh.time(),
151  ),
153  ).points();
154  }
155 
156  genSamples();
157 }
158 
159 
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 
163 (
164  const List<point>& pts
165 ) const
166 {
167  if (pts.size())
168  {
169  // Use first samplePt as starting point
170  return pts.first();
171  }
172 
173  return Zero;
174 }
175 
176 
177 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
dictionary dict
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
Ignore writing from objectRegistry::writeObject()
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:759
const Time & time() const noexcept
Return time registry.
triSurfaceMeshPointSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:474
virtual point getRefPoint(const List< point > &pts) const
Get reference point.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
const polyMesh & mesh() const noexcept
Definition: sampledSet.H:373
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
messageStream Info
Information stream (stdout output on master, null elsewhere)
const meshSearch & searchEngine() const noexcept
Definition: sampledSet.H:378
Do not request registration (bool: false)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
const pointField & pts
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127