FreeFOAM The Cross-Platform CFD Toolkit
cloudSet.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) 1991-2010 OpenCFD Ltd.
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 "cloudSet.H"
27 #include <sampling/sampledSet.H>
28 #include <meshTools/meshSearch.H>
29 #include <OpenFOAM/DynamicList.H>
30 #include <OpenFOAM/polyMesh.H>
32 #include <OpenFOAM/word.H>
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(cloudSet, 0);
39  addToRunTimeSelectionTable(sampledSet, cloudSet, word);
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 void Foam::cloudSet::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::cloudSet::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  meshSearch& searchEngine,
112  const word& axis,
113  const List<point>& sampleCoords
114 )
115 :
116  sampledSet(name, mesh, searchEngine, axis),
117  sampleCoords_(sampleCoords)
118 {
119  genSamples();
120 
121  if (debug)
122  {
123  write(Info);
124  }
125 }
126 
127 
129 (
130  const word& name,
131  const polyMesh& mesh,
132  meshSearch& searchEngine,
133  const dictionary& dict
134 )
135 :
136  sampledSet(name, mesh, searchEngine, dict),
137  sampleCoords_(dict.lookup("points"))
138 {
139  genSamples();
140 
141  if (debug)
142  {
143  write(Info);
144  }
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
149 
151 {}
152 
153 
154 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
155 
157 {
158  if (pts.size())
159  {
160  // Use first samplePt as starting point
161  return pts[0];
162  }
163  else
164  {
165  return vector::zero;
166  }
167 }
168 
169 
170 // ************************ vim: set sw=4 sts=4 et: ************************ //