fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / lagrangian / intermediate / submodels / Kinematic / PostProcessingModel / PatchPostProcessing / PatchPostProcessing.C
blob35c8828dd19127f652a023e83c90c40d5a6716e9
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "PatchPostProcessing.H"
28 #include "Pstream.H"
29 #include "ListListOps.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 template <class CloudType>
34 Foam::label Foam::PatchPostProcessing<CloudType>::applyToPatch
36     const label globalPatchI
37 ) const
39     forAll(patchIds_, patchI)
40     {
41         if (patchIds_[patchI] == globalPatchI)
42         {
43             return patchI;
44         }
45     }
47     return -1;
51 // * * * * * * * * * * * * * protected Member Functions  * * * * * * * * * * //
53 template<class CloudType>
54 void Foam::PatchPostProcessing<CloudType>::write()
56     forAll(patchData_, patchI)
57     {
58         List<List<string> > procData(Pstream::nProcs());
59         procData[Pstream::myProcNo()] = patchData_[patchI];
61         Pstream::gatherList(procData);
63         if (Pstream::master())
64         {
65             fileName outputDir;
67             if (Pstream::parRun())
68             {
69                 // Put in undecomposed case (Note: gives problems for
70                 // distributed data running)
71                 outputDir =
72                     mesh_.time().path()/".."/"postProcessing"/cloud::prefix/
73                     this->owner().name()/this->owner().time().timeName();
74             }
75             else
76             {
77                 outputDir =
78                     mesh_.time().path()/"postProcessing"/cloud::prefix/
79                     this->owner().name()/this->owner().time().timeName();
80             }
82             // Create directory if it doesn't exist
83             mkDir(outputDir);
85             OFstream patchOutFile
86             (
87                 outputDir/patchNames_[patchI] + ".post",
88                 ios_base::out|ios_base::trunc,
89                 IOstream::ASCII,
90                 IOstream::currentVersion,
91                 mesh_.time().writeCompression()
92             );
94             List<string> globalData;
95             globalData = ListListOps::combine<List<string> >
96             (
97                 procData,
98                 accessOp<List<string> >()
99             );
100             sort(globalData);
102             patchOutFile<< "# Time " + parcelType::propHeader << nl;
104             forAll(globalData, i)
105             {
106                 patchOutFile<< globalData[i].c_str() << nl;
107             }
108         }
110         patchData_[patchI].clearStorage();
111     }
115 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
117 template<class CloudType>
118 Foam::PatchPostProcessing<CloudType>::PatchPostProcessing
120     const dictionary& dict,
121     CloudType& owner
124     PostProcessingModel<CloudType>(dict, owner, typeName),
125     mesh_(owner.mesh()),
126     maxStoredParcels_(readLabel(this->coeffDict().lookup("maxStoredParcels"))),
127     patchNames_(this->coeffDict().lookup("patches")),
128     patchData_(patchNames_.size()),
129     patchIds_(patchNames_.size())
131     forAll(patchNames_, patchI)
132     {
133         label id = mesh_.boundaryMesh().findPatchID(patchNames_[patchI]);
134         if (id < 0)
135         {
136             FatalErrorIn
137             (
138                 "PatchPostProcessing<CloudType>::PatchPostProcessing"
139                 "("
140                     "const dictionary&, "
141                     "CloudType& owner"
142                 ")"
143             )<< "Requested patch " << patchNames_[patchI] << " not found" << nl
144              << "Available patches are: " << mesh_.boundaryMesh().names() << nl
145              << exit(FatalError);
146         }
147         patchIds_[patchI] = id;
148     }
152 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
154 template<class CloudType>
155 Foam::PatchPostProcessing<CloudType>::~PatchPostProcessing()
159 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
161 template<class CloudType>
162 bool Foam::PatchPostProcessing<CloudType>::active() const
164     return true;
168 template<class CloudType>
169 void Foam::PatchPostProcessing<CloudType>::postPatch
171     const parcelType& p,
172     const label patchI
175     label localPatchI = applyToPatch(patchI);
176     if (localPatchI >= 0 && patchData_[localPatchI].size() < maxStoredParcels_)
177     {
178         OStringStream data;
179         data<< this->owner().time().timeName() << ' ' << p;
180         patchData_[localPatchI].append(data.str());
181     }
185 // ************************************************************************* //