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-2016 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->writeTimeDir());
73 
74  const word& patchName = mesh.boundaryMesh()[patchIDs_[i]].name();
75 
76  OFstream patchOutFile
77  (
78  this->writeTimeDir()/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  {
148  << "Cannot find any patch names matching " << patchName[i]
149  << endl;
150  }
151 
152  uniquePatchIDs.insert(patchIDs);
153  }
154 
155  patchIDs_ = uniquePatchIDs.toc();
156 
157  if (debug)
158  {
159  forAll(patchIDs_, i)
160  {
161  const label patchi = patchIDs_[i];
162  const word& patchName = owner.mesh().boundaryMesh()[patchi].name();
163  Info<< "Post-process patch " << patchName << endl;
164  }
165  }
166 
167  patchData_.setSize(patchIDs_.size());
168  times_.setSize(patchIDs_.size());
169 }
170 
171 
172 template<class CloudType>
174 (
176 )
177 :
179  maxStoredParcels_(ppm.maxStoredParcels_),
180  patchIDs_(ppm.patchIDs_),
181  times_(ppm.times_),
182  patchData_(ppm.patchData_)
183 {}
184 
185 
186 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
187 
188 template<class CloudType>
190 {}
191 
192 
193 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
194 
195 template<class CloudType>
197 (
198  const parcelType& p,
199  const polyPatch& pp,
200  const scalar,
201  const tetIndices& tetIs,
202  bool&
203 )
204 {
205  const label patchi = pp.index();
206  const label localPatchi = applyToPatch(patchi);
207 
208  if (localPatchi != -1 && patchData_[localPatchi].size() < maxStoredParcels_)
209  {
210  times_[localPatchi].append(this->owner().time().value());
211 
213  data<< Pstream::myProcNo() << ' ' << p;
214 
215  patchData_[localPatchi].append(data.str());
216  }
217 }
218 
219 
220 // ************************************************************************* //
#define readScalar
Definition: doubleScalar.C:38
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:424
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:313
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
const word & name() const
Return name.
Definition: IOobject.H:291
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
void write()
Write post-processing info.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:60
Output to file stream.
Definition: OFstream.H:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:440
virtual ~PatchPostProcessing()
Destructor.
Operations on lists of strings.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:116
virtual void postPatch(const parcelType &p, const polyPatch &pp, const scalar trackFraction, const tetIndices &tetIs, bool &keepParticle)
Post-patch hook.
Various functions to operate on Lists.
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
stressControl lookup("compactNormalStress") >> compactNormalStress
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
IOstream::compressionType writeCompression() const
Default write compression.
Definition: Time.H:303
Storage and named access for the indices of a tet which is part of the decomposition of a cell...
Definition: tetIndices.H:81
static const char nl
Definition: Ostream.H:262
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:297
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label index() const
Return the index of this patch in the boundaryMesh.
string str() const
Return the string.
messageStream Info
Standard post-processing.
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
volScalarField & p
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:69
Output to memory buffer stream.
Definition: OStringStream.H:49
Templated cloud function object base class.
PatchPostProcessing(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.