toSubFieldTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "toSubField.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 /*---------------------------------------------------------------------------*\
34  Class DimensionedFieldToDimensionedSubField Declaration
35 \*---------------------------------------------------------------------------*/
36 
37 template<class Type, class GeoMesh>
39 :
40  public DimensionedField<Type, GeoMesh, SubField>
41 {
42  // Private Data
43 
44  //- The primitive field
45  autoPtr<Field<Type>> primitiveFieldPtr_;
46 
47 
48 public:
49 
50  // Constructors
51 
52  //- Construct from a temporary field
54  (
56  )
57  :
59  (
60  tField(),
61  tField->mesh(),
62  tField->dimensions(),
63  SubField<Type>::null()
64  ),
65  primitiveFieldPtr_(nullptr)
66  {
67  if (tField.isTmp())
68  {
69  primitiveFieldPtr_ =
70  new Field<Type>(tField.ref().primitiveFieldRef(), true);
71 
72  this->shallowCopy(primitiveFieldPtr_());
73  }
74  else
75  {
76  this->shallowCopy(tField->primitiveField());
77  }
78 
79  tField.clear();
80  }
81 
82 
83  //- Destructor
85  {}
86 };
87 
88 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
89 
90 } // End namespace Foam
91 
92 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 
94 template<class Type, class GeoMesh>
96 Foam::toSubField(const DimensionedField<Type, GeoMesh, Field>& f)
97 {
98  return
99  tmp<DimensionedField<Type, GeoMesh, SubField>>
100  (
101  // Use the converter class to deep-copy the IOobject and
102  // dimensionSet and shallow-copy the Field
103  /*
104  new DimensionedFieldToDimensionedSubField<Type, GeoMesh>
105  (
106  tmp<DimensionedField<Type, GeoMesh, Field>>(f)
107  )
108  */
109 
110  // Cast. The layout of Field and SubField are the same, and because
111  // this is a const-reference tmp, we don't have to worry about the
112  // SubField not destructing the data. This prevents the converter
113  // class' copy of the IOobject and dimensionSet.
114  reinterpret_cast<const DimensionedField<Type, GeoMesh, SubField>&>
115  (
116  f
117  )
118  );
119 }
120 
121 
122 template<class Type, class GeoMesh>
124 Foam::toSubField(const DimensionedField<Type, GeoMesh, SubField>& f)
125 {
126  return tmp<DimensionedField<Type, GeoMesh, SubField>>(f);
127 }
128 
129 
130 template<class Type, class GeoMesh>
132 Foam::toSubField(const tmp<DimensionedField<Type, GeoMesh, Field>>& tf)
133 {
134  return
135  tmp<DimensionedField<Type, GeoMesh, SubField>>
136  (
137  new DimensionedFieldToDimensionedSubField<Type, GeoMesh>(tf),
138  true
139  );
140 }
141 
142 
143 template<class Type, class GeoMesh>
145 Foam::toSubField(const tmp<DimensionedField<Type, GeoMesh, SubField>>& tf)
146 {
147  return tmp<DimensionedField<Type, GeoMesh, SubField>>(tf, true);
148 }
149 
150 
151 template<class Type, class GeoMesh, class ... Args>
153 Foam::toSubField(const Args& ... args)
154 {
156 }
157 
158 
159 // ************************************************************************* //
DimensionedFieldToDimensionedSubField(const tmp< DimensionedField< Type, GeoMesh, Field >> &tField)
Construct from a temporary field.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static const DimensionedField< Type, GeoMesh, SubField > & null()
Return a null DimensionedField.
const dimensionSet & dimensions() const
Return dimensions.
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic mesh wrapper used by volMesh, surfaceMesh, pointMesh etc.
Definition: GeoMesh.H:47
Pre-declare related SubField type.
Definition: SubField.H:63
void shallowCopy(const UList< Type > &)
Copy the pointer held by the given UList.
Definition: UListI.H:156
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A class for managing temporary objects.
Definition: tmp.H:55
const tensorField & tf
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
Namespace for OpenFOAM.
tmp< DimensionedField< Type, GeoMesh, SubField > > toSubField(const DimensionedField< Type, GeoMesh, Field > &)
Return a temporary sub-field from a reference to a field.
labelList f(nPoints)
Foam::argList args(argc, argv)
Functions to cast/convert dimensioned field references and temporaries based on a primitive field to ...