OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

sampledSurfaceTemplates.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "sampledSurface.H"
00028 
00029 template<class Type>
00030 bool Foam::sampledSurface::checkFieldSize(const Field<Type>& field) const
00031 {
00032     if (faces().empty() || field.empty())
00033     {
00034         return false;
00035     }
00036 
00037     if (field.size() != faces().size())
00038     {
00039         FatalErrorIn
00040         (
00041             "sampledSurface::checkFieldSize(const Field<Type>&) const"
00042         )
00043             << "size mismatch: "
00044             << "field (" << field.size()
00045             << ") != surface (" << faces().size() << ")"
00046             << exit(FatalError);
00047     }
00048 
00049     return true;
00050 }
00051 
00052 
00053 template<class Type>
00054 Type Foam::sampledSurface::integrate(const Field<Type>& field) const
00055 {
00056     Type value = pTraits<Type>::zero;
00057 
00058     if (checkFieldSize(field))
00059     {
00060         value = sum(field * magSf());
00061     }
00062 
00063     reduce(value, sumOp<Type>());
00064     return value;
00065 }
00066 
00067 
00068 template<class Type>
00069 Type Foam::sampledSurface::integrate(const tmp<Field<Type> >& field) const
00070 {
00071     Type value = integrate(field());
00072     field.clear();
00073     return value;
00074 }
00075 
00076 
00077 template<class Type>
00078 Type Foam::sampledSurface::average(const Field<Type>& field) const
00079 {
00080     Type value = pTraits<Type>::zero;
00081 
00082     if (checkFieldSize(field))
00083     {
00084         value = sum(field * magSf());
00085     }
00086 
00087     reduce(value, sumOp<Type>());
00088 
00089     // avoid divide-by-zero
00090     if (area())
00091     {
00092         return value / area();
00093     }
00094     else
00095     {
00096         return pTraits<Type>::zero;
00097     }
00098 }
00099 
00100 
00101 template<class Type>
00102 Type Foam::sampledSurface::average(const tmp<Field<Type> >& field) const
00103 {
00104     Type value = average(field());
00105     field.clear();
00106     return value;
00107 }
00108 
00109 
00110 template<class ReturnType, class Type>
00111 void Foam::sampledSurface::project
00112 (
00113     Field<ReturnType>& res,
00114     const Field<Type>& field
00115 ) const
00116 {
00117     if (checkFieldSize(field))
00118     {
00119         const vectorField& norm = Sf();
00120 
00121         forAll(norm, faceI)
00122         {
00123             res[faceI] = field[faceI] & (norm[faceI] / mag(norm[faceI]));
00124         }
00125     }
00126     else
00127     {
00128         res.clear();
00129     }
00130 }
00131 
00132 
00133 template<class ReturnType, class Type>
00134 void Foam::sampledSurface::project
00135 (
00136     Field<ReturnType>& res,
00137     const tmp<Field<Type> >& field
00138 ) const
00139 {
00140     project(res, field());
00141     field.clear();
00142 }
00143 
00144 
00145 template<class ReturnType, class Type>
00146 Foam::tmp<Foam::Field<ReturnType> >
00147 Foam::sampledSurface::project
00148 (
00149     const tmp<Field<Type> >& field
00150 ) const
00151 {
00152     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(faces().size()));
00153     project(tRes(), field);
00154     return tRes;
00155 }
00156 
00157 
00158 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd