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-------------------------------------------------------------------------------
11License
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
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
39namespace Foam
40{
43}
44
45
46// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47
48void 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
73void 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 (
143 (
144 surfaceName_,
145 mesh.time().constant(), // instance
146 "triSurface", // local
147 mesh.time(),
150 false
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
const Field< point_type > & points() const noexcept
Return reference to global points.
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
T & first()
Return the first element of the list.
Definition: UListI.H:202
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:61
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:780
const Time & time() const noexcept
Return time registry.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:86
const meshSearch & searchEngine() const noexcept
Definition: sampledSet.H:324
const polyMesh & mesh() const noexcept
Definition: sampledSet.H:319
A sampleSet from all points of a triSurfaceMesh.
virtual point getRefPoint(const List< point > &pts) const
Get reference point.
IOoject and searching on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:79
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333