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-2022 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
223  explicit MappedFile(const MappedFile<Type>& rhs);
224 
225  //- Copy construct setting patch
226  explicit MappedFile
227  (
228  const MappedFile<Type>& rhs,
229  const polyPatch& pp
230  );
231 
232  //- Construct and return a clone
233  virtual tmp<PatchFunction1<Type>> clone() const
234  {
236  (
237  new MappedFile<Type>(*this)
238  );
239  }
240 
241  //- Construct and return a clone setting patch
242  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
243  {
245  (
246  new MappedFile<Type>(*this, pp)
247  );
248  }
249 
250 
251  //- Destructor
252  virtual ~MappedFile() = default;
253 
254 
255  // Member Functions
256 
257  //- Value is independent of x if there is only a single sample time
258  virtual bool constant() const
259  {
260  return sampleTimes_.size() == 1;
261  }
262 
263  //- Is value uniform (i.e. independent of coordinate)
264  virtual inline bool uniform() const
265  {
267  }
268 
269 
270  // Evaluation
271 
272  //- Return MappedFile value
273  virtual tmp<Field<Type>> value(const scalar) const;
274 
275  //- Integrate between two values
276  virtual tmp<Field<Type>> integrate
277  (
278  const scalar x1,
279  const scalar x2
280  ) const;
281 
282 
283  // Mapping
284 
285  //- Map (and resize as needed) from self given a mapping object
286  virtual void autoMap(const FieldMapper& mapper);
287 
288  //- Reverse map the given PatchFunction1 onto this PatchFunction1
289  virtual void rmap
290  (
291  const PatchFunction1<Type>& pf1,
292  const labelList& addr
293  );
294 
295 
296  // I-O
297 
298  //- Write coefficient entries in dictionary format
299  virtual void writeEntries(Ostream& os) const;
300 
301  //- Write in dictionary format
302  virtual void writeData(Ostream& os) const;
303 };
304 
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 } // End namespace PatchFunction1Types
309 } // End namespace Foam
310 
311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
312 
313 #ifdef NoRepository
314  #include "MappedFile.C"
315 #endif
316 
317 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 
319 #endif
320 
321 // ************************************************************************* //
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
Construct and return a clone.
Definition: MappedFile.H:357
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
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:643
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:748
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:238
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:388
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: MappedFile.C:760
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: MappedFile.C:214
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.
Namespace for OpenFOAM.
const polyPatch & pp
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: MappedFile.H:396
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: MappedFile.C:809