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-2021 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"
30 #include "sampledSetCloud.H"
31 #include "points.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace sampledSets
39 {
40  defineTypeNameAndDebug(lineUniform, 0);
41  addToRunTimeSelectionTable(sampledSet, lineUniform, word);
42 }
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::sampledSets::lineUniform::calcSamples
49 (
50  DynamicList<point>& samplingPositions,
51  DynamicList<scalar>& samplingDistances,
52  DynamicList<label>& samplingSegments,
53  DynamicList<label>& samplingCells,
54  DynamicList<label>& samplingFaces
55 ) const
56 {
57  // Calculate all sampling points
58  const scalarField ts(scalarList(identity(nPoints_))/(nPoints_ - 1));
59  const pointField points((1 - ts)*start_ + ts*end_);
60 
61  // Calculate the sampling topology
63  (
64  mesh(),
65  searchEngine(),
66  points,
67  samplingPositions,
68  samplingDistances,
69  samplingSegments,
70  samplingCells,
71  samplingFaces
72  );
73 
74  // Overwrite the distances
75  forAll(samplingPositions, i)
76  {
77  samplingDistances[i] = mag(samplingPositions[i] - start_);
78  }
79 }
80 
81 
82 void Foam::sampledSets::lineUniform::genSamples()
83 {
84  DynamicList<point> samplingPositions;
85  DynamicList<scalar> samplingDistances;
86  DynamicList<label> samplingSegments;
87  DynamicList<label> samplingCells;
88  DynamicList<label> samplingFaces;
89 
90  calcSamples
91  (
92  samplingPositions,
93  samplingDistances,
94  samplingSegments,
95  samplingCells,
96  samplingFaces
97  );
98 
99  samplingPositions.shrink();
100  samplingDistances.shrink();
101  samplingSegments.shrink();
102  samplingCells.shrink();
103  samplingFaces.shrink();
104 
105  setSamples
106  (
107  samplingPositions,
108  samplingDistances,
109  samplingSegments,
110  samplingCells,
111  samplingFaces
112  );
113 }
114 
115 
116 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
117 
119 (
120  const word& name,
121  const polyMesh& mesh,
122  const meshSearch& searchEngine,
123  const dictionary& dict
124 )
125 :
126  sampledSet(name, mesh, searchEngine, dict),
127  start_(dict.lookup("start")),
128  end_(dict.lookup("end")),
129  nPoints_(dict.lookup<label>("nPoints"))
130 {
131  genSamples();
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
136 
138 {}
139 
140 
141 // ************************************************************************* //
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:434
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
virtual ~lineUniform()
Destructor.
Definition: lineUniform.C:137
fvMesh & mesh
Macros for easy insertion into run-time selection tables.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
const pointField & points
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:61
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
static void calcSamples(const polyMesh &mesh, const meshSearch &searchEngine, const pointField &points, DynamicList< point > &samplingPositons, DynamicList< scalar > &samplingDistances, DynamicList< label > &samplingSegments, DynamicList< label > &samplingCells, DynamicList< label > &samplingFaces)
Calculate all the sampling points.
Definition: points.C:48
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
lineUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: lineUniform.C:119
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
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:864