GeometricFieldNew.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) 2017 OpenFOAM Foundation
9  Copyright (C) 2019-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type, template<class> class PatchField, class GeoMesh>
32 template<class... Args>
35 (
37  const word& name,
38  const Mesh& mesh,
39  Args&&... args
40 )
41 {
43  (
44  // == mesh.thisDb().newIOobject(name)
45  IOobject
46  (
47  name,
48  mesh.thisDb().time().timeName(),
49  mesh.thisDb(),
50  IOobjectOption::NO_READ,
51  IOobjectOption::NO_WRITE,
52  IOobjectOption::NO_REGISTER
53  ),
54  mesh,
55  std::forward<Args>(args)...
56  );
57 
58  // Registration
59  {
60  if (IOobjectOption::REGISTER == regOpt)
61  {
62  ptr->checkIn();
63  }
64  else if
65  (
66  // LEGACY_REGISTER: detect if caching is desired
67  (IOobjectOption::LEGACY_REGISTER == regOpt)
68  && ptr->db().is_cacheTemporaryObject(ptr.get())
69  )
70  {
71  ptr.protect(true);
72  ptr->checkIn();
73  }
74  }
75  return ptr;
76 }
77 
78 
79 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
80 
81 template<class Type, template<class> class PatchField, class GeoMesh>
84 (
85  const word& name,
87  const Mesh& mesh,
88  const dimensionSet& dims,
89  const word& patchFieldType
90 )
91 {
93  (
94  regOpt,
95  name,
96  mesh,
97  dims,
98  patchFieldType
99  );
100 }
101 
102 
103 template<class Type, template<class> class PatchField, class GeoMesh>
106 (
107  const word& name,
108  const Mesh& mesh,
109  const dimensionSet& dims,
110  const word& patchFieldType
111 )
112 {
114  (
115  IOobjectOption::LEGACY_REGISTER,
116  name,
117  mesh,
118  dims,
119  patchFieldType
120  );
121 }
122 
123 
124 template<class Type, template<class> class PatchField, class GeoMesh>
127 (
128  const word& name,
130  const Mesh& mesh,
131  const dimensionSet& dims,
132  const Field<Type>& iField,
133  const word& patchFieldType
134 )
135 {
137  (
138  regOpt,
139  name,
140  mesh,
141  dims,
142  iField,
143  patchFieldType
144  );
145 }
146 
147 
148 template<class Type, template<class> class PatchField, class GeoMesh>
151 (
152  const word& name,
153  const Mesh& mesh,
154  const dimensionSet& dims,
155  const Field<Type>& iField,
156  const word& patchFieldType
157 )
158 {
160  (
161  IOobjectOption::LEGACY_REGISTER,
162  name,
163  mesh,
164  dims,
165  iField,
166  patchFieldType
167  );
168 }
169 
170 
171 template<class Type, template<class> class PatchField, class GeoMesh>
174 (
175  const word& name,
177  const Mesh& mesh,
178  const dimensionSet& dims,
179  Field<Type>&& iField,
180  const word& patchFieldType
181 )
182 {
184  (
185  regOpt,
186  name,
187  mesh,
188  dims,
189  std::move(iField),
190  patchFieldType
191  );
192 }
193 
194 
195 template<class Type, template<class> class PatchField, class GeoMesh>
198 (
199  const word& name,
200  const Mesh& mesh,
201  const dimensionSet& dims,
202  Field<Type>&& iField,
203  const word& patchFieldType
204 )
205 {
207  (
208  IOobjectOption::LEGACY_REGISTER,
209  name,
210  mesh,
211  dims,
212  std::move(iField),
213  patchFieldType
214  );
215 }
216 
217 
218 template<class Type, template<class> class PatchField, class GeoMesh>
221 (
222  const word& name,
224  const Mesh& mesh,
225  const dimensionSet& dims,
226  const tmp<Field<Type>>& tfield,
227  const word& patchFieldType
228 )
229 {
231  (
232  regOpt,
233  name,
234  mesh,
235  dims,
236  tfield,
237  patchFieldType
238  );
239 }
240 
241 
242 template<class Type, template<class> class PatchField, class GeoMesh>
245 (
246  const word& name,
247  const Mesh& mesh,
248  const dimensionSet& dims,
249  const tmp<Field<Type>>& tfield,
250  const word& patchFieldType
251 )
252 {
254  (
255  IOobjectOption::LEGACY_REGISTER,
256  name,
257  mesh,
258  dims,
259  tfield,
260  patchFieldType
261  );
262 }
263 
264 
265 template<class Type, template<class> class PatchField, class GeoMesh>
268 (
269  const word& name,
271  const Mesh& mesh,
272  const dimensionSet& dims,
273  const Field<Type>& iField,
274  const PtrList<PatchField<Type>>& pflds
275 )
276 {
278  (
279  regOpt,
280  name,
281  mesh,
282  dims,
283  iField,
284  pflds
285  );
286 }
287 
288 
289 template<class Type, template<class> class PatchField, class GeoMesh>
292 (
293  const word& name,
294  const Mesh& mesh,
295  const dimensionSet& dims,
296  const Field<Type>& iField,
297  const PtrList<PatchField<Type>>& pflds
298 )
299 {
301  (
302  IOobjectOption::LEGACY_REGISTER,
303  name,
304  mesh,
305  dims,
306  iField,
307  pflds
308  );
309 }
310 
311 
312 template<class Type, template<class> class PatchField, class GeoMesh>
315 (
316  const word& name,
318  const Mesh& mesh,
319  const dimensionSet& dims,
320  Field<Type>&& iField,
321  const PtrList<PatchField<Type>>& pflds
322 )
323 {
325  (
326  regOpt,
327  name,
328  mesh,
329  dims,
330  std::move(iField),
331  pflds
332  );
333 }
334 
335 
336 template<class Type, template<class> class PatchField, class GeoMesh>
339 (
340  const word& name,
341  const Mesh& mesh,
342  const dimensionSet& dims,
343  Field<Type>&& iField,
344  const PtrList<PatchField<Type>>& pflds
345 )
346 {
348  (
349  IOobjectOption::LEGACY_REGISTER,
350  name,
351  mesh,
352  dims,
353  std::move(iField),
354  pflds
355  );
356 }
357 
358 
359 template<class Type, template<class> class PatchField, class GeoMesh>
362 (
363  const word& name,
365  const Mesh& mesh,
366  const Type& value,
367  const dimensionSet& dims,
368  const word& patchFieldType
369 )
370 {
372  (
373  regOpt,
374  name,
375  mesh,
376  value,
377  dims,
378  patchFieldType
379  );
380 }
381 
382 
383 template<class Type, template<class> class PatchField, class GeoMesh>
386 (
387  const word& name,
388  const Mesh& mesh,
389  const Type& value,
390  const dimensionSet& dims,
391  const word& patchFieldType
392 )
393 {
395  (
396  IOobjectOption::LEGACY_REGISTER,
397  name,
398  mesh,
399  value,
400  dims,
401  patchFieldType
402  );
403 }
404 
405 
406 template<class Type, template<class> class PatchField, class GeoMesh>
409 (
410  const word& name,
412  const Mesh& mesh,
413  const Type& value,
414  const dimensionSet& dims,
415  const wordList& patchFieldTypes,
416  const wordList& actualPatchTypes
417 )
418 {
420  (
421  regOpt,
422  name,
423  mesh,
424  value,
425  dims,
426  patchFieldTypes,
427  actualPatchTypes
428  );
429 }
430 
431 
432 template<class Type, template<class> class PatchField, class GeoMesh>
435 (
436  const word& name,
437  const Mesh& mesh,
438  const Type& value,
439  const dimensionSet& dims,
440  const wordList& patchFieldTypes,
441  const wordList& actualPatchTypes
442 )
443 {
445  (
446  IOobjectOption::LEGACY_REGISTER,
447  name,
448  mesh,
449  value,
450  dims,
451  patchFieldTypes,
452  actualPatchTypes
453  );
454 }
455 
456 
457 template<class Type, template<class> class PatchField, class GeoMesh>
460 (
461  const word& name,
463  const Mesh& mesh,
464  const dimensioned<Type>& dt,
465  const word& patchFieldType
466 )
467 {
469  (
470  name,
471  regOpt,
472  mesh,
473  dt.value(),
474  dt.dimensions(),
475  patchFieldType
476  );
477 }
478 
479 
480 template<class Type, template<class> class PatchField, class GeoMesh>
483 (
484  const word& name,
485  const Mesh& mesh,
486  const dimensioned<Type>& dt,
487  const word& patchFieldType
488 )
489 {
491  (
492  name,
493  mesh,
494  dt.value(),
495  dt.dimensions(),
496  patchFieldType
497  );
498 }
499 
500 
501 template<class Type, template<class> class PatchField, class GeoMesh>
504 (
505  const word& name,
507  const Mesh& mesh,
508  const dimensioned<Type>& dt,
509  const wordList& patchFieldTypes,
510  const wordList& actualPatchTypes
511 )
512 {
514  (
515  name,
516  regOpt,
517  mesh,
518  dt.value(),
519  dt.dimensions(),
520  patchFieldTypes,
521  actualPatchTypes
522  );
523 }
524 
525 
526 template<class Type, template<class> class PatchField, class GeoMesh>
529 (
530  const word& name,
531  const Mesh& mesh,
532  const dimensioned<Type>& dt,
533  const wordList& patchFieldTypes,
534  const wordList& actualPatchTypes
535 )
536 {
538  (
539  name,
540  mesh,
541  dt.value(),
542  dt.dimensions(),
543  patchFieldTypes,
544  actualPatchTypes
545  );
546 }
547 
548 
549 template<class Type, template<class> class PatchField, class GeoMesh>
552 (
553  const word& name,
556 )
557 {
559  (
560  IOobject
561  (
562  name,
563  tfld().instance(),
564  tfld().local(),
565  tfld().db(),
566  IOobjectOption::NO_READ,
567  IOobjectOption::NO_WRITE,
568  IOobjectOption::NO_REGISTER
569  ),
570  tfld
571  );
572 
573  // Registration
574  {
575  if (IOobjectOption::REGISTER == regOpt)
576  {
577  ptr->checkIn();
578  }
579  else if
580  (
581  // LEGACY_REGISTER: detect if caching is desired
582  (IOobjectOption::LEGACY_REGISTER == regOpt)
583  && ptr->db().is_cacheTemporaryObject(ptr.get())
584  )
585  {
586  ptr.protect(true);
587  ptr->checkIn();
588  }
589  }
590  return ptr;
591 }
592 
593 
594 template<class Type, template<class> class PatchField, class GeoMesh>
597 (
598  const word& name,
600 )
601 {
603  (
604  name,
605  IOobjectOption::LEGACY_REGISTER,
606  tfld
607  );
608 }
609 
610 
611 template<class Type, template<class> class PatchField, class GeoMesh>
614 (
615  const word& name,
618  const word& patchFieldType
619 )
620 {
622  (
623  IOobject
624  (
625  name,
626  tfld().instance(),
627  tfld().local(),
628  tfld().db(),
629  IOobjectOption::NO_READ,
630  IOobjectOption::NO_WRITE,
631  IOobjectOption::NO_REGISTER
632  ),
633  tfld,
634  patchFieldType
635  );
636 
637  // Registration
638  {
639  if (IOobjectOption::REGISTER == regOpt)
640  {
641  ptr->checkIn();
642  }
643  else if
644  (
645  // LEGACY_REGISTER: detect if caching is desired
646  (IOobjectOption::LEGACY_REGISTER == regOpt)
647  && ptr->db().is_cacheTemporaryObject(ptr.get())
648  )
649  {
650  ptr.protect(true);
651  ptr->checkIn();
652  }
653  }
654  return ptr;
655 }
656 
657 
658 template<class Type, template<class> class PatchField, class GeoMesh>
661 (
662  const word& name,
664  const word& patchFieldType
665 )
666 {
668  (
669  name,
670  IOobjectOption::LEGACY_REGISTER,
671  tfld,
672  patchFieldType
673  );
674 }
675 
676 
677 template<class Type, template<class> class PatchField, class GeoMesh>
680 (
681  const word& name,
684  const wordList& patchFieldTypes,
685  const wordList& actualPatchTypes
686 )
687 {
689  (
690  IOobject
691  (
692  name,
693  tfld().instance(),
694  tfld().local(),
695  tfld().db(),
696  IOobjectOption::NO_READ,
697  IOobjectOption::NO_WRITE,
698  IOobjectOption::NO_REGISTER
699  ),
700  tfld,
701  patchFieldTypes,
702  actualPatchTypes
703  );
704 
705  // Registration
706  {
707  if (IOobjectOption::REGISTER == regOpt)
708  {
709  ptr->checkIn();
710  }
711  else if
712  (
713  // LEGACY_REGISTER: detect if caching is desired
714  (IOobjectOption::LEGACY_REGISTER == regOpt)
715  && ptr->db().is_cacheTemporaryObject(ptr.get())
716  )
717  {
718  ptr.protect(true);
719  ptr->checkIn();
720  }
721  }
722  return ptr;
723 }
724 
725 
726 template<class Type, template<class> class PatchField, class GeoMesh>
729 (
730  const word& name,
732  const wordList& patchFieldTypes,
733  const wordList& actualPatchTypes
734 )
735 {
737  (
738  name,
739  IOobjectOption::LEGACY_REGISTER,
740  tfld,
741  patchFieldTypes,
742  actualPatchTypes
743  );
744 }
745 
746 
747 template<class Type, template<class> class PatchField, class GeoMesh>
748 template<class AnyType>
751 (
753  const word& name,
754  const dimensionSet& dims,
755  const word& patchFieldType
756 )
757 {
759  (
760  IOobject
761  (
762  name,
763  fld.instance(),
764  fld.db(),
765  IOobjectOption::NO_READ,
766  IOobjectOption::NO_WRITE,
767  IOobjectOption::NO_REGISTER
768  ),
769  fld.mesh(),
770  dims,
771  patchFieldType
772  );
773 
774  // Registration
775  {
776  if
777  (
778  // LEGACY_REGISTER: detect if caching is desired
779  ptr->db().is_cacheTemporaryObject(ptr.get())
780  )
781  {
782  ptr.protect(true);
783  ptr->checkIn();
784  }
785  }
786  return ptr;
787 }
788 
789 
790 template<class Type, template<class> class PatchField, class GeoMesh>
791 template<class AnyType>
794 (
796  const word& name,
797  const dimensioned<Type>& dt,
798  const word& patchFieldType
799 )
800 {
802  (
803  IOobject
804  (
805  name,
806  fld.instance(),
807  fld.db(),
808  IOobjectOption::NO_READ,
809  IOobjectOption::NO_WRITE,
810  IOobjectOption::NO_REGISTER
811  ),
812  fld.mesh(),
813  dt.value(),
814  dt.dimensions(),
815  patchFieldType
816  );
817 
818  // Registration
819  {
820  if
821  (
822  // LEGACY_REGISTER: detect if caching is desired
823  ptr->db().is_cacheTemporaryObject(ptr.get())
824  )
825  {
826  ptr.protect(true);
827  ptr->checkIn();
828  }
829  }
830  return ptr;
831 }
832 
833 
834 // ************************************************************************* //
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 GeometricField class.
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.
GeoMesh::Mesh Mesh
The mesh type for the DimensionedField.
static tmp< GeometricField< Type, PatchField, GeoMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=PatchField< Type >::calculatedType())
Return tmp field (NO_READ, NO_WRITE) from name, mesh, dimensions and patch type. [Takes current timeN...
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)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:54
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:45
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