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-2021 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 <!--
42  --> | planarInterpolation
43  offset | Time-varying offset values to interpolated data <!--
44  --> | Function1<Type> | no | -
45  fieldTable | Name of field data table | word | no | field-name
46  points | Name of the points file | word | no | points
47  perturb | Perturbation fraction of bounding box | scalar | no | 1e-5
48  setAverage | Adjust mapped field to maintain average value <!--
49  --> | scalar | no | false
50  \endtable
51 
52  Options for the \c mapMethod entry:
53  \verbatim
54  nearest | Use nearest points only (avoids triangulation)
55  planarInterpolation | Interpolation using 2D Delaunay triangulation
56  \endverbatim
57 
58 SourceFiles
59  MappedFile.C
60 
61 \*---------------------------------------------------------------------------*/
62 
63 #ifndef PatchFunction1Types_MappedFile_H
64 #define PatchFunction1Types_MappedFile_H
65 
66 #include "PatchFunction1.H"
67 #include "Function1.H"
69 
70 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
71 
72 namespace Foam
73 {
74 namespace PatchFunction1Types
75 {
76 
77 /*---------------------------------------------------------------------------*\
78  Class MappedFile Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class Type>
82 class MappedFile
83 :
84  public PatchFunction1<Type>
85 {
86  // Private Data
87 
88  //- Whether constructed from dictionary
89  const bool dictConstructed_;
90 
91  //- If true adjust the mapped field to maintain average value
92  bool setAverage_;
93 
94  //- Name of the field data table, defaults to the name of the field
95  word fieldTableName_;
96 
97  //- Fraction of perturbation (fraction of bounding box) to add
98  scalar perturb_;
99 
100  //- Name of points file; default = "points"
101  word pointsName_;
102 
103  //- Interpolation scheme to use
104  word mapMethod_;
105 
106  //- 2D interpolation (for 'planarInterpolation' mapMethod)
107  mutable autoPtr<pointToPointPlanarInterpolation> mapperPtr_;
108 
109  //- List of boundaryData time directories
110  mutable instantList sampleTimes_;
111 
112  //- Current starting index in sampleTimes
113  mutable label startSampleTime_;
114 
115  //- Interpolated values from startSampleTime
116  mutable Field<Type> startSampledValues_;
117 
118  //- If setAverage: starting average value
119  mutable Type startAverage_;
120 
121  //- Current end index in sampleTimes
122  mutable label endSampleTime_;
123 
124  //- Interpolated values from endSampleTime
125  mutable Field<Type> endSampledValues_;
126 
127  //- If setAverage: end average value
128  mutable Type endAverage_;
129 
130  //- Time varying offset values to interpolated data
131  autoPtr<Function1<Type>> offset_;
132 
133 
134  // Private Member Functions
135 
136  void checkTable(const scalar t) const;
137 
138 public:
139 
140  //- Runtime type information
141  TypeName("mappedFile");
142 
143 
144  // Generated Methods
145 
146  //- No copy assignment
147  void operator=(const MappedFile<Type>&) = delete;
148 
149 
150  // Constructors
151 
152  //- Construct from entry name and dictionary
153  MappedFile
154  (
155  const polyPatch& pp,
156  const word& redirectType,
157  const word& entryName,
158  const dictionary& dict,
159  const bool faceValues = true
160  );
161 
162  //- Construct from entry name and dictionary
163  MappedFile
164  (
165  const polyPatch& pp,
166  const word& entryName,
167  const dictionary& dict,
168  const word& fieldTableName,
169  const bool faceValues
170  );
171 
172  //- Copy construct
173  explicit MappedFile(const MappedFile<Type>& rhs);
174 
175  //- Copy construct setting patch
176  explicit MappedFile
177  (
178  const MappedFile<Type>& rhs,
179  const polyPatch& pp
180  );
181 
182  //- Construct and return a clone
183  virtual tmp<PatchFunction1<Type>> clone() const
184  {
186  (
187  new MappedFile<Type>(*this)
188  );
189  }
190 
191  //- Construct and return a clone setting patch
192  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
193  {
195  (
196  new MappedFile<Type>(*this, pp)
197  );
198  }
199 
200 
201  //- Destructor
202  virtual ~MappedFile() = default;
203 
204 
205  // Member Functions
206 
207  //- Value is independent of x if there is only a single sample time
208  virtual bool constant() const
209  {
210  return sampleTimes_.size() == 1;
211  }
212 
213  //- Is value uniform (i.e. independent of coordinate)
214  virtual inline bool uniform() const
215  {
217  }
218 
219 
220  // Evaluation
221 
222  //- Return MappedFile value
223  virtual tmp<Field<Type>> value(const scalar) const;
224 
225  //- Integrate between two values
226  virtual tmp<Field<Type>> integrate
227  (
228  const scalar x1,
229  const scalar x2
230  ) const;
231 
232 
233  // Mapping
234 
235  //- Map (and resize as needed) from self given a mapping object
236  virtual void autoMap(const FieldMapper& mapper);
237 
238  //- Reverse map the given PatchFunction1 onto this PatchFunction1
239  virtual void rmap
240  (
241  const PatchFunction1<Type>& pf1,
242  const labelList& addr
243  );
244 
245 
246  // I-O
247 
248  //- Write coefficient entries in dictionary format
249  void writeEntries(Ostream& os) const;
250 
251  //- Write in dictionary format
252  virtual void writeData(Ostream& os) const;
253 };
254 
255 
256 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 
258 } // End namespace PatchFunction1Types
259 } // End namespace Foam
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #ifdef NoRepository
264  #include "MappedFile.C"
265 #endif
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 #endif
270 
271 // ************************************************************************* //
Foam::PatchFunction1Types::MappedFile::autoMap
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: MappedFile.C:169
Foam::PatchFunction1Types::MappedFile::~MappedFile
virtual ~MappedFile()=default
Destructor.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::PatchFunction1Types::MappedFile::clone
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: MappedFile.H:239
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::PatchFunction1Types::MappedFile::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: MappedFile.C:631
Foam::PatchFunction1Types::MappedFile::TypeName
TypeName("mappedFile")
Runtime type information.
Function1.H
PatchFunction1.H
Foam::FieldMapper
Abstract base class to hold the Field mapping addressing and weights.
Definition: FieldMapper.H:49
Foam::instantList
List< instant > instantList
List of instants.
Definition: instantList.H:44
Foam::PatchFunction1::entryName
const polyPatch const word const word & entryName
Definition: PatchFunction1.H:118
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
pointToPointPlanarInterpolation.H
Foam::PatchFunction1Types::MappedFile::constant
virtual bool constant() const
Value is independent of x if there is only a single sample time.
Definition: MappedFile.H:255
Foam::PatchFunction1::uniform
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
Definition: PatchFunction1.C:83
Foam::PatchFunction1Types::MappedFile::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: MappedFile.C:590
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:60
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PatchFunction1Types::MappedFile::operator=
void operator=(const MappedFile< Type > &)=delete
No copy assignment.
Foam::PatchFunction1Types::MappedFile
Patch value mapping from a set of values stored in a file and a set of unstructured points using the ...
Definition: MappedFile.H:129
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::PatchFunction1::pp
const polyPatch & pp
Definition: PatchFunction1.H:116
Foam::PatchFunction1Types::MappedFile::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: MappedFile.H:261
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:119
Foam::List< instant >
Foam::PatchFunction1Types::MappedFile::rmap
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
Definition: MappedFile.C:194
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:121
MappedFile.C
Foam::PatchFunction1Types::MappedFile::MappedFile
MappedFile(const polyPatch &pp, const word &redirectType, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from entry name and dictionary.
Definition: MappedFile.C:35
Foam::PatchFunction1Types::MappedFile::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: MappedFile.C:602
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::PatchFunction1Types::MappedFile::clone
virtual tmp< PatchFunction1< Type > > clone() const
Construct and return a clone.
Definition: MappedFile.H:230
Foam::PatchFunction1Types::MappedFile::value
virtual tmp< Field< Type > > value(const scalar) const
Return MappedFile value.
Definition: MappedFile.C:480