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 "faceSource.H"
27 #include "surfaceFields.H"
28 #include "volFields.H"
29 #include "sampledSurface.H"
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
34 bool Foam::fieldValues::faceSource::validField(const word& fieldName) const
36 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
37 typedef GeometricField<Type, fvPatchField, volMesh> vf;
39 if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
43 else if (obr_.foundObject<vf>(fieldName))
53 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues
55 const word& fieldName,
59 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
60 typedef GeometricField<Type, fvPatchField, volMesh> vf;
62 if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
64 return filterField(obr_.lookupObject<sf>(fieldName), true);
66 else if (obr_.foundObject<vf>(fieldName))
68 if (surfacePtr_.valid())
70 return surfacePtr_().sample(obr_.lookupObject<vf>(fieldName));
74 return filterField(obr_.lookupObject<vf>(fieldName), true);
82 "Foam::tmp<Foam::Field<Type> > "
83 "Foam::fieldValues::faceSource::getFieldValues"
88 ) << "Field " << fieldName << " not found in database"
92 return tmp<Field<Type> >(new Field<Type>(0));
97 Type Foam::fieldValues::faceSource::processValues
99 const Field<Type>& values,
100 const scalarField& magSf,
101 const scalarField& weightField
104 Type result = pTraits<Type>::zero;
109 result = sum(values);
114 result = sum(values*magSf)/sum(magSf);
117 case opAreaIntegrate:
119 result = sum(values*magSf);
122 case opWeightedAverage:
124 result = sum(values*weightField)/sum(weightField);
129 result = min(values);
134 result = max(values);
147 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
150 bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
152 const bool ok = validField<Type>(fieldName);
156 Field<Type> values(getFieldValues<Type>(fieldName));
157 scalarField weightField;
159 if (operation_ == opWeightedAverage)
161 weightField = getFieldValues<scalar>(weightFieldName_, true);
166 if (surfacePtr_.valid())
168 // Get unoriented magSf
169 magSf = surfacePtr_().magSf();
173 // Get unoriented magSf
174 magSf = filterField(mesh().magSf(), false);
177 // Combine onto master
178 combineFields(values);
179 combineFields(magSf);
180 combineFields(weightField);
183 if (Pstream::master())
185 Type result = processValues(values, magSf, weightField);
193 fieldName + "_" + sourceTypeNames_[source_] + "-"
195 obr_.time().timeName(),
204 outputFilePtr_()<< tab << result;
208 Info<< " " << operationTypeNames_[operation_]
209 << "(" << sourceName_ << ") for " << fieldName
210 << " = " << result << endl;
220 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
222 const GeometricField<Type, fvPatchField, volMesh>& field,
223 const bool applyOrientation
226 tmp<Field<Type> > tvalues(new Field<Type>(faceId_.size()));
227 Field<Type>& values = tvalues();
231 label faceI = faceId_[i];
232 label patchI = facePatchId_[i];
235 values[i] = field.boundaryField()[patchI][faceI];
241 "fieldValues::faceSource::filterField"
243 "const GeometricField<Type, fvPatchField, volMesh>&"
245 ) << type() << " " << name_ << ": "
246 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
248 << " Unable to process internal faces for volume field "
249 << field.name() << nl << abort(FatalError);
253 if (applyOrientation)
257 values[i] *= faceSign_[i];
266 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
268 const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
269 const bool applyOrientation
272 tmp<Field<Type> > tvalues(new Field<Type>(faceId_.size()));
273 Field<Type>& values = tvalues();
277 label faceI = faceId_[i];
278 label patchI = facePatchId_[i];
281 values[i] = field.boundaryField()[patchI][faceI];
285 values[i] = field[faceI];
289 if (applyOrientation)
293 values[i] *= faceSign_[i];
301 // ************************************************************************* //