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-2026 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 "lineCell.H"
29 #include "lineCellFace.H"
30 #include "lineFace.H"
31 #include "lineUniform.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
39 }
40 
41 
42 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
43 
44 void Foam::sampledSet::setSamples() const
45 {
46  DynamicList<point> samplingPositions;
47  DynamicList<scalar> samplingDistances;
48  DynamicList<label> samplingSegments;
49  DynamicList<label> samplingCells;
50  DynamicList<label> samplingFaces;
51 
52  const bool ordered =
53  calcSamples
54  (
55  samplingPositions,
56  samplingDistances,
57  samplingSegments,
58  samplingCells,
59  samplingFaces
60  );
61 
62  if
63  (
64  (ordered && samplingDistances.size() != samplingPositions.size())
65  || (samplingCells.size() != samplingPositions.size())
66  || (samplingFaces.size() != samplingPositions.size())
67  || (samplingSegments.size() != samplingPositions.size())
68  )
69  {
71  << "sizes not equal : "
72  << " positions:" << samplingPositions.size();
73  if (ordered) FatalError
74  << " distances:" << samplingDistances.size();
76  << " segments:" << samplingSegments.size()
77  << " cells:" << samplingCells.size()
78  << " faces:" << samplingFaces.size()
79  << abort(FatalError);
80  }
81 
83  positions.transfer(samplingPositions);
84 
85  scalarField distances;
86  if (ordered) distances.transfer(samplingDistances);
87 
88  coordsPtr_.reset
89  (
90  new coordSet
91  (
92  samplingSegments,
93  word::null,
94  positions,
96  ordered ? distances : NullObjectRef<scalarField>(),
98  )
99  );
100 
101  cellsPtr_.reset(new labelList());
102  cellsPtr_().transfer(samplingCells);
103 
104  facesPtr_.reset(new labelList());
105  facesPtr_().transfer(samplingFaces);
106 }
107 
108 
109 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
110 
112 (
113  const word& name,
114  const polyMesh& mesh,
115  const word& axis
116 )
117 :
118  name_(name),
119  mesh_(mesh),
120  coordsPtr_(nullptr),
121  cellsPtr_(),
122  facesPtr_(),
123  axis_(coordSet::axisTypeNames_[axis])
124 {}
125 
126 
128 (
129  const word& name,
130  const polyMesh& mesh,
131  const dictionary& dict
132 )
133 :
134  name_(name),
135  mesh_(mesh),
136  coordsPtr_(),
137  cellsPtr_(),
138  facesPtr_(),
139  axis_
140  (
141  coordSet::axisTypeNames_
142  [
143  dict.lookupOrDefault<word>
144  (
145  "axis",
146  coordSet::axisTypeNames_[coordSet::axisType::DEFAULT]
147  )
148  ]
149  )
150 {}
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 (
163  const word& name,
164  const polyMesh& mesh,
165  const dictionary& dict
166 )
167 {
168  const word sampleType(dict.lookup("type"));
169 
170  const HashTable<word> oldToNewType =
171  {
174  (
175  "midPointAndFace",
177  ),
180  };
181 
182  if (oldToNewType.found(sampleType))
183  {
184  const word newSampleType = oldToNewType[sampleType];
185 
187  << "Unknown sample set type "
188  << sampleType << nl << nl
189  << "The sample set type " << sampleType << " has been renamed "
190  << newSampleType << nl << nl
191  << "Replace \"type " << sampleType << ";\" with \"type "
192  << newSampleType << ";\" for the set " << name << " in "
193  << dict.name() << exit(FatalError);
194  }
195 
196  wordConstructorTable::iterator cstrIter =
197  wordConstructorTablePtr_->find(sampleType);
198 
199  if (cstrIter == wordConstructorTablePtr_->end())
200  {
202  << "Unknown sample set type "
203  << sampleType << nl << nl
204  << "Valid sample set types : " << endl
205  << wordConstructorTablePtr_->sortedToc()
206  << exit(FatalError);
207  }
208 
209  return autoPtr<sampledSet>
210  (
211  cstrIter()
212  (
213  name,
214  mesh,
215  dict.optionalTypeDict(sampleType)
216  )
217  );
218 }
219 
220 
221 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
222 
224 {
225  coordsPtr_.clear();
226  cellsPtr_.clear();
227  facesPtr_.clear();
228 }
229 
230 
232 {
233  coordsPtr_.clear();
234  cellsPtr_.clear();
235  facesPtr_.clear();
236 }
237 
238 
240 {
241  coordsPtr_.clear();
242  cellsPtr_.clear();
243  facesPtr_.clear();
244 }
245 
246 
248 (
249  const polyDistributionMap& map
250 )
251 {
252  coordsPtr_.clear();
253  cellsPtr_.clear();
254  facesPtr_.clear();
255 }
256 
257 
258 // ************************************************************************* //
An STL-conforming hash table.
Definition: HashTable.H:127
bool found(const Key &) const
Return true if hashedEntry is found in table.
Definition: HashTable.C:138
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Definition: List.C:342
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:66
Holds list of sampling positions.
Definition: coordSet.H:51
static const NamedEnum< axisType, 6 > axisTypeNames_
String representation of axis enums.
Definition: coordSet.H:69
const fileName & name() const
Return the dictionary name.
Definition: dictionary.H:111
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
const dictionary & optionalTypeDict(const word &typeName) const
Find and return an optional type sub-dictionary.
Definition: dictionary.C:921
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:64
static autoPtr< sampledSet > New(const word &name, const polyMesh &mesh, const dictionary &dict)
Return a reference to the selected sampledSet.
Definition: sampledSet.C:162
virtual void topoChange(const polyTopoChangeMap &)
Update topology using the given map.
Definition: sampledSet.C:231
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
Definition: sampledSet.C:248
sampledSet(const word &name, const polyMesh &mesh, const word &axis)
Construct from components.
Definition: sampledSet.C:112
virtual void movePoints()
Update for mesh point-motion.
Definition: sampledSet.C:223
virtual ~sampledSet()
Destructor.
Definition: sampledSet.C:155
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
Definition: sampledSet.C:239
const pointField & positions() const
Access the positions.
Definition: sampledSetI.H:64
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< label > labelList
A List of labels.
Definition: labelList.H:56
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
defineRunTimeSelectionTable(fvConstraint, dictionary)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
static const char nl
Definition: Ostream.H:297
dictionary dict