fieldMinMaxTemplates.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) 2015-2022 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 "fieldMinMax.H"
30#include "volFields.H"
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34template<class Type>
36(
37 const word& fieldName,
38 const word& outputName,
39 const label minCell,
40 const label maxCell,
41 const vector& minC,
42 const vector& maxC,
43 const label minProci,
44 const label maxProci,
45 const Type& minValue,
46 const Type& maxValue
47)
48{
49 OFstream& file = this->file();
50
51 if (location_)
52 {
53 writeCurrentTime(file);
54
55 writeTabbed(file, fieldName);
56
58 << token::TAB << minC;
59
60 if (Pstream::parRun())
61 {
62 file<< token::TAB << minProci;
63 }
64
66 << token::TAB << maxC;
67
68 if (Pstream::parRun())
69 {
70 file<< token::TAB << maxProci;
71 }
72
73 file<< endl;
74
75 Log << " min(" << outputName << ") = " << minValue
76 << " in cell " << minCell
77 << " at location " << minC;
78
79 if (Pstream::parRun())
80 {
81 Log << " on processor " << minProci;
82 }
83
84 Log << nl << " max(" << outputName << ") = " << maxValue
85 << " in cell " << maxCell
86 << " at location " << maxC;
87
88 if (Pstream::parRun())
89 {
90 Log << " on processor " << maxProci;
91 }
92 }
93 else
94 {
96
97 Log << " min/max(" << outputName << ") = "
98 << minValue << ' ' << maxValue;
99 }
100
101 Log << endl;
102
103 // Write state/results information
104 word nameStr('(' + outputName + ')');
105 this->setResult("min" + nameStr, minValue);
106 this->setResult("min" + nameStr + "_cell", minCell);
107 this->setResult("min" + nameStr + "_position", minC);
108 this->setResult("min" + nameStr + "_processor", minProci);
109 this->setResult("max" + nameStr, maxValue);
110 this->setResult("max" + nameStr + "_cell", maxCell);
111 this->setResult("max" + nameStr + "_position", maxC);
112 this->setResult("max" + nameStr + "_processor", maxProci);
113}
114
115
116template<class Type>
118(
120 const word& outputFieldName
121)
122{
123 const label proci = Pstream::myProcNo();
124
125 // Find min/max internal field value info
126
128 labelList minCells(Pstream::nProcs(), Zero);
130
132 labelList maxCells(Pstream::nProcs(), Zero);
134
135 labelPair minMaxIds = findMinMax(field);
136
137 label minId = minMaxIds.first();
138 if (minId != -1)
139 {
140 minVs[proci] = field[minId];
141 minCells[proci] = minId;
142 minCs[proci] = mesh_.C()[minId];
143 }
144
145 label maxId = minMaxIds.second();
146 if (maxId != -1)
147 {
148 maxVs[proci] = field[maxId];
149 maxCells[proci] = maxId;
150 maxCs[proci] = mesh_.C()[maxId];
151 }
152
153
154 // Find min/max boundary field info
155 const auto& fieldBoundary = field.boundaryField();
156 const auto& CfBoundary = mesh_.C().boundaryField();
157
158 forAll(fieldBoundary, patchi)
159 {
160 const Field<Type>& fp = fieldBoundary[patchi];
161 if (fp.size())
162 {
163 const vectorField& Cfp = CfBoundary[patchi];
164
165 const labelList& faceCells =
166 fieldBoundary[patchi].patch().faceCells();
167
168 minMaxIds = findMinMax(fp);
169
170 minId = minMaxIds.first();
171 if (minVs[proci] > fp[minId])
172 {
173 minVs[proci] = fp[minId];
174 minCells[proci] = faceCells[minId];
175 minCs[proci] = Cfp[minId];
176 }
177
178 maxId = minMaxIds.second();
179 if (maxVs[proci] < fp[maxId])
180 {
181 maxVs[proci] = fp[maxId];
182 maxCells[proci] = faceCells[maxId];
183 maxCs[proci] = Cfp[maxId];
184 }
185 }
186 }
187
188 // Collect info from all processors and output
190 Pstream::allGatherList(minCells);
192
194 Pstream::allGatherList(maxCells);
196
197 minId = findMin(minVs);
198 const Type& minValue = minVs[minId];
199 const label minCell = minCells[minId];
200 const vector& minC = minCs[minId];
201
202 maxId = findMax(maxVs);
203 const Type& maxValue = maxVs[maxId];
204 const label maxCell = maxCells[maxId];
205 const vector& maxC = maxCs[maxId];
206
207 output
208 (
209 field.name(),
210 outputFieldName,
211 minCell,
212 maxCell,
213 minC,
214 maxC,
215 minId,
216 maxId,
217 minValue,
219 );
220}
221
222
223template<class Type>
225(
226 const word& fieldName,
227 const modeType& mode
228)
229{
231
232 if (obr_.foundObject<fieldType>(fieldName))
233 {
234 const fieldType& field = lookupObject<fieldType>(fieldName);
235
236 switch (mode)
237 {
238 case mdMag:
239 {
240 calcMinMaxFieldType<scalar>
241 (
242 mag(field),
243 word("mag(" + fieldName + ")")
244 );
245 break;
246 }
247 case mdCmpt:
248 {
249 calcMinMaxFieldType(field, fieldName);
250 break;
251 }
252 default:
253 {
255 << "Unknown min/max mode: " << modeTypeNames_[mode_]
256 << exit(FatalError);
257 }
258 }
259 }
260}
261
262
263// ************************************************************************* //
scalar maxValue
scalar minValue
#define Log
Definition: PDRblock.C:35
Generic templated field type.
Definition: Field.H:82
T & first() noexcept
The first element of the list, position [0].
Definition: FixedListI.H:207
Generic GeometricField class.
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
Output to file stream, using an OSstream.
Definition: OFstream.H:57
const T & second() const noexcept
Return second element, which is also the last element.
Definition: PairI.H:120
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void allGatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
The TAB Method for Numerical Calculation of Spray Droplet Breakup.
Definition: TAB.H:69
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
bool location_
Flag to write location of min/max values.
Definition: fieldMinMax.H:198
void calcMinMaxFields(const word &fieldName, const modeType &mode)
Calculate the field min/max.
void calcMinMaxFieldType(const GeometricField< Type, fvPatchField, volMesh > &field, const word &outputFieldName)
Calculate the field min/max for a given field type.
Computes the magnitude of an input field.
Definition: mag.H:153
void setResult(const word &entryName, const Type &value)
Add result.
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:285
virtual OFstream & file()
Return access to the file (if only 1)
Definition: writeFile.C:233
virtual void writeCurrentTime(Ostream &os) const
Write the current time to stream.
Definition: writeFile.C:305
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
int myProcNo() const noexcept
Return processor number.
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
word outputName("finiteArea-edges.obj")
label findMin(const ListType &input, label start=0)
mode_t mode(const fileName &name, const bool followLink=true)
Return the file mode, normally following symbolic links.
Definition: MSwindows.C:572
labelPair findMinMax(const ListType &input, label start=0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
label findMax(const ListType &input, label start=0)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333