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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "triSurfaceMeshPointSet.H"
29 #include "meshSearch.H"
30 #include "DynamicList.H"
31 #include "polyMesh.H"
33 #include "triSurfaceMesh.H"
34 #include "Time.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  defineTypeNameAndDebug(triSurfaceMeshPointSet, 0);
41  addToRunTimeSelectionTable(sampledSet, triSurfaceMeshPointSet, word);
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
47 void Foam::triSurfaceMeshPointSet::calcSamples
48 (
49  DynamicList<point>& samplingPts,
50  DynamicList<label>& samplingCells,
51  DynamicList<label>& samplingFaces,
52  DynamicList<label>& samplingSegments,
53  DynamicList<scalar>& samplingCurveDist
54 ) const
55 {
56  forAll(sampleCoords_, sampleI)
57  {
58  label celli = searchEngine().findCell(sampleCoords_[sampleI]);
59 
60  if (celli != -1)
61  {
62  samplingPts.append(sampleCoords_[sampleI]);
63  samplingCells.append(celli);
64  samplingFaces.append(-1);
65  samplingSegments.append(0);
66  samplingCurveDist.append(1.0 * sampleI);
67  }
68  }
69 }
70 
71 
72 void Foam::triSurfaceMeshPointSet::genSamples()
73 {
74  // Storage for sample points
75  DynamicList<point> samplingPts;
76  DynamicList<label> samplingCells;
77  DynamicList<label> samplingFaces;
78  DynamicList<label> samplingSegments;
79  DynamicList<scalar> samplingCurveDist;
80 
81  calcSamples
82  (
83  samplingPts,
84  samplingCells,
85  samplingFaces,
86  samplingSegments,
87  samplingCurveDist
88  );
89 
90  samplingPts.shrink();
91  samplingCells.shrink();
92  samplingFaces.shrink();
93  samplingSegments.shrink();
94  samplingCurveDist.shrink();
95 
96  // Move into *this
97  setSamples
98  (
99  std::move(samplingPts),
100  std::move(samplingCells),
101  std::move(samplingFaces),
102  std::move(samplingSegments),
103  std::move(samplingCurveDist)
104  );
105 
106  if (debug)
107  {
108  write(Info);
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
116 (
117  const word& name,
118  const polyMesh& mesh,
119  const meshSearch& searchEngine,
120  const dictionary& dict
121 )
122 :
123  sampledSet(name, mesh, searchEngine, dict),
124  surface_(dict.get<word>("surface"))
125 {
126  // Load surface.
127  if (mesh.time().foundObject<triSurfaceMesh>(surface_))
128  {
129  // Note: should use localPoints() instead of points() but assume
130  // trisurface is compact.
131  sampleCoords_ = mesh.time().lookupObject<triSurfaceMesh>
132  (
133  surface_
134  ).points();
135  }
136  else
137  {
138  sampleCoords_ = triSurfaceMesh
139  (
140  IOobject
141  (
142  surface_,
143  mesh.time().constant(), // instance
144  "triSurface", // local
145  mesh.time(),
148  false
149  )
150  ).points();
151  }
152 
153  genSamples();
154 }
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
160 (
161  const List<point>& pts
162 ) const
163 {
164  if (pts.size())
165  {
166  // Use first samplePt as starting point
167  return pts.first();
168  }
169 
170  return Zero;
171 }
172 
173 
174 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
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:130
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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.
Definition: zero.H:128
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:116
Foam::triSurfaceMesh
IOoject and searching on triSurface.
Definition: triSurfaceMesh.H:100
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
Foam::triSurfaceMeshPointSet::getRefPoint
virtual point getRefPoint(const List< point > &pts) const
Get reference point.
Definition: triSurfaceMeshPointSet.C:160
Foam::meshSearch::findCell
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:751
polyMesh.H
Foam::objectRegistry::foundObject
bool foundObject(const word &name, const bool recursive=false) const
Is the named Type found?
Definition: objectRegistryTemplates.C:379
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:290
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
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:121
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:677
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Time.H
meshSearch.H
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: HashTable.H:102
points
const pointField & points
Definition: gmvOutputHeader.H:1
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:35
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:246
DynamicList.H
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
triSurfaceMesh.H
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::IOobject::MUST_READ
Definition: IOobject.H:120