boxUniform.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-2021 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 "boxUniform.H"
27 #include "sampledSet.H"
28 #include "meshSearch.H"
29 #include "DynamicList.H"
30 #include "polyMesh.H"
32 #include "word.H"
33 #include "transform.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::boxUniform::calcSamples
50 (
51  DynamicList<point>& samplingPositions,
52  DynamicList<label>& samplingSegments,
53  DynamicList<label>& samplingCells,
54  DynamicList<label>& samplingFaces
55 ) const
56 {
57  for (label k = 0; k < nPoints_.z(); ++ k)
58  {
59  for (label j = 0; j < nPoints_.y(); ++ j)
60  {
61  for (label i = 0; i < nPoints_.x(); ++ i)
62  {
63  const vector t =
64  cmptDivide(vector(i, j, k), vector(nPoints_) - vector::one);
65 
66  const point pt =
67  cmptMultiply(vector::one - t, box_.min())
68  + cmptMultiply(t, box_.max());
69 
70  const label celli = searchEngine().findCell(pt);
71 
72  if (celli != -1)
73  {
74  samplingPositions.append(pt);
75  samplingSegments.append
76  (
77  i + j*nPoints_.x() + k*nPoints_.x()*nPoints_.y()
78  );
79  samplingCells.append(celli);
80  samplingFaces.append(-1);
81  }
82  }
83  }
84  }
85 }
86 
87 
88 void Foam::sampledSets::boxUniform::genSamples()
89 {
90  DynamicList<point> samplingPositions;
91  DynamicList<label> samplingSegments;
92  DynamicList<label> samplingCells;
93  DynamicList<label> samplingFaces;
94 
95  calcSamples
96  (
97  samplingPositions,
98  samplingSegments,
99  samplingCells,
100  samplingFaces
101  );
102 
103  samplingPositions.shrink();
104  samplingSegments.shrink();
105  samplingCells.shrink();
106  samplingFaces.shrink();
107 
108  setSamples
109  (
110  samplingPositions,
111  samplingSegments,
112  samplingCells,
113  samplingFaces
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  box_(dict.lookup("box")),
130  nPoints_(dict.lookup("nPoints"))
131 {
132  genSamples();
133 }
134 
135 
136 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
137 
139 {}
140 
141 
142 // ************************************************************************* //
label k
Macros for easy insertion into run-time selection tables.
static const Form one
Definition: VectorSpace.H:114
const Cmpt & z() const
Definition: VectorI.H:87
const Cmpt & y() const
Definition: VectorI.H:81
const Cmpt & x() const
Definition: VectorI.H:75
const point & min() const
Minimum point defining the bounding box.
Definition: boundBoxI.H:54
const point & max() const
Maximum point defining the bounding box.
Definition: boundBoxI.H:60
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:58
label findCell(const point &location, const label seedCelli=-1, const bool useTreeSearch=true) const
Find cell containing location.
Definition: meshSearch.C:750
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
const meshSearch & searchEngine() const
Access the search engine.
Definition: sampledSet.H:216
Uniform 3D-grid of samples.
Definition: boxUniform.H:94
virtual ~boxUniform()
Destructor.
Definition: boxUniform.C:138
boxUniform(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: boxUniform.C:121
Set of sets to sample. Call sampledSets.write() to sample&write files.
A class for handling words, derived from string.
Definition: word.H:62
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
vector point
Point is a vector.
Definition: point.H:41
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
dimensioned< Type > cmptDivide(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
dictionary dict
3D tensor transformation operations.