sampledSet.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 "sampledSet.H"
27 #include "polyMesh.H"
28 #include "meshSearch.H"
29 #include "setWriter.H"
30 #include "lineCell.H"
31 #include "lineCellFace.H"
32 #include "lineFace.H"
33 #include "lineUniform.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(sampledSet, 0);
40  defineRunTimeSelectionTable(sampledSet, word);
41 }
42 
43 
44 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 
47 (
48  const List<point>& samplingPositions,
49  const labelList& samplingSegments,
50  const labelList& samplingCells,
51  const labelList& samplingFaces
52 )
53 {
54  if
55  (
56  (samplingCells.size() != samplingPositions.size())
57  || (samplingFaces.size() != samplingPositions.size())
58  || (samplingSegments.size() != samplingPositions.size())
59  )
60  {
62  << "sizes not equal : "
63  << " positions:" << samplingPositions.size()
64  << " segments:" << samplingSegments.size()
65  << " cells:" << samplingCells.size()
66  << " faces:" << samplingFaces.size()
67  << abort(FatalError);
68  }
69 
70  (*this).coordSet::operator=
71  (
72  coordSet
73  (
74  samplingSegments,
75  word::null,
76  pointField(samplingPositions),
77  axisTypeNames_[axisType::DISTANCE],
79  axisTypeNames_[axis_]
80  )
81  );
82 
83  cells_ = samplingCells;
84  faces_ = samplingFaces;
85 }
86 
87 
89 (
90  const List<point>& samplingPositions,
91  const List<scalar>& samplingDistances,
92  const labelList& samplingSegments,
93  const labelList& samplingCells,
94  const labelList& samplingFaces
95 )
96 {
97  if
98  (
99  (samplingDistances.size() != samplingPositions.size())
100  || (samplingCells.size() != samplingPositions.size())
101  || (samplingFaces.size() != samplingPositions.size())
102  || (samplingSegments.size() != samplingPositions.size())
103  )
104  {
106  << "sizes not equal : "
107  << " positions:" << samplingPositions.size()
108  << " distances:" << samplingDistances.size()
109  << " segments:" << samplingSegments.size()
110  << " cells:" << samplingCells.size()
111  << " faces:" << samplingFaces.size()
112  << abort(FatalError);
113  }
114 
115  (*this).coordSet::operator=
116  (
117  coordSet
118  (
119  samplingSegments,
120  word::null,
121  pointField(samplingPositions),
122  axisTypeNames_[axisType::DISTANCE],
123  scalarField(samplingDistances),
124  axisTypeNames_[axis_]
125  )
126  );
127 
128  cells_ = samplingCells;
129  faces_ = samplingFaces;
130 }
131 
132 
133 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
134 
136 (
137  const word& name,
138  const polyMesh& mesh,
139  const meshSearch& searchEngine,
140  const word& axis
141 )
142 :
143  coordSet(),
144  name_(name),
145  mesh_(mesh),
146  searchEngine_(searchEngine),
147  cells_(0),
148  faces_(0)
149 {
150  axis_ = axisTypeNames_[axis];
151 }
152 
153 
155 (
156  const word& name,
157  const polyMesh& mesh,
158  const meshSearch& searchEngine,
159  const dictionary& dict
160 )
161 :
162  coordSet(),
163  name_(name),
164  mesh_(mesh),
165  searchEngine_(searchEngine),
166  cells_(0),
167  faces_(0)
168 {
169  axis_ =
170  axisTypeNames_
171  [
172  dict.lookupOrDefault<word>
173  (
174  "axis",
175  axisTypeNames_[axisType::DEFAULT]
176  )
177  ];
178 }
179 
180 
181 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
182 
184 {}
185 
186 
187 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
188 
190 (
191  const word& name,
192  const polyMesh& mesh,
193  const meshSearch& searchEngine,
194  const dictionary& dict
195 )
196 {
197  const word sampleType(dict.lookup("type"));
198 
199  const HashTable<word> oldToNewType =
200  {
201  Tuple2<word, word>("midPoint", sampledSets::lineCell::typeName),
203  (
204  "midPointAndFace",
205  sampledSets::lineCellFace::typeName
206  ),
207  Tuple2<word, word>("face", sampledSets::lineFace::typeName),
208  Tuple2<word, word>("uniform", sampledSets::lineUniform::typeName)
209  };
210 
211  if (oldToNewType.found(sampleType))
212  {
213  const word newSampleType = oldToNewType[sampleType];
214 
216  << "Unknown sample set type "
217  << sampleType << nl << nl
218  << "The sample set type " << sampleType << " has been renamed "
219  << newSampleType << nl << nl
220  << "Replace \"type " << sampleType << ";\" with \"type "
221  << newSampleType << ";\" for the set " << name << " in "
222  << dict.name() << exit(FatalError);
223  }
224 
225  wordConstructorTable::iterator cstrIter =
226  wordConstructorTablePtr_->find(sampleType);
227 
228  if (cstrIter == wordConstructorTablePtr_->end())
229  {
231  << "Unknown sample set type "
232  << sampleType << nl << nl
233  << "Valid sample set types : " << endl
234  << wordConstructorTablePtr_->sortedToc()
235  << exit(FatalError);
236  }
237 
238  return autoPtr<sampledSet>
239  (
240  cstrIter()
241  (
242  name,
243  mesh,
244  searchEngine,
245  dict.optionalSubDict(sampleType + "Coeffs")
246  )
247  );
248 }
249 
250 
251 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
static autoPtr< sampledSet > New(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Return a reference to the selected sampledSet.
Definition: sampledSet.C:190
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void setSamples(const List< point > &samplingPositions, const labelList &samplingSegments, const labelList &samplingCells, const labelList &samplingFaces)
Sets sample data.
Definition: sampledSet.C:47
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual ~sampledSet()
Destructor.
Definition: sampledSet.C:183
fvMesh & mesh
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Holds list of sampling positions.
Definition: coordSet.H:50
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:109
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:1060
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static const word null
An empty word.
Definition: word.H:77
An STL-conforming hash table.
Definition: HashTable.H:61
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static const char nl
Definition: Ostream.H:260
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
sampledSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis)
Construct from components.
Definition: sampledSet.C:136
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
static const Field< scalar > & null()
Return a null field.
Definition: Field.H:111
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864