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-2016 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 vector& minC,
37  const vector& maxC,
38  const label minProci,
39  const label maxProci,
40  const Type& minValue,
41  const Type& maxValue
42 )
43 {
44  OFstream& file = this->file();
45 
46  if (location_)
47  {
48  writeTime(file());
49 
50  writeTabbed(file, fieldName);
51 
52  file<< token::TAB << minValue
53  << token::TAB << minC;
54 
55  if (Pstream::parRun())
56  {
57  file<< token::TAB << minProci;
58  }
59 
60  file<< token::TAB << maxValue
61  << token::TAB << maxC;
62 
63  if (Pstream::parRun())
64  {
65  file<< token::TAB << maxProci;
66  }
67 
68  file<< endl;
69 
70  Log << " min(" << outputName << ") = " << minValue
71  << " at location " << minC;
72 
73  if (Pstream::parRun())
74  {
75  Log << " on processor " << minProci;
76  }
77 
78  Log << nl << " max(" << outputName << ") = " << maxValue
79  << " at location " << maxC;
80 
81  if (Pstream::parRun())
82  {
83  Log << " on processor " << maxProci;
84  }
85  }
86  else
87  {
88  file<< token::TAB << minValue << token::TAB << maxValue;
89 
90  Log << " min/max(" << outputName << ") = "
91  << minValue << ' ' << maxValue;
92  }
93 
94  Log << endl;
95 }
96 
97 
98 template<class Type>
100 (
101  const word& fieldName,
102  const modeType& mode
103 )
104 {
106 
107  if (obr_.foundObject<fieldType>(fieldName))
108  {
109  const label proci = Pstream::myProcNo();
110 
111  const fieldType& field = obr_.lookupObject<fieldType>(fieldName);
112  const fvMesh& mesh = field.mesh();
113 
114  const volVectorField::Boundary& CfBoundary =
115  mesh.C().boundaryField();
116 
117  switch (mode)
118  {
119  case mdMag:
120  {
121  const volScalarField magField(mag(field));
122  const volScalarField::Boundary& magFieldBoundary =
123  magField.boundaryField();
124 
125  scalarList minVs(Pstream::nProcs());
126  List<vector> minCs(Pstream::nProcs());
127  label minProci = findMin(magField);
128  minVs[proci] = magField[minProci];
129  minCs[proci] = field.mesh().C()[minProci];
130 
131 
132  labelList maxIs(Pstream::nProcs());
133  scalarList maxVs(Pstream::nProcs());
134  List<vector> maxCs(Pstream::nProcs());
135  label maxProci = findMax(magField);
136  maxVs[proci] = magField[maxProci];
137  maxCs[proci] = field.mesh().C()[maxProci];
138 
139  forAll(magFieldBoundary, patchi)
140  {
141  const scalarField& mfp = magFieldBoundary[patchi];
142  if (mfp.size())
143  {
144  const vectorField& Cfp = CfBoundary[patchi];
145 
146  label minPI = findMin(mfp);
147  if (mfp[minPI] < minVs[proci])
148  {
149  minVs[proci] = mfp[minPI];
150  minCs[proci] = Cfp[minPI];
151  }
152 
153  label maxPI = findMax(mfp);
154  if (mfp[maxPI] > maxVs[proci])
155  {
156  maxVs[proci] = mfp[maxPI];
157  maxCs[proci] = Cfp[maxPI];
158  }
159  }
160  }
161 
162  Pstream::gatherList(minVs);
163  Pstream::gatherList(minCs);
164 
165  Pstream::gatherList(maxVs);
166  Pstream::gatherList(maxCs);
167 
168  if (Pstream::master())
169  {
170  label minI = findMin(minVs);
171  scalar minValue = minVs[minI];
172  const vector& minC = minCs[minI];
173 
174  label maxI = findMax(maxVs);
175  scalar maxValue = maxVs[maxI];
176  const vector& maxC = maxCs[maxI];
177 
178  output
179  (
180  fieldName,
181  word("mag(" + fieldName + ")"),
182  minC,
183  maxC,
184  minI,
185  maxI,
186  minValue,
187  maxValue
188  );
189  }
190  break;
191  }
192  case mdCmpt:
193  {
194  const typename fieldType::Boundary&
195  fieldBoundary = field.boundaryField();
196 
197  List<Type> minVs(Pstream::nProcs());
198  List<vector> minCs(Pstream::nProcs());
199  label minProci = findMin(field);
200  minVs[proci] = field[minProci];
201  minCs[proci] = field.mesh().C()[minProci];
202 
203  Pstream::gatherList(minVs);
204  Pstream::gatherList(minCs);
205 
206  List<Type> maxVs(Pstream::nProcs());
207  List<vector> maxCs(Pstream::nProcs());
208  label maxProci = findMax(field);
209  maxVs[proci] = field[maxProci];
210  maxCs[proci] = field.mesh().C()[maxProci];
211 
212  forAll(fieldBoundary, patchi)
213  {
214  const Field<Type>& fp = fieldBoundary[patchi];
215  if (fp.size())
216  {
217  const vectorField& Cfp = CfBoundary[patchi];
218 
219  label minPI = findMin(fp);
220  if (fp[minPI] < minVs[proci])
221  {
222  minVs[proci] = fp[minPI];
223  minCs[proci] = Cfp[minPI];
224  }
225 
226  label maxPI = findMax(fp);
227  if (fp[maxPI] > maxVs[proci])
228  {
229  maxVs[proci] = fp[maxPI];
230  maxCs[proci] = Cfp[maxPI];
231  }
232  }
233  }
234 
235  Pstream::gatherList(minVs);
236  Pstream::gatherList(minCs);
237 
238  Pstream::gatherList(maxVs);
239  Pstream::gatherList(maxCs);
240 
241  if (Pstream::master())
242  {
243  label minI = findMin(minVs);
244  Type minValue = minVs[minI];
245  const vector& minC = minCs[minI];
246 
247  label maxI = findMax(maxVs);
248  Type maxValue = maxVs[maxI];
249  const vector& maxC = maxCs[maxI];
250 
251  output
252  (
253  fieldName,
254  fieldName,
255  minC,
256  maxC,
257  minI,
258  maxI,
259  minValue,
260  maxValue
261  );
262  }
263  break;
264  }
265  default:
266  {
268  << "Unknown min/max mode: " << modeTypeNames_[mode_]
269  << exit(FatalError);
270  }
271  }
272  }
273 }
274 
275 
276 // ************************************************************************* //
#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
Output to file stream.
Definition: OFstream.H:81
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
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
dynamicFvMesh & mesh
const Boundary & boundaryField() const
Return const-reference to the boundary field.
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
label patchi
void output(const word &fieldName, const word &outputName, const vector &minC, const vector &maxC, const label minProci, const label maxProci, const Type &minValue, const Type &maxValue)
Helper function to write the output.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
#define Log
Report write to Foam::Info if the local log switch is true.
dimensioned< scalar > mag(const dimensioned< Type > &)