1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
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 "cellSource.H"
27 #include "volFields.H"
29 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 bool Foam::fieldValues::cellSource::validField(const word& fieldName) const
34 typedef GeometricField<Type, fvPatchField, volMesh> vf;
36 if (obr_.foundObject<vf>(fieldName))
46 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::setFieldValues
51 typedef GeometricField<Type, fvPatchField, volMesh> vf;
53 if (obr_.foundObject<vf>(fieldName))
55 return filterField(obr_.lookupObject<vf>(fieldName));
58 return tmp<Field<Type> >(new Field<Type>(0.0));
63 Type Foam::fieldValues::cellSource::processValues
65 const Field<Type>& values,
67 const scalarField& weightField
70 Type result = pTraits<Type>::zero;
80 result = sum(values*V)/sum(V);
85 result = sum(values*V);
88 case opWeightedAverage:
90 result = sum(values*weightField)/sum(weightField);
100 result = max(values);
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
118 const bool ok = validField<Type>(fieldName);
122 Field<Type> values(setFieldValues<Type>(fieldName));
123 combineFields(values);
125 scalarField V(filterField(mesh().V()));
128 scalarField weightField(setFieldValues<scalar>(weightFieldName_));
129 combineFields(weightField);
131 if (Pstream::master())
133 Type result = processValues(values, V, weightField);
141 fieldName + "_" + sourceTypeNames_[source_] + "-"
143 obr_.time().timeName(),
153 outputFilePtr_()<< tab << result;
157 Info<< " " << operationTypeNames_[operation_]
158 << "(" << sourceName_ << ") for " << fieldName
159 << " = " << result << endl;
169 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::filterField
171 const Field<Type>& field
174 return tmp<Field<Type> >(new Field<Type>(field, cellId_));
178 // ************************************************************************* //