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 | Copyright (C) 2011-2012 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 "triSurfaceMeshPointSet.H"
27 #include "meshSearch.H"
28 #include "DynamicList.H"
29 #include "polyMesh.H"
31 #include "triSurfaceMesh.H"
32 #include "Time.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(triSurfaceMeshPointSet, 0);
39  addToRunTimeSelectionTable(sampledSet, triSurfaceMeshPointSet, word);
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::triSurfaceMeshPointSet::calcSamples
46 (
47  DynamicList<point>& samplingPts,
48  DynamicList<label>& samplingCells,
49  DynamicList<label>& samplingFaces,
50  DynamicList<label>& samplingSegments,
51  DynamicList<scalar>& samplingCurveDist
52 ) const
53 {
54  forAll(sampleCoords_, sampleI)
55  {
56  label cellI = searchEngine().findCell(sampleCoords_[sampleI]);
57 
58  if (cellI != -1)
59  {
60  samplingPts.append(sampleCoords_[sampleI]);
61  samplingCells.append(cellI);
62  samplingFaces.append(-1);
63  samplingSegments.append(0);
64  samplingCurveDist.append(1.0 * sampleI);
65  }
66  }
67 }
68 
69 
70 void Foam::triSurfaceMeshPointSet::genSamples()
71 {
72  // Storage for sample points
73  DynamicList<point> samplingPts;
74  DynamicList<label> samplingCells;
75  DynamicList<label> samplingFaces;
76  DynamicList<label> samplingSegments;
77  DynamicList<scalar> samplingCurveDist;
78 
79  calcSamples
80  (
81  samplingPts,
82  samplingCells,
83  samplingFaces,
84  samplingSegments,
85  samplingCurveDist
86  );
87 
88  samplingPts.shrink();
89  samplingCells.shrink();
90  samplingFaces.shrink();
91  samplingSegments.shrink();
92  samplingCurveDist.shrink();
93 
94  setSamples
95  (
96  samplingPts,
97  samplingCells,
98  samplingFaces,
99  samplingSegments,
100  samplingCurveDist
101  );
102 }
103 
104 
105 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
106 
108 (
109  const word& name,
110  const polyMesh& mesh,
111  const meshSearch& searchEngine,
112  const dictionary& dict
113 )
114 :
115  sampledSet(name, mesh, searchEngine, dict),
116  surface_(dict.lookup("surface"))
117 {
118  // Load surface.
119  if (mesh.time().foundObject<triSurfaceMesh>(surface_))
120  {
121  // Note: should use localPoints() instead of points() but assume
122  // trisurface is compact.
123  sampleCoords_ = mesh.time().lookupObject<triSurfaceMesh>
124  (
125  surface_
126  ).points();
127  }
128  else
129  {
130  sampleCoords_ = triSurfaceMesh
131  (
132  IOobject
133  (
134  surface_,
135  mesh.time().constant(), // instance
136  "triSurface", // local
137  mesh.time(),
140  false
141  )
142  ).points();
143  }
144 
145  genSamples();
146 
147  if (debug)
148  {
149  write(Info);
150  }
151 }
152 
153 
154 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
155 
157 {}
158 
159 
160 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
161 
163  const
164 {
165  if (pts.size())
166  {
167  // Use first samplePt as starting point
168  return pts[0];
169  }
170  else
171  {
172  return vector::zero;
173  }
174 }
175 
176 
177 // ************************************************************************* //
const pointField & points
triSurfaceMeshPointSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
bool foundObject(const word &name) const
Is the named Type found?
A class for handling words, derived from string.
Definition: word.H:59
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:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
messageStream Info
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
Namespace for OpenFOAM.
runTime write()
virtual ~triSurfaceMeshPointSet()
Destructor.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
label findCell(const point &location, const label seedCellI=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:789
#define forAll(list, i)
Definition: UList.H:421
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Macros for easy insertion into run-time selection tables.
virtual tmp< pointField > points() const
Get the points that define the surface.
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
static const Vector zero
Definition: Vector.H:80
const Time & time() const
Return time.
virtual point getRefPoint(const List< point > &) const
Get reference point.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
IOoject and searching on triSurface.
defineTypeNameAndDebug(combustionModel, 0)