DimensionedFieldNew.C
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) 2022-2023 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 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type, class GeoMesh>
31 template<class... Args>
34 (
36  const word& name,
37  const Mesh& mesh,
38  Args&&... args
39 )
40 {
42  (
43  IOobject
44  (
45  name,
46  mesh.thisDb().time().timeName(),
47  mesh.thisDb(),
48  IOobjectOption::NO_READ,
49  IOobjectOption::NO_WRITE,
50  IOobjectOption::NO_REGISTER
51  ),
52  mesh,
53  std::forward<Args>(args)...
54  );
55 
56  if (IOobjectOption::REGISTER == regOpt)
57  {
58  ptr->checkIn();
59  }
60  else if
61  (
62  // LEGACY_REGISTER: detect if caching is desired
63  (IOobjectOption::LEGACY_REGISTER == regOpt)
64  && ptr->db().is_cacheTemporaryObject(ptr.get())
65  )
66  {
67  ptr.protect(true);
68  ptr->checkIn();
69  }
70  return ptr;
71 }
72 
73 
74 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
75 
76 template<class Type, class GeoMesh>
79 (
80  const word& name,
82  const Mesh& mesh,
83  const dimensionSet& dims,
84  const Field<Type>& iField
85 )
86 {
88  (
89  regOpt,
90  name,
91  mesh,
92  dims,
93  iField
94  );
95 }
96 
97 
98 template<class Type, class GeoMesh>
101 (
102  const word& name,
103  const Mesh& mesh,
104  const dimensionSet& dims,
105  const Field<Type>& iField
106 )
107 {
109  (
110  IOobjectOption::LEGACY_REGISTER,
111  name,
112  mesh,
113  dims,
114  iField
115  );
116 }
117 
118 
119 template<class Type, class GeoMesh>
122 (
123  const word& name,
125  const Mesh& mesh,
126  const dimensionSet& dims,
127  Field<Type>&& iField
128 )
129 {
131  (
132  regOpt,
133  name,
134  mesh,
135  dims,
136  std::move(iField)
137  );
138 }
139 
140 
141 template<class Type, class GeoMesh>
144 (
145  const word& name,
146  const Mesh& mesh,
147  const dimensionSet& dims,
148  Field<Type>&& iField
149 )
150 {
152  (
153  IOobjectOption::LEGACY_REGISTER,
154  name,
155  mesh,
156  dims,
157  std::move(iField)
158  );
159 }
160 
161 
162 template<class Type, class GeoMesh>
165 (
166  const word& name,
168  const Mesh& mesh,
169  const dimensionSet& dims
170 )
171 {
173  (
174  regOpt,
175  name,
176  mesh,
177  dims,
178  false // No checkIOFlags (is NO_READ anyhow)
179  );
180 }
181 
182 
183 template<class Type, class GeoMesh>
186 (
187  const word& name,
188  const Mesh& mesh,
189  const dimensionSet& dims
190 )
191 {
193  (
194  IOobjectOption::LEGACY_REGISTER,
195  name,
196  mesh,
197  dims,
198  false // No checkIOFlags (is NO_READ anyhow)
199  );
200 }
201 
202 
203 template<class Type, class GeoMesh>
206 (
207  const word& name,
209  const Mesh& mesh,
210  const Type& value,
211  const dimensionSet& dims
212 )
213 {
215  (
216  regOpt,
217  name,
218  mesh,
219  value,
220  dims,
221  false // No checkIOFlags (is NO_READ anyhow)
222  );
223 }
224 
225 
226 template<class Type, class GeoMesh>
229 (
230  const word& name,
231  const Mesh& mesh,
232  const Type& value,
233  const dimensionSet& dims
234 )
235 {
237  (
238  IOobjectOption::LEGACY_REGISTER,
239  name,
240  mesh,
241  value,
242  dims,
243  false // No checkIOFlags (is NO_READ anyhow)
244  );
245 }
246 
247 
248 template<class Type, class GeoMesh>
251 (
252  const word& name,
254  const Mesh& mesh,
255  const dimensioned<Type>& dt
256 )
257 {
259  (
260  name,
261  regOpt,
262  mesh,
263  dt.value(),
264  dt.dimensions()
265  );
266 }
267 
268 
269 template<class Type, class GeoMesh>
272 (
273  const word& name,
274  const Mesh& mesh,
275  const dimensioned<Type>& dt
276 )
277 {
279  (
280  name,
281  mesh,
282  dt.value(),
283  dt.dimensions()
284  );
285 }
286 
287 
288 template<class Type, class GeoMesh>
291 (
292  const word& name,
294 )
295 {
297  (
298  IOobject
299  (
300  name,
301  tfld().instance(),
302  tfld().local(),
303  tfld().db(),
304  IOobjectOption::NO_READ,
305  IOobjectOption::NO_WRITE,
306  IOobjectOption::NO_REGISTER
307  ),
308  tfld
309  );
310 
311  if
312  (
313  ptr->db().is_cacheTemporaryObject(ptr.get())
314  )
315  {
316  ptr.protect(true);
317  ptr->checkIn();
318  }
319  return ptr;
320 }
321 
322 
323 template<class Type, class GeoMesh>
324 template<class AnyType>
327 (
329  const word& name,
330  const dimensionSet& dims
331 )
332 {
334  (
335  IOobject
336  (
337  name,
338  fld.instance(),
339  fld.db(),
340  IOobjectOption::NO_READ,
341  IOobjectOption::NO_WRITE,
342  IOobjectOption::NO_REGISTER
343  ),
344  fld.mesh(),
345  dims
346  );
347 
348  if
349  (
350  ptr->db().is_cacheTemporaryObject(ptr.get())
351  )
352  {
353  ptr.protect(true);
354  ptr->checkIn();
355  }
356  return ptr;
357 }
358 
359 
360 template<class Type, class GeoMesh>
361 template<class AnyType>
364 (
366  const word& name,
367  const dimensioned<Type>& dt
368 )
369 {
371  (
372  IOobject
373  (
374  name,
375  fld.instance(),
376  fld.db(),
377  IOobjectOption::NO_READ,
378  IOobjectOption::NO_WRITE,
379  IOobjectOption::NO_REGISTER
380  ),
381  fld.mesh(),
382  dt.value(),
383  dt.dimensions()
384  );
385 
386  if
387  (
388  ptr->db().is_cacheTemporaryObject(ptr.get())
389  )
390  {
391  ptr.protect(true);
392  ptr->checkIn();
393  }
394  return ptr;
395 }
396 
397 
398 // ************************************************************************* //
const Type & value() const noexcept
Return const reference to value.
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.
Generic dimensioned Type class.
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Generic templated field type.
Definition: Field.H:62
A class for handling words, derived from Foam::string.
Definition: word.H:63
bool local
Definition: EEqn.H:20
const dimensionSet & dimensions() const noexcept
Return const reference to dimensions.
Foam::pointMesh ::Mesh Mesh
The mesh type for the DimensionedField.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true)
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...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Foam::argList args(argc, argv)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172