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

fvFieldDecomposerDecomposeFields.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 "fvFieldDecomposer.H"
00028 #include "processorFvPatchField.H"
00029 #include "processorFvsPatchField.H"
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00037 
00038 template<class Type>
00039 tmp<GeometricField<Type, fvPatchField, volMesh> >
00040 fvFieldDecomposer::decomposeField
00041 (
00042     const GeometricField<Type, fvPatchField, volMesh>& field
00043 ) const
00044 {
00045     // Create and map the internal field values
00046     Field<Type> internalField(field.internalField(), cellAddressing_);
00047 
00048     // Create and map the patch field values
00049     PtrList<fvPatchField<Type> > patchFields(boundaryAddressing_.size());
00050 
00051     forAll (boundaryAddressing_, patchi)
00052     {
00053         if (boundaryAddressing_[patchi] >= 0)
00054         {
00055             patchFields.set
00056             (
00057                 patchi,
00058                 fvPatchField<Type>::New
00059                 (
00060                     field.boundaryField()[boundaryAddressing_[patchi]],
00061                     procMesh_.boundary()[patchi],
00062                     DimensionedField<Type, volMesh>::null(),
00063                     *patchFieldDecomposerPtrs_[patchi]
00064                 )
00065             );
00066         }
00067         else
00068         {
00069             patchFields.set
00070             (
00071                 patchi,
00072                 new processorFvPatchField<Type>
00073                 (
00074                     procMesh_.boundary()[patchi],
00075                     DimensionedField<Type, volMesh>::null(),
00076                     Field<Type>
00077                     (
00078                         field.internalField(),
00079                         *processorVolPatchFieldDecomposerPtrs_[patchi]
00080                     )
00081                 )
00082             );
00083         }
00084     }
00085 
00086     // Create the field for the processor
00087     return tmp<GeometricField<Type, fvPatchField, volMesh> >
00088     (
00089         new GeometricField<Type, fvPatchField, volMesh>
00090         (
00091             IOobject
00092             (
00093                 field.name(),
00094                 procMesh_.time().timeName(),
00095                 procMesh_,
00096                 IOobject::NO_READ,
00097                 IOobject::NO_WRITE
00098             ),
00099             procMesh_,
00100             field.dimensions(),
00101             internalField,
00102             patchFields
00103         )
00104     );
00105 }
00106 
00107 
00108 template<class Type>
00109 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00110 fvFieldDecomposer::decomposeField
00111 (
00112     const GeometricField<Type, fvsPatchField, surfaceMesh>& field
00113 ) const
00114 {
00115     labelList mapAddr
00116     (
00117         labelList::subList
00118         (
00119             faceAddressing_,
00120             procMesh_.nInternalFaces()
00121         )
00122     );
00123     forAll (mapAddr, i)
00124     {
00125         mapAddr[i] -= 1;
00126     }
00127 
00128     // Create and map the internal field values
00129     Field<Type> internalField
00130     (
00131         field.internalField(),
00132         mapAddr
00133     );
00134 
00135     // Problem with addressing when a processor patch picks up both internal
00136     // faces and faces from cyclic boundaries. This is a bit of a hack, but
00137     // I cannot find a better solution without making the internal storage
00138     // mechanism for surfaceFields correspond to the one of faces in polyMesh
00139     // (i.e. using slices)
00140     Field<Type> allFaceField(field.mesh().nFaces());
00141 
00142     forAll (field.internalField(), i)
00143     {
00144         allFaceField[i] = field.internalField()[i];
00145     }
00146 
00147     forAll (field.boundaryField(), patchi)
00148     {
00149         const Field<Type> & p = field.boundaryField()[patchi];
00150 
00151         const label patchStart = field.mesh().boundaryMesh()[patchi].start();
00152 
00153         forAll (p, i)
00154         {
00155             allFaceField[patchStart + i] = p[i];
00156         }
00157     }
00158 
00159     // Create and map the patch field values
00160     PtrList<fvsPatchField<Type> > patchFields(boundaryAddressing_.size());
00161 
00162     forAll (boundaryAddressing_, patchi)
00163     {
00164         if (boundaryAddressing_[patchi] >= 0)
00165         {
00166             patchFields.set
00167             (
00168                 patchi,
00169                 fvsPatchField<Type>::New
00170                 (
00171                     field.boundaryField()[boundaryAddressing_[patchi]],
00172                     procMesh_.boundary()[patchi],
00173                     DimensionedField<Type, surfaceMesh>::null(),
00174                     *patchFieldDecomposerPtrs_[patchi]
00175                 )
00176             );
00177         }
00178         else
00179         {
00180             patchFields.set
00181             (
00182                 patchi,
00183                 new processorFvsPatchField<Type>
00184                 (
00185                     procMesh_.boundary()[patchi],
00186                     DimensionedField<Type, surfaceMesh>::null(),
00187                     Field<Type>
00188                     (
00189                         allFaceField,
00190                         *processorSurfacePatchFieldDecomposerPtrs_[patchi]
00191                     )
00192                 )
00193             );
00194         }
00195     }
00196 
00197     // Create the field for the processor
00198     return tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00199     (
00200         new GeometricField<Type, fvsPatchField, surfaceMesh>
00201         (
00202             IOobject
00203             (
00204                 field.name(),
00205                 procMesh_.time().timeName(),
00206                 procMesh_,
00207                 IOobject::NO_READ,
00208                 IOobject::NO_WRITE
00209             ),
00210             procMesh_,
00211             field.dimensions(),
00212             internalField,
00213             patchFields
00214         )
00215     );
00216 }
00217 
00218 
00219 template<class GeoField>
00220 void fvFieldDecomposer::decomposeFields
00221 (
00222     const PtrList<GeoField>& fields
00223 ) const
00224 {
00225     forAll (fields, fieldI)
00226     {
00227         decomposeField(fields[fieldI])().write();
00228     }
00229 }
00230 
00231 
00232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00233 
00234 } // End namespace Foam
00235 
00236 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd