1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "faceSource.H"
28 #include "surfaceFields.H"
29 #include "volFields.H"
31 #include "ListListOps.H"
33 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
36 bool Foam::fieldValues::faceSource::setFieldValues
38 const word& fieldName,
42 values.setSize(faceId_.size(), pTraits<Type>::zero);
44 typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
45 typedef GeometricField<Type, fvPatchField, volMesh> vf;
47 if (obr_.foundObject<sf>(fieldName))
49 const sf& field = obr_.lookupObject<sf>(fieldName);
53 label faceI = faceId_[i];
54 label patchI = facePatchId_[i];
57 values[i] = field.boundaryField()[patchI][faceI];
61 values[i] = field[faceI];
64 values[i] *= flipMap_[i];
69 else if (obr_.foundObject<vf>(fieldName))
71 const vf& field = obr_.lookupObject<vf>(fieldName);
75 label faceI = faceId_[i];
76 label patchI = facePatchId_[i];
79 values[i] = field.boundaryField()[patchI][faceI];
85 "fieldValues::faceSource::setFieldValues"
90 ) << type() << " " << name_ << ": "
91 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
93 << " Unable to process internal faces for volume field "
94 << fieldName << nl << abort(FatalError);
97 values[i] *= flipMap_[i];
108 Type Foam::fieldValues::faceSource::processValues
110 const List<Type>& values
113 Type result = pTraits<Type>::zero;
118 result = sum(values);
123 tmp<scalarField> magSf = filterField(mesh().magSf());
124 result = sum(values*magSf())/sum(magSf());
127 case opAreaIntegrate:
129 result = sum(values*filterField(mesh().magSf()));
132 case opWeightedAverage:
134 if (mesh().foundObject<volScalarField>(weightFieldName_))
136 tmp<scalarField> wField =
139 mesh().lookupObject<volScalarField>(weightFieldName_)
141 result = sum(values*wField())/sum(wField());
143 else if (mesh().foundObject<surfaceScalarField>(weightFieldName_))
145 tmp<scalarField> wField =
148 mesh().lookupObject<surfaceScalarField>
153 result = sum(values*wField())/sum(wField());
159 "fieldValues::faceSource::processValues"
163 ) << type() << " " << name_ << ": "
164 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
166 << " Weight field " << weightFieldName_
167 << " must be either a " << volScalarField::typeName
168 << " or " << surfaceScalarField::typeName << nl
169 << abort(FatalError);
183 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
186 bool Foam::fieldValues::faceSource::writeValues(const word& fieldName)
188 List<List<Type> > allValues(Pstream::nProcs());
191 setFieldValues<Type>(fieldName, allValues[Pstream::myProcNo()]);
195 Pstream::gatherList(allValues);
197 if (Pstream::master())
200 ListListOps::combine<List<Type> >
203 accessOp<List<Type> >()
206 Type result = processValues(values);
214 fieldName + "_" + sourceTypeNames_[source_] + "-"
216 obr_.time().timeName(),
226 outputFilePtr_()<< tab << result;
230 Info<< " " << operationTypeNames_[operation_]
231 << "(" << sourceName_ << ") for " << fieldName
232 << " = " << result << endl;
242 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
244 const GeometricField<Type, fvPatchField, volMesh>& field
247 tmp<Field<Type> > tvalues(new Field<Type>(faceId_.size()));
248 Field<Type>& values = tvalues();
252 label faceI = faceId_[i];
253 label patchI = facePatchId_[i];
256 values[i] = field.boundaryField()[patchI][faceI];
262 "fieldValues::faceSource::filterField"
264 "const GeometricField<Type, fvPatchField, volMesh>&"
266 ) << type() << " " << name_ << ": "
267 << sourceTypeNames_[source_] << "(" << sourceName_ << "):"
269 << " Unable to process internal faces for volume field "
270 << field.name() << nl << abort(FatalError);
273 values[i] *= flipMap_[i];
281 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::filterField
283 const GeometricField<Type, fvsPatchField, surfaceMesh>& field
286 tmp<Field<Type> > tvalues(new Field<Type>(faceId_.size()));
287 Field<Type>& values = tvalues();
291 label faceI = faceId_[i];
292 label patchI = facePatchId_[i];
295 values[i] = field.boundaryField()[patchI][faceI];
299 values[i] = field[faceI];
302 values[i] *= flipMap_[i];
309 // ************************************************************************* //