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

PatchPostProcessing.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) 2008-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 "PatchPostProcessing.H"
00027 #include <OpenFOAM/Pstream.H>
00028 #include <OpenFOAM/ListListOps.H>
00029 
00030 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00031 
00032 template <class CloudType>
00033 Foam::label Foam::PatchPostProcessing<CloudType>::applyToPatch
00034 (
00035     const label globalPatchI
00036 ) const
00037 {
00038     forAll(patchIds_, patchI)
00039     {
00040         if (patchIds_[patchI] == globalPatchI)
00041         {
00042             return patchI;
00043         }
00044     }
00045 
00046     return -1;
00047 }
00048 
00049 
00050 // * * * * * * * * * * * * * protected Member Functions  * * * * * * * * * * //
00051 
00052 template<class CloudType>
00053 void Foam::PatchPostProcessing<CloudType>::write()
00054 {
00055     forAll(patchData_, patchI)
00056     {
00057         List<List<string> > procData(Pstream::nProcs());
00058         procData[Pstream::myProcNo()] = patchData_[patchI];
00059 
00060         Pstream::gatherList(procData);
00061 
00062         if (Pstream::master())
00063         {
00064             fileName outputDir;
00065 
00066             if (Pstream::parRun())
00067             {
00068                 // Put in undecomposed case (Note: gives problems for
00069                 // distributed data running)
00070                 outputDir =
00071                     mesh_.time().path()/".."/"postProcessing"/cloud::prefix/
00072                     this->owner().name()/this->owner().time().timeName();
00073             }
00074             else
00075             {
00076                 outputDir =
00077                     mesh_.time().path()/"postProcessing"/cloud::prefix/
00078                     this->owner().name()/this->owner().time().timeName();
00079             }
00080 
00081             // Create directory if it doesn't exist
00082             mkDir(outputDir);
00083 
00084             OFstream patchOutFile
00085             (
00086                 outputDir/patchNames_[patchI] + ".post",
00087                 IOstream::ASCII,
00088                 IOstream::currentVersion,
00089                 mesh_.time().writeCompression()
00090             );
00091 
00092             List<string> globalData;
00093             globalData = ListListOps::combine<List<string> >
00094             (
00095                 procData,
00096                 accessOp<List<string> >()
00097             );
00098             sort(globalData);
00099 
00100             patchOutFile<< "# Time " + parcelType::propHeader << nl;
00101 
00102             forAll(globalData, i)
00103             {
00104                 patchOutFile<< globalData[i].c_str() << nl;
00105             }
00106         }
00107 
00108         patchData_[patchI].clearStorage();
00109     }
00110 }
00111 
00112 
00113 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00114 
00115 template<class CloudType>
00116 Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
00117 (
00118     const dictionary& dict,
00119     CloudType& owner
00120 )
00121 :
00122     PostProcessingModel<CloudType>(dict, owner, typeName),
00123     mesh_(owner.mesh()),
00124     maxStoredParcels_(readLabel(this->coeffDict().lookup("maxStoredParcels"))),
00125     patchNames_(this->coeffDict().lookup("patches")),
00126     patchData_(patchNames_.size()),
00127     patchIds_(patchNames_.size())
00128 {
00129     forAll(patchNames_, patchI)
00130     {
00131         label id = mesh_.boundaryMesh().findPatchID(patchNames_[patchI]);
00132         if (id < 0)
00133         {
00134             FatalErrorIn
00135             (
00136                 "PatchPostProcessing<CloudType>::PatchPostProcessing"
00137                 "("
00138                     "const dictionary&, "
00139                     "CloudType& owner"
00140                 ")"
00141             )<< "Requested patch " << patchNames_[patchI] << " not found" << nl
00142              << "Available patches are: " << mesh_.boundaryMesh().names() << nl
00143              << exit(FatalError);
00144         }
00145         patchIds_[patchI] = id;
00146     }
00147 }
00148 
00149 
00150 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00151 
00152 template<class CloudType>
00153 Foam::PatchPostProcessing<CloudType>::~PatchPostProcessing()
00154 {}
00155 
00156 
00157 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00158 
00159 template<class CloudType>
00160 bool Foam::PatchPostProcessing<CloudType>::active() const
00161 {
00162     return true;
00163 }
00164 
00165 
00166 template<class CloudType>
00167 void Foam::PatchPostProcessing<CloudType>::postPatch
00168 (
00169     const parcelType& p,
00170     const label patchI
00171 )
00172 {
00173     label localPatchI = applyToPatch(patchI);
00174     if (localPatchI >= 0 && patchData_[localPatchI].size() < maxStoredParcels_)
00175     {
00176         OStringStream data;
00177         data<< this->owner().time().timeName() << ' ' << p;
00178         patchData_[localPatchI].append(data.str());
00179     }
00180 }
00181 
00182 
00183 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines