Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / field / fieldMinMax / fieldMinMaxTemplates.C
blobfc3b90b235f7c63fc3f41655dcc61684689e27a8
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2008-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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.
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.
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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "fieldMinMax.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "Time.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 template<class Type>
34 void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName)
36     typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
38     if (obr_.foundObject<fieldType>(fieldName))
39     {
40         const fieldType& field = obr_.lookupObject<fieldType>(fieldName);
41         switch (mode_)
42         {
43             case mdMag:
44             {
45                 const scalar minValue = min(mag(field)).value();
46                 const scalar maxValue = max(mag(field)).value();
48                 if (Pstream::master())
49                 {
50                     if (write_)
51                     {
52                         fieldMinMaxFilePtr_()
53                             << obr_.time().value() << tab
54                             << fieldName << tab << minValue << tab << maxValue
55                             << endl;
56                     }
58                     if (log_)
59                     {
60                         Info<< "fieldMinMax output:" << nl
61                             << "    min(mag(" << fieldName << ")) = "
62                             << minValue << nl
63                             << "    max(mag(" << fieldName << ")) = "
64                             << maxValue << nl
65                             << endl;
66                     }
67                 }
68                 break;
69             }
70             case mdCmpt:
71             {
72                 const Type minValue = min(field).value();
73                 const Type maxValue = max(field).value();
75                 if (Pstream::master())
76                 {
77                     if (write_)
78                     {
79                         fieldMinMaxFilePtr_()
80                             << obr_.time().value() << tab
81                             << fieldName << tab << minValue << tab << maxValue
82                             << endl;
83                     }
85                     if (log_)
86                     {
87                         Info<< "fieldMinMax output:" << nl
88                             << "    cmptMin(" << fieldName << ") = "
89                             << minValue << nl
90                             << "    cmptMax(" << fieldName << ") = "
91                             << maxValue << nl
92                             << endl;
93                     }
94                 }
95                 break;
96             }
97             default:
98             {
99                 FatalErrorIn
100                 (
101                     "Foam::fieldMinMax::calcMinMaxFields"
102                     "(const word& fieldName)"
103                 )<< "Unknown min/max mode: " << modeTypeNames_[mode_]
104                  << exit(FatalError);
105             }
106         }
107     }
111 // ************************************************************************* //