1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "SlicedGeometricField.H"
28 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
33 template<class> class PatchField,
34 template<class> class SlicedPatchField,
37 Foam::tmp<Foam::FieldField<PatchField, Type> >
38 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
42 const Field<Type>& completeField,
43 const bool preserveCouples
46 tmp<FieldField<PatchField, Type> > tbf
48 new FieldField<PatchField, Type>(mesh.boundary().size())
51 FieldField<PatchField, Type>& bf = tbf();
53 forAll(mesh.boundary(), patchi)
55 if (preserveCouples && mesh.boundary()[patchi].coupled())
57 // For coupled patched construct the correct patch field type
63 mesh.boundary()[patchi].type(),
64 mesh.boundary()[patchi],
69 // Initialize the values on the coupled patch to those of the slice
70 // of the given field.
71 // Note: these will usually be over-ridden by the boundary field
72 // evaluation e.g. in the case of processor and cyclic patches.
73 bf[patchi] = SlicedPatchField<Type>
75 mesh.boundary()[patchi],
76 DimensionedField<Type, GeoMesh>::null(),
85 new SlicedPatchField<Type>
87 mesh.boundary()[patchi],
88 DimensionedField<Type, GeoMesh>::null(),
102 template<class> class PatchField,
103 template<class> class SlicedPatchField,
106 Foam::tmp<Foam::FieldField<PatchField, Type> >
107 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
111 const FieldField<PatchField, Type>& bField,
112 const bool preserveCouples
115 tmp<FieldField<PatchField, Type> > tbf
117 new FieldField<PatchField, Type>(mesh.boundary().size())
120 FieldField<PatchField, Type>& bf = tbf();
122 forAll(mesh.boundary(), patchi)
124 if (preserveCouples && mesh.boundary()[patchi].coupled())
126 // For coupled patched construct the correct patch field type
130 PatchField<Type>::New
132 mesh.boundary()[patchi].type(),
133 mesh.boundary()[patchi],
139 bf[patchi] == bField[patchi];
143 // Create unallocated copy of patch field
147 new SlicedPatchField<Type>
149 mesh.boundary()[patchi],
150 DimensionedField<Type, GeoMesh>::null()
153 bf[patchi].UList<Type>::operator=(bField[patchi]);
161 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
166 template<class> class PatchField,
167 template<class> class SlicedPatchField,
170 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
171 DimensionedInternalField::DimensionedInternalField
175 const dimensionSet& ds,
176 const Field<Type>& iField
179 DimensionedField<Type, GeoMesh>
187 // Set the internalField to the slice of the complete field
188 UList<Type>::operator=
190 typename Field<Type>::subField(iField, GeoMesh::size(mesh))
198 template<class> class PatchField,
199 template<class> class SlicedPatchField,
202 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
207 const dimensionSet& ds,
208 const Field<Type>& completeField,
209 const bool preserveCouples
212 GeometricField<Type, PatchField, GeoMesh>
218 slicedBoundaryField(mesh, completeField, preserveCouples)
221 // Set the internalField to the slice of the complete field
222 UList<Type>::operator=
224 typename Field<Type>::subField(completeField, GeoMesh::size(mesh))
227 correctBoundaryConditions();
234 template<class> class PatchField,
235 template<class> class SlicedPatchField,
238 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
243 const dimensionSet& ds,
244 const Field<Type>& completeIField,
245 const Field<Type>& completeBField,
246 const bool preserveCouples
249 GeometricField<Type, PatchField, GeoMesh>
255 slicedBoundaryField(mesh, completeBField, preserveCouples)
258 // Set the internalField to the slice of the complete field
259 UList<Type>::operator=
261 typename Field<Type>::subField(completeIField, GeoMesh::size(mesh))
264 correctBoundaryConditions();
271 template<class> class PatchField,
272 template<class> class SlicedPatchField,
275 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
279 const GeometricField<Type, PatchField, GeoMesh>& gf,
280 const bool preserveCouples
283 GeometricField<Type, PatchField, GeoMesh>
289 slicedBoundaryField(gf.mesh(), gf.boundaryField(), preserveCouples)
292 // Set the internalField to the supplied internal field
293 UList<Type>::operator=(gf.internalField());
295 correctBoundaryConditions();
302 template<class> class PatchField,
303 template<class> class SlicedPatchField,
306 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
309 const SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>& gf
312 GeometricField<Type, PatchField, GeoMesh>
318 slicedBoundaryField(gf.mesh(), gf.boundaryField(), true)
321 // Set the internalField to the supplied internal field
322 UList<Type>::operator=(gf.internalField());
326 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
331 template<class> class PatchField,
332 template<class> class SlicedPatchField,
335 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
336 ~SlicedGeometricField()
338 // Set the internalField storage pointer to NULL before its destruction
339 // to protect the field it a slice of.
340 UList<Type>::operator=(UList<Type>(NULL, 0));
347 template<class> class PatchField,
348 template<class> class SlicedPatchField,
351 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
352 DimensionedInternalField::~DimensionedInternalField()
354 // Set the internalField storage pointer to NULL before its destruction
355 // to protect the field it a slice of.
356 UList<Type>::operator=(UList<Type>(NULL, 0));
360 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
365 template<class> class PatchField,
366 template<class> class SlicedPatchField,
369 void Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
370 correctBoundaryConditions()
372 GeometricField<Type, PatchField, GeoMesh>::correctBoundaryConditions();
376 // ************************************************************************* //