MappedFile.H
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) 2018-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::PatchFunction1Types::MappedFile
28 
29 Description
30  Patch value mapping from a set of values stored in a file and
31  a set of unstructured points using the following directory structure:
32 
33  \verbatim
34  constant/boundaryData/<patchName>/points
35  constant/boundaryData/<patchName>/<time>/<field>
36  \endverbatim
37 
38  Options:
39  \table
40  Property | Description | Type | Reqd | Deflt
41  mapMethod | Mapping method | word | no | planar
42  offset | Time-varying offset values to interpolated data <!--
43  --> | Function1<Type> | no | -
44  fieldTable | Name of field data table | word | no | field-name
45  points | Name of the points file | word | no | points
46  perturb | Perturbation fraction of bounding box | scalar | no | 1e-5
47  setAverage | Adjust mapped field to maintain average value <!--
48  --> | scalar | no | false
49  \endtable
50 
51  Options for the \c mapMethod entry:
52  \table
53  Property | Description
54  nearest | Use nearest points only (avoids triangulation)
55  planar | Interpolation using 2D Delaunay triangulation
56  \endtable
57 
58  Options for reading and filtering:
59  \table
60  Property | Description
61  sampleFormat | The surfaceReader format (eg, ensight)
62  sampleFile | <case>/foo/bar/window.case
63  filterRadius | Search radius [m] for median filter neighbours
64  filterSweeps | Filter sweeps for median filter
65  readOptions | Format options for surfaceReader format (eg, ensight)
66  \endtable
67 
68 Note
69  The MappedFile handling currently has two different reading types:
70  a builtin boundaryData reader (default) and a surfaceReader
71  (specified by sampleFormat and sampleFile keywords). The generic
72  surfaceReader handling does \em not support field averaging.
73 
74 SourceFiles
75  MappedFile.C
76 
77 \*---------------------------------------------------------------------------*/
78 
79 #ifndef Foam_PatchFunction1Types_MappedFile_H
80 #define Foam_PatchFunction1Types_MappedFile_H
81 
82 #include "PatchFunction1.H"
83 #include "Function1.H"
84 #include "Pair.H"
85 #include "instantList.H"
86 #include "surfaceReader.H"
87 #include "MappedFileFilterField.H"
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 namespace PatchFunction1Types
95 {
96 
97 /*---------------------------------------------------------------------------*\
98  Class MappedFile Declaration
99 \*---------------------------------------------------------------------------*/
100 
101 template<class Type>
102 class MappedFile
103 :
104  public PatchFunction1<Type>
105 {
106  // Private Data
107 
108  //- Whether constructed from dictionary
109  const bool dictConstructed_;
110 
111  //- If true adjust the mapped field to maintain average value
112  bool setAverage_;
113 
114  //- Fraction of perturbation (fraction of bounding box) to add
115  scalar perturb_;
116 
117  //- Name of the field data table, defaults to the name of the field
118  word fieldTableName_;
119 
120  //- Name of points file (default: "points")
121  word pointsName_;
122 
123  //- Interpolation scheme to use (default is empty == "planar")
124  word mapMethod_;
125 
126  //- Radius for filter
127  scalar filterRadius_;
128 
129  //- Number of median filter sweeps
130  label filterSweeps_;
131 
132  //- Median filtering (for input values)
133  mutable autoPtr<FilterField> filterFieldPtr_;
134 
135  //- Format name for surfaceReader
136  word readerFormat_;
137 
138  //- File name associated with surfaceReader
139  fileName readerFile_;
140 
141  //- Meshed surface with fields (for input values)
142  mutable autoPtr<surfaceReader> readerPtr_;
143 
144  //- 2D interpolation (for 'planar' mapMethod)
145  mutable autoPtr<pointToPointPlanarInterpolation> mapperPtr_;
146 
147  //- List of boundaryData time directories
148  mutable instantList sampleTimes_;
149 
150  //- The first/second sample indices in sampleTimes
151  mutable labelPair sampleIndex_;
152 
153  //- The average values at first/second sampleIndex_ (if setAverage)
154  mutable Pair<Type> sampleAverage_;
155 
156  //- The interpolated values at first/second sampleIndex_
157  mutable Pair<Field<Type>> sampleValues_;
158 
159  //- Time varying offset values to interpolated data
160  autoPtr<Function1<Type>> offset_;
161 
162 
163  // Private Member Functions
164 
165  //- Find boundary data between time 't' and interpolate
166  void checkTable(const scalar t) const;
167 
168  //- Update field and average value using interpolation at
169  //- given instant index
170  void updateSampledValues
171  (
172  const label sampleIndex,
174  Type& avg
175  ) const;
176 
177  //- Construct from entry name and dictionary
178  MappedFile
179  (
180  const bool dictConstructed,
181  const polyPatch& pp,
182  const word& entryName,
183  const dictionary& dict,
184  const word& fieldTableName,
185  const bool faceValues
186  );
187 
188 public:
189 
190  //- Runtime type information
191  TypeName("mappedFile");
192 
193 
194  // Generated Methods
195 
196  //- No copy assignment
197  void operator=(const MappedFile<Type>&) = delete;
198 
199 
200  // Constructors
201 
202  //- Construct from entry name and dictionary
203  MappedFile
204  (
205  const polyPatch& pp,
206  const word& redirectType,
207  const word& entryName,
208  const dictionary& dict,
209  const bool faceValues = true
210  );
211 
212  //- Construct from entry name and dictionary
213  MappedFile
214  (
215  const polyPatch& pp,
216  const word& entryName,
217  const dictionary& dict,
218  const word& fieldTableName,
219  const bool faceValues = true
220  );
221 
222  //- Copy construct setting patch
223  explicit MappedFile
224  (
225  const MappedFile<Type>& rhs,
226  const polyPatch& pp
227  );
228 
229  //- Copy construct
230  explicit MappedFile(const MappedFile<Type>& rhs);
231 
232  //- Return a clone
233  virtual tmp<PatchFunction1<Type>> clone() const
234  {
235  return PatchFunction1<Type>::Clone(*this, this->patch());
236  }
237 
238  //- Return a clone, setting the patch
239  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
240  {
241  return PatchFunction1<Type>::Clone(*this, pp);
242  }
243 
244 
245  //- Destructor
246  virtual ~MappedFile() = default;
247 
248 
249  // Member Functions
250 
251  //- Value is independent of x if there is only a single sample time
252  virtual bool constant() const
253  {
254  return sampleTimes_.size() == 1;
255  }
256 
257  //- Is value uniform (i.e. independent of coordinate)
258  virtual inline bool uniform() const
259  {
261  }
262 
263 
264  // Evaluation
265 
266  //- Return MappedFile value
267  virtual tmp<Field<Type>> value(const scalar) const;
268 
269  //- Integrate between two values
270  virtual tmp<Field<Type>> integrate
271  (
272  const scalar x1,
273  const scalar x2
274  ) const;
275 
276 
277  // Mapping
278 
279  //- Map (and resize as needed) from self given a mapping object
280  virtual void autoMap(const FieldMapper& mapper);
281 
282  //- Reverse map the given PatchFunction1 onto this PatchFunction1
283  virtual void rmap
284  (
285  const PatchFunction1<Type>& pf1,
286  const labelList& addr
287  );
288 
289 
290  // I-O
291 
292  //- Write coefficient entries in dictionary format
293  virtual void writeEntries(Ostream& os) const;
294 
295  //- Write in dictionary format
296  virtual void writeData(Ostream& os) const;
297 };
298 
299 
300 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
301 
302 } // End namespace PatchFunction1Types
303 } // End namespace Foam
304 
305 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
306 
307 #ifdef NoRepository
308  #include "MappedFile.C"
309 #endif
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 #endif
314 
315 // ************************************************************************* //
Patch value mapping from a set of values stored in a file and a set of unstructured points using the ...
Definition: MappedFile.H:170
virtual tmp< PatchFunction1< Type > > clone() const
Return a clone.
Definition: MappedFile.H:357
rDeltaTY field()
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
virtual ~MappedFile()=default
Destructor.
virtual tmp< Field< Type > > value(const scalar) const
Return MappedFile value.
Definition: MappedFile.C:651
const polyPatch const word const word const dictionary & dict
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: MappedFile.C:756
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
void operator=(const MappedFile< Type > &)=delete
No copy assignment.
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: MappedFile.C:246
const polyPatch const word const word & entryName
bool faceValues() const noexcept
Generate face or point values on patch?
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:51
OBJstream os(runTime.globalPath()/outputName)
virtual bool constant() const
Value is independent of x if there is only a single sample time.
Definition: MappedFile.H:382
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: MappedFile.C:768
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: MappedFile.C:222
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50
List< instant > instantList
List of instants.
Definition: instantList.H:41
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
TypeName("mappedFile")
Runtime type information.
static tmp< PatchFunction1< Type > > Clone(const Derived &fun)
Clone a PatchFunction1.
Namespace for OpenFOAM.
const polyPatch & pp
const polyPatch & patch() const noexcept
Reference to the patch.
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: MappedFile.H:390
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: MappedFile.C:817