initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / fields / GeometricFields / SlicedGeometricField / SlicedGeometricField.C
blobf1b9e60a108fe87b12094e57d01b1852bb0299b9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "SlicedGeometricField.H"
29 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
31 template
33     class Type,
34     template<class> class PatchField,
35     template<class> class SlicedPatchField,
36     class GeoMesh
38 Foam::tmp<Foam::FieldField<PatchField, Type> >
39 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
40 slicedBoundaryField
42     const Mesh& mesh,
43     const Field<Type>& completeField,
44     const bool preserveCouples
47     tmp<FieldField<PatchField, Type> > tbf
48     (
49         new FieldField<PatchField, Type>(mesh.boundary().size())
50     );
52     FieldField<PatchField, Type>& bf = tbf();
54     forAll (mesh.boundary(), patchi)
55     {
56         if (preserveCouples && mesh.boundary()[patchi].coupled())
57         {
58             // For coupled patched construct the correct patch field type
59             bf.set
60             (
61                 patchi,
62                 PatchField<Type>::New
63                 (
64                     mesh.boundary()[patchi].type(),
65                     mesh.boundary()[patchi],
66                     *this
67                 )
68             );
70             // Initialize the values on the coupled patch to those of the slice
71             // of the given field.
72             // Note: these will usually be over-ridden by the boundary field
73             // evaluation e.g. in the case of processor and cyclic patches.
74             bf[patchi] = SlicedPatchField<Type>
75             (
76                 mesh.boundary()[patchi],
77                 DimensionedField<Type, GeoMesh>::null(),
78                 completeField
79             );
80         }
81         else
82         {
83             bf.set
84             (
85                 patchi,
86                 new SlicedPatchField<Type>
87                 (
88                     mesh.boundary()[patchi],
89                     DimensionedField<Type, GeoMesh>::null(),
90                     completeField
91                 )
92             );
93         }
94     }
96     return tbf;
100 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
102 template
104     class Type,
105     template<class> class PatchField,
106     template<class> class SlicedPatchField,
107     class GeoMesh
109 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
110 DimensionedInternalField::DimensionedInternalField
112     const IOobject& io,
113     const Mesh& mesh,
114     const dimensionSet& ds,
115     const Field<Type>& iField
118     DimensionedField<Type, GeoMesh>
119     (
120         io,
121         mesh,
122         ds,
123         Field<Type>()
124     )
126     // Set the internalField to the slice of the complete field
127     UList<Type>::operator=
128     (
129         typename Field<Type>::subField(iField, GeoMesh::size(mesh))
130     );
134 template
136     class Type,
137     template<class> class PatchField,
138     template<class> class SlicedPatchField,
139     class GeoMesh
141 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
142 SlicedGeometricField
144     const IOobject& io,
145     const Mesh& mesh,
146     const dimensionSet& ds,
147     const Field<Type>& completeField,
148     const bool preserveCouples
151     GeometricField<Type, PatchField, GeoMesh>
152     (
153         io,
154         mesh,
155         ds,
156         Field<Type>(),
157         slicedBoundaryField(mesh, completeField, preserveCouples)
158     )
160     // Set the internalField to the slice of the complete field
161     UList<Type>::operator=
162     (
163         typename Field<Type>::subField(completeField, GeoMesh::size(mesh))
164     );
166     correctBoundaryConditions();
170 template
172     class Type,
173     template<class> class PatchField,
174     template<class> class SlicedPatchField,
175     class GeoMesh
177 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
178 SlicedGeometricField
180     const IOobject& io,
181     const Mesh& mesh,
182     const dimensionSet& ds,
183     const Field<Type>& completeIField,
184     const Field<Type>& completeBField,
185     const bool preserveCouples
188     GeometricField<Type, PatchField, GeoMesh>
189     (
190         io,
191         mesh,
192         ds,
193         Field<Type>(),
194         slicedBoundaryField(mesh, completeBField, preserveCouples)
195     )
197     // Set the internalField to the slice of the complete field
198     UList<Type>::operator=
199     (
200         typename Field<Type>::subField(completeIField, GeoMesh::size(mesh))
201     );
203     correctBoundaryConditions();
207 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
209 template
211     class Type,
212     template<class> class PatchField,
213     template<class> class SlicedPatchField,
214     class GeoMesh
216 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
217 ~SlicedGeometricField()
219     // Set the internalField storage pointer to NULL before its destruction
220     // to protect the field it a slice of.
221     UList<Type>::operator=(UList<Type>(NULL, 0));
225 template
227     class Type,
228     template<class> class PatchField,
229     template<class> class SlicedPatchField,
230     class GeoMesh
232 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
233 DimensionedInternalField::~DimensionedInternalField()
235     // Set the internalField storage pointer to NULL before its destruction
236     // to protect the field it a slice of.
237     UList<Type>::operator=(UList<Type>(NULL, 0));
241 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
243 template
245     class Type,
246     template<class> class PatchField,
247     template<class> class SlicedPatchField,
248     class GeoMesh
250 void Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
251 correctBoundaryConditions()
253     GeometricField<Type, PatchField, GeoMesh>::correctBoundaryConditions();
257 // ************************************************************************* //