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-2018 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 "writer.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>& samplingPts,
49  const labelList& samplingCells,
50  const labelList& samplingFaces,
51  const labelList& samplingSegments,
52  const scalarList& samplingCurveDist
53 )
54 {
55  setSize(samplingPts.size());
56  cells_.setSize(samplingCells.size());
57  faces_.setSize(samplingFaces.size());
58  segments_.setSize(samplingSegments.size());
59  curveDist_.setSize(samplingCurveDist.size());
60 
61  if
62  (
63  (cells_.size() != size())
64  || (faces_.size() != size())
65  || (segments_.size() != size())
66  || (curveDist_.size() != size())
67  )
68  {
70  << "sizes not equal : "
71  << " points:" << size()
72  << " cells:" << cells_.size()
73  << " faces:" << faces_.size()
74  << " segments:" << segments_.size()
75  << " curveDist:" << curveDist_.size()
76  << abort(FatalError);
77  }
78 
79  forAll(samplingPts, sampleI)
80  {
81  operator[](sampleI) = samplingPts[sampleI];
82  }
83  curveDist_ = samplingCurveDist;
84 
85  cells_ = samplingCells;
86  faces_ = samplingFaces;
87  segments_ = samplingSegments;
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
94 (
95  const word& name,
96  const polyMesh& mesh,
97  const meshSearch& searchEngine,
98  const word& axis
99 )
100 :
101  coordSet(name, axis),
102  mesh_(mesh),
103  searchEngine_(searchEngine),
104  segments_(0),
105  cells_(0),
106  faces_(0)
107 {}
108 
109 
111 (
112  const word& name,
113  const polyMesh& mesh,
114  const meshSearch& searchEngine,
115  const dictionary& dict
116 )
117 :
118  coordSet(name, dict.lookup("axis")),
119  mesh_(mesh),
120  searchEngine_(searchEngine),
121  segments_(0),
122  cells_(0),
123  faces_(0)
124 {}
125 
126 
127 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
128 
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
134 
136 (
137  const word& name,
138  const polyMesh& mesh,
139  const meshSearch& searchEngine,
140  const dictionary& dict
141 )
142 {
143  const word sampleType(dict.lookup("type"));
144 
145  const HashTable<word> oldToNewType =
146  {
149  (
150  "midPointAndFace",
152  ),
155  };
156 
157  if (oldToNewType.found(sampleType))
158  {
159  const word newSampleType = oldToNewType[sampleType];
160 
162  << "Unknown sample set type "
163  << sampleType << nl << nl
164  << "The sample set type " << sampleType << " has been renamed "
165  << newSampleType << nl << nl
166  << "Replace \"type " << sampleType << ";\" with \"type "
167  << newSampleType << ";\" for the set " << name << " in "
168  << dict.name() << exit(FatalError);
169  }
170 
171  wordConstructorTable::iterator cstrIter =
172  wordConstructorTablePtr_->find(sampleType);
173 
174  if (cstrIter == wordConstructorTablePtr_->end())
175  {
177  << "Unknown sample set type "
178  << sampleType << nl << nl
179  << "Valid sample set types : " << endl
180  << wordConstructorTablePtr_->sortedToc()
181  << exit(FatalError);
182  }
183 
184  return autoPtr<sampledSet>
185  (
186  cstrIter()
187  (
188  name,
189  mesh,
190  searchEngine,
191  dict.optionalSubDict(sampleType + "Coeffs")
192  )
193  );
194 }
195 
196 
198 {
199  coordSet::write(os);
200 
201  os << endl << "\t(celli)\t(facei)" << endl;
202 
203  forAll(*this, sampleI)
204  {
205  os << '\t' << cells_[sampleI]
206  << '\t' << faces_[sampleI]
207  << endl;
208  }
209 
210  return os;
211 }
212 
213 
214 // ************************************************************************* //
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:158
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:136
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
static const char *const typeName
Definition: Field.H:105
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 size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
virtual ~sampledSet()
Destructor.
Definition: sampledSet.C:129
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingCurveDist)
Sets sample data.
Definition: sampledSet.C:47
points setSize(newPointi)
Ostream & write(Ostream &) const
Output for debugging.
Definition: sampledSet.C:197
dynamicFvMesh & mesh
Holds list of sampling positions.
Definition: coordSet.H:49
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:766
A class for handling words, derived from string.
Definition: word.H:59
Ostream & write(Ostream &os) const
Definition: coordSet.C:134
An STL-conforming hash table.
Definition: HashTable.H:61
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
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:94
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:583