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-------------------------------------------------------------------------------
11License
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
39namespace Foam
40{
43}
44
45
46// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
47
48void 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
102void 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// ************************************************************************* //
label k
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
Specifies an x,y,z array of uniformly distributed sampling points.
Definition: arraySet.H:105
A Cartesian coordinate system.
Definition: cartesianCS.H:72
point globalPosition(const point &local) const
From local coordinate position to global (cartesian) position.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:61
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:86
const meshSearch & searchEngine() const noexcept
Definition: sampledSet.H:324
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
void cmptMin(FieldField< Field, typename FieldField< Field, Type >::cmptType > &cf, const FieldField< Field, Type > &f)
messageStream Info
Information stream (stdout output on master, null elsewhere)
vector point
Point is a vector.
Definition: point.H:43
error FatalError
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
runTime write()
dictionary dict