timeVaryingMappedFvPatchField.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::timeVaryingMappedFvPatchField
26 
27 Description
28  Patch field mapper which interpolates the values from a set of supplied
29  points in space and time.
30 
31  By default the data files should be provide in
32  constant/boundaryData/<patch name>/ directory:
33  - points : pointField of locations
34  - <time>/<field> : field of values at time <time>
35 
36  Alternatively the names and locations of the points and field files may be
37  specified explicitly via the optional dictionary entries:
38  - dataDir <optional top-level directory of the points and field data>;
39  - points <optional path including name of points file relative to
40  dataDir>;
41  - sample <optional name of the sub-directory in the time directories
42  containing the fields>;
43  This is particularly useful when mapping data from another case for which
44  the \c sample \c functionObject is used to obtain the patch field data for
45  mapping.
46 
47  If the surface from which the data was obtained changes in time, e.g. when
48  sampled from a case with a changing mesh, a separate points file may be
49  provided in each time directory alongside the field data, i.e.
50  dataDir/<time>/<sample>/<points name>. Points files found in the
51  time directories take precedence over the static points file.
52 
53  Note: unfortunately if the points files exist in any of the time directories
54  they MUST exist in ALL of the time directories and read from each. It would
55  be much better if this functionality were changed for consistency with
56  polyMesh and on restart the time directories are scanned backwards for the
57  most recent points file, that way the points files are only read for times
58  at which they change.
59 
60  The default mode of operation (mapMethod planarInterpolation) is to project
61  the points onto a plane (constructed from the first three points) and
62  construct a 2D triangulation and finds for the face centres the triangle it
63  is in and the weights to the 3 vertices.
64 
65  The optional mapMethod nearest will avoid all projection and triangulation
66  and just use the value at the nearest vertex.
67 
68  Values are interpolated linearly between times.
69 
70 Usage
71  \table
72  Property | Description | Required | Default value
73  setAverage | Switch to activate setting of average value | no | false
74  perturb | Perturb points for regular geometries | no | 1e-5
75  fieldTable | Alternative field name to sample | no| this field name
76  mapMethod | Type of mapping | no | planarInterpolation
77  offset | Offset to mapped values | no | Zero
78  dataDir | Top-level directory of the points and field data \\
79  | no | constant/boundaryData/<patch name>
80  points | Path including name of points file relative to dataDir \\
81  | no | points
82  sample | Name of the sub-directory in the time directories \\
83  containing the fields | no | ""
84  \endtable
85 
86 See also
87  Foam::timeVaryingMappedFixedValueFvPatchField
88  Foam::Function1s
89 
90 SourceFiles
91  timeVaryingMappedFvPatchField.C
92 
93 \*---------------------------------------------------------------------------*/
94 
95 #ifndef timeVaryingMappedFvPatchField_H
96 #define timeVaryingMappedFvPatchField_H
97 
98 #include "fvPatchField.H"
99 #include "instantList.H"
100 #include "Function1.H"
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
104 namespace Foam
105 {
106 
107 // Forward declaration of classes
108 class pointToPointPlanarInterpolation;
109 TemplateName(timeVaryingMappedFvPatchField);
110 
111 /*---------------------------------------------------------------------------*\
112  Class timeVaryingMappedFvPatchField Declaration
113 \*---------------------------------------------------------------------------*/
114 
115 template<class Type>
116 class timeVaryingMappedFvPatchField
117 :
118  public timeVaryingMappedFvPatchFieldName
119 {
120  // Private Data
121 
122  //- Reference to the patch the data is mapped to
123  const fvPatch& patch_;
124 
125  //- Reference to internal field
126  const DimensionedField<Type, fvMesh>& internalField_;
127 
128  //- Name of the field data table, defaults to the name of the field
129  word fieldTableName_;
130 
131  //- Optional name of the data directory,
132  // defaults to "constant/boundaryData/<patch name>"
133  fileName dataDir_;
134 
135  //- Optional name of the points file, defaults to "points"
136  fileName pointsName_;
137 
138  //- Optional name of the sample sub-directory from which the field are
139  // read, defaults to ""
140  fileName sampleName_;
141 
142  //- If true adjust the mapped field to maintain average value
143  Switch setAverage_;
144 
145  //- Fraction of perturbation (fraction of bounding box) to add
146  scalar perturb_;
147 
148  //- Interpolation scheme to use
149  word mapMethod_;
150 
151  //- 2D interpolation (for 'planarInterpolation' mapMethod)
153 
154  //- Path of the points file from which the mapper was constructed
155  fileName mapperPointsFile_;
156 
157  //- List of boundaryData time directories
158  instantList sampleTimes_;
159 
160  //- Current starting index in sampleTimes
161  label startSampleTime_;
162 
163  //- Interpolated values from startSampleTime
164  Field<Type> startSampledValues_;
165 
166  //- If setAverage: starting average value
167  Type startAverage_;
168 
169  //- Current end index in sampleTimes
170  label endSampleTime_;
171 
172  //- Interpolated values from endSampleTime
173  Field<Type> endSampledValues_;
174 
175  //- If setAverage: end average value
176  Type endAverage_;
177 
178  //- Time varying offset values to interpolated data
179  autoPtr<Function1<Type>> offset_;
180 
181  //- Helper function to find the field files
182  fileName findFieldFile(const word& timeName) const;
183 
184  //- Helper function to find the points file for the given sample
185  // time. Returns the points file in the time directory if present,
186  // otherwise the static points file.
187  fileName findPointsFile(const word& timeName) const;
188 
189  //- Return the mapper for the given sample time, updating it if the
190  // points file differs from that from which it was constructed
191  const pointToPointPlanarInterpolation& mapper(const word& timeName);
192 
193  //- Find boundary data in between current time and interpolate
194  void checkTable();
195 
196 
197 public:
198 
199  // Constructors
200 
201  //- Construct from patch, internal field and dictionary
203  (
204  const fvPatch&,
206  const dictionary&
207  );
208 
209  //- Construct by mapping given timeVaryingMappedFvPatchField
210  // onto a new patch
212  (
214  const fvPatch&,
216  const fieldMapper&
217  );
218 
219  //- Copy constructor
221  (
223  );
224 
225 
226  // Member Functions
227 
228  //- Return reference to time
229  const Time& time() const
230  {
231  return patch_.time();
232  }
233 
234  // Mapping functions
235 
236  //- Map the given timeVaryingMappedFvPatchField
237  // onto this timeVaryingMappedFvPatchField
238  void map
239  (
241  const fieldMapper&
242  );
243 
244  //- Reset the fvPatchField to the given fvPatchField
245  // Used for mesh to mesh mapping
247 
248 
249  // Evaluation functions
250 
251  //- Return the current mapped patch field
253 
254 
255  //- Write
256  void write(Ostream&) const;
257 };
258 
259 
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261 
262 } // End namespace Foam
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 #ifdef NoRepository
268 #endif
269 
270 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
271 
272 #endif
273 
274 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:83
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
A class for handling file names.
Definition: fileName.H:82
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
const Time & time() const
Return time.
Interpolates between two sets of unstructured points using 2D Delaunay triangulation....
Patch field mapper which interpolates the values from a set of supplied points in space and time.
const Time & time() const
Return reference to time.
void reset(const timeVaryingMappedFvPatchField &)
Reset the fvPatchField to the given fvPatchField.
timeVaryingMappedFvPatchField(const fvPatch &, const DimensionedField< Type, fvMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
tmp< Field< Type > > map()
Return the current mapped patch field.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
word timeName
Definition: getTimeIndex.H:3
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
TemplateName(FvFaceCellWave)