1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
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
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"
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 defineTypeNameAndDebug(Foam::fieldMinMax, 0);
39 const char* Foam::NamedEnum
41 Foam::fieldMinMax::modeType,
51 const Foam::NamedEnum<Foam::fieldMinMax::modeType, 2>
52 Foam::fieldMinMax::modeTypeNames_;
55 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 Foam::fieldMinMax::fieldMinMax
60 const objectRegistry& obr,
61 const dictionary& dict,
62 const bool loadFromFiles
72 fieldMinMaxFilePtr_(NULL)
74 // Check if the available mesh is an fvMesh otherise deactivate
75 if (!isA<fvMesh>(obr_))
80 "fieldMinMax::fieldMinMax"
81 "(const objectRegistry& obr, const dictionary& dict)"
82 ) << "No fvMesh available, deactivating."
90 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
92 Foam::fieldMinMax::~fieldMinMax()
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 void Foam::fieldMinMax::read(const dictionary& dict)
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_;
111 void Foam::fieldMinMax::makeFile()
113 // Create the fieldMinMax file if not already created
114 if (fieldMinMaxFilePtr_.empty())
118 Info<< "Creating fieldMinMax file." << endl;
122 if (Pstream::master())
124 fileName fieldMinMaxDir;
125 if (Pstream::parRun())
127 // Put in undecomposed case (Note: gives problems for
128 // distributed data running)
130 obr_.time().path()/".."/name_/obr_.time().timeName();
135 obr_.time().path()/name_/obr_.time().timeName();
138 // Create directory if does not exist.
139 mkDir(fieldMinMaxDir);
141 // Open new file at start up
142 fieldMinMaxFilePtr_.reset
144 new OFstream(fieldMinMaxDir/(type() + ".dat"))
147 // Add headers to output data
154 void Foam::fieldMinMax::writeFileHeader()
156 if (fieldMinMaxFilePtr_.valid())
158 fieldMinMaxFilePtr_()
159 << "# Time" << tab << "field" << tab << "min" << tab << "max"
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()
181 // Create the fieldMinMax file if not already created
187 forAll(fieldSet_, fieldI)
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]);
200 void Foam::fieldMinMax::calcMinMaxFields<Foam::scalar>
202 const word& fieldName
205 if (obr_.foundObject<volScalarField>(fieldName))
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())
216 fieldMinMaxFilePtr_()
217 << obr_.time().value() << tab
218 << fieldName << tab << minValue << tab << maxValue << endl;
223 Info<< "fieldMinMax output:" << nl
224 << " min(" << fieldName << ") = " << minValue << nl
225 << " max(" << fieldName << ") = " << maxValue << nl
233 // ************************************************************************* //