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-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 "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 #include "unitConversion.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace sampledSets
41 {
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::sampledSets::arcUniform::calcSamples
51 (
52  DynamicList<point>& samplingPositions,
53  DynamicList<scalar>& samplingDistances,
54  DynamicList<label>& samplingSegments,
55  DynamicList<label>& samplingCells,
56  DynamicList<label>& samplingFaces
57 ) const
58 {
59  // Get the coordinate system
60  const vector axis1 = radial_ - (radial_ & normal_)*normal_;
61  const vector axis2 = normal_ ^ axis1;
62  const scalar radius = mag(axis1);
63 
64  // Compute all point locations
65  const scalarField ts(scalarList(identityMap(nPoints_))/(nPoints_ - 1));
66  const scalarField theta((1 - ts)*startAngle_ + ts*endAngle_);
67  const scalarField c(cos(theta)), s(sin(theta));
68  const pointField points(centre_ + c*axis1 + s*axis2);
69 
70  // Calculate the sampling topology
72  (
73  mesh(),
74  searchEngine(),
75  points,
76  samplingPositions,
77  samplingDistances,
78  samplingSegments,
79  samplingCells,
80  samplingFaces
81  );
82 
83  // Overwrite the distances
84  forAll(samplingPositions, i)
85  {
86  const vector v = samplingPositions[i] - centre_;
87  const scalar theta = atan2(v & axis2, v & axis1);
88  samplingDistances[i] = radius*theta;
89  }
90 }
91 
92 
93 void Foam::sampledSets::arcUniform::genSamples()
94 {
95  DynamicList<point> samplingPositions;
96  DynamicList<scalar> samplingDistances;
97  DynamicList<label> samplingSegments;
98  DynamicList<label> samplingCells;
99  DynamicList<label> samplingFaces;
100 
101  calcSamples
102  (
103  samplingPositions,
104  samplingDistances,
105  samplingSegments,
106  samplingCells,
107  samplingFaces
108  );
109 
110  samplingPositions.shrink();
111  samplingDistances.shrink();
112  samplingSegments.shrink();
113  samplingCells.shrink();
114  samplingFaces.shrink();
115 
116  setSamples
117  (
118  samplingPositions,
119  samplingDistances,
120  samplingSegments,
121  samplingCells,
122  samplingFaces
123  );
124 }
125 
126 
127 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
128 
130 (
131  const word& name,
132  const polyMesh& mesh,
133  const meshSearch& searchEngine,
134  const dictionary& dict
135 )
136 :
137  sampledSet(name, mesh, searchEngine, dict),
138  centre_(dict.lookup("centre")),
139  normal_(normalised(dict.lookup<vector>("normal"))),
140  radial_(dict.lookup<vector>("radial")),
141  startAngle_(dict.lookup<scalar>("startAngle")),
142  endAngle_(dict.lookup<scalar>("endAngle")),
143  nPoints_(dict.lookup<scalar>("nPoints"))
144 {
145  genSamples();
146 }
147 
148 
149 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
150 
152 {}
153 
154 
155 // ************************************************************************* //
#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 an arc.
Definition: arcUniform.H:120
virtual ~arcUniform()
Destructor.
Definition: arcUniform.C:151
arcUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: arcUniform.C:130
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.
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
dimensioned< scalar > mag(const dimensioned< Type > &)
Form normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:413
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
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict
Unit conversion functions.