FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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