1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. 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 * * * * * * * * * * * * * //
36 defineTypeNameAndDebug(fieldMinMax, 0);
41 const char* Foam::NamedEnum<Foam::fieldMinMax::modeType, 2>::names[] =
48 const Foam::NamedEnum<Foam::fieldMinMax::modeType, 2>
49 Foam::fieldMinMax::modeTypeNames_;
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 Foam::fieldMinMax::fieldMinMax
57 const objectRegistry& obr,
58 const dictionary& dict,
59 const bool loadFromFiles
68 fieldMinMaxFilePtr_(NULL)
70 // Check if the available mesh is an fvMesh otherise deactivate
71 if (!isA<fvMesh>(obr_))
76 "fieldMinMax::fieldMinMax"
77 "(const objectRegistry& obr, const dictionary& dict)"
78 ) << "No fvMesh available, deactivating."
86 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 Foam::fieldMinMax::~fieldMinMax()
92 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
94 void Foam::fieldMinMax::read(const dictionary& dict)
98 log_ = dict.lookupOrDefault<Switch>("log", false);
100 mode_ = modeTypeNames_[dict.lookup("mode")];
101 dict.lookup("fields") >> fieldSet_;
106 void Foam::fieldMinMax::makeFile()
108 // Create the fieldMinMax file if not already created
109 if (fieldMinMaxFilePtr_.empty())
113 Info<< "Creating fieldMinMax file." << endl;
117 if (Pstream::master())
119 fileName fieldMinMaxDir;
120 if (Pstream::parRun())
122 // Put in undecomposed case (Note: gives problems for
123 // distributed data running)
125 obr_.time().path()/".."/name_/obr_.time().timeName();
130 obr_.time().path()/name_/obr_.time().timeName();
133 // Create directory if does not exist.
134 mkDir(fieldMinMaxDir);
136 // Open new file at start up
137 fieldMinMaxFilePtr_.reset
139 new OFstream(fieldMinMaxDir/(type() + ".dat"))
142 // Add headers to output data
149 void Foam::fieldMinMax::writeFileHeader()
151 if (fieldMinMaxFilePtr_.valid())
153 fieldMinMaxFilePtr_()
154 << "# Time" << tab << "field" << tab << "min" << tab << "max"
160 void Foam::fieldMinMax::execute()
162 // Do nothing - only valid on write
166 void Foam::fieldMinMax::end()
168 // Do nothing - only valid on write
172 void Foam::fieldMinMax::write()
176 // Create the fieldMinMax file if not already created
179 forAll(fieldSet_, fieldI)
181 calcMinMaxFields<scalar>(fieldSet_[fieldI]);
182 calcMinMaxFields<vector>(fieldSet_[fieldI]);
183 calcMinMaxFields<sphericalTensor>(fieldSet_[fieldI]);
184 calcMinMaxFields<symmTensor>(fieldSet_[fieldI]);
185 calcMinMaxFields<tensor>(fieldSet_[fieldI]);
192 void Foam::fieldMinMax::calcMinMaxFields<Foam::scalar>
194 const word& fieldName
197 if (obr_.foundObject<volScalarField>(fieldName))
199 const volScalarField& field =
200 obr_.lookupObject<volScalarField>(fieldName);
201 scalar minValue = min(field).value();
202 scalar maxValue = max(field).value();
204 if (Pstream::master())
206 fieldMinMaxFilePtr_() << obr_.time().value() << tab
207 << fieldName << tab << minValue << tab << maxValue << endl;
211 Info<< "fieldMinMax output:" << nl
212 << " min(" << fieldName << ") = " << minValue << nl
213 << " max(" << fieldName << ") = " << maxValue << nl
221 // ************************************************************************* //