sphereRandom.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 "sphereRandom.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::sphereRandom::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  for (label i = 0; i < nPoints_; ++ i)
58  {
59  // Request all random numbers simultaneously on all processors so that
60  // the generator state stays consistent
61 
62  vector dpt(vector::uniform(radius_));
63  while (magSqr(dpt) > sqr(radius_))
64  {
65  dpt = 2*radius_*(rndGen.sample01<vector>() - vector::uniform(0.5));
66  }
67 
68  const point pt = centre_ + dpt;
69  const label celli = searchEngine.findCell(pt);
70 
71  if (celli != -1)
72  {
73  samplingPositions.append(pt);
74  samplingSegments.append(i);
75  samplingCells.append(celli);
76  samplingFaces.append(-1);
77  }
78  }
79 
80  // This set is unordered. Distances have not been created.
81  return false;
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
88 (
89  const word& name,
90  const polyMesh& mesh,
91  const dictionary& dict
92 )
93 :
95  centre_(dict.lookup("centre")),
96  radius_(dict.lookup<scalar>("radius")),
97  nPoints_(dict.lookup<label>("nPoints"))
98 {}
99 
100 
101 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
102 
104 {}
105 
106 
107 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
static Form uniform(const Cmpt &s)
Return a VectorSpace with all elements = s.
Definition: VectorSpaceI.H:168
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 sphere.
Definition: sphereRandom.H:99
virtual ~sphereRandom()
Destructor.
Definition: sphereRandom.C:103
sphereRandom(const word &name, const polyMesh &mesh, const dictionary &dict)
Construct from dictionary.
Definition: sphereRandom.C:88
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)
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
vector point
Point is a vector.
Definition: point.H:41
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dictionary dict
randomGenerator rndGen(653213)