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-2025 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  // == mesh.thisDb().newIOobject(name)
44  IOobject
45  (
46  name,
47  mesh.thisDb().time().timeName(),
48  mesh.thisDb(),
49  IOobjectOption::NO_READ,
50  IOobjectOption::NO_WRITE,
51  IOobjectOption::NO_REGISTER
52  ),
53  mesh,
54  std::forward<Args>(args)...
55  );
56 
57  // Registration
58  {
59  if (IOobjectOption::REGISTER == regOpt)
60  {
61  ptr->checkIn();
62  }
63  else if
64  (
65  // LEGACY_REGISTER: detect if caching is desired
66  (IOobjectOption::LEGACY_REGISTER == regOpt)
67  && ptr->db().is_cacheTemporaryObject(ptr.get())
68  )
69  {
70  ptr.protect(true);
71  ptr->checkIn();
72  }
73  }
74  return ptr;
75 }
76 
77 
78 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
79 
80 template<class Type, class GeoMesh>
83 (
84  const word& name,
86  const Mesh& mesh,
87  const dimensionSet& dims,
88  const Field<Type>& iField
89 )
90 {
92  (
93  regOpt,
94  name,
95  mesh,
96  dims,
97  iField
98  );
99 }
100 
101 
102 template<class Type, class GeoMesh>
105 (
106  const word& name,
107  const Mesh& mesh,
108  const dimensionSet& dims,
109  const Field<Type>& iField
110 )
111 {
113  (
114  IOobjectOption::LEGACY_REGISTER,
115  name,
116  mesh,
117  dims,
118  iField
119  );
120 }
121 
122 
123 template<class Type, class GeoMesh>
126 (
127  const word& name,
129  const Mesh& mesh,
130  const dimensionSet& dims,
131  Field<Type>&& iField
132 )
133 {
135  (
136  regOpt,
137  name,
138  mesh,
139  dims,
140  std::move(iField)
141  );
142 }
143 
144 
145 template<class Type, class GeoMesh>
148 (
149  const word& name,
150  const Mesh& mesh,
151  const dimensionSet& dims,
152  Field<Type>&& iField
153 )
154 {
156  (
157  IOobjectOption::LEGACY_REGISTER,
158  name,
159  mesh,
160  dims,
161  std::move(iField)
162  );
163 }
164 
165 
166 template<class Type, class GeoMesh>
169 (
170  const word& name,
172  const Mesh& mesh,
173  const dimensionSet& dims,
174  const tmp<Field<Type>>& tfield
175 )
176 {
178  (
179  regOpt,
180  name,
181  mesh,
182  dims,
183  tfield
184  );
185 }
186 
187 
188 template<class Type, class GeoMesh>
191 (
192  const word& name,
193  const Mesh& mesh,
194  const dimensionSet& dims,
195  const tmp<Field<Type>>& tfield
196 )
197 {
199  (
200  IOobjectOption::LEGACY_REGISTER,
201  name,
202  mesh,
203  dims,
204  tfield
205  );
206 }
207 
208 
209 template<class Type, class GeoMesh>
212 (
213  const word& name,
215  const Mesh& mesh,
216  const dimensionSet& dims
217 )
218 {
220  (
221  regOpt,
222  name,
223  mesh,
224  dims,
225  false // No checkIOFlags (is NO_READ anyhow)
226  );
227 }
228 
229 
230 template<class Type, class GeoMesh>
233 (
234  const word& name,
235  const Mesh& mesh,
236  const dimensionSet& dims
237 )
238 {
240  (
241  IOobjectOption::LEGACY_REGISTER,
242  name,
243  mesh,
244  dims,
245  false // No checkIOFlags (is NO_READ anyhow)
246  );
247 }
248 
249 
250 template<class Type, class GeoMesh>
253 (
254  const word& name,
256  const Mesh& mesh,
257  const Type& value,
258  const dimensionSet& dims
259 )
260 {
262  (
263  regOpt,
264  name,
265  mesh,
266  value,
267  dims,
268  false // No checkIOFlags (is NO_READ anyhow)
269  );
270 }
271 
272 
273 template<class Type, class GeoMesh>
276 (
277  const word& name,
278  const Mesh& mesh,
279  const Type& value,
280  const dimensionSet& dims
281 )
282 {
284  (
285  IOobjectOption::LEGACY_REGISTER,
286  name,
287  mesh,
288  value,
289  dims,
290  false // No checkIOFlags (is NO_READ anyhow)
291  );
292 }
293 
294 
295 template<class Type, class GeoMesh>
298 (
299  const word& name,
301  const Mesh& mesh,
302  const dimensioned<Type>& dt
303 )
304 {
306  (
307  name,
308  regOpt,
309  mesh,
310  dt.value(),
311  dt.dimensions()
312  );
313 }
314 
315 
316 template<class Type, class GeoMesh>
319 (
320  const word& name,
321  const Mesh& mesh,
322  const dimensioned<Type>& dt
323 )
324 {
326  (
327  name,
328  mesh,
329  dt.value(),
330  dt.dimensions()
331  );
332 }
333 
334 
335 template<class Type, class GeoMesh>
338 (
339  const word& name,
342 )
343 {
345  (
346  IOobject
347  (
348  name,
349  tfld().instance(),
350  tfld().local(),
351  tfld().db(),
352  IOobjectOption::NO_READ,
353  IOobjectOption::NO_WRITE,
354  IOobjectOption::NO_REGISTER
355  ),
356  tfld
357  );
358 
359  // Registration
360  {
361  if (IOobjectOption::REGISTER == regOpt)
362  {
363  ptr->checkIn();
364  }
365  else if
366  (
367  // LEGACY_REGISTER: detect if caching is desired
368  (IOobjectOption::LEGACY_REGISTER == regOpt)
369  && ptr->db().is_cacheTemporaryObject(ptr.get())
370  )
371  {
372  ptr.protect(true);
373  ptr->checkIn();
374  }
375  }
376  return ptr;
377 }
378 
379 
380 template<class Type, class GeoMesh>
383 (
384  const word& name,
386 )
387 {
389  (
390  name,
391  IOobjectOption::LEGACY_REGISTER,
392  tfld
393  );
394 }
395 
396 
397 template<class Type, class GeoMesh>
398 template<class AnyType>
401 (
403  const word& name,
404  const dimensionSet& dims
405 )
406 {
408  (
409  IOobject
410  (
411  name,
412  fld.instance(),
413  fld.db(),
414  IOobjectOption::NO_READ,
415  IOobjectOption::NO_WRITE,
416  IOobjectOption::NO_REGISTER
417  ),
418  fld.mesh(),
419  dims
420  );
421 
422  // Registration
423  {
424  if
425  (
426  ptr->db().is_cacheTemporaryObject(ptr.get())
427  )
428  {
429  ptr.protect(true);
430  ptr->checkIn();
431  }
432  }
433  return ptr;
434 }
435 
436 
437 template<class Type, class GeoMesh>
438 template<class AnyType>
441 (
443  const word& name,
444  const dimensioned<Type>& dt
445 )
446 {
448  (
449  IOobject
450  (
451  name,
452  fld.instance(),
453  fld.db(),
454  IOobjectOption::NO_READ,
455  IOobjectOption::NO_WRITE,
456  IOobjectOption::NO_REGISTER
457  ),
458  fld.mesh(),
459  dt.value(),
460  dt.dimensions()
461  );
462 
463  // Registration
464  {
465  if
466  (
467  ptr->db().is_cacheTemporaryObject(ptr.get())
468  )
469  {
470  ptr.protect(true);
471  ptr->checkIn();
472  }
473  }
474  return ptr;
475 }
476 
477 
478 // ************************************************************************* //
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:63
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...
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:180