BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / postProcessing / functionObjects / field / fieldMinMax / fieldMinMax.C
blobb2b03af70dc23165f9bdb320fe46f469cc5b693f
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::fieldMinMax, 0);
36 namespace Foam
38     template<>
39     const char* Foam::NamedEnum
40     <
41         Foam::fieldMinMax::modeType,
42         2
43     >::names[] =
44     {
45         "magnitude",
46         "component"
47     };
51 const Foam::NamedEnum<Foam::fieldMinMax::modeType, 2>
52 Foam::fieldMinMax::modeTypeNames_;
55 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
57 Foam::fieldMinMax::fieldMinMax
59     const word& name,
60     const objectRegistry& obr,
61     const dictionary& dict,
62     const bool loadFromFiles
65     name_(name),
66     obr_(obr),
67     active_(true),
68     write_(true),
69     log_(false),
70     mode_(mdMag),
71     fieldSet_(),
72     fieldMinMaxFilePtr_(NULL)
74     // Check if the available mesh is an fvMesh otherise deactivate
75     if (!isA<fvMesh>(obr_))
76     {
77         active_ = false;
78         WarningIn
79         (
80             "fieldMinMax::fieldMinMax"
81             "(const objectRegistry& obr, const dictionary& dict)"
82         )   << "No fvMesh available, deactivating."
83             << endl;
84     }
86     read(dict);
90 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
92 Foam::fieldMinMax::~fieldMinMax()
96 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
98 void Foam::fieldMinMax::read(const dictionary& dict)
100     if (active_)
101     {
102         write_ = dict.lookupOrDefault<Switch>("write", true);
103         log_ = dict.lookupOrDefault<Switch>("log", false);
105         mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
106         dict.lookup("fields") >> fieldSet_;
107     }
111 void Foam::fieldMinMax::makeFile()
113     // Create the fieldMinMax file if not already created
114     if (fieldMinMaxFilePtr_.empty())
115     {
116         if (debug)
117         {
118             Info<< "Creating fieldMinMax file." << endl;
119         }
121         // File update
122         if (Pstream::master())
123         {
124             fileName fieldMinMaxDir;
125             if (Pstream::parRun())
126             {
127                 // Put in undecomposed case (Note: gives problems for
128                 // distributed data running)
129                 fieldMinMaxDir =
130                     obr_.time().path()/".."/name_/obr_.time().timeName();
131             }
132             else
133             {
134                 fieldMinMaxDir =
135                     obr_.time().path()/name_/obr_.time().timeName();
136             }
138             // Create directory if does not exist.
139             mkDir(fieldMinMaxDir);
141             // Open new file at start up
142             fieldMinMaxFilePtr_.reset
143             (
144                 new OFstream(fieldMinMaxDir/(type() + ".dat"))
145             );
147             // Add headers to output data
148             writeFileHeader();
149         }
150     }
154 void Foam::fieldMinMax::writeFileHeader()
156     if (fieldMinMaxFilePtr_.valid())
157     {
158         fieldMinMaxFilePtr_()
159             << "# Time" << tab << "field" << tab << "min" << tab << "max"
160             << endl;
161     }
165 void Foam::fieldMinMax::execute()
167     // Do nothing - only valid on write
171 void Foam::fieldMinMax::end()
173     // Do nothing - only valid on write
177 void Foam::fieldMinMax::write()
179     if (active_)
180     {
181         // Create the fieldMinMax file if not already created
182         if (write_)
183         {
184             makeFile();
185         }
187         forAll(fieldSet_, fieldI)
188         {
189             calcMinMaxFields<scalar>(fieldSet_[fieldI]);
190             calcMinMaxFields<vector>(fieldSet_[fieldI]);
191             calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI]);
192             calcMinMaxFields<symmTensor>(fieldSet_[fieldI]);
193             calcMinMaxFields<tensor>(fieldSet_[fieldI]);
194         }
195     }
199 template<>
200 void Foam::fieldMinMax::calcMinMaxFields<Foam::scalar>
202     const word& fieldName
205     if (obr_.foundObject<volScalarField>(fieldName))
206     {
207         const volScalarField& field =
208             obr_.lookupObject<volScalarField>(fieldName);
209         const scalar minValue = min(field).value();
210         const scalar maxValue = max(field).value();
212         if (Pstream::master())
213         {
214             if (write_)
215             {
216                 fieldMinMaxFilePtr_()
217                     << obr_.time().value() << tab
218                     << fieldName << tab << minValue << tab << maxValue << endl;
219             }
221             if (log_)
222             {
223                 Info<< "fieldMinMax output:" << nl
224                     << "    min(" << fieldName << ") = " << minValue << nl
225                     << "    max(" << fieldName << ") = " << maxValue << nl
226                     << endl;
227             }
228         }
229     }
233 // ************************************************************************* //