Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30
31template<class Type, template<class> class PatchField, class GeoMesh>
32template<class... Args>
34Foam::GeometricField<Type, PatchField, GeoMesh>::New_impl
35(
37 const word& name,
38 const Mesh& mesh,
39 Args&&... args
40)
41{
43 (
44 // == mesh.thisDb().newIOobject(name)
46 (
47 name,
48 mesh.thisDb().time().timeName(),
49 mesh.thisDb(),
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
68 && ptr->db().is_cacheTemporaryObject(ptr.get())
69 )
70 {
71 ptr.protect(true);
72 ptr->checkIn();
73 }
74 }
75 return ptr;
77
78
79// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
80
81template<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{
92 return GeometricField<Type, PatchField, GeoMesh>::New_impl
93 (
94 regOpt,
95 name,
96 mesh,
97 dims,
98 patchFieldType
99 );
100}
101
102
103template<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{
113 return GeometricField<Type, PatchField, GeoMesh>::New_impl
114 (
116 name,
117 mesh,
118 dims,
119 patchFieldType
120 );
121}
122
123
124template<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{
136 return GeometricField<Type, PatchField, GeoMesh>::New_impl
137 (
138 regOpt,
139 name,
140 mesh,
141 dims,
142 iField,
143 patchFieldType
144 );
145}
146
147
148template<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{
159 return GeometricField<Type, PatchField, GeoMesh>::New_impl
160 (
162 name,
163 mesh,
164 dims,
165 iField,
166 patchFieldType
167 );
168}
169
170
171template<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{
183 return GeometricField<Type, PatchField, GeoMesh>::New_impl
184 (
185 regOpt,
186 name,
187 mesh,
188 dims,
189 std::move(iField),
190 patchFieldType
191 );
192}
193
194
195template<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{
206 return GeometricField<Type, PatchField, GeoMesh>::New_impl
207 (
209 name,
210 mesh,
211 dims,
212 std::move(iField),
213 patchFieldType
214 );
215}
216
217
218template<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{
230 return GeometricField<Type, PatchField, GeoMesh>::New_impl
231 (
232 regOpt,
233 name,
234 mesh,
235 dims,
236 tfield,
237 patchFieldType
238 );
239}
240
241
242template<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{
253 return GeometricField<Type, PatchField, GeoMesh>::New_impl
254 (
256 name,
257 mesh,
258 dims,
259 tfield,
260 patchFieldType
261 );
262}
263
264
265template<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{
277 return GeometricField<Type, PatchField, GeoMesh>::New_impl
278 (
279 regOpt,
280 name,
281 mesh,
282 dims,
283 iField,
284 pflds
285 );
286}
287
288
289template<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{
300 return GeometricField<Type, PatchField, GeoMesh>::New_impl
301 (
303 name,
304 mesh,
305 dims,
306 iField,
307 pflds
308 );
309}
310
311
312template<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{
324 return GeometricField<Type, PatchField, GeoMesh>::New_impl
325 (
326 regOpt,
327 name,
328 mesh,
329 dims,
330 std::move(iField),
331 pflds
332 );
333}
334
335
336template<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{
347 return GeometricField<Type, PatchField, GeoMesh>::New_impl
348 (
350 name,
351 mesh,
352 dims,
353 std::move(iField),
354 pflds
355 );
356}
357
358
359template<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{
371 return GeometricField<Type, PatchField, GeoMesh>::New_impl
372 (
373 regOpt,
374 name,
375 mesh,
376 value,
377 dims,
378 patchFieldType
379 );
380}
381
382
383template<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{
394 return GeometricField<Type, PatchField, GeoMesh>::New_impl
395 (
397 name,
398 mesh,
399 value,
400 dims,
401 patchFieldType
402 );
403}
404
405
406template<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{
419 return GeometricField<Type, PatchField, GeoMesh>::New_impl
420 (
421 regOpt,
422 name,
423 mesh,
424 value,
425 dims,
426 patchFieldTypes,
427 actualPatchTypes
428 );
429}
430
431
432template<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{
444 return GeometricField<Type, PatchField, GeoMesh>::New_impl
445 (
447 name,
448 mesh,
449 value,
450 dims,
451 patchFieldTypes,
452 actualPatchTypes
453 );
454}
455
456
457template<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
480template<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
501template<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
526template<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
549template<class Type, template<class> class PatchField, class GeoMesh>
552(
553 const word& name,
556)
557{
559 (
561 (
562 name,
563 tfld().instance(),
564 tfld().local(),
565 tfld().db(),
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 }
590 return ptr;
591}
592
593
594template<class Type, template<class> class PatchField, class GeoMesh>
597(
598 const word& name,
599 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld
600)
601{
602 return GeometricField<Type, PatchField, GeoMesh>::New
603 (
604 name,
605 IOobjectOption::LEGACY_REGISTER,
606 tfld
607 );
608}
609
610
611template<class Type, template<class> class PatchField, class GeoMesh>
614(
615 const word& name,
618 const word& patchFieldType
619)
620{
622 (
624 (
625 name,
626 tfld().instance(),
627 tfld().local(),
628 tfld().db(),
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 }
654 return ptr;
655}
656
657
658template<class Type, template<class> class PatchField, class GeoMesh>
661(
662 const word& name,
663 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld,
664 const word& patchFieldType
665)
666{
667 return GeometricField<Type, PatchField, GeoMesh>::New
668 (
669 name,
670 IOobjectOption::LEGACY_REGISTER,
671 tfld,
672 patchFieldType
673 );
674}
675
676
677template<class Type, template<class> class PatchField, class GeoMesh>
680(
681 const word& name,
684 const wordList& patchFieldTypes,
685 const wordList& actualPatchTypes
686)
687{
689 (
691 (
692 name,
693 tfld().instance(),
694 tfld().local(),
695 tfld().db(),
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 }
722 return ptr;
723}
724
725
726template<class Type, template<class> class PatchField, class GeoMesh>
729(
730 const word& name,
731 const tmp<GeometricField<Type, PatchField, GeoMesh>>& tfld,
732 const wordList& patchFieldTypes,
733 const wordList& actualPatchTypes
734)
735{
736 return GeometricField<Type, PatchField, GeoMesh>::New
737 (
738 name,
739 IOobjectOption::LEGACY_REGISTER,
740 tfld,
741 patchFieldTypes,
742 actualPatchTypes
743 );
744}
745
746
747template<class Type, template<class> class PatchField, class GeoMesh>
748template<class AnyType>
751(
753 const word& name,
754 const dimensionSet& dims,
755 const word& patchFieldType
756)
757{
759 (
761 (
762 name,
763 fld.instance(),
764 fld.db(),
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
790template<class Type, template<class> class PatchField, class GeoMesh>
791template<class AnyType>
794(
796 const word& name,
797 const dimensioned<Type>& dt,
798 const word& patchFieldType
799)
800{
802 (
804 (
805 name,
806 fld.instance(),
807 fld.db(),
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// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition GeoMesh.H:46
Generic GeometricField class.
static tmp< GeometricField< Type, faPatchField, areaMesh > > New(const word &name, IOobjectOption::registerOption regOpt, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=faPatchField< Type >::calculatedType())
GeometricField(const IOobject &io, const Mesh &mesh, const dimensionSet &dims, const word &patchFieldType=PatchField< Type >::calculatedType())
Construct given IOobject, mesh, dimensions and patch type.
registerOption
Enumeration for use with registerObject(). Values map to bool (false/true).
@ NO_REGISTER
Do not request registration (bool: false).
@ LEGACY_REGISTER
Legacy/default registration request (bool: true).
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition IOobject.C:450
const fileName & instance() const noexcept
Read access to instance path component.
Definition IOobjectI.H:289
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition PtrList.H:67
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Generic dimensioned Type class.
const dimensionSet & dimensions() const noexcept
Return const reference to dimensions.
const Type & value() const noexcept
Return const reference to value.
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
bool local
Definition EEqn.H:20
dynamicFvMesh & mesh
auto & name
List< word > wordList
List of word.
Definition fileName.H:60
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
Foam::argList args(argc, argv)