/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "cellSource.H" #include "volFields.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template bool Foam::fieldValues::cellSource::validField(const word& fieldName) const { typedef GeometricField vf; if (obr_.foundObject(fieldName)) { return true; } return false; } template Foam::tmp > Foam::fieldValues::cellSource::setFieldValues ( const word& fieldName, const bool mustGet ) const { typedef GeometricField vf; if (obr_.foundObject(fieldName)) { return filterField(obr_.lookupObject(fieldName)); } if (mustGet) { FatalErrorIn ( "Foam::tmp > " "Foam::fieldValues::cellSource::setFieldValues" "(" "const word&, " "const bool" ") const" ) << "Field " << fieldName << " not found in database" << abort(FatalError); } return tmp >(new Field(0.0)); } template Type Foam::fieldValues::cellSource::processValues ( const Field& values, const scalarField& V, const scalarField& weightField ) const { Type result = pTraits::zero; switch (operation_) { case opSum: { result = sum(values); break; } case opVolAverage: { result = sum(values*V)/sum(V); break; } case opVolIntegrate: { result = sum(values*V); break; } case opWeightedAverage: { result = sum(values*weightField)/sum(weightField); break; } case opMin: { result = min(values); break; } case opMax: { result = max(values); break; } default: { // Do nothing } } return result; } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template bool Foam::fieldValues::cellSource::writeValues(const word& fieldName) { const bool ok = validField(fieldName); if (ok) { Field values(setFieldValues(fieldName)); combineFields(values); scalarField V(filterField(mesh().V())); combineFields(V); scalarField weightField; if (operation_ == opWeightedAverage) { weightField = setFieldValues(weightFieldName_, true); } combineFields(weightField); if (Pstream::master()) { Type result = processValues(values, V, weightField); if (valueOutput_) { IOField ( IOobject ( fieldName + "_" + sourceTypeNames_[source_] + "-" + sourceName_, obr_.time().timeName(), obr_, IOobject::NO_READ, IOobject::NO_WRITE ), values ).write(); } outputFilePtr_()<< tab << result; if (log_) { Info<< " " << operationTypeNames_[operation_] << "(" << sourceName_ << ") for " << fieldName << " = " << result << endl; } } } return ok; } template Foam::tmp > Foam::fieldValues::cellSource::filterField ( const Field& field ) const { return tmp >(new Field(field, cellId_)); } // ************************************************************************* //