arraySet.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-2016 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 "arraySet.H"
27 #include "sampledSet.H"
28 #include "meshSearch.H"
29 #include "DynamicList.H"
30 #include "polyMesh.H"
32 #include "word.H"
33 #include "transform.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(arraySet, 0);
40  addToRunTimeSelectionTable(sampledSet, arraySet, word);
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::arraySet::calcSamples
47 (
48  DynamicList<point>& samplingPts,
49  DynamicList<label>& samplingCells,
50  DynamicList<label>& samplingFaces,
51  DynamicList<label>& samplingSegments,
52  DynamicList<scalar>& samplingCurveDist
53 ) const
54 {
55  const meshSearch& queryMesh = searchEngine();
56 
57  label nTotalSamples
58  (
59  pointsDensity_.x()
60  *pointsDensity_.y()
61  *pointsDensity_.z()
62  );
63 
64  List<point> sampleCoords(nTotalSamples);
65 
66  const scalar deltax = spanBox_.x()/(pointsDensity_.x() + 1);
67  const scalar deltay = spanBox_.y()/(pointsDensity_.y() + 1);
68  const scalar deltaz = spanBox_.z()/(pointsDensity_.z() + 1);
69 
70  label p(0);
71  for (label k=1; k<=pointsDensity_.z(); k++)
72  {
73  for (label j=1; j<=pointsDensity_.y(); j++)
74  {
75  for (label i=1; i<=pointsDensity_.x(); i++)
76  {
77  vector t(deltax*i , deltay*j, deltaz*k);
78  sampleCoords[p] = coordSys_.origin() + t;
79  p++;
80  }
81  }
82  }
83 
84  forAll(sampleCoords, i)
85  {
86  sampleCoords[i] = transform(coordSys_.R().R(), sampleCoords[i]);
87  }
88 
89  forAll(sampleCoords, sampleI)
90  {
91  label celli = queryMesh.findCell(sampleCoords[sampleI]);
92 
93  if (celli != -1)
94  {
95  samplingPts.append(sampleCoords[sampleI]);
96  samplingCells.append(celli);
97  samplingFaces.append(-1);
98  samplingSegments.append(0);
99  samplingCurveDist.append(1.0 * sampleI);
100  }
101  }
102 }
103 
104 
105 void Foam::arraySet::genSamples()
106 {
107  // Storage for sample points
108  DynamicList<point> samplingPts;
109  DynamicList<label> samplingCells;
110  DynamicList<label> samplingFaces;
111  DynamicList<label> samplingSegments;
112  DynamicList<scalar> samplingCurveDist;
113 
114  calcSamples
115  (
116  samplingPts,
117  samplingCells,
118  samplingFaces,
119  samplingSegments,
120  samplingCurveDist
121  );
122 
123  samplingPts.shrink();
124  samplingCells.shrink();
125  samplingFaces.shrink();
126  samplingSegments.shrink();
127  samplingCurveDist.shrink();
128 
129  setSamples
130  (
131  samplingPts,
132  samplingCells,
133  samplingFaces,
134  samplingSegments,
135  samplingCurveDist
136  );
137 }
138 
139 
140 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
141 
143 (
144  const word& name,
145  const polyMesh& mesh,
146  const meshSearch& searchEngine,
147  const word& axis,
148  const coordinateSystem& origin,
149  const Vector<label>& pointsDensity,
150  const Vector<scalar>& spanBox
151 )
152 :
153  sampledSet(name, mesh, searchEngine, axis),
154  coordSys_(origin),
155  pointsDensity_(pointsDensity),
156  spanBox_(spanBox)
157 {
158  genSamples();
159 
160  if (debug)
161  {
162  write(Info);
163  }
164 }
165 
166 
168 (
169  const word& name,
170  const polyMesh& mesh,
171  const meshSearch& searchEngine,
172  const dictionary& dict
173 )
174 :
175  sampledSet(name, mesh, searchEngine, dict),
176  coordSys_(dict),
177  pointsDensity_(dict.lookup("pointsDensity")),
178  spanBox_(dict.lookup("spanBox"))
179 {
180  genSamples();
181 
182  if (debug)
183  {
184  write(Info);
185  }
186 }
187 
188 
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 
192 {}
193 
194 
195 // ************************************************************************* //
arraySet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const coordinateSystem &coordSys, const Vector< label > &pointsDensity, const Vector< scalar > &spanBox)
Construct from components.
Definition: arraySet.C:143
Base class for other coordinate system specifications.
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
virtual ~arraySet()
Destructor.
Definition: arraySet.C:191
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
A class for handling words, derived from string.
Definition: word.H:59
3D tensor transformation operations.
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
runTime write()
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451