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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "PatchPostProcessing.H"
30 #include "Pstream.H"
31 #include "stringListOps.H"
32 #include "ListOps.H"
33 #include "ListListOps.H"
34 
35 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
36 
37 template<class CloudType>
39 (
40  const label globalPatchi
41 ) const
42 {
43  return patchIDs_.find(globalPatchi);
44 }
45 
46 
47 // * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
48 
49 template<class CloudType>
51 {
52  forAll(patchData_, i)
53  {
54  List<List<scalar>> procTimes(Pstream::nProcs());
55  procTimes[Pstream::myProcNo()] = times_[i];
56  Pstream::gatherList(procTimes);
57 
58  List<List<string>> procData(Pstream::nProcs());
59  procData[Pstream::myProcNo()] = patchData_[i];
60  Pstream::gatherList(procData);
61 
62  if (Pstream::master())
63  {
64  const fvMesh& mesh = this->owner().mesh();
65 
66  // Create directory if it doesn't exist
67  mkDir(this->writeTimeDir());
68 
69  const word& patchName = mesh.boundaryMesh()[patchIDs_[i]].name();
70 
71  OFstream patchOutFile
72  (
73  this->writeTimeDir()/patchName + ".post",
74  IOstream::ASCII,
75  IOstream::currentVersion,
76  mesh.time().writeCompression()
77  );
78 
79  List<string> globalData;
80  globalData = ListListOps::combine<List<string>>
81  (
82  procData,
84  );
85 
86  List<scalar> globalTimes;
87  globalTimes = ListListOps::combine<List<scalar>>
88  (
89  procTimes,
91  );
92 
93  labelList indices(sortedOrder(globalTimes));
94 
95  string header("# Time currentProc " + header_);
96  patchOutFile<< header.c_str() << nl;
97 
98  forAll(globalTimes, i)
99  {
100  label dataI = indices[i];
101 
102  patchOutFile
103  << globalTimes[dataI] << ' '
104  << globalData[dataI].c_str()
105  << nl;
106  }
107  }
108 
109  patchData_[i].clearStorage();
110  times_[i].clearStorage();
111  }
112 }
113 
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
117 template<class CloudType>
119 (
120  const dictionary& dict,
121  CloudType& owner,
122  const word& modelName
123 )
124 :
125  CloudFunctionObject<CloudType>(dict, owner, modelName, typeName),
126  maxStoredParcels_(this->coeffDict().getScalar("maxStoredParcels")),
127  fields_(),
128  patchIDs_(),
129  times_(),
130  patchData_(),
131  header_()
132 {
133  // The "fields" filter is optional
134  this->coeffDict().readIfPresent("fields", fields_);
135 
136  // The "patches" are required
137  const wordRes patchMatcher(this->coeffDict().lookup("patches"));
138 
139  patchIDs_ = patchMatcher.matching(owner.mesh().boundaryMesh().names());
140 
141  if (patchIDs_.empty())
142  {
144  << "No matching patches found: "
145  << flatOutput(patchMatcher) << nl;
146  }
147 
148  if (debug)
149  {
150  Info<< "Post-process fields "
151  << flatOutput(fields_) << nl;
152 
153  Info<< "On patches (";
154 
155  for (const label patchi : patchIDs_)
156  {
157  Info<< ' ' << owner.mesh().boundaryMesh()[patchi].name();
158  }
159 
160  Info<< " )" << nl;
161  }
162 
163  patchData_.setSize(patchIDs_.size());
164  times_.setSize(patchIDs_.size());
165 }
166 
167 
168 template<class CloudType>
170 (
172 )
173 :
175  maxStoredParcels_(ppm.maxStoredParcels_),
176  fields_(ppm.fields_),
177  patchIDs_(ppm.patchIDs_),
178  times_(ppm.times_),
179  patchData_(ppm.patchData_),
180  header_(ppm.header_)
181 {}
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 
186 template<class CloudType>
188 (
189  const parcelType& p,
190  const polyPatch& pp,
191  bool&
192 )
193 {
194  const label patchi = pp.index();
195  const label localPatchi = applyToPatch(patchi);
196 
197  if (header_.empty())
198  {
200  p.writeProperties(data, fields_, " ", true);
201  header_ = data.str();
202  }
203 
204  if (localPatchi != -1 && patchData_[localPatchi].size() < maxStoredParcels_)
205  {
206  times_[localPatchi].append(this->owner().time().value());
207 
209  data<< Pstream::myProcNo();
210  p.writeProperties(data, fields_, " ", false);
211 
212  patchData_[localPatchi].append(data.str());
213  }
214 }
215 
216 
217 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::wordRes::matching
labelList matching(const UList< StringType > &input, const bool invert=false) const
Return list indices for all matches.
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::accessOp
Definition: UList.H:668
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
ListListOps.H
Foam::polyMesh::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:444
Foam::polyBoundaryMesh::names
wordList names() const
Return a list of patch names.
Definition: polyBoundaryMesh.C:555
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::DSMCCloud::mesh
const fvMesh & mesh() const
Return reference to the mesh.
Definition: DSMCCloudI.H:44
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::radiation::lookup
Lookup type of boundary radiation properties.
Definition: lookup.H:63
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::PatchPostProcessing
Standard post-processing.
Definition: PatchPostProcessing.H:55
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Pstream.H
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
Foam::flatOutput
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:216
Foam::patchIdentifier::index
label index() const noexcept
The index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:147
Foam::PatchPostProcessing::postPatch
virtual void postPatch(const parcelType &p, const polyPatch &pp, bool &keepParticle)
Post-patch hook.
Definition: PatchPostProcessing.C:188
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::OStringStream
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:227
Foam::CloudFunctionObject
Templated cloud function object base class.
Definition: CloudFunctionObject.H:62
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
PatchPostProcessing.H
Foam::PatchPostProcessing::write
void write()
Write post-processing info.
Definition: PatchPostProcessing.C:50
stringListOps.H
Operations on lists of strings.
Foam::PatchPostProcessing::PatchPostProcessing
PatchPostProcessing(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
Definition: PatchPostProcessing.C:119
ListOps.H
Various functions to operate on Lists.
Foam::sortedOrder
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
Foam::mkDir
bool mkDir(const fileName &pathName, mode_t mode=0777)
Make a directory and return an error if it could not be created.
Definition: MSwindows.C:507
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55