OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

SlicedGeometricField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "SlicedGeometricField.H"
00028 
00029 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
00030 
00031 template
00032 <
00033     class Type,
00034     template<class> class PatchField,
00035     template<class> class SlicedPatchField,
00036     class GeoMesh
00037 >
00038 Foam::tmp<Foam::FieldField<PatchField, Type> >
00039 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00040 slicedBoundaryField
00041 (
00042     const Mesh& mesh,
00043     const Field<Type>& completeField,
00044     const bool preserveCouples
00045 )
00046 {
00047     tmp<FieldField<PatchField, Type> > tbf
00048     (
00049         new FieldField<PatchField, Type>(mesh.boundary().size())
00050     );
00051 
00052     FieldField<PatchField, Type>& bf = tbf();
00053 
00054     forAll (mesh.boundary(), patchi)
00055     {
00056         if (preserveCouples && mesh.boundary()[patchi].coupled())
00057         {
00058             // For coupled patched construct the correct patch field type
00059             bf.set
00060             (
00061                 patchi,
00062                 PatchField<Type>::New
00063                 (
00064                     mesh.boundary()[patchi].type(),
00065                     mesh.boundary()[patchi],
00066                     *this
00067                 )
00068             );
00069 
00070             // Initialize the values on the coupled patch to those of the slice
00071             // of the given field.
00072             // Note: these will usually be over-ridden by the boundary field
00073             // evaluation e.g. in the case of processor and cyclic patches.
00074             bf[patchi] = SlicedPatchField<Type>
00075             (
00076                 mesh.boundary()[patchi],
00077                 DimensionedField<Type, GeoMesh>::null(),
00078                 completeField
00079             );
00080         }
00081         else
00082         {
00083             bf.set
00084             (
00085                 patchi,
00086                 new SlicedPatchField<Type>
00087                 (
00088                     mesh.boundary()[patchi],
00089                     DimensionedField<Type, GeoMesh>::null(),
00090                     completeField
00091                 )
00092             );
00093         }
00094     }
00095 
00096     return tbf;
00097 }
00098 
00099 
00100 template
00101 <
00102     class Type,
00103     template<class> class PatchField,
00104     template<class> class SlicedPatchField,
00105     class GeoMesh
00106 >
00107 Foam::tmp<Foam::FieldField<PatchField, Type> >
00108 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00109 slicedBoundaryField
00110 (
00111     const Mesh& mesh,
00112     const FieldField<PatchField, Type>& bField,
00113     const bool preserveCouples
00114 )
00115 {
00116     tmp<FieldField<PatchField, Type> > tbf
00117     (
00118         new FieldField<PatchField, Type>(mesh.boundary().size())
00119     );
00120 
00121     FieldField<PatchField, Type>& bf = tbf();
00122 
00123     forAll (mesh.boundary(), patchi)
00124     {
00125         if (preserveCouples && mesh.boundary()[patchi].coupled())
00126         {
00127             // For coupled patched construct the correct patch field type
00128             bf.set
00129             (
00130                 patchi,
00131                 PatchField<Type>::New
00132                 (
00133                     mesh.boundary()[patchi].type(),
00134                     mesh.boundary()[patchi],
00135                     *this
00136                 )
00137             );
00138 
00139             // Assign field
00140             bf[patchi] == bField[patchi];
00141         }
00142         else
00143         {
00144             // Create unallocated copy of patch field
00145             bf.set
00146             (
00147                 patchi,
00148                 new SlicedPatchField<Type>
00149                 (
00150                     mesh.boundary()[patchi],
00151                     DimensionedField<Type, GeoMesh>::null()
00152                 )
00153             );
00154             bf[patchi].UList<Type>::operator=(bField[patchi]);
00155         }
00156     }
00157 
00158     return tbf;
00159 }
00160 
00161 
00162 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00163 
00164 template
00165 <
00166     class Type,
00167     template<class> class PatchField,
00168     template<class> class SlicedPatchField,
00169     class GeoMesh
00170 >
00171 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00172 DimensionedInternalField::DimensionedInternalField
00173 (
00174     const IOobject& io,
00175     const Mesh& mesh,
00176     const dimensionSet& ds,
00177     const Field<Type>& iField
00178 )
00179 :
00180     DimensionedField<Type, GeoMesh>
00181     (
00182         io,
00183         mesh,
00184         ds,
00185         Field<Type>()
00186     )
00187 {
00188     // Set the internalField to the slice of the complete field
00189     UList<Type>::operator=
00190     (
00191         typename Field<Type>::subField(iField, GeoMesh::size(mesh))
00192     );
00193 }
00194 
00195 
00196 template
00197 <
00198     class Type,
00199     template<class> class PatchField,
00200     template<class> class SlicedPatchField,
00201     class GeoMesh
00202 >
00203 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00204 SlicedGeometricField
00205 (
00206     const IOobject& io,
00207     const Mesh& mesh,
00208     const dimensionSet& ds,
00209     const Field<Type>& completeField,
00210     const bool preserveCouples
00211 )
00212 :
00213     GeometricField<Type, PatchField, GeoMesh>
00214     (
00215         io,
00216         mesh,
00217         ds,
00218         Field<Type>(),
00219         slicedBoundaryField(mesh, completeField, preserveCouples)
00220     )
00221 {
00222     // Set the internalField to the slice of the complete field
00223     UList<Type>::operator=
00224     (
00225         typename Field<Type>::subField(completeField, GeoMesh::size(mesh))
00226     );
00227 
00228     correctBoundaryConditions();
00229 }
00230 
00231 
00232 template
00233 <
00234     class Type,
00235     template<class> class PatchField,
00236     template<class> class SlicedPatchField,
00237     class GeoMesh
00238 >
00239 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00240 SlicedGeometricField
00241 (
00242     const IOobject& io,
00243     const Mesh& mesh,
00244     const dimensionSet& ds,
00245     const Field<Type>& completeIField,
00246     const Field<Type>& completeBField,
00247     const bool preserveCouples
00248 )
00249 :
00250     GeometricField<Type, PatchField, GeoMesh>
00251     (
00252         io,
00253         mesh,
00254         ds,
00255         Field<Type>(),
00256         slicedBoundaryField(mesh, completeBField, preserveCouples)
00257     )
00258 {
00259     // Set the internalField to the slice of the complete field
00260     UList<Type>::operator=
00261     (
00262         typename Field<Type>::subField(completeIField, GeoMesh::size(mesh))
00263     );
00264 
00265     correctBoundaryConditions();
00266 }
00267 
00268 
00269 template
00270 <
00271     class Type,
00272     template<class> class PatchField,
00273     template<class> class SlicedPatchField,
00274     class GeoMesh
00275 >
00276 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00277 SlicedGeometricField
00278 (
00279     const IOobject& io,
00280     const GeometricField<Type, PatchField, GeoMesh>& gf,
00281     const bool preserveCouples
00282 )
00283 :
00284     GeometricField<Type, PatchField, GeoMesh>
00285     (
00286         io,
00287         gf.mesh(),
00288         gf.dimensions(),
00289         Field<Type>(),
00290         slicedBoundaryField(gf.mesh(), gf.boundaryField(), preserveCouples)
00291     )
00292 {
00293     // Set the internalField to the supplied internal field
00294     UList<Type>::operator=(gf.internalField());
00295 
00296     correctBoundaryConditions();
00297 }
00298 
00299 
00300 template
00301 <
00302     class Type,
00303     template<class> class PatchField,
00304     template<class> class SlicedPatchField,
00305     class GeoMesh
00306 >
00307 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00308 SlicedGeometricField
00309 (
00310     const SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>& gf
00311 )
00312 :
00313     GeometricField<Type, PatchField, GeoMesh>
00314     (
00315         gf,
00316         gf.mesh(),
00317         gf.dimensions(),
00318         Field<Type>(),
00319         slicedBoundaryField(gf.mesh(), gf.boundaryField(), true)
00320     )
00321 {
00322     // Set the internalField to the supplied internal field
00323     UList<Type>::operator=(gf.internalField());
00324 }
00325 
00326 
00327 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00328 
00329 template
00330 <
00331     class Type,
00332     template<class> class PatchField,
00333     template<class> class SlicedPatchField,
00334     class GeoMesh
00335 >
00336 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00337 ~SlicedGeometricField()
00338 {
00339     // Set the internalField storage pointer to NULL before its destruction
00340     // to protect the field it a slice of.
00341     UList<Type>::operator=(UList<Type>(NULL, 0));
00342 }
00343 
00344 
00345 template
00346 <
00347     class Type,
00348     template<class> class PatchField,
00349     template<class> class SlicedPatchField,
00350     class GeoMesh
00351 >
00352 Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00353 DimensionedInternalField::~DimensionedInternalField()
00354 {
00355     // Set the internalField storage pointer to NULL before its destruction
00356     // to protect the field it a slice of.
00357     UList<Type>::operator=(UList<Type>(NULL, 0));
00358 }
00359 
00360 
00361 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00362 
00363 template
00364 <
00365     class Type,
00366     template<class> class PatchField,
00367     template<class> class SlicedPatchField,
00368     class GeoMesh
00369 >
00370 void Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>::
00371 correctBoundaryConditions()
00372 {
00373     GeometricField<Type, PatchField, GeoMesh>::correctBoundaryConditions();
00374 }
00375 
00376 
00377 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd