PatchPostProcessing.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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_
133  (
134  this->coeffDict().template lookup<scalar>("maxStoredParcels")
135  ),
136  patchIDs_(),
137  times_(),
138  patchData_()
139 {
140  const wordList allPatchNames = owner.mesh().boundaryMesh().names();
141  wordList patchName(this->coeffDict().lookup("patches"));
142 
143  labelHashSet uniquePatchIDs;
144  forAllReverse(patchName, i)
145  {
146  labelList patchIDs = findStrings(patchName[i], allPatchNames);
147 
148  if (patchIDs.empty())
149  {
151  << "Cannot find any patch names matching " << patchName[i]
152  << endl;
153  }
154 
155  uniquePatchIDs.insert(patchIDs);
156  }
157 
158  patchIDs_ = uniquePatchIDs.toc();
159 
160  if (debug)
161  {
162  forAll(patchIDs_, i)
163  {
164  const label patchi = patchIDs_[i];
165  const word& patchName = owner.mesh().boundaryMesh()[patchi].name();
166  Info<< "Post-process patch " << patchName << endl;
167  }
168  }
169 
170  patchData_.setSize(patchIDs_.size());
171  times_.setSize(patchIDs_.size());
172 }
173 
174 
175 template<class CloudType>
177 (
179 )
180 :
182  maxStoredParcels_(ppm.maxStoredParcels_),
183  patchIDs_(ppm.patchIDs_),
184  times_(ppm.times_),
185  patchData_(ppm.patchData_)
186 {}
187 
188 
189 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
190 
191 template<class CloudType>
193 {}
194 
195 
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 
198 template<class CloudType>
200 (
201  const parcelType& p,
202  const polyPatch& pp,
203  bool&
204 )
205 {
206  const label patchi = pp.index();
207  const label localPatchi = applyToPatch(patchi);
208 
209  if (localPatchi != -1 && patchData_[localPatchi].size() < maxStoredParcels_)
210  {
211  times_[localPatchi].append(this->owner().time().value());
212 
214  data<< Pstream::myProcNo() << ' ' << p;
215 
216  patchData_[localPatchi].append(data.str());
217  }
218 }
219 
220 
221 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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:303
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:158
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
Output to file stream.
Definition: OFstream.H:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:446
virtual ~PatchPostProcessing()
Destructor.
Operations on lists of strings.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
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:299
virtual void postPatch(const parcelType &p, const polyPatch &pp, bool &keepParticle)
Post-patch hook.
static const char nl
Definition: Ostream.H:260
Database for solution and other reduced data.
Definition: data.H:51
bool mkDir(const fileName &, mode_t=0777)
Make a directory and return an error if it could not be created.
Definition: POSIX.C:290
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.