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  //- Name of the field data table, defaults to the name of the field
77  word fieldTableName_;
78 
79  //- If true adjust the mapped field to maintain average value
80  bool setAverage_;
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  //- No copy assignment
124  void operator=(const MappedFile<Type>&) = delete;
125 
126 
127 public:
128 
129  //- Runtime type information
130  TypeName("mappedFile");
131 
132 
133  // Constructors
134 
135  //- Construct from entry name and dictionary
136  MappedFile
137  (
138  const polyPatch& pp,
139  const word& type,
140  const word& entryName,
141  const dictionary& dict,
142  const bool faceValues = true
143  );
144 
145  //- Construct from entry name and dictionary
146  MappedFile
147  (
148  const polyPatch& pp,
149  const word& entryName,
150  const dictionary& dict,
151  const word& fieldTableName,
152  const bool faceValues
153  );
154 
155  //- Copy constructor
156  explicit MappedFile(const MappedFile<Type>& ut);
157 
158  //- Copy constructor setting patch
159  explicit MappedFile
160  (
161  const MappedFile<Type>& ut,
162  const polyPatch& pp
163  );
164 
165  //- Construct and return a clone
166  virtual tmp<PatchFunction1<Type>> clone() const
167  {
169  (
170  new MappedFile<Type>(*this)
171  );
172  }
173 
174  //- Construct and return a clone setting patch
175  virtual tmp<PatchFunction1<Type>> clone(const polyPatch& pp) const
176  {
178  (
179  new MappedFile<Type>(*this, pp)
180  );
181  }
182 
183 
184  //- Destructor
185  virtual ~MappedFile() = default;
186 
187 
188  // Member Functions
189 
190  // Evaluation
191 
192  //- Return MappedFile value
193  virtual tmp<Field<Type>> value(const scalar) const;
194 
195  //- Is value constant (i.e. independent of x)
196  virtual bool constant() const
197  {
198  return sampleTimes_.size() == 1;
199  }
200 
201  //- Is value uniform (i.e. independent of coordinate)
202  virtual bool uniform() const
203  {
205  }
206 
207  //- Integrate between two values
208  virtual tmp<Field<Type>> integrate
209  (
210  const scalar x1,
211  const scalar x2
212  ) const;
213 
214 
215  // Mapping
216 
217  //- Map (and resize as needed) from self given a mapping object
218  virtual void autoMap(const FieldMapper& mapper);
219 
220  //- Reverse map the given PatchFunction1 onto this PatchFunction1
221  virtual void rmap
222  (
223  const PatchFunction1<Type>& pf1,
224  const labelList& addr
225  );
226 
227 
228  // I-O
229 
230  //- Write in dictionary format
231  virtual void writeData(Ostream& os) const;
232 };
233 
234 
235 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 
237 } // End namespace PatchFunction1Types
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #ifdef NoRepository
243  #include "MappedFile.C"
244 #endif
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 #endif
249 
250 // ************************************************************************* //
Foam::PatchFunction1Types::MappedFile::autoMap
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
Definition: MappedFile.C:194
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:209
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::PatchFunction1Types::MappedFile::writeData
virtual void writeData(Ostream &os) const
Write in dictionary format.
Definition: MappedFile.C:613
Foam::PatchFunction1::faceValues
bool faceValues() const
Whether to generate face or point values on patch.
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:120
Foam::PatchFunction1::type
const polyPatch const word & type
Definition: PatchFunction1.H:119
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:67
pointToPointPlanarInterpolation.H
Foam::PatchFunction1Types::MappedFile::constant
virtual bool constant() const
Is value constant (i.e. independent of x)
Definition: MappedFile.H:230
Foam::PatchFunction1::uniform
virtual bool uniform() const =0
Is value uniform (i.e. independent of coordinate)
Definition: PatchFunction1.C:133
Foam::PatchFunction1Types::MappedFile::integrate
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: MappedFile.C:601
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:63
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
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:118
Foam::PatchFunction1Types::MappedFile::MappedFile
MappedFile(const polyPatch &pp, const word &type, const word &entryName, const dictionary &dict, const bool faceValues=true)
Construct from entry name and dictionary.
Definition: MappedFile.C:35
Foam::PatchFunction1Types::MappedFile::uniform
virtual bool uniform() const
Is value uniform (i.e. independent of coordinate)
Definition: MappedFile.H:236
Foam::PatchFunction1::dict
const polyPatch const word const word const dictionary & dict
Definition: PatchFunction1.H:121
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:214
MappedFile.C
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:200
Foam::PatchFunction1Types::MappedFile::value
virtual tmp< Field< Type > > value(const scalar) const
Return MappedFile value.
Definition: MappedFile.C:491