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-2023 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(patchIndices_, i)
42  {
43  if (patchIndices_[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 =
76  mesh.boundaryMesh()[patchIndices_[i]].name();
77 
78  OFstream patchOutFile
79  (
80  this->writeTimeDir()/patchName + ".post",
81  IOstream::ASCII,
82  IOstream::currentVersion,
83  mesh.time().writeCompression()
84  );
85 
86  List<string> globalData;
87  globalData = ListListOps::combine<List<string>>
88  (
89  procData,
91  );
92 
93  List<scalar> globalTimes;
94  globalTimes = ListListOps::combine<List<scalar>>
95  (
96  procTimes,
98  );
99 
100  labelList indices;
101  sortedOrder(globalTimes, indices);
102 
103  string header("# Time currentProc " + parcelType::propertyList_);
104  patchOutFile<< header.c_str() << nl;
105 
106  forAll(globalTimes, i)
107  {
108  label dataI = indices[i];
109 
110  patchOutFile
111  << globalTimes[dataI] << ' '
112  << globalData[dataI].c_str()
113  << nl;
114  }
115  }
116 
117  patchData_[i].clearStorage();
118  times_[i].clearStorage();
119  }
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
124 
125 template<class CloudType>
127 (
128  const dictionary& dict,
129  CloudType& owner,
130  const word& modelName
131 )
132 :
133  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
134  maxStoredParcels_
135  (
136  this->coeffDict().template lookup<scalar>("maxStoredParcels")
137  ),
138  patchIndices_(),
139  times_(),
140  patchData_()
141 {
142  const wordList allPatchNames = owner.mesh().boundaryMesh().names();
143  wordList patchName(this->coeffDict().lookup("patches"));
144 
145  labelHashSet uniquePatchIDs;
146  forAllReverse(patchName, i)
147  {
148  labelList patchIDs = findStrings(patchName[i], allPatchNames);
149 
150  if (patchIDs.empty())
151  {
153  << "Cannot find any patch names matching " << patchName[i]
154  << endl;
155  }
156 
157  uniquePatchIDs.insert(patchIDs);
158  }
159 
160  patchIndices_ = uniquePatchIDs.toc();
161 
162  if (debug)
163  {
164  forAll(patchIndices_, i)
165  {
166  const label patchi = patchIndices_[i];
167  const word& patchName = owner.mesh().boundaryMesh()[patchi].name();
168  Info<< "Post-process patch " << patchName << endl;
169  }
170  }
171 
172  patchData_.setSize(patchIndices_.size());
173  times_.setSize(patchIndices_.size());
174 }
175 
176 
177 template<class CloudType>
179 (
181 )
182 :
184  maxStoredParcels_(ppm.maxStoredParcels_),
185  patchIndices_(ppm.patchIndices_),
186  times_(ppm.times_),
187  patchData_(ppm.patchData_)
188 {}
189 
190 
191 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
192 
193 template<class CloudType>
195 {}
196 
197 
198 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
199 
200 template<class CloudType>
202 (
203  const parcelType& p,
204  const polyPatch& pp
205 )
206 {
207  const label patchi = pp.index();
208  const label localPatchi = applyToPatch(patchi);
209 
210  if (localPatchi != -1 && patchData_[localPatchi].size() < maxStoredParcels_)
211  {
212  times_[localPatchi].append(this->owner().time().value());
213 
214  OStringStream data;
215  data<< Pstream::myProcNo() << ' ' << p;
216 
217  patchData_[localPatchi].append(data.str());
218  }
219 }
220 
221 
222 // ************************************************************************* //
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:80
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:109
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:227
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
string str() const
Return the string.
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.
virtual ~PatchPostProcessing()
Destructor.
void write()
Write post-processing info.
IOstream::compressionType writeCompression() const
Default write compression.
Definition: Time.H:299
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
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:418
const polyMesh & mesh() const
Return reference to polyMesh.
Definition: fvMesh.H:441
label index() const
Return the index of this patch in the boundaryMesh.
wordList names() const
Return the list of patch names.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
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:257
messageStream Info
void sortedOrder(const UList< T > &, labelList &order)
Generate the (stable) sort order for the list.
static const char nl
Definition: Ostream.H:266
dictionary dict
volScalarField & p
Operations on lists of strings.
mkDir(pdfPath)