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-2020 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 file
31 
32  Options:
33  \table
34  Property | Description | Required | Default
35  mapMethod | (nearest/planarInterpolation) | no | planarInterpolation
36  offset | Time-varying offset values to interpolated data | no |
37  fieldTable | Name of field data table | no | field-name
38  points | The name of the points file | no | points
39  perturb | Perturbation fraction of bounding box | no | 1e-5
40  setAverage | adjust mapped field to maintain average value | no | false
41  \endtable
42 
43 SourceFiles
44  MappedFile.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef PatchFunction1Types_MappedFile_H
49 #define PatchFunction1Types_MappedFile_H
50 
51 #include "PatchFunction1.H"
53 #include "Function1.H"
54 
55 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
56 
57 namespace Foam
58 {
59 namespace PatchFunction1Types
60 {
61 
62 /*---------------------------------------------------------------------------*\
63  Class MappedFile Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class Type>
67 class MappedFile
68 :
69  public PatchFunction1<Type>
70 {
71  // Private Data
72 
73  //- Whether constructed from dictionary
74  const bool dictConstructed_;
75 
76  //- If true adjust the mapped field to maintain average value
77  bool setAverage_;
78 
79  //- Name of the field data table, defaults to the name of the field
80  word fieldTableName_;
81 
82  //- Fraction of perturbation (fraction of bounding box) to add
83  scalar perturb_;
84 
85  //- Name of points file; default = "points"
86  word pointsName_;
87 
88  //- Interpolation scheme to use
89  word mapMethod_;
90 
91  //- 2D interpolation (for 'planarInterpolation' mapMethod)
92  mutable autoPtr<pointToPointPlanarInterpolation> mapperPtr_;
93 
94  //- List of boundaryData time directories
95  mutable instantList sampleTimes_;
96 
97  //- Current starting index in sampleTimes
98  mutable label startSampleTime_;
99 
100  //- Interpolated values from startSampleTime
101  mutable Field<Type> startSampledValues_;
102 
103  //- If setAverage: starting average value
104  mutable Type startAverage_;
105 
106  //- Current end index in sampleTimes
107  mutable label endSampleTime_;
108 
109  //- Interpolated values from endSampleTime
110  mutable Field<Type> endSampledValues_;
111 
112  //- If setAverage: end average value
113  mutable Type endAverage_;
114 
115  //- Time varying offset values to interpolated data
116  autoPtr<Function1<Type>> offset_;
117 
118 
119  // Private Member Functions
120 
121  void checkTable(const scalar t) const;
122 
123 public:
124 
125  //- Runtime type information
126  TypeName("mappedFile");
127 
128 
129  // Generated Methods
130 
131  //- No copy assignment
132  void operator=(const MappedFile<Type>&) = delete;
133 
134 
135  // Constructors
136 
137  //- Construct from entry name and dictionary
138  MappedFile
139  (
140  const polyPatch& pp,
141  const word& redirectType,
142  const word& entryName,
143  const dictionary& dict,
144  const bool faceValues = true
145  );
146 
147  //- Construct from entry name and dictionary
148  MappedFile
149  (
150  const polyPatch& pp,
151  const word& entryName,
152  const dictionary& dict,
153  const word& fieldTableName,
154  const bool faceValues
155  );
156 
157  //- Copy construct
158  explicit MappedFile(const MappedFile<Type>& rhs);
159 
160  //- Copy construct setting patch
161  explicit MappedFile
162  (
163  const MappedFile<Type>& rhs,
164  const polyPatch& pp
165  );
166 
167  //- Construct and return a clone
168  virtual tmp<PatchFunction1<Type>> clone() const
169  {
171  (
172  new MappedFile<Type>(*this)
173  );
174  }
175 
176  //- Construct and return a clone setting patch
177  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
178  {
180  (
181  new MappedFile<Type>(*this, pp)
182  );
183  }
184 
185 
186  //- Destructor
187  virtual ~MappedFile() = default;
188 
189 
190  // Member Functions
191 
192  // Evaluation
193 
194  //- Return MappedFile value
195  virtual tmp<Field<Type>> value(const scalar) const;
196 
197  //- Is value constant (i.e. independent of x)
198  virtual bool constant() const
199  {
200  return sampleTimes_.size() == 1;
201  }
202 
203  //- Is value uniform (i.e. independent of coordinate)
204  virtual bool uniform() const
205  {
207  }
208 
209  //- Integrate between two values
210  virtual tmp<Field<Type>> integrate
211  (
212  const scalar x1,
213  const scalar x2
214  ) const;
215 
216 
217  // Mapping
218 
219  //- Map (and resize as needed) from self given a mapping object
220  virtual void autoMap(const FieldMapper& mapper);
221 
222  //- Reverse map the given PatchFunction1 onto this PatchFunction1
223  virtual void rmap
224  (
225  const PatchFunction1<Type>& pf1,
226  const labelList& addr
227  );
228 
229 
230  // I-O
231 
232  //- Write in dictionary format
233  virtual void writeData(Ostream& os) const;
234 };
235 
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 } // End namespace PatchFunction1Types
240 } // End namespace Foam
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 #ifdef NoRepository
245  #include "MappedFile.C"
246 #endif
247 
248 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
249 
250 #endif
251 
252 // ************************************************************************* //
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:62
Foam::PatchFunction1Types::MappedFile::clone
virtual tmp< PatchFunction1< Type > > clone(const polyPatch &pp) const
Construct and return a clone setting patch.
Definition: MappedFile.H:211
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:588
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:117
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
Is value constant (i.e. independent of x)
Definition: MappedFile.H:232
Foam::PatchFunction1::uniform
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
Definition: PatchFunction1.C:93
Foam::PatchFunction1Types::MappedFile::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: MappedFile.C:576
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
Foam::PatchFunction1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: PatchFunction1.H:59
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 file.
Definition: MappedFile.H:101
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:115
Foam::PatchFunction1Types::MappedFile::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: MappedFile.H:238
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:118
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:189
Foam::PatchFunction1::faceValues
const polyPatch const word const word const dictionary const bool faceValues
Definition: PatchFunction1.H:120
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::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:202
Foam::PatchFunction1Types::MappedFile::value
virtual tmp< Field< Type > > value(const scalar) const
Return MappedFile value.
Definition: MappedFile.C:466