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

fvMeshDistributeTemplates.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 "mapPolyMesh.H"
00028 
00029 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00030 
00031 template<class GeoField>
00032 void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh)
00033 {
00034     HashTable<const GeoField*> flds
00035     (
00036         mesh.objectRegistry::lookupClass<GeoField>()
00037     );
00038 
00039     for
00040     (
00041         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
00042         iter != flds.end();
00043         ++iter
00044     )
00045     {
00046         const GeoField& fld = *iter();
00047 
00048         Pout<< "Field:" << iter.key() << " internalsize:" << fld.size()
00049             //<< " value:" << fld
00050             << endl;
00051 
00052         forAll(fld.boundaryField(), patchI)
00053         {
00054             Pout<< "    " << patchI
00055                 << ' ' << fld.boundaryField()[patchI].patch().name()
00056                 << ' ' << fld.boundaryField()[patchI].type()
00057                 << ' ' << fld.boundaryField()[patchI].size()
00058                 << endl;
00059         }
00060     }
00061 }
00062 
00063 
00064 template<class GeoField>
00065 void Foam::fvMeshDistribute::addPatchFields(const word& patchFieldType)
00066 {
00067     HashTable<const GeoField*> flds
00068     (
00069         mesh_.objectRegistry::lookupClass<GeoField>()
00070     );
00071 
00072     for
00073     (
00074         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
00075         iter != flds.end();
00076         ++iter
00077     )
00078     {
00079         const GeoField& fld = *iter();
00080 
00081         typename GeoField::GeometricBoundaryField& bfld =
00082             const_cast<typename GeoField::GeometricBoundaryField&>
00083             (
00084                 fld.boundaryField()
00085             );
00086 
00087         label sz = bfld.size();
00088         bfld.setSize(sz + 1);
00089         bfld.set
00090         (
00091             sz,
00092             GeoField::PatchFieldType::New
00093             (
00094                 patchFieldType,
00095                 mesh_.boundary()[sz],
00096                 fld.dimensionedInternalField()
00097             )
00098         );
00099     }
00100 }
00101 
00102 
00103 // Delete trailing patch fields
00104 template<class GeoField>
00105 void Foam::fvMeshDistribute::deleteTrailingPatchFields()
00106 {
00107     HashTable<const GeoField*> flds
00108     (
00109         mesh_.objectRegistry::lookupClass<GeoField>()
00110     );
00111 
00112     for
00113     (
00114         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
00115         iter != flds.end();
00116         ++iter
00117     )
00118     {
00119         const GeoField& fld = *iter();
00120 
00121         typename GeoField::GeometricBoundaryField& bfld =
00122             const_cast<typename GeoField::GeometricBoundaryField&>
00123             (
00124                 fld.boundaryField()
00125             );
00126 
00127         // Shrink patchFields
00128         bfld.setSize(bfld.size() - 1);
00129     }
00130 }
00131 
00132 
00133 // Save whole boundary field
00134 template <class T, class Mesh>
00135 void Foam::fvMeshDistribute::saveBoundaryFields
00136 (
00137     PtrList<FieldField<fvsPatchField, T> >& bflds
00138 ) const
00139 {
00140     typedef GeometricField<T, fvsPatchField, Mesh> fldType;
00141 
00142     HashTable<const fldType*> flds
00143     (
00144         mesh_.objectRegistry::lookupClass<fldType>()
00145     );
00146 
00147     bflds.setSize(flds.size());
00148 
00149     label i = 0;
00150 
00151     for
00152     (
00153         typename HashTable<const fldType*>::const_iterator iter = flds.begin();
00154         iter != flds.end();
00155         ++iter
00156     )
00157     {
00158         const fldType& fld = *iter();
00159 
00160         bflds.set(i, fld.boundaryField().clone().ptr());
00161 
00162         i++;
00163     }
00164 }
00165 
00166 
00167 // Map boundary field
00168 template <class T, class Mesh>
00169 void Foam::fvMeshDistribute::mapBoundaryFields
00170 (
00171     const mapPolyMesh& map,
00172     const PtrList<FieldField<fvsPatchField, T> >& oldBflds
00173 )
00174 {
00175     const labelList& oldPatchStarts = map.oldPatchStarts();
00176     const labelList& faceMap = map.faceMap();
00177 
00178     typedef GeometricField<T, fvsPatchField, Mesh> fldType;
00179 
00180     HashTable<const fldType*> flds
00181     (
00182         mesh_.objectRegistry::lookupClass<fldType>()
00183     );
00184 
00185     if (flds.size() != oldBflds.size())
00186     {
00187         FatalErrorIn("fvMeshDistribute::mapBoundaryFields") << "problem"
00188             << abort(FatalError);
00189     }
00190 
00191     label fieldI = 0;
00192 
00193     for
00194     (
00195         typename HashTable<const fldType*>::const_iterator iter = flds.begin();
00196         iter != flds.end();
00197         ++iter
00198     )
00199     {
00200         const fldType& fld = *iter();
00201         typename fldType::GeometricBoundaryField& bfld =
00202             const_cast<typename fldType::GeometricBoundaryField&>
00203             (
00204                 fld.boundaryField()
00205             );
00206 
00207 
00208         const FieldField<fvsPatchField, T>& oldBfld = oldBflds[fieldI++];
00209 
00210         // Pull from old boundary field into bfld.
00211 
00212         forAll(bfld, patchI)
00213         {
00214             fvsPatchField<T>& patchFld = bfld[patchI];
00215             label faceI = patchFld.patch().patch().start();
00216 
00217             forAll(patchFld, i)
00218             {
00219                 label oldFaceI = faceMap[faceI++];
00220 
00221                 // Find patch and local patch face oldFaceI was in.
00222                 forAll(oldPatchStarts, oldPatchI)
00223                 {
00224                     label oldLocalI = oldFaceI - oldPatchStarts[oldPatchI];
00225 
00226                     if (oldLocalI >= 0 && oldLocalI < oldBfld[oldPatchI].size())
00227                     {
00228                         patchFld[i] = oldBfld[oldPatchI][oldLocalI];
00229                     }
00230                 }
00231             }
00232         }
00233     }
00234 }
00235 
00236 
00237 // Init patch fields of certain type
00238 template<class GeoField>
00239 void Foam::fvMeshDistribute::initPatchFields
00240 (
00241     const word& patchFieldType,
00242     const typename GeoField::value_type& initVal
00243 )
00244 {
00245     HashTable<const GeoField*> flds
00246     (
00247         mesh_.objectRegistry::lookupClass<GeoField>()
00248     );
00249 
00250     for
00251     (
00252         typename HashTable<const GeoField*>::const_iterator iter = flds.begin();
00253         iter != flds.end();
00254         ++iter
00255     )
00256     {
00257         const GeoField& fld = *iter();
00258 
00259         typename GeoField::GeometricBoundaryField& bfld =
00260             const_cast<typename GeoField::GeometricBoundaryField&>
00261             (
00262                 fld.boundaryField()
00263             );
00264 
00265         forAll(bfld, patchI)
00266         {
00267             if (bfld[patchI].type() == patchFieldType)
00268             {
00269                 bfld[patchI] == initVal;
00270             }
00271         }
00272     }
00273 }
00274 
00275 
00276 // Send fields. Note order supplied so we can receive in exactly the same order.
00277 template<class GeoField>
00278 void Foam::fvMeshDistribute::sendFields
00279 (
00280     const label domain,
00281     const wordList& fieldNames,
00282     const fvMeshSubset& subsetter
00283 )
00284 {
00285     forAll(fieldNames, i)
00286     {
00287         //Pout<< "Subsetting field " << fieldNames[i]
00288         //    << " for domain:" << domain
00289         //    << endl;
00290 
00291         // Send all fieldNames. This has to be exactly the same set as is
00292         // being received!
00293         const GeoField& fld =
00294             subsetter.baseMesh().lookupObject<GeoField>(fieldNames[i]);
00295 
00296         tmp<GeoField> tsubfld = subsetter.interpolate(fld);
00297 
00298         // Send
00299         OPstream toNbr(Pstream::blocking, domain);
00300         toNbr << tsubfld();
00301     }
00302 }
00303 
00304 
00305 // Opposite of sendFields
00306 template<class GeoField>
00307 void Foam::fvMeshDistribute::receiveFields
00308 (
00309     const label domain,
00310     const wordList& fieldNames,
00311     fvMesh& mesh,
00312     PtrList<GeoField>& fields
00313 )
00314 {
00315     fields.setSize(fieldNames.size());
00316 
00317     forAll(fieldNames, i)
00318     {
00319         //Pout<< "Receiving field " << fieldNames[i]
00320         //    << " from domain:" << domain
00321         //    << endl;
00322 
00323         IPstream fromNbr(Pstream::blocking, domain);
00324 
00325         fields.set
00326         (
00327             i,
00328             new GeoField
00329             (
00330                 IOobject
00331                 (
00332                     fieldNames[i],
00333                     mesh.time().timeName(),
00334                     mesh,
00335                     IOobject::NO_READ,
00336                     IOobject::AUTO_WRITE
00337                 ),
00338                 mesh,
00339                 fromNbr
00340             )
00341         );
00342     }
00343 }
00344 
00345 
00346 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd