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-2024 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 )
175 {
177  (
178  regOpt,
179  name,
180  mesh,
181  dims,
182  false // No checkIOFlags (is NO_READ anyhow)
183  );
184 }
185 
186 
187 template<class Type, class GeoMesh>
190 (
191  const word& name,
192  const Mesh& mesh,
193  const dimensionSet& dims
194 )
195 {
197  (
198  IOobjectOption::LEGACY_REGISTER,
199  name,
200  mesh,
201  dims,
202  false // No checkIOFlags (is NO_READ anyhow)
203  );
204 }
205 
206 
207 template<class Type, class GeoMesh>
210 (
211  const word& name,
213  const Mesh& mesh,
214  const Type& value,
215  const dimensionSet& dims
216 )
217 {
219  (
220  regOpt,
221  name,
222  mesh,
223  value,
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 Type& value,
237  const dimensionSet& dims
238 )
239 {
241  (
242  IOobjectOption::LEGACY_REGISTER,
243  name,
244  mesh,
245  value,
246  dims,
247  false // No checkIOFlags (is NO_READ anyhow)
248  );
249 }
250 
251 
252 template<class Type, class GeoMesh>
255 (
256  const word& name,
258  const Mesh& mesh,
259  const dimensioned<Type>& dt
260 )
261 {
263  (
264  name,
265  regOpt,
266  mesh,
267  dt.value(),
268  dt.dimensions()
269  );
270 }
271 
272 
273 template<class Type, class GeoMesh>
276 (
277  const word& name,
278  const Mesh& mesh,
279  const dimensioned<Type>& dt
280 )
281 {
283  (
284  name,
285  mesh,
286  dt.value(),
287  dt.dimensions()
288  );
289 }
290 
291 
292 template<class Type, class GeoMesh>
295 (
296  const word& name,
299 )
300 {
302  (
303  IOobject
304  (
305  name,
306  tfld().instance(),
307  tfld().local(),
308  tfld().db(),
309  IOobjectOption::NO_READ,
310  IOobjectOption::NO_WRITE,
311  IOobjectOption::NO_REGISTER
312  ),
313  tfld
314  );
315 
316  // Registration
317  {
318  if (IOobjectOption::REGISTER == regOpt)
319  {
320  ptr->checkIn();
321  }
322  else if
323  (
324  // LEGACY_REGISTER: detect if caching is desired
325  (IOobjectOption::LEGACY_REGISTER == regOpt)
326  && ptr->db().is_cacheTemporaryObject(ptr.get())
327  )
328  {
329  ptr.protect(true);
330  ptr->checkIn();
331  }
332  }
333  return ptr;
334 }
335 
336 
337 template<class Type, class GeoMesh>
340 (
341  const word& name,
343 )
344 {
346  (
347  name,
348  IOobjectOption::LEGACY_REGISTER,
349  tfld
350  );
351 }
352 
353 
354 template<class Type, class GeoMesh>
355 template<class AnyType>
358 (
360  const word& name,
361  const dimensionSet& dims
362 )
363 {
365  (
366  IOobject
367  (
368  name,
369  fld.instance(),
370  fld.db(),
371  IOobjectOption::NO_READ,
372  IOobjectOption::NO_WRITE,
373  IOobjectOption::NO_REGISTER
374  ),
375  fld.mesh(),
376  dims
377  );
378 
379  // Registration
380  {
381  if
382  (
383  ptr->db().is_cacheTemporaryObject(ptr.get())
384  )
385  {
386  ptr.protect(true);
387  ptr->checkIn();
388  }
389  }
390  return ptr;
391 }
392 
393 
394 template<class Type, class GeoMesh>
395 template<class AnyType>
398 (
400  const word& name,
401  const dimensioned<Type>& dt
402 )
403 {
405  (
406  IOobject
407  (
408  name,
409  fld.instance(),
410  fld.db(),
411  IOobjectOption::NO_READ,
412  IOobjectOption::NO_WRITE,
413  IOobjectOption::NO_REGISTER
414  ),
415  fld.mesh(),
416  dt.value(),
417  dt.dimensions()
418  );
419 
420  // Registration
421  {
422  if
423  (
424  ptr->db().is_cacheTemporaryObject(ptr.get())
425  )
426  {
427  ptr.protect(true);
428  ptr->checkIn();
429  }
430  }
431  return ptr;
432 }
433 
434 
435 // ************************************************************************* //
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...
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