lineUniform.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 
26 #include "lineUniform.H"
27 #include "meshSearch.H"
28 #include "DynamicList.H"
29 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace sampledSets
37 {
38  defineTypeNameAndDebug(lineUniform, 0);
39  addToRunTimeSelectionTable(sampledSet, lineUniform, word);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
45 
46 void Foam::sampledSets::lineUniform::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  label sampleSegmentI = 0, sampleI = 0;
56  scalar sampleT = 0;
57 
58  while (sampleI < nPoints_)
59  {
60  const point pt = (1 - sampleT)*start_ + sampleT*end_;
61 
62  const label sampleCellI = searchEngine().findCell(pt);
63 
64  if (sampleCellI == -1)
65  {
66  if (++ sampleI < nPoints_)
67  {
68  sampleT = scalar(sampleI)/(nPoints_ - 1);
69  }
70  }
71  else
72  {
73  passiveParticle sampleParticle(mesh(), pt, sampleCellI);
74 
75  do
76  {
77  samplingPts.append(sampleParticle.position());
78  samplingCells.append(sampleParticle.cell());
79  samplingFaces.append(-1);
80  samplingSegments.append(sampleSegmentI);
81  samplingCurveDist.append(sampleT*mag(end_ - start_));
82 
83  if (++ sampleI < nPoints_)
84  {
85  sampleT = scalar(sampleI)/(nPoints_ - 1);
86  sampleParticle.track((end_ - start_)/(nPoints_ - 1), 0);
87  }
88  }
89  while (sampleI < nPoints_ && !sampleParticle.onBoundaryFace());
90 
91  ++ sampleSegmentI;
92  }
93  }
94 }
95 
96 
97 void Foam::sampledSets::lineUniform::genSamples()
98 {
99  DynamicList<point> samplingPts;
100  DynamicList<label> samplingCells;
101  DynamicList<label> samplingFaces;
102  DynamicList<label> samplingSegments;
103  DynamicList<scalar> samplingCurveDist;
104 
105  calcSamples
106  (
107  samplingPts,
108  samplingCells,
109  samplingFaces,
110  samplingSegments,
111  samplingCurveDist
112  );
113 
114  samplingPts.shrink();
115  samplingCells.shrink();
116  samplingFaces.shrink();
117  samplingSegments.shrink();
118  samplingCurveDist.shrink();
119 
120  setSamples
121  (
122  samplingPts,
123  samplingCells,
124  samplingFaces,
125  samplingSegments,
126  samplingCurveDist
127  );
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
132 
134 (
135  const word& name,
136  const polyMesh& mesh,
137  const meshSearch& searchEngine,
138  const dictionary& dict
139 )
140 :
141  sampledSet(name, mesh, searchEngine, dict),
142  start_(dict.lookup("start")),
143  end_(dict.lookup("end")),
144  nPoints_(readLabel(dict.lookup("nPoints")))
145 {
146  genSamples();
147 
148  if (debug)
149  {
150  write(Pout);
151  }
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
158 {}
159 
160 
161 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
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:158
virtual ~lineUniform()
Destructor.
Definition: lineUniform.C:157
Macros for easy insertion into run-time selection tables.
dynamicFvMesh & mesh
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:750
A class for handling words, derived from string.
Definition: word.H:59
label readLabel(Istream &is)
Definition: label.H:64
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
lineUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: lineUniform.C:134
vector point
Point is a vector.
Definition: point.H:41
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
virtual bool write()
Sample and write.
Definition: sampledSets.C:241
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
defineTypeNameAndDebug(arcUniform, 0)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583