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 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  const scalar dx = spanBox_.x()/(pointsDensity_.x() + 1);
60  const scalar dy = spanBox_.y()/(pointsDensity_.y() + 1);
61  const scalar dz = spanBox_.z()/(pointsDensity_.z() + 1);
62 
63  label sampleI(0);
64 
65  for (label k=1; k<=pointsDensity_.z(); ++k)
66  {
67  for (label j=1; j<=pointsDensity_.y(); ++j)
68  {
69  for (label i=1; i<=pointsDensity_.x(); ++i)
70  {
71  // Local Cartesian
72  point pt(i*dx, j*dy, k*dz);
73 
74  // Global Cartesian
75  pt = csys_.globalPosition(pt);
76 
77  const label celli = queryMesh.findCell(pt);
78 
79  if (celli != -1)
80  {
81  samplingPts.append(pt);
82  samplingCells.append(celli);
83  samplingFaces.append(-1);
84  samplingSegments.append(0);
85  samplingCurveDist.append(1.0 * sampleI);
86  }
87  }
88  }
89  }
90 }
91 
92 
93 void Foam::arraySet::genSamples()
94 {
95  // Storage for sample points
96  DynamicList<point> samplingPts;
97  DynamicList<label> samplingCells;
98  DynamicList<label> samplingFaces;
99  DynamicList<label> samplingSegments;
100  DynamicList<scalar> samplingCurveDist;
101 
102  calcSamples
103  (
104  samplingPts,
105  samplingCells,
106  samplingFaces,
107  samplingSegments,
108  samplingCurveDist
109  );
110 
111  samplingPts.shrink();
112  samplingCells.shrink();
113  samplingFaces.shrink();
114  samplingSegments.shrink();
115  samplingCurveDist.shrink();
116 
117  // Move into *this
118  setSamples
119  (
120  std::move(samplingPts),
121  std::move(samplingCells),
122  std::move(samplingFaces),
123  std::move(samplingSegments),
124  std::move(samplingCurveDist)
125  );
126 
127  if (debug)
128  {
129  write(Info);
130  }
131 }
132 
133 
134 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
135 
137 (
138  const word& name,
139  const polyMesh& mesh,
140  const meshSearch& searchEngine,
141  const word& axis,
142  const coordSystem::cartesian& csys,
143  const Vector<label>& pointsDensity,
144  const Vector<scalar>& spanBox
145 )
146 :
147  sampledSet(name, mesh, searchEngine, axis),
148  csys_(csys),
149  pointsDensity_(pointsDensity),
150  spanBox_(spanBox)
151 {
152  genSamples();
153 }
154 
155 
157 (
158  const word& name,
159  const polyMesh& mesh,
160  const meshSearch& searchEngine,
161  const dictionary& dict
162 )
163 :
164  sampledSet(name, mesh, searchEngine, dict),
165  csys_(dict), // Note: no indirect cs with this constructor
166  pointsDensity_(dict.get<labelVector>("pointsDensity")),
167  spanBox_(dict.get<vector>("spanBox"))
168 {
169  genSamples();
170 }
171 
172 
173 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::sampledSet
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:83
Foam::coordinateSystem::globalPosition
point globalPosition(const point &local) const
From local coordinate position to global (cartesian) position.
Definition: coordinateSystem.H:595
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:60
Foam::sampledSet::searchEngine
const meshSearch & searchEngine() const
Definition: sampledSet.H:286
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
polyMesh.H
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
sampledSet.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::arraySet::arraySet
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:137
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
meshSearch.H
Foam::coordSystem::cartesian
A Cartesian coordinate system.
Definition: cartesianCS.H:69
Foam::Vector< label >
arraySet.H
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
DynamicList.H
word.H
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)