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

fvFieldReconstructorReconstructFields.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 "fvFieldReconstructor.H"
00028 #include "Time.H"
00029 #include "PtrList.H"
00030 #include "fvPatchFields.H"
00031 #include "emptyFvPatch.H"
00032 #include "emptyFvPatchField.H"
00033 #include "emptyFvsPatchField.H"
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 template<class Type>
00038 Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> >
00039 Foam::fvFieldReconstructor::reconstructFvVolumeField
00040 (
00041     const IOobject& fieldIoObject
00042 )
00043 {
00044     // Read the field for all the processors
00045     PtrList<GeometricField<Type, fvPatchField, volMesh> > procFields
00046     (
00047         procMeshes_.size()
00048     );
00049 
00050     forAll (procMeshes_, procI)
00051     {
00052         procFields.set
00053         (
00054             procI,
00055             new GeometricField<Type, fvPatchField, volMesh>
00056             (
00057                 IOobject
00058                 (
00059                     fieldIoObject.name(),
00060                     procMeshes_[procI].time().timeName(),
00061                     procMeshes_[procI],
00062                     IOobject::MUST_READ,
00063                     IOobject::NO_WRITE
00064                 ),
00065                 procMeshes_[procI]
00066             )
00067         );
00068     }
00069 
00070 
00071     // Create the internalField
00072     Field<Type> internalField(mesh_.nCells());
00073 
00074     // Create the patch fields
00075     PtrList<fvPatchField<Type> > patchFields(mesh_.boundary().size());
00076 
00077 
00078     forAll (procMeshes_, procI)
00079     {
00080         const GeometricField<Type, fvPatchField, volMesh>& procField =
00081             procFields[procI];
00082 
00083         // Set the cell values in the reconstructed field
00084         internalField.rmap
00085         (
00086             procField.internalField(),
00087             cellProcAddressing_[procI]
00088         );
00089 
00090         // Set the boundary patch values in the reconstructed field
00091         forAll(boundaryProcAddressing_[procI], patchI)
00092         {
00093             // Get patch index of the original patch
00094             const label curBPatch = boundaryProcAddressing_[procI][patchI];
00095 
00096             // Get addressing slice for this patch
00097             const labelList::subList cp =
00098                 procMeshes_[procI].boundary()[patchI].patchSlice
00099                 (
00100                     faceProcAddressing_[procI]
00101                 );
00102 
00103             // check if the boundary patch is not a processor patch
00104             if (curBPatch >= 0)
00105             {
00106                 // Regular patch. Fast looping
00107 
00108                 if (!patchFields(curBPatch))
00109                 {
00110                     patchFields.set
00111                     (
00112                         curBPatch,
00113                         fvPatchField<Type>::New
00114                         (
00115                             procField.boundaryField()[patchI],
00116                             mesh_.boundary()[curBPatch],
00117                             DimensionedField<Type, volMesh>::null(),
00118                             fvPatchFieldReconstructor
00119                             (
00120                                 mesh_.boundary()[curBPatch].size()
00121                             )
00122                         )
00123                     );
00124                 }
00125 
00126                 const label curPatchStart =
00127                     mesh_.boundaryMesh()[curBPatch].start();
00128 
00129                 labelList reverseAddressing(cp.size());
00130 
00131                 forAll(cp, faceI)
00132                 {
00133                     // Subtract one to take into account offsets for
00134                     // face direction.
00135                     reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
00136                 }
00137 
00138                 patchFields[curBPatch].rmap
00139                 (
00140                     procField.boundaryField()[patchI],
00141                     reverseAddressing
00142                 );
00143             }
00144             else
00145             {
00146                 const Field<Type>& curProcPatch =
00147                     procField.boundaryField()[patchI];
00148 
00149                 // In processor patches, there's a mix of internal faces (some
00150                 // of them turned) and possible cyclics. Slow loop
00151                 forAll(cp, faceI)
00152                 {
00153                     // Subtract one to take into account offsets for
00154                     // face direction.
00155                     label curF = cp[faceI] - 1;
00156 
00157                     // Is the face on the boundary?
00158                     if (curF >= mesh_.nInternalFaces())
00159                     {
00160                         label curBPatch = mesh_.boundaryMesh().whichPatch(curF);
00161 
00162                         if (!patchFields(curBPatch))
00163                         {
00164                             patchFields.set
00165                             (
00166                                 curBPatch,
00167                                 fvPatchField<Type>::New
00168                                 (
00169                                     mesh_.boundary()[curBPatch].type(),
00170                                     mesh_.boundary()[curBPatch],
00171                                     DimensionedField<Type, volMesh>::null()
00172                                 )
00173                             );
00174                         }
00175 
00176                         // add the face
00177                         label curPatchFace =
00178                             mesh_.boundaryMesh()
00179                                 [curBPatch].whichFace(curF);
00180 
00181                         patchFields[curBPatch][curPatchFace] =
00182                             curProcPatch[faceI];
00183                     }
00184                 }
00185             }
00186         }
00187     }
00188 
00189     forAll(mesh_.boundary(), patchI)
00190     {
00191         // add empty patches
00192         if
00193         (
00194             typeid(mesh_.boundary()[patchI]) == typeid(emptyFvPatch)
00195          && !patchFields(patchI)
00196         )
00197         {
00198             patchFields.set
00199             (
00200                 patchI,
00201                 fvPatchField<Type>::New
00202                 (
00203                     emptyFvPatchField<Type>::typeName,
00204                     mesh_.boundary()[patchI],
00205                     DimensionedField<Type, volMesh>::null()
00206                 )
00207             );
00208         }
00209     }
00210 
00211 
00212     // Now construct and write the field
00213     // setting the internalField and patchFields
00214     return tmp<GeometricField<Type, fvPatchField, volMesh> >
00215     (
00216         new GeometricField<Type, fvPatchField, volMesh>
00217         (
00218             IOobject
00219             (
00220                 fieldIoObject.name(),
00221                 mesh_.time().timeName(),
00222                 mesh_,
00223                 IOobject::NO_READ,
00224                 IOobject::NO_WRITE
00225             ),
00226             mesh_,
00227             procFields[0].dimensions(),
00228             internalField,
00229             patchFields
00230         )
00231     );
00232 }
00233 
00234 
00235 template<class Type>
00236 Foam::tmp<Foam::GeometricField<Type, Foam::fvsPatchField, Foam::surfaceMesh> >
00237 Foam::fvFieldReconstructor::reconstructFvSurfaceField
00238 (
00239     const IOobject& fieldIoObject
00240 )
00241 {
00242     // Read the field for all the processors
00243     PtrList<GeometricField<Type, fvsPatchField, surfaceMesh> > procFields
00244     (
00245         procMeshes_.size()
00246     );
00247 
00248     forAll (procMeshes_, procI)
00249     {
00250         procFields.set
00251         (
00252             procI,
00253             new GeometricField<Type, fvsPatchField, surfaceMesh>
00254             (
00255                 IOobject
00256                 (
00257                     fieldIoObject.name(),
00258                     procMeshes_[procI].time().timeName(),
00259                     procMeshes_[procI],
00260                     IOobject::MUST_READ,
00261                     IOobject::NO_WRITE
00262                 ),
00263                 procMeshes_[procI]
00264             )
00265         );
00266     }
00267 
00268 
00269     // Create the internalField
00270     Field<Type> internalField(mesh_.nInternalFaces());
00271 
00272     // Create the patch fields
00273     PtrList<fvsPatchField<Type> > patchFields(mesh_.boundary().size());
00274 
00275 
00276     forAll (procMeshes_, procI)
00277     {
00278         const GeometricField<Type, fvsPatchField, surfaceMesh>& procField =
00279             procFields[procI];
00280 
00281         // Set the face values in the reconstructed field
00282 
00283         // It is necessary to create a copy of the addressing array to
00284         // take care of the face direction offset trick.
00285         //
00286         {
00287             labelList curAddr(faceProcAddressing_[procI]);
00288 
00289             forAll (curAddr, addrI)
00290             {
00291                 curAddr[addrI] -= 1;
00292             }
00293 
00294             internalField.rmap
00295             (
00296                 procField.internalField(),
00297                 curAddr
00298             );
00299         }
00300 
00301         // Set the boundary patch values in the reconstructed field
00302         forAll(boundaryProcAddressing_[procI], patchI)
00303         {
00304             // Get patch index of the original patch
00305             const label curBPatch = boundaryProcAddressing_[procI][patchI];
00306 
00307             // Get addressing slice for this patch
00308             const labelList::subList cp =
00309                 procMeshes_[procI].boundary()[patchI].patchSlice
00310                 (
00311                     faceProcAddressing_[procI]
00312                 );
00313 
00314             // check if the boundary patch is not a processor patch
00315             if (curBPatch >= 0)
00316             {
00317                 // Regular patch. Fast looping
00318 
00319                 if (!patchFields(curBPatch))
00320                 {
00321                     patchFields.set
00322                     (
00323                         curBPatch,
00324                         fvsPatchField<Type>::New
00325                         (
00326                             procField.boundaryField()[patchI],
00327                             mesh_.boundary()[curBPatch],
00328                             DimensionedField<Type, surfaceMesh>::null(),
00329                             fvPatchFieldReconstructor
00330                             (
00331                                 mesh_.boundary()[curBPatch].size()
00332                             )
00333                         )
00334                     );
00335                 }
00336 
00337                 const label curPatchStart =
00338                     mesh_.boundaryMesh()[curBPatch].start();
00339 
00340                 labelList reverseAddressing(cp.size());
00341 
00342                 forAll(cp, faceI)
00343                 {
00344                     // Subtract one to take into account offsets for
00345                     // face direction.
00346                     reverseAddressing[faceI] = cp[faceI] - 1 - curPatchStart;
00347                 }
00348 
00349                 patchFields[curBPatch].rmap
00350                 (
00351                     procField.boundaryField()[patchI],
00352                     reverseAddressing
00353                 );
00354             }
00355             else
00356             {
00357                 const Field<Type>& curProcPatch =
00358                     procField.boundaryField()[patchI];
00359 
00360                 // In processor patches, there's a mix of internal faces (some
00361                 // of them turned) and possible cyclics. Slow loop
00362                 forAll(cp, faceI)
00363                 {
00364                     label curF = cp[faceI] - 1;
00365 
00366                     // Is the face turned the right side round
00367                     if (curF >= 0)
00368                     {
00369                         // Is the face on the boundary?
00370                         if (curF >= mesh_.nInternalFaces())
00371                         {
00372                             label curBPatch =
00373                                 mesh_.boundaryMesh().whichPatch(curF);
00374 
00375                             if (!patchFields(curBPatch))
00376                             {
00377                                 patchFields.set
00378                                 (
00379                                     curBPatch,
00380                                     fvsPatchField<Type>::New
00381                                     (
00382                                         mesh_.boundary()[curBPatch].type(),
00383                                         mesh_.boundary()[curBPatch],
00384                                         DimensionedField<Type, surfaceMesh>
00385                                            ::null()
00386                                     )
00387                                 );
00388                             }
00389 
00390                             // add the face
00391                             label curPatchFace =
00392                                 mesh_.boundaryMesh()
00393                                 [curBPatch].whichFace(curF);
00394 
00395                             patchFields[curBPatch][curPatchFace] =
00396                                 curProcPatch[faceI];
00397                         }
00398                         else
00399                         {
00400                             // Internal face
00401                             internalField[curF] = curProcPatch[faceI];
00402                         }
00403                     }
00404                 }
00405             }
00406         }
00407     }
00408 
00409     forAll(mesh_.boundary(), patchI)
00410     {
00411         // add empty patches
00412         if
00413         (
00414             typeid(mesh_.boundary()[patchI]) == typeid(emptyFvPatch)
00415          && !patchFields(patchI)
00416         )
00417         {
00418             patchFields.set
00419             (
00420                 patchI,
00421                 fvsPatchField<Type>::New
00422                 (
00423                     emptyFvsPatchField<Type>::typeName,
00424                     mesh_.boundary()[patchI],
00425                     DimensionedField<Type, surfaceMesh>::null()
00426                 )
00427             );
00428         }
00429     }
00430 
00431 
00432     // Now construct and write the field
00433     // setting the internalField and patchFields
00434     return tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
00435     (
00436         new GeometricField<Type, fvsPatchField, surfaceMesh>
00437         (
00438             IOobject
00439             (
00440                 fieldIoObject.name(),
00441                 mesh_.time().timeName(),
00442                 mesh_,
00443                 IOobject::NO_READ,
00444                 IOobject::NO_WRITE
00445             ),
00446             mesh_,
00447             procFields[0].dimensions(),
00448             internalField,
00449             patchFields
00450         )
00451     );
00452 }
00453 
00454 
00455 // Reconstruct and write all/selected volume fields
00456 template<class Type>
00457 void Foam::fvFieldReconstructor::reconstructFvVolumeFields
00458 (
00459     const IOobjectList& objects,
00460     const HashSet<word>& selectedFields
00461 )
00462 {
00463     const word& fieldClassName =
00464         GeometricField<Type, fvPatchField, volMesh>::typeName;
00465 
00466     IOobjectList fields = objects.lookupClass(fieldClassName);
00467 
00468     if (fields.size())
00469     {
00470         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
00471 
00472         forAllConstIter(IOobjectList, fields, fieldIter)
00473         {
00474             if
00475             (
00476                 !selectedFields.size()
00477              || selectedFields.found(fieldIter()->name())
00478             )
00479             {
00480                 Info<< "        " << fieldIter()->name() << endl;
00481 
00482                 reconstructFvVolumeField<Type>(*fieldIter())().write();
00483             }
00484         }
00485         Info<< endl;
00486     }
00487 }
00488 
00489 // Reconstruct and write all/selected surface fields
00490 template<class Type>
00491 void Foam::fvFieldReconstructor::reconstructFvSurfaceFields
00492 (
00493     const IOobjectList& objects,
00494     const HashSet<word>& selectedFields
00495 )
00496 {
00497     const word& fieldClassName =
00498         GeometricField<Type, fvsPatchField, surfaceMesh>::typeName;
00499 
00500     IOobjectList fields = objects.lookupClass(fieldClassName);
00501 
00502     if (fields.size())
00503     {
00504         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
00505 
00506         forAllConstIter(IOobjectList, fields, fieldIter)
00507         {
00508             if
00509             (
00510                 !selectedFields.size()
00511              || selectedFields.found(fieldIter()->name())
00512             )
00513             {
00514                 Info<< "        " << fieldIter()->name() << endl;
00515 
00516                 reconstructFvSurfaceField<Type>(*fieldIter())().write();
00517             }
00518         }
00519         Info<< endl;
00520     }
00521 }
00522 
00523 
00524 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd