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-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 "arcUniform.H"
27 #include "sampledSet.H"
28 #include "meshSearch.H"
29 #include "DynamicList.H"
30 #include "polyMesh.H"
32 #include "word.H"
33 #include "unitConversion.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 namespace sampledSets
40 {
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::sampledSets::arcUniform::calcSamples
50 (
51  DynamicList<point>& samplingPts,
52  DynamicList<label>& samplingCells,
53  DynamicList<label>& samplingFaces,
54  DynamicList<label>& samplingSegments,
55  DynamicList<scalar>& samplingCurveDist
56 ) const
57 {
58  const vector axis1 = radial_ - (radial_ & normal_)*normal_;
59  const vector axis2 = normal_ ^ axis1;
60  const scalar radius = mag(axis1);
61 
62  for (label i = 0; i < nPoints_; ++ i)
63  {
64  const scalar t = scalar(i)/(nPoints_ - 1);
65  const scalar theta = (1 - t)*startAngle_ + t*endAngle_;
66  const scalar c = cos(theta), s = sin(theta);
67 
68  const point pt = centre_ + c*axis1 + s*axis2;
69  const label celli = searchEngine().findCell(pt);
70 
71  if (celli != -1)
72  {
73  samplingPts.append(pt);
74  samplingCells.append(celli);
75  samplingFaces.append(-1);
76  samplingSegments.append(samplingSegments.size());
77  samplingCurveDist.append(radius*theta);
78  }
79  }
80 }
81 
82 
83 void Foam::sampledSets::arcUniform::genSamples()
84 {
85  // Storage for sample points
86  DynamicList<point> samplingPts;
87  DynamicList<label> samplingCells;
88  DynamicList<label> samplingFaces;
89  DynamicList<label> samplingSegments;
90  DynamicList<scalar> samplingCurveDist;
91 
92  calcSamples
93  (
94  samplingPts,
95  samplingCells,
96  samplingFaces,
97  samplingSegments,
98  samplingCurveDist
99  );
100 
101  samplingPts.shrink();
102  samplingCells.shrink();
103  samplingFaces.shrink();
104  samplingSegments.shrink();
105  samplingCurveDist.shrink();
106 
107  setSamples
108  (
109  samplingPts,
110  samplingCells,
111  samplingFaces,
112  samplingSegments,
113  samplingCurveDist
114  );
115 }
116 
117 
118 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
119 
121 (
122  const word& name,
123  const polyMesh& mesh,
124  const meshSearch& searchEngine,
125  const dictionary& dict
126 )
127 :
128  sampledSet(name, mesh, searchEngine, dict),
129  centre_(dict.lookup("centre")),
130  normal_(normalised(dict.lookup<vector>("normal"))),
131  radial_(dict.lookup<vector>("radial")),
132  startAngle_(dict.lookup<scalar>("startAngle")),
133  endAngle_(dict.lookup<scalar>("endAngle")),
134  nPoints_(dict.lookup<scalar>("nPoints"))
135 {
136  genSamples();
137 
138  if (debug)
139  {
140  write(Info);
141  }
142 }
143 
144 
145 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
146 
148 {}
149 
150 
151 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
arcUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: arcUniform.C:121
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
Unit conversion functions.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const dimensionedScalar & c
Speed of light in a vacuum.
Macros for easy insertion into run-time selection tables.
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)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
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
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
dimensionedScalar sin(const dimensionedScalar &ds)
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:252
virtual bool write()
Sample and write.
Definition: sampledSets.C:241
Set of sets to sample. Call sampledSets.write() to sample&write files.
Definition: sampledSets.H:62
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Uniform samples along an arc.
Definition: arcUniform.H:117
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