arcUniform.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-2024 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 "arcUniform.H"
27 #include "sampledSet.H"
28 #include "meshSearch.H"
29 #include "DynamicList.H"
30 #include "polyMesh.H"
32 #include "word.H"
33 #include "points.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace sampledSets
40 {
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::sampledSets::arcUniform::calcSamples
50 (
51  DynamicList<point>& samplingPositions,
52  DynamicList<scalar>& samplingDistances,
53  DynamicList<label>& samplingSegments,
54  DynamicList<label>& samplingCells,
55  DynamicList<label>& samplingFaces
56 ) const
57 {
58  // Get the coordinate system
59  const vector axis1 = radial_ - (radial_ & normal_)*normal_;
60  const vector axis2 = normal_ ^ axis1;
61  const scalar radius = mag(axis1);
62 
63  // Compute all point locations
64  const scalarField ts(scalarList(identityMap(nPoints_))/(nPoints_ - 1));
65  const scalarField theta((1 - ts)*startAngle_ + ts*endAngle_);
66  const scalarField c(cos(theta)), s(sin(theta));
67  const pointField points(centre_ + c*axis1 + s*axis2);
68 
69  // Calculate the sampling topology
71  (
72  mesh(),
73  searchEngine(),
74  points,
75  samplingPositions,
76  samplingDistances,
77  samplingSegments,
78  samplingCells,
79  samplingFaces
80  );
81 
82  // Overwrite the distances
83  forAll(samplingPositions, i)
84  {
85  const vector v = samplingPositions[i] - centre_;
86  const scalar theta = atan2(v & axis2, v & axis1);
87  samplingDistances[i] = radius*theta;
88  }
89 }
90 
91 
92 void Foam::sampledSets::arcUniform::genSamples()
93 {
94  DynamicList<point> samplingPositions;
95  DynamicList<scalar> samplingDistances;
96  DynamicList<label> samplingSegments;
97  DynamicList<label> samplingCells;
98  DynamicList<label> samplingFaces;
99 
100  calcSamples
101  (
102  samplingPositions,
103  samplingDistances,
104  samplingSegments,
105  samplingCells,
106  samplingFaces
107  );
108 
109  samplingPositions.shrink();
110  samplingDistances.shrink();
111  samplingSegments.shrink();
112  samplingCells.shrink();
113  samplingFaces.shrink();
114 
115  setSamples
116  (
117  samplingPositions,
118  samplingDistances,
119  samplingSegments,
120  samplingCells,
121  samplingFaces
122  );
123 }
124 
125 
126 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
127 
129 (
130  const word& name,
131  const polyMesh& mesh,
132  const meshSearch& searchEngine,
133  const dictionary& dict
134 )
135 :
136  sampledSet(name, mesh, searchEngine, dict),
137  centre_(dict.lookup("centre")),
138  normal_(normalised(dict.lookup<vector>("normal"))),
139  radial_(dict.lookup<vector>("radial")),
140  startAngle_(dict.lookup<scalar>("startAngle")),
141  endAngle_(dict.lookup<scalar>("endAngle")),
142  nPoints_(dict.lookup<scalar>("nPoints"))
143 {
144  genSamples();
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
149 
151 {}
152 
153 
154 // ************************************************************************* //
#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:162
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 an arc.
Definition: arcUniform.H:120
virtual ~arcUniform()
Destructor.
Definition: arcUniform.C:150
arcUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: arcUniform.C:129
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
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const dimensionedScalar c
Speed of light in a vacuum.
defineTypeNameAndDebug(arcUniform, 0)
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
Namespace for OpenFOAM.
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
dimensionedScalar sin(const dimensionedScalar &ds)
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.
dimensionedScalar atan2(const dimensionedScalar &x, const dimensionedScalar &y)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:510
dimensioned< scalar > mag(const dimensioned< Type > &)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict