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-2023 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 {
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(identityMap(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 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:58
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
const meshSearch & searchEngine() const
Access the search engine.
Definition: sampledSet.H:216
const polyMesh & mesh() const
Access the mesh.
Definition: sampledSet.H:210
Uniform samples along a line.
Definition: lineUniform.H:100
lineUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: lineUniform.C:119
virtual ~lineUniform()
Destructor.
Definition: lineUniform.C:137
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
Set of sets to sample. Call sampledSets.write() to sample&write files.
A class for handling words, derived from string.
Definition: word.H:62
const pointField & points
defineTypeNameAndDebug(arcUniform, 0)
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
Namespace for OpenFOAM.
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
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensioned< scalar > mag(const dimensioned< Type > &)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict