1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 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 "sampledSurface.H"
29 bool Foam::sampledSurface::checkFieldSize(const Field<Type>& field) const
31 if (faces().empty() || field.empty())
36 if (field.size() != faces().size())
40 "sampledSurface::checkFieldSize(const Field<Type>&) const"
43 << "field (" << field.size()
44 << ") != surface (" << faces().size() << ")"
53 Type Foam::sampledSurface::integrate(const Field<Type>& field) const
55 Type value = pTraits<Type>::zero;
57 if (checkFieldSize(field))
59 value = sum(field * magSf());
62 reduce(value, sumOp<Type>());
68 Type Foam::sampledSurface::integrate(const tmp<Field<Type> >& field) const
70 Type value = integrate(field());
77 Type Foam::sampledSurface::average(const Field<Type>& field) const
79 Type value = pTraits<Type>::zero;
81 if (checkFieldSize(field))
83 value = sum(field * magSf());
86 reduce(value, sumOp<Type>());
88 // avoid divide-by-zero
91 return value / area();
95 return pTraits<Type>::zero;
101 Type Foam::sampledSurface::average(const tmp<Field<Type> >& field) const
103 Type value = average(field());
109 template<class ReturnType, class Type>
110 void Foam::sampledSurface::project
112 Field<ReturnType>& res,
113 const Field<Type>& field
116 if (checkFieldSize(field))
118 const vectorField& norm = Sf();
122 res[faceI] = field[faceI] & (norm[faceI] / mag(norm[faceI]));
132 template<class ReturnType, class Type>
133 void Foam::sampledSurface::project
135 Field<ReturnType>& res,
136 const tmp<Field<Type> >& field
139 project(res, field());
144 template<class ReturnType, class Type>
145 Foam::tmp<Foam::Field<ReturnType> >
146 Foam::sampledSurface::project
148 const tmp<Field<Type> >& field
151 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(faces().size()));
152 project(tRes(), field);
157 // ************************************************************************* //