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-2025 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 "meshSearch.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace sampledSets
35 {
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 bool Foam::sampledSets::circleRandom::calcSamples
45 (
46  DynamicList<point>& samplingPositions,
47  DynamicList<scalar>&,
48  DynamicList<label>& samplingSegments,
49  DynamicList<label>& samplingCells,
50  DynamicList<label>& samplingFaces
51 ) const
52 {
53  const meshSearch& searchEngine = meshSearch::New(mesh());
54 
55  randomGenerator rndGen(261782, true);
56 
57  const vector radial1 = normalised(perpendicular(normal_));
58  const vector radial2 = normalised(normal_ ^ radial1);
59 
60  for (label i = 0; i < nPoints_; ++ i)
61  {
62  // Request all random numbers simultaneously on all processors so that
63  // the generator state stays consistent
64 
65  const scalar r = radius_*rndGen.scalar01();
66  const scalar theta = 2*constant::mathematical::pi*rndGen.scalar01();
67  const scalar c = cos(theta), s = sin(theta);
68 
69  const point pt = centre_ + r*(c*radial1 + s*radial2);
70  const label celli = searchEngine.findCell(pt);
71 
72  if (celli != -1)
73  {
74  samplingPositions.append(pt);
75  samplingSegments.append(i);
76  samplingCells.append(celli);
77  samplingFaces.append(-1);
78  }
79  }
80 
81  // This set is unordered. Distances have not been created.
82  return false;
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
87 
89 (
90  const word& name,
91  const polyMesh& mesh,
92  const dictionary& dict
93 )
94 :
96  centre_(dict.lookup("centre")),
97  normal_(normalised(dict.lookup<vector>("normal"))),
98  radius_(dict.lookup<scalar>("radius")),
99  nPoints_(dict.lookup<label>("nPoints"))
100 {}
101 
102 
103 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
104 
106 {}
107 
108 
109 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
const polyMesh & mesh() const
Access the mesh.
Definition: sampledSetI.H:36
Random samples within a circle.
Definition: circleRandom.H:106
circleRandom(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: circleRandom.C:89
virtual ~circleRandom()
Destructor.
Definition: circleRandom.C:105
Set of sets to sample. Call sampledSets.write() to sample&write files.
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), lagrangian::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.
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
dimensionedScalar sin(const dimensionedScalar &ds)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensionSet normalised(const dimensionSet &)
Definition: dimensionSet.C:507
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dimensionSet perpendicular(const dimensionSet &)
Definition: dimensionSet.C:513
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict
randomGenerator rndGen(653213)