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-2026 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"
28 #include "mathematicalConstants.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace sampledSets
36 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 
45 bool Foam::sampledSets::circleRandom::calcSamples
46 (
47  DynamicList<point>& samplingPositions,
48  DynamicList<scalar>&,
49  DynamicList<label>& samplingSegments,
50  DynamicList<label>& samplingCells,
51  DynamicList<label>& samplingFaces
52 ) const
53 {
54  const meshSearch& searchEngine = meshSearch::New(mesh());
55 
56  randomGenerator rndGen(261782, true);
57 
58  const vector radial1 = normalised(perpendicular(normal_));
59  const vector radial2 = normalised(normal_ ^ radial1);
60 
61  for (label i = 0; i < nPoints_; ++ i)
62  {
63  // Request all random numbers simultaneously on all processors so that
64  // the generator state stays consistent
65 
66  const scalar r = radius_*rndGen.scalar01();
67  const scalar theta = 2*constant::mathematical::pi*rndGen.scalar01();
68  const scalar c = cos(theta), s = sin(theta);
69 
70  const point pt = centre_ + r*(c*radial1 + s*radial2);
71  const label celli = searchEngine.findCell(pt);
72 
73  if (celli != -1)
74  {
75  samplingPositions.append(pt);
76  samplingSegments.append(i);
77  samplingCells.append(celli);
78  samplingFaces.append(-1);
79  }
80  }
81 
82  // This set is unordered. Distances have not been created.
83  return false;
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
90 (
91  const word& name,
92  const polyMesh& mesh,
93  const dictionary& dict
94 )
95 :
97  centre_(dict.lookup("centre")),
98  normal_(normalised(dict.lookup<vector>("normal"))),
99  radius_(dict.lookup<scalar>("radius")),
100  nPoints_(dict.lookup<label>("nPoints"))
101 {}
102 
103 
104 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
105 
107 {}
108 
109 
110 // ************************************************************************* //
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:90
virtual ~circleRandom()
Destructor.
Definition: circleRandom.C:106
Set of sets to sample. Call sampledSets.write() to sample&write files.
A class for handling words, derived from string.
Definition: word.H:63
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)
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
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:509
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dimensionSet perpendicular(const dimensionSet &)
Definition: dimensionSet.C:515
dimensionedScalar cos(const dimensionedScalar &ds)
dictionary dict
randomGenerator rndGen(653213)