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-2024 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  The default mode of operation (mapMethod planarInterpolation) is to project
48  the points onto a plane (constructed from the first three points) and
49  construct a 2D triangulation and finds for the face centres the triangle it
50  is in and the weights to the 3 vertices.
51 
52  The optional mapMethod nearest will avoid all projection and triangulation
53  and just use the value at the nearest vertex.
54 
55  Values are interpolated linearly between times.
56 
57 Usage
58  \table
59  Property | Description | Required | Default value
60  setAverage | Switch to activate setting of average value | no | false
61  perturb | Perturb points for regular geometries | no | 1e-5
62  fieldTable | Alternative field name to sample | no| this field name
63  mapMethod | Type of mapping | no | planarInterpolation
64  offset | Offset to mapped values | no | Zero
65  dataDir | Top-level directory of the points and field data \\
66  | no | constant/boundaryData/<patch name>
67  points | Path including name of points file relative to dataDir \\
68  | no | points
69  sample | Name of the sub-directory in the time directories \\
70  containing the fields | no | ""
71  \endtable
72 
73 See also
74  Foam::timeVaryingMappedFixedValueFvPatchField
75  Foam::Function1s
76 
77 SourceFiles
78  timeVaryingMappedFvPatchField.C
79 
80 \*---------------------------------------------------------------------------*/
81 
82 #ifndef timeVaryingMappedFvPatchField_H
83 #define timeVaryingMappedFvPatchField_H
84 
85 #include "fvPatchField.H"
86 #include "FixedList.H"
87 #include "instantList.H"
89 #include "Function1.H"
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 namespace Foam
94 {
95 
96 /*---------------------------------------------------------------------------*\
97  Class timeVaryingMappedFvPatchFieldName Declaration
98 \*---------------------------------------------------------------------------*/
99 
100 TemplateName(timeVaryingMappedFvPatchField);
101 
102 
103 /*---------------------------------------------------------------------------*\
104  Class timeVaryingMappedFvPatchField Declaration
105 \*---------------------------------------------------------------------------*/
106 
107 template<class Type>
108 class timeVaryingMappedFvPatchField
109 :
110  public timeVaryingMappedFvPatchFieldName
111 {
112  // Private Data
113 
114  //- Reference to the patch the data is mapped to
115  const fvPatch& patch_;
116 
117  //- Reference to internal field
118  const DimensionedField<Type, volMesh>& internalField_;
119 
120  //- Name of the field data table, defaults to the name of the field
121  word fieldTableName_;
122 
123  //- Optional name of the data directory,
124  // defaults to "constant/boundaryData/<patch name>"
125  fileName dataDir_;
126 
127  //- Optional name of the points file, defaults to "points"
128  fileName pointsName_;
129 
130  //- Optional name of the sample sub-directory from which the field are
131  // read, defaults to ""
132  fileName sampleName_;
133 
134  //- If true adjust the mapped field to maintain average value
135  Switch setAverage_;
136 
137  //- Fraction of perturbation (fraction of bounding box) to add
138  scalar perturb_;
139 
140  //- Interpolation scheme to use
141  word mapMethod_;
142 
143  //- 2D interpolation (for 'planarInterpolation' mapMethod)
145 
146  //- List of boundaryData time directories
147  instantList sampleTimes_;
148 
149  //- Current starting index in sampleTimes
150  label startSampleTime_;
151 
152  //- Interpolated values from startSampleTime
153  Field<Type> startSampledValues_;
154 
155  //- If setAverage: starting average value
156  Type startAverage_;
157 
158  //- Current end index in sampleTimes
159  label endSampleTime_;
160 
161  //- Interpolated values from endSampleTime
162  Field<Type> endSampledValues_;
163 
164  //- If setAverage: end average value
165  Type endAverage_;
166 
167  //- Time varying offset values to interpolated data
168  autoPtr<Function1<Type>> offset_;
169 
170  //- Helper function to find the field files
171  fileName findFieldFile(const word& timeName) const;
172 
173  //- Find boundary data in between current time and interpolate
174  void checkTable();
175 
176 
177 public:
178 
179  // Constructors
180 
181  //- Construct from patch, internal field and dictionary
183  (
184  const fvPatch&,
186  const dictionary&
187  );
188 
189  //- Copy constructor
191  (
193  );
194 
195 
196  // Member Functions
197 
198  const Time& time() const
199  {
200  return patch_.boundaryMesh().mesh().time();
201  }
202 
203  // Mapping functions
204 
205  //- Map the given timeVaryingMappedFvPatchField
206  // onto this timeVaryingMappedFvPatchField
207  void map
208  (
210  const fieldMapper&
211  );
212 
213  //- Reset the fvPatchField to the given fvPatchField
214  // Used for mesh to mesh mapping
216 
217 
218  // Evaluation functions
219 
220  //- Return the current mapped patch field
221  tmp<Field<Type>> map();
222 
223 
224  //- Write
225  void write(Ostream&) const;
226 };
227 
228 
229 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230 
231 } // End namespace Foam
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 #ifdef NoRepository
237 #endif
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 #endif
242 
243 // ************************************************************************* //
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 keyword definitions, which are a keyword followed by any number of values (e....
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:64
const Time & time() const
Return time.
Patch field mapper which interpolates the values from a set of supplied points in space and time.
timeVaryingMappedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &, const dictionary &)
Construct from patch, internal field and dictionary.
void reset(const timeVaryingMappedFvPatchField &)
Reset the fvPatchField to the given fvPatchField.
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:62
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)