triSurfaceMeshSampledSet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 
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 namespace sampledSets
39 {
40  defineTypeNameAndDebug(triSurfaceMeshSampledSet, 0);
41  addToRunTimeSelectionTable(sampledSet, triSurfaceMeshSampledSet, word);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::sampledSets::triSurfaceMeshSampledSet::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(points_, i)
58  {
59  const point& pt = points_[i];
60  const label celli = searchEngine().findCell(pt);
61 
62  if (celli != -1)
63  {
64  samplingPts.append(pt);
65  samplingCells.append(celli);
66  samplingFaces.append(-1);
67  samplingSegments.append(0);
68  samplingCurveDist.append(scalar(i));
69  }
70  }
71 }
72 
73 
74 void Foam::sampledSets::triSurfaceMeshSampledSet::genSamples()
75 {
76  // Storage for sample points
77  DynamicList<point> samplingPts;
78  DynamicList<label> samplingCells;
79  DynamicList<label> samplingFaces;
80  DynamicList<label> samplingSegments;
81  DynamicList<scalar> samplingCurveDist;
82 
83  calcSamples
84  (
85  samplingPts,
86  samplingCells,
87  samplingFaces,
88  samplingSegments,
89  samplingCurveDist
90  );
91 
92  samplingPts.shrink();
93  samplingCells.shrink();
94  samplingFaces.shrink();
95  samplingSegments.shrink();
96  samplingCurveDist.shrink();
97 
98  setSamples
99  (
100  samplingPts,
101  samplingCells,
102  samplingFaces,
103  samplingSegments,
104  samplingCurveDist
105  );
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const word& name,
114  const polyMesh& mesh,
115  const meshSearch& searchEngine,
116  const dictionary& dict
117 )
118 :
119  sampledSet(name, mesh, searchEngine, dict),
120  surface_(dict.lookup("surface")),
121  points_
122  (
123  mesh.time().foundObject<triSurfaceMesh>(surface_)
124  ? mesh.time().lookupObject<triSurfaceMesh>(surface_).points()
126  (
127  IOobject
128  (
129  surface_,
130  mesh.time().constant(),
131  "triSurface",
132  mesh.time(),
133  IOobject::MUST_READ,
134  IOobject::NO_WRITE,
135  false
136  )
137  ).points()
138  )
139 {
140  genSamples();
141 
142  if (debug)
143  {
144  write(Info);
145  }
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
150 
152 {}
153 
154 
155 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
bool foundObject(const word &name) const
Is the named Type found?
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.
IOoject and searching on triSurface.
const pointField & points
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:61
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:690
A class for handling words, derived from string.
Definition: word.H:59
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
const Time & time() const
Return time.
vector point
Point is a vector.
Definition: point.H:41
triSurfaceMeshSampledSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
virtual bool write()
Sample and write.
Definition: sampledSets.C:241
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
defineTypeNameAndDebug(arcUniform, 0)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576