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-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 (writeLocation_)
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  if (log_) Info
71  << " min(" << outputName << ") = " << minValue
72  << " at location " << minC;
73 
74  if (Pstream::parRun())
75  {
76  if (log_) Info<< " on processor " << minProcI;
77  }
78 
79  if (log_) Info
80  << nl << " max(" << outputName << ") = " << maxValue
81  << " at location " << maxC;
82 
83  if (Pstream::parRun())
84  {
85  if (log_) Info<< " on processor " << maxProcI;
86  }
87  }
88  else
89  {
90  file<< token::TAB << minValue << token::TAB << maxValue;
91 
92  if (log_) Info
93  << " min/max(" << outputName << ") = "
94  << minValue << ' ' << maxValue;
95  }
96 
97  if (log_) Info<< endl;
98 
99  // Write state/results information
100  word nameStr('(' + outputName + ')');
101  this->setResult("min" + nameStr, minValue);
102  this->setResult("min" + nameStr + "_position", minC);
103  this->setResult("min" + nameStr + "_processor", minProcI);
104  this->setResult("max" + nameStr, maxValue);
105  this->setResult("max" + nameStr + "_position", maxC);
106  this->setResult("max" + nameStr + "_processor", maxProcI);
107 }
108 
109 
110 template<class Type>
112 (
113  const word& fieldName,
114  const modeType& mode
115 )
116 {
118 
119  if (obr_.foundObject<fieldType>(fieldName))
120  {
121  const label procI = Pstream::myProcNo();
122 
123  const fieldType& field = obr_.lookupObject<fieldType>(fieldName);
124  const fvMesh& mesh = field.mesh();
125 
126  const volVectorField::GeometricBoundaryField& CfBoundary =
127  mesh.C().boundaryField();
128 
129  switch (mode)
130  {
131  case mdMag:
132  {
133  const volScalarField magField(mag(field));
134  const volScalarField::GeometricBoundaryField& magFieldBoundary =
135  magField.boundaryField();
136 
137  scalarList minVs(Pstream::nProcs());
138  List<vector> minCs(Pstream::nProcs());
139  label minProcI = findMin(magField);
140  minVs[procI] = magField[minProcI];
141  minCs[procI] = field.mesh().C()[minProcI];
142 
143 
144  labelList maxIs(Pstream::nProcs());
145  scalarList maxVs(Pstream::nProcs());
146  List<vector> maxCs(Pstream::nProcs());
147  label maxProcI = findMax(magField);
148  maxVs[procI] = magField[maxProcI];
149  maxCs[procI] = field.mesh().C()[maxProcI];
150 
151  forAll(magFieldBoundary, patchI)
152  {
153  const scalarField& mfp = magFieldBoundary[patchI];
154  if (mfp.size())
155  {
156  const vectorField& Cfp = CfBoundary[patchI];
157 
158  label minPI = findMin(mfp);
159  if (mfp[minPI] < minVs[procI])
160  {
161  minVs[procI] = mfp[minPI];
162  minCs[procI] = Cfp[minPI];
163  }
164 
165  label maxPI = findMax(mfp);
166  if (mfp[maxPI] > maxVs[procI])
167  {
168  maxVs[procI] = mfp[maxPI];
169  maxCs[procI] = Cfp[maxPI];
170  }
171  }
172  }
173 
174  Pstream::gatherList(minVs);
175  Pstream::scatterList(minVs);
176  Pstream::gatherList(minCs);
177  Pstream::scatterList(minCs);
178 
179  Pstream::gatherList(maxVs);
180  Pstream::scatterList(maxVs);
181  Pstream::gatherList(maxCs);
182  Pstream::scatterList(maxCs);
183 
184  label minI = findMin(minVs);
185  scalar minValue = minVs[minI];
186  const vector& minC = minCs[minI];
187 
188  label maxI = findMax(maxVs);
189  scalar maxValue = maxVs[maxI];
190  const vector& maxC = maxCs[maxI];
191 
192  output
193  (
194  fieldName,
195  word("mag(" + fieldName + ")"),
196  minC,
197  maxC,
198  minI,
199  maxI,
200  minValue,
201  maxValue
202  );
203  break;
204  }
205  case mdCmpt:
206  {
207  const typename fieldType::GeometricBoundaryField&
208  fieldBoundary = field.boundaryField();
209 
210  List<Type> minVs(Pstream::nProcs());
211  List<vector> minCs(Pstream::nProcs());
212  label minProcI = findMin(field);
213  minVs[procI] = field[minProcI];
214  minCs[procI] = field.mesh().C()[minProcI];
215 
216  Pstream::gatherList(minVs);
217  Pstream::gatherList(minCs);
218 
219  List<Type> maxVs(Pstream::nProcs());
220  List<vector> maxCs(Pstream::nProcs());
221  label maxProcI = findMax(field);
222  maxVs[procI] = field[maxProcI];
223  maxCs[procI] = field.mesh().C()[maxProcI];
224 
225  forAll(fieldBoundary, patchI)
226  {
227  const Field<Type>& fp = fieldBoundary[patchI];
228  if (fp.size())
229  {
230  const vectorField& Cfp = CfBoundary[patchI];
231 
232  label minPI = findMin(fp);
233  if (fp[minPI] < minVs[procI])
234  {
235  minVs[procI] = fp[minPI];
236  minCs[procI] = Cfp[minPI];
237  }
238 
239  label maxPI = findMax(fp);
240  if (fp[maxPI] > maxVs[procI])
241  {
242  maxVs[procI] = fp[maxPI];
243  maxCs[procI] = Cfp[maxPI];
244  }
245  }
246  }
247 
248  Pstream::gatherList(minVs);
249  Pstream::scatterList(minVs);
250  Pstream::gatherList(minCs);
251  Pstream::scatterList(minCs);
252 
253  Pstream::gatherList(maxVs);
254  Pstream::scatterList(maxVs);
255  Pstream::gatherList(maxCs);
256  Pstream::scatterList(maxCs);
257 
258  label minI = findMin(minVs);
259  Type minValue = minVs[minI];
260  const vector& minC = minCs[minI];
261 
262  label maxI = findMax(maxVs);
263  Type maxValue = maxVs[maxI];
264  const vector& maxC = maxCs[maxI];
265 
266  output
267  (
268  fieldName,
269  fieldName,
270  minC,
271  maxC,
272  minI,
273  maxI,
274  minValue,
275  maxValue
276  );
277  break;
278  }
279  default:
280  {
282  << "Unknown min/max mode: " << modeTypeNames_[mode_]
283  << exit(FatalError);
284  }
285  }
286  }
287 }
288 
289 
290 // ************************************************************************* //
volFields.H
Foam::findMax
label findMax(const ListType &, const label start=0)
Find index of max element (and larger than given element).
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::fieldMinMax::calcMinMaxFields
void calcMinMaxFields(const word &fieldName, const modeType &mode)
Calculate the field min/max.
Definition: fieldMinMaxTemplates.C:112
Foam::fieldMinMax::output
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.
Definition: fieldMinMaxTemplates.C:33
Foam::GeometricField::boundaryField
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
Definition: GeometricField.C:735
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::fieldMinMax::modeType
modeType
Definition: fieldMinMax.H:145
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
fieldMinMax.H
Foam::mode
mode_t mode(const fileName &)
Return the file mode.
Definition: POSIX.C:573
modeTypeNames_
const Foam::NamedEnum< Foam::scene::modeType, 2 > modeTypeNames_
Definition: scene.C:53
Foam::findMin
label findMin(const ListType &, const label start=0)
Find index of min element (and less than given element).
Foam::label
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
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
minValue
scalar minValue
Definition: LISASMDCalcMethod2.H:12
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::GeometricField::GeometricBoundaryField
Definition: GeometricField.H:105
maxValue
scalar maxValue
Definition: LISASMDCalcMethod1.H:5