arraySet.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018,2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "arraySet.H"
30 #include "sampledSet.H"
31 #include "meshSearch.H"
32 #include "DynamicList.H"
33 #include "polyMesh.H"
35 #include "word.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41  defineTypeNameAndDebug(arraySet, 0);
42  addToRunTimeSelectionTable(sampledSet, arraySet, word);
43 }
44 
45 
46 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47 
48 void Foam::arraySet::calcSamples
49 (
50  DynamicList<point>& samplingPts,
51  DynamicList<label>& samplingCells,
52  DynamicList<label>& samplingFaces,
53  DynamicList<label>& samplingSegments,
54  DynamicList<scalar>& samplingCurveDist
55 ) const
56 {
57  const meshSearch& queryMesh = searchEngine();
58 
59  if (cmptMin(pointsDensity_) < 1)
60  {
61  FatalErrorInFunction << "Illegal specification for pointsDensity "
62  << pointsDensity_
63  << ". It specifies the number of points per coordinate axis"
64  << " so should contain positive integers only."
65  << exit(FatalError);
66  }
67 
68  const scalar dx = spanBox_.x()/(pointsDensity_.x() + 1);
69  const scalar dy = spanBox_.y()/(pointsDensity_.y() + 1);
70  const scalar dz = spanBox_.z()/(pointsDensity_.z() + 1);
71 
72  label sampleI(0);
73 
74  for (label k=1; k<=pointsDensity_.z(); ++k)
75  {
76  for (label j=1; j<=pointsDensity_.y(); ++j)
77  {
78  for (label i=1; i<=pointsDensity_.x(); ++i)
79  {
80  // Local Cartesian
81  point pt(i*dx, j*dy, k*dz);
82 
83  // Global Cartesian
84  pt = csys_.globalPosition(pt);
85 
86  const label celli = queryMesh.findCell(pt);
87 
88  if (celli != -1)
89  {
90  samplingPts.append(pt);
91  samplingCells.append(celli);
92  samplingFaces.append(-1);
93  samplingSegments.append(0);
94  samplingCurveDist.append(1.0 * sampleI);
95  }
96  }
97  }
98  }
99 }
100 
101 
102 void Foam::arraySet::genSamples()
103 {
104  // Storage for sample points
105  DynamicList<point> samplingPts;
106  DynamicList<label> samplingCells;
107  DynamicList<label> samplingFaces;
108  DynamicList<label> samplingSegments;
109  DynamicList<scalar> samplingCurveDist;
110 
111  calcSamples
112  (
113  samplingPts,
114  samplingCells,
115  samplingFaces,
116  samplingSegments,
117  samplingCurveDist
118  );
119 
120  samplingPts.shrink();
121  samplingCells.shrink();
122  samplingFaces.shrink();
123  samplingSegments.shrink();
124  samplingCurveDist.shrink();
125 
126  // Move into *this
127  setSamples
128  (
129  std::move(samplingPts),
130  std::move(samplingCells),
131  std::move(samplingFaces),
132  std::move(samplingSegments),
133  std::move(samplingCurveDist)
134  );
135 
136  if (debug)
137  {
138  write(Info);
139  }
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
144 
146 (
147  const word& name,
148  const polyMesh& mesh,
149  const meshSearch& searchEngine,
150  const word& axis,
151  const coordSystem::cartesian& csys,
152  const Vector<label>& pointsDensity,
153  const Vector<scalar>& spanBox
154 )
155 :
156  sampledSet(name, mesh, searchEngine, axis),
157  csys_(csys),
158  pointsDensity_(pointsDensity),
159  spanBox_(spanBox)
160 {
161  genSamples();
162 }
163 
164 
166 (
167  const word& name,
168  const polyMesh& mesh,
169  const meshSearch& searchEngine,
170  const dictionary& dict
171 )
172 :
173  sampledSet(name, mesh, searchEngine, dict),
174  csys_(dict), // Note: no indirect cs with this constructor
175  pointsDensity_(dict.get<labelVector>("pointsDensity")),
176  spanBox_(dict.get<vector>("spanBox"))
177 {
178  genSamples();
179 }
180 
181 
182 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:56
dictionary dict
point globalPosition(const point &local) const
From local coordinate position to global (cartesian) position.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
const Cmpt & y() const noexcept
Access to the vector y component.
Definition: Vector.H:140
label k
Boltzmann constant.
Macros for easy insertion into run-time selection tables.
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:79
A class for handling words, derived from Foam::string.
Definition: word.H:63
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
const Cmpt & x() const noexcept
Access to the vector x component.
Definition: Vector.H:135
int debug
Static debugging option.
defineTypeNameAndDebug(combustionModel, 0)
const Cmpt & z() const noexcept
Access to the vector z component.
Definition: Vector.H:145
vector point
Point is a vector.
Definition: point.H:37
messageStream Info
Information stream (stdout output on master, null elsewhere)
const meshSearch & searchEngine() const noexcept
Definition: sampledSet.H:378
arraySet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const coordSystem::cartesian &csys, const Vector< label > &pointsDensity, const Vector< scalar > &spanBox)
Construct from components.
Definition: arraySet.C:139
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)