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-2022 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 #include "OSspecific.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 template<class CloudType>
37 (
38  const label globalPatchi
39 ) const
40 {
41  forAll(patchIDs_, i)
42  {
43  if (patchIDs_[i] == globalPatchi)
44  {
45  return i;
46  }
47  }
48 
49  return -1;
50 }
51 
52 
53 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
54 
55 template<class CloudType>
57 {
58  forAll(patchData_, i)
59  {
60  List<List<scalar>> procTimes(Pstream::nProcs());
61  procTimes[Pstream::myProcNo()] = times_[i];
62  Pstream::gatherList(procTimes);
63 
64  List<List<string>> procData(Pstream::nProcs());
65  procData[Pstream::myProcNo()] = patchData_[i];
66  Pstream::gatherList(procData);
67 
68  if (Pstream::master())
69  {
70  const fvMesh& mesh = this->owner().mesh();
71 
72  // Create directory if it doesn't exist
73  mkDir(this->writeTimeDir());
74 
75  const word& patchName = mesh.boundaryMesh()[patchIDs_[i]].name();
76 
77  OFstream patchOutFile
78  (
79  this->writeTimeDir()/patchName + ".post",
80  IOstream::ASCII,
81  IOstream::currentVersion,
82  mesh.time().writeCompression()
83  );
84 
85  List<string> globalData;
86  globalData = ListListOps::combine<List<string>>
87  (
88  procData,
90  );
91 
92  List<scalar> globalTimes;
93  globalTimes = ListListOps::combine<List<scalar>>
94  (
95  procTimes,
97  );
98 
99  labelList indices;
100  sortedOrder(globalTimes, indices);
101 
102  string header("# Time currentProc " + parcelType::propertyList_);
103  patchOutFile<< header.c_str() << nl;
104 
105  forAll(globalTimes, i)
106  {
107  label dataI = indices[i];
108 
109  patchOutFile
110  << globalTimes[dataI] << ' '
111  << globalData[dataI].c_str()
112  << nl;
113  }
114  }
115 
116  patchData_[i].clearStorage();
117  times_[i].clearStorage();
118  }
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
124 template<class CloudType>
126 (
127  const dictionary& dict,
128  CloudType& owner,
129  const word& modelName
130 )
131 :
132  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
133  maxStoredParcels_
134  (
135  this->coeffDict().template lookup<scalar>("maxStoredParcels")
136  ),
137  patchIDs_(),
138  times_(),
139  patchData_()
140 {
141  const wordList allPatchNames = owner.mesh().boundaryMesh().names();
142  wordList patchName(this->coeffDict().lookup("patches"));
143 
144  labelHashSet uniquePatchIDs;
145  forAllReverse(patchName, i)
146  {
147  labelList patchIDs = findStrings(patchName[i], allPatchNames);
148 
149  if (patchIDs.empty())
150  {
152  << "Cannot find any patch names matching " << patchName[i]
153  << endl;
154  }
155 
156  uniquePatchIDs.insert(patchIDs);
157  }
158 
159  patchIDs_ = uniquePatchIDs.toc();
160 
161  if (debug)
162  {
163  forAll(patchIDs_, i)
164  {
165  const label patchi = patchIDs_[i];
166  const word& patchName = owner.mesh().boundaryMesh()[patchi].name();
167  Info<< "Post-process patch " << patchName << endl;
168  }
169  }
170 
171  patchData_.setSize(patchIDs_.size());
172  times_.setSize(patchIDs_.size());
173 }
174 
175 
176 template<class CloudType>
178 (
180 )
181 :
183  maxStoredParcels_(ppm.maxStoredParcels_),
184  patchIDs_(ppm.patchIDs_),
185  times_(ppm.times_),
186  patchData_(ppm.patchData_)
187 {}
188 
189 
190 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
191 
192 template<class CloudType>
194 {}
195 
196 
197 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
198 
199 template<class CloudType>
201 (
202  const parcelType& p,
203  const polyPatch& pp
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 // ************************************************************************* //
Various functions to operate on Lists.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllReverse(list, i)
Reverse loop across all elements in list.
Definition: UList.H:446
Templated cloud function object base class.
const CloudType & owner() const
Return const access to the owner cloud.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:79
const fvMesh & mesh() const
Return references to the mesh.
Definition: DSMCCloudI.H:41
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:111
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:202
const word & name() const
Return name.
Definition: IOobject.H:310
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:178
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Output to file stream.
Definition: OFstream.H:86
Output to memory buffer stream.
Definition: OStringStream.H:52
Standard post-processing.
virtual void postPatch(const parcelType &p, const polyPatch &pp)
Post-patch hook.
PatchPostProcessing(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
const labelList & patchIDs() const
Return const mapping from local to global patch ids.
virtual ~PatchPostProcessing()
Destructor.
void write()
Write post-processing info.
IOstream::compressionType writeCompression() const
Default write compression.
Definition: Time.H:295
bool empty() const
Return true if the UList is empty (ie, size() is zero)
Definition: UListI.H:325
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
Database for solution and other reduced data.
Definition: data.H:54
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:406
label index() const
Return the index of this patch in the boundaryMesh.
wordList names() const
Return a list of patch names.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:403
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:128
A class for handling words, derived from string.
Definition: word.H:62
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
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
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
static const char nl
Definition: Ostream.H:260
dictionary dict
volScalarField & p
Operations on lists of strings.
mkDir(pdfPath)