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 | Copyright (C) 2011-2017 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 "fieldMinMax.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const word& fieldName,
35  const word& outputName,
36  const label minCell,
37  const label maxCell,
38  const vector& minC,
39  const vector& maxC,
40  const label minProci,
41  const label maxProci,
42  const Type& minValue,
43  const Type& maxValue
44 )
45 {
46  OFstream& file = this->file();
47 
48  if (location_)
49  {
50  writeTime(file());
51 
52  writeTabbed(file, fieldName);
53 
54  file<< token::TAB << minValue
55  << token::TAB << minC;
56 
57  if (Pstream::parRun())
58  {
59  file<< token::TAB << minProci;
60  }
61 
62  file<< token::TAB << maxValue
63  << token::TAB << maxC;
64 
65  if (Pstream::parRun())
66  {
67  file<< token::TAB << maxProci;
68  }
69 
70  file<< endl;
71 
72  Log << " min(" << outputName << ") = " << minValue
73  << " in cell " << minCell
74  << " at location " << minC;
75 
76  if (Pstream::parRun())
77  {
78  Log << " on processor " << minProci;
79  }
80 
81  Log << nl << " max(" << outputName << ") = " << maxValue
82  << " in cell " << maxCell
83  << " at location " << maxC;
84 
85  if (Pstream::parRun())
86  {
87  Log << " on processor " << maxProci;
88  }
89  }
90  else
91  {
92  file<< token::TAB << minValue << token::TAB << maxValue;
93 
94  Log << " min/max(" << outputName << ") = "
95  << minValue << ' ' << maxValue;
96  }
97 
98  Log << endl;
99 }
100 
101 
102 template<class Type>
104 (
105  const word& fieldName,
106  const modeType& mode
107 )
108 {
110 
111  if (obr_.foundObject<fieldType>(fieldName))
112  {
113  const label proci = Pstream::myProcNo();
114 
115  const fieldType& field = obr_.lookupObject<fieldType>(fieldName);
116 
117  const volVectorField::Boundary& CfBoundary =
118  mesh_.C().boundaryField();
119 
120  switch (mode)
121  {
122  case mdMag:
123  {
124  const volScalarField magField(mag(field));
125  const volScalarField::Boundary& magFieldBoundary =
126  magField.boundaryField();
127 
128  scalarList minVs(Pstream::nProcs());
129  labelList minCells(Pstream::nProcs());
130  List<vector> minCs(Pstream::nProcs());
131  label minProci = findMin(magField);
132  minVs[proci] = magField[minProci];
133  minCells[proci] = minProci;
134  minCs[proci] = mesh_.C()[minProci];
135 
136  scalarList maxVs(Pstream::nProcs());
137  labelList maxCells(Pstream::nProcs());
138  List<vector> maxCs(Pstream::nProcs());
139  label maxProci = findMax(magField);
140  maxVs[proci] = magField[maxProci];
141  maxCells[proci] = maxProci;
142  maxCs[proci] = mesh_.C()[maxProci];
143 
144  forAll(magFieldBoundary, patchi)
145  {
146  const scalarField& mfp = magFieldBoundary[patchi];
147  if (mfp.size())
148  {
149  const vectorField& Cfp = CfBoundary[patchi];
150 
151  const labelList& faceCells =
152  magFieldBoundary[patchi].patch().faceCells();
153 
154  label minPI = findMin(mfp);
155  if (mfp[minPI] < minVs[proci])
156  {
157  minVs[proci] = mfp[minPI];
158  minCells[proci] = faceCells[minPI];
159  minCs[proci] = Cfp[minPI];
160  }
161 
162  label maxPI = findMax(mfp);
163  if (mfp[maxPI] > maxVs[proci])
164  {
165  maxVs[proci] = mfp[maxPI];
166  maxCells[proci] = faceCells[maxPI];
167  maxCs[proci] = Cfp[maxPI];
168  }
169  }
170  }
171 
172  Pstream::gatherList(minVs);
173  Pstream::gatherList(minCells);
174  Pstream::gatherList(minCs);
175 
176  Pstream::gatherList(maxVs);
177  Pstream::gatherList(maxCells);
178  Pstream::gatherList(maxCs);
179 
180  if (Pstream::master())
181  {
182  const label minI = findMin(minVs);
183  const scalar minValue = minVs[minI];
184  const label minCell = minCells[minI];
185  const vector& minC = minCs[minI];
186 
187  const label maxI = findMax(maxVs);
188  const scalar maxValue = maxVs[maxI];
189  const label maxCell = maxCells[maxI];
190  const vector& maxC = maxCs[maxI];
191 
192  output
193  (
194  fieldName,
195  word("mag(" + fieldName + ")"),
196  minCell,
197  maxCell,
198  minC,
199  maxC,
200  minI,
201  maxI,
202  minValue,
203  maxValue
204  );
205  }
206  break;
207  }
208  case mdCmpt:
209  {
210  const typename fieldType::Boundary&
211  fieldBoundary = field.boundaryField();
212 
213  List<Type> minVs(Pstream::nProcs());
214  labelList minCells(Pstream::nProcs());
215  List<vector> minCs(Pstream::nProcs());
216  label minProci = findMin(field);
217  minVs[proci] = field[minProci];
218  minCells[proci] = minProci;
219  minCs[proci] = mesh_.C()[minProci];
220 
221  List<Type> maxVs(Pstream::nProcs());
222  labelList maxCells(Pstream::nProcs());
223  List<vector> maxCs(Pstream::nProcs());
224  label maxProci = findMax(field);
225  maxVs[proci] = field[maxProci];
226  maxCells[proci] = maxProci;
227  maxCs[proci] = mesh_.C()[maxProci];
228 
229  forAll(fieldBoundary, patchi)
230  {
231  const Field<Type>& fp = fieldBoundary[patchi];
232 
233  if (fp.size())
234  {
235  const vectorField& Cfp = CfBoundary[patchi];
236 
237  const labelList& faceCells =
238  fieldBoundary[patchi].patch().faceCells();
239 
240  label minPI = findMin(fp);
241  if (fp[minPI] < minVs[proci])
242  {
243  minVs[proci] = fp[minPI];
244  minCells[proci] = faceCells[minPI];
245  minCs[proci] = Cfp[minPI];
246  }
247 
248  label maxPI = findMax(fp);
249  if (fp[maxPI] > maxVs[proci])
250  {
251  maxVs[proci] = fp[maxPI];
252  maxCells[proci] = faceCells[maxPI];
253  maxCs[proci] = Cfp[maxPI];
254  }
255  }
256  }
257 
258  Pstream::gatherList(minVs);
259  Pstream::gatherList(minCells);
260  Pstream::gatherList(minCs);
261 
262  Pstream::gatherList(maxVs);
263  Pstream::gatherList(maxCells);
264  Pstream::gatherList(maxCs);
265 
266  if (Pstream::master())
267  {
268  label minI = findMin(minVs);
269  Type minValue = minVs[minI];
270  const label minCell = minCells[minI];
271  const vector& minC = minCs[minI];
272 
273  label maxI = findMax(maxVs);
274  Type maxValue = maxVs[maxI];
275  const label maxCell = maxCells[maxI];
276  const vector& maxC = maxCs[maxI];
277 
278  output
279  (
280  fieldName,
281  fieldName,
282  minCell,
283  maxCell,
284  minC,
285  maxC,
286  minI,
287  maxI,
288  minValue,
289  maxValue
290  );
291  }
292  break;
293  }
294  default:
295  {
297  << "Unknown min/max mode: " << modeTypeNames_[mode_]
298  << exit(FatalError);
299  }
300  }
301  }
302 }
303 
304 
305 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Output to file stream.
Definition: OFstream.H:82
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
Generic GeometricField class.
void calcMinMaxFields(const word &fieldName, const modeType &mode)
Calculate the field min/max.
scalar maxValue
A class for handling words, derived from string.
Definition: word.H:59
label findMax(const ListType &, const label start=0)
Find index of max element (and larger than given element).
static const char nl
Definition: Ostream.H:262
void output(const word &fieldName, const word &outputName, const label minCell, const label maxCell, const vector &minC, const vector &maxC, const label minProci, const label maxProci, const Type &minValue, const Type &maxValue)
Helper function to write the output.
label patchi
#define Log
Report write to Foam::Info if the local log switch is true.
dimensioned< scalar > mag(const dimensioned< Type > &)