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(),
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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::PrimitivePatch::points
const Field< point_type > & points() const noexcept
Return reference to global points.
Definition: PrimitivePatch.H:299
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::sampledSet
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:83
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:60
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::sampledSet::searchEngine
const meshSearch & searchEngine() const
Definition: sampledSet.H:286
Foam::triSurfaceMeshPointSet::triSurfaceMeshPointSet
triSurfaceMeshPointSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: triSurfaceMeshPointSet.C:117
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:106
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
Foam::triSurfaceMeshPointSet::getRefPoint
virtual point getRefPoint(const List< point > &pts) const
Get reference point.
Definition: triSurfaceMeshPointSet.C:163
Foam::meshSearch::findCell
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:780
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::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
triSurfaceMeshPointSet.H
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::triSurfaceMesh::points
virtual tmp< pointField > points() const
Get the points that define the surface.
Definition: triSurfaceMesh.C:596
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Time.H
meshSearch.H
Foam::objectRegistry::cfindObject
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Definition: objectRegistryTemplates.C:390
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
DynamicList.H
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
triSurfaceMesh.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:185