PatchPostProcessing.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "PatchPostProcessing.H"
27 #include "Pstream.H"
28 #include "stringListOps.H"
29 #include "ListOps.H"
30 #include "ListListOps.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class CloudType>
36 (
37  const label globalPatchI
38 ) const
39 {
40  forAll(patchIDs_, i)
41  {
42  if (patchIDs_[i] == globalPatchI)
43  {
44  return i;
45  }
46  }
47 
48  return -1;
49 }
50 
51 
52 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
53 
54 template<class CloudType>
56 {
57  forAll(patchData_, i)
58  {
59  List<List<scalar> > procTimes(Pstream::nProcs());
60  procTimes[Pstream::myProcNo()] = times_[i];
61  Pstream::gatherList(procTimes);
62 
63  List<List<string> > procData(Pstream::nProcs());
64  procData[Pstream::myProcNo()] = patchData_[i];
65  Pstream::gatherList(procData);
66 
67  if (Pstream::master())
68  {
69  const fvMesh& mesh = this->owner().mesh();
70 
71  // Create directory if it doesn't exist
72  mkDir(this->outputTimeDir());
73 
74  const word& patchName = mesh.boundaryMesh()[patchIDs_[i]].name();
75 
76  OFstream patchOutFile
77  (
78  this->outputTimeDir()/patchName + ".post",
79  IOstream::ASCII,
80  IOstream::currentVersion,
81  mesh.time().writeCompression()
82  );
83 
84  List<string> globalData;
85  globalData = ListListOps::combine<List<string> >
86  (
87  procData,
89  );
90 
91  List<scalar> globalTimes;
92  globalTimes = ListListOps::combine<List<scalar> >
93  (
94  procTimes,
96  );
97 
98  labelList indices;
99  sortedOrder(globalTimes, indices);
100 
101  string header("# Time currentProc " + parcelType::propertyList_);
102  patchOutFile<< header.c_str() << nl;
103 
104  forAll(globalTimes, i)
105  {
106  label dataI = indices[i];
107 
108  patchOutFile
109  << globalTimes[dataI] << ' '
110  << globalData[dataI].c_str()
111  << nl;
112  }
113  }
114 
115  patchData_[i].clearStorage();
116  times_[i].clearStorage();
117  }
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
122 
123 template<class CloudType>
125 (
126  const dictionary& dict,
127  CloudType& owner,
128  const word& modelName
129 )
130 :
131  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
132  maxStoredParcels_(readScalar(this->coeffDict().lookup("maxStoredParcels"))),
133  patchIDs_(),
134  times_(),
135  patchData_()
136 {
137  const wordList allPatchNames = owner.mesh().boundaryMesh().names();
138  wordList patchName(this->coeffDict().lookup("patches"));
139 
140  labelHashSet uniquePatchIDs;
141  forAllReverse(patchName, i)
142  {
143  labelList patchIDs = findStrings(patchName[i], allPatchNames);
144 
145  if (patchIDs.empty())
146  {
147  WarningIn
148  (
149  "Foam::PatchPostProcessing<CloudType>::PatchPostProcessing"
150  "("
151  "const dictionary&, "
152  "CloudType& "
153  ")"
154  ) << "Cannot find any patch names matching " << patchName[i]
155  << endl;
156  }
157 
158  uniquePatchIDs.insert(patchIDs);
159  }
160 
161  patchIDs_ = uniquePatchIDs.toc();
162 
163  if (debug)
164  {
165  forAll(patchIDs_, i)
166  {
167  const label patchI = patchIDs_[i];
168  const word& patchName = owner.mesh().boundaryMesh()[patchI].name();
169  Info<< "Post-process patch " << patchName << endl;
170  }
171  }
172 
173  patchData_.setSize(patchIDs_.size());
174  times_.setSize(patchIDs_.size());
175 }
176 
177 
178 template<class CloudType>
180 (
182 )
183 :
185  maxStoredParcels_(ppm.maxStoredParcels_),
186  patchIDs_(ppm.patchIDs_),
187  times_(ppm.times_),
188  patchData_(ppm.patchData_)
189 {}
190 
191 
192 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
193 
194 template<class CloudType>
196 {}
197 
198 
199 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
200 
201 template<class CloudType>
203 (
204  const parcelType& p,
205  const polyPatch& pp,
206  const scalar,
207  const tetIndices& tetIs,
208  bool&
209 )
210 {
211  const label patchI = pp.index();
212  const label localPatchI = applyToPatch(patchI);
213 
214  if (localPatchI != -1 && patchData_[localPatchI].size() < maxStoredParcels_)
215  {
216  times_[localPatchI].append(this->owner().time().value());
217 
219  data<< Pstream::myProcNo() << ' ' << p;
220 
221  patchData_[localPatchI].append(data.str());
222  }
223 }
224 
225 
226 // ************************************************************************* //
Output to file stream.
Definition: OFstream.H:81
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
#define readScalar
Definition: doubleScalar.C:38
bool empty() const
Return true if the UList is empty (ie, size() is zero).
Definition: UListI.H:313
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
string str() const
Return the string.
label index() const
Return the index of this patch in the boundaryMesh.
A class for handling words, derived from string.
Definition: word.H:59
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Various functions to operate on Lists.
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
void write()
Write post-processing info.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
stressControl lookup("compactNormalStress") >> compactNormalStress
#define WarningIn(functionName)
Report a warning using Foam::Warning.
Standard post-processing.
volScalarField & p
Definition: createFields.H:51
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
#define forAll(list, i)
Definition: UList.H:421
Output to memory buffer stream.
Definition: OStringStream.H:49
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:201
IOstream::compressionType writeCompression() const
Default write compression.
Definition: Time.H:315
const word & name() const
Return name.
Definition: IOobject.H:260
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:421
virtual ~PatchPostProcessing()
Destructor.
#define forAllReverse(list, i)
Definition: UList.H:424
PatchPostProcessing(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Operations on lists of strings.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:420
Templated cloud function object base class.
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
Definition: tetIndices.H:73
virtual void postPatch(const parcelType &p, const polyPatch &pp, const scalar trackFraction, const tetIndices &tetIs, bool &keepParticle)
Post-patch hook.
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116