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-------------------------------------------------------------------------------
11License
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
37template<class CloudType>
39(
40 const label globalPatchi
41) const
42{
43 return patchIDs_.find(globalPatchi);
44}
45
46
47// * * * * * * * * * * * * * protected Member Functions * * * * * * * * * * //
48
49template<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
117template<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
168template<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
186template<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
210 p.writeProperties(data, fields_, " ", false);
211
212 patchData_[localPatchi].append(data.str());
213 }
214}
215
216
217// ************************************************************************* //
Various functions to operate on Lists.
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:75
const fvMesh & mesh() const
Return reference to the mesh.
Definition: DSMCCloudI.H:44
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
Output to file stream, using an OSstream.
Definition: OFstream.H:57
Output to string buffer, using a OSstream. Always UNCOMPRESSED.
Definition: StringStream.H:231
Standard post-processing.
virtual void postPatch(const parcelType &p, const polyPatch &pp, bool &keepParticle)
Post-patch hook.
void write()
Write post-processing info.
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Database for solution data, solver performance and other reduced data.
Definition: data.H:58
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
label index() const noexcept
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:456
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
int myProcNo() const noexcept
Return processor number.
Lookup type of boundary radiation properties.
Definition: lookup.H:66
const dictionary & coeffDict() const
Return const access to the coefficients dictionary.
Definition: subModelBase.C:131
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
labelList matching(const UList< StringType > &input, const bool invert=false) const
Return list indices for all matches.
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
messageStream Info
Information stream (stdout output on master, null elsewhere)
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:215
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Operations on lists of strings.
mkDir(pdfPath)