circleRandom.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-2019 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 "circleRandom.H"
27 #include "sampledSet.H"
28 #include "meshSearch.H"
29 #include "DynamicList.H"
30 #include "polyMesh.H"
32 #include "word.H"
33 #include "mathematicalConstants.H"
34 #include "Random.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40 namespace sampledSets
41 {
42  defineTypeNameAndDebug(circleRandom, 0);
43  addToRunTimeSelectionTable(sampledSet, circleRandom, word);
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::sampledSets::circleRandom::calcSamples
51 (
52  DynamicList<point>& samplingPts,
53  DynamicList<label>& samplingCells,
54  DynamicList<label>& samplingFaces,
55  DynamicList<label>& samplingSegments,
56  DynamicList<scalar>& samplingCurveDist
57 ) const
58 {
59  Random rndGen(261782);
60 
61  const vector radial1 = normalised(perpendicular(normal_));
62  const vector radial2 = normalised(normal_ ^ radial1);
63 
64  for (label i = 0; i < nPoints_; ++ i)
65  {
66  // Request all random numbers simultaneously on all processors so that
67  // the generator state stays consistent
68 
69  const scalar r = radius_*rndGen.scalar01();
70  const scalar theta = 2*constant::mathematical::pi*rndGen.scalar01();
71  const scalar c = cos(theta), s = sin(theta);
72 
73  const point pt = centre_ + r*(c*radial1 + s*radial2);
74  const label celli = searchEngine().findCell(pt);
75 
76  if (celli != -1)
77  {
78  samplingPts.append(pt);
79  samplingCells.append(celli);
80  samplingFaces.append(-1);
81  samplingSegments.append(0);
82  samplingCurveDist.append(scalar(i));
83  }
84  }
85 }
86 
87 
88 void Foam::sampledSets::circleRandom::genSamples()
89 {
90  // Storage for sample points
91  DynamicList<point> samplingPts;
92  DynamicList<label> samplingCells;
93  DynamicList<label> samplingFaces;
94  DynamicList<label> samplingSegments;
95  DynamicList<scalar> samplingCurveDist;
96 
97  calcSamples
98  (
99  samplingPts,
100  samplingCells,
101  samplingFaces,
102  samplingSegments,
103  samplingCurveDist
104  );
105 
106  samplingPts.shrink();
107  samplingCells.shrink();
108  samplingFaces.shrink();
109  samplingSegments.shrink();
110  samplingCurveDist.shrink();
111 
112  setSamples
113  (
114  samplingPts,
115  samplingCells,
116  samplingFaces,
117  samplingSegments,
118  samplingCurveDist
119  );
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 
126 (
127  const word& name,
128  const polyMesh& mesh,
129  const meshSearch& searchEngine,
130  const dictionary& dict
131 )
132 :
133  sampledSet(name, mesh, searchEngine, dict),
134  centre_(dict.lookup("centre")),
135  normal_(normalised(dict.lookup<vector>("normal"))),
136  radius_(dict.lookup<scalar>("radius")),
137  nPoints_(dict.lookup<label>("nPoints"))
138 {
139  genSamples();
140 
141  if (debug)
142  {
143  write(Info);
144  }
145 }
146 
147 
148 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
149 
151 {}
152 
153 
154 // ************************************************************************* //
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
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Macros for easy insertion into run-time selection tables.
circleRandom(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: circleRandom.C:126
Random rndGen(label(0))
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.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Form normalised(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:413
dimensionedScalar cos(const dimensionedScalar &ds)
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
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
dimensionedScalar sin(const dimensionedScalar &ds)
Vector< Cmpt > perpendicular(const Vector< Cmpt > &v)
Definition: VectorI.H:166
vector point
Point is a vector.
Definition: point.H:41
virtual bool write()
Sample and write.
Definition: sampledSets.C:241
messageStream Info
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:812