Loading...
Searching...
No Matches
DimensionedFieldReuseFunctions.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2018-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#ifndef Foam_DimensionedFieldReuseFunctions_H
30#define Foam_DimensionedFieldReuseFunctions_H
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38// One-parameter versions
40template<class TypeR, class Type1, class GeoMesh>
42{
43 //- Pass-through to New DimensionedField
45 (
47 const word& name,
48 const dimensionSet& dimensions
49 )
50 {
52 (
53 name,
54 f1.mesh(),
55 dimensions
56 );
57 }
58
59 //- Dissimilar types: return new field
61 (
63 const word& name,
64 const dimensionSet& dimensions
65 )
66 {
67 const auto& f1 = tf1();
68
70 (
71 name,
72 f1.mesh(),
73 dimensions
74 );
75 }
76};
78
79template<class TypeR, class GeoMesh>
80struct reuseTmpDimensionedField<TypeR, TypeR, GeoMesh>
81{
82 //- Allow optional copy assignment of the initial content
83 //- for identical input and output types
85 (
87 const word& name,
88 const dimensionSet& dimensions,
89 const bool initCopy = false
90 )
91 {
92 if (tf1.movable())
93 {
94 auto& f1 = tf1.constCast();
95
96 f1.rename(name);
97 f1.dimensions().reset(dimensions);
98 return tf1;
99 }
100
101 const auto& f1 = tf1();
102
104 (
105 name,
106 f1.mesh(),
107 dimensions
108 );
109
110 if (initCopy)
111 {
112 tresult.ref().field() = f1.field();
113 }
114
115 return tresult;
116 }
117};
118
119
120//- Global function forwards to reuseTmpDimensionedField::New
121template<class TypeR, class GeoMesh>
122tmp<DimensionedField<TypeR, GeoMesh>> New
125 const word& name,
126 const dimensionSet& dimensions,
127 const bool initCopy = false
128)
129{
131 (
132 tf1,
133 name,
134 dimensions,
135 initCopy
136 );
137}
138
139
140template<class TypeR, class Type1, class Type12, class Type2, class GeoMesh>
141struct reuseTmpTmpDimensionedField
147 const word& name,
148 const dimensionSet& dimensions
149 )
150 {
151 const auto& f1 = tf1();
152
154 (
155 name,
156 f1.mesh(),
157 dimensions
158 );
159 }
160};
161
162
163template<class TypeR, class Type1, class Type12, class GeoMesh>
164struct reuseTmpTmpDimensionedField<TypeR, Type1, Type12, TypeR, GeoMesh>
170 const word& name,
171 const dimensionSet& dimensions
172 )
173 {
174 if (tf2.movable())
175 {
176 auto& f2 = tf2.constCast();
177
178 f2.rename(name);
179 f2.dimensions().reset(dimensions);
180 return tf2;
181 }
182
183 const auto& f1 = tf1();
184
186 (
187 name,
188 f1.mesh(),
189 dimensions
190 );
191 }
192};
193
194
195template<class TypeR, class Type2, class GeoMesh>
196struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, Type2, GeoMesh>
202 const word& name,
203 const dimensionSet& dimensions
204 )
205 {
206 if (tf1.movable())
207 {
208 auto& f1 = tf1.constCast();
209
210 f1.rename(name);
211 f1.dimensions().reset(dimensions);
212 return tf1;
213 }
214
215 const auto& f1 = tf1();
216
218 (
219 name,
220 f1.mesh(),
221 dimensions
222 );
223 }
224};
225
226
227template<class TypeR, class GeoMesh>
228struct reuseTmpTmpDimensionedField<TypeR, TypeR, TypeR, TypeR, GeoMesh>
234 const word& name,
235 const dimensionSet& dimensions
236 )
237 {
238 if (tf1.movable())
239 {
240 auto& f1 = tf1.constCast();
241
242 f1.rename(name);
243 f1.dimensions().reset(dimensions);
244 return tf1;
245 }
246 if (tf2.movable())
247 {
248 auto& f2 = tf2.constCast();
249
250 f2.rename(name);
251 f2.dimensions().reset(dimensions);
252 return tf2;
253 }
254
255 const auto& f1 = tf1();
256
258 (
259 name,
260 f1.mesh(),
261 dimensions
262 );
263 }
264};
265
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269} // End namespace Foam
270
271// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272
273#endif
274
275// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const Mesh & mesh() const noexcept
Return const reference to mesh.
static tmp< DimensionedField< Type, GeoMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const Field< Type > &iField)
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions, copy of internal field....
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition GeoMesh.H:46
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
Namespace for OpenFOAM.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition exprTraits.C:127
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Allow optional copy assignment of the initial content for identical input and output types.
static tmp< DimensionedField< TypeR, GeoMesh > > New(const DimensionedField< Type1, GeoMesh > &f1, const word &name, const dimensionSet &dimensions)
Pass-through to New DimensionedField.
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions)
Dissimilar types: return new field.
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tf1, const tmp< DimensionedField< TypeR, GeoMesh > > &tf2, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const tmp< DimensionedField< Type2, GeoMesh > > &tf2, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const tmp< DimensionedField< TypeR, GeoMesh > > &tf2, const word &name, const dimensionSet &dimensions)
static tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< Type1, GeoMesh > > &tf1, const tmp< DimensionedField< Type2, GeoMesh > > &tf2, const word &name, const dimensionSet &dimensions)