FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <sampling/sampledSurface.H>
00027 
00028 template<class Type>
00029 bool Foam::sampledSurface::checkFieldSize(const Field<Type>& field) const
00030 {
00031     if (faces().empty() || field.empty())
00032     {
00033         return false;
00034     }
00035 
00036     if (field.size() != faces().size())
00037     {
00038         FatalErrorIn
00039         (
00040             "sampledSurface::checkFieldSize(const Field<Type>&) const"
00041         )
00042             << "size mismatch: "
00043             << "field (" << field.size()
00044             << ") != surface (" << faces().size() << ")"
00045             << exit(FatalError);
00046     }
00047 
00048     return true;
00049 }
00050 
00051 
00052 template<class Type>
00053 Type Foam::sampledSurface::integrate(const Field<Type>& field) const
00054 {
00055     Type value = pTraits<Type>::zero;
00056 
00057     if (checkFieldSize(field))
00058     {
00059         value = sum(field * magSf());
00060     }
00061 
00062     reduce(value, sumOp<Type>());
00063     return value;
00064 }
00065 
00066 
00067 template<class Type>
00068 Type Foam::sampledSurface::integrate(const tmp<Field<Type> >& field) const
00069 {
00070     Type value = integrate(field());
00071     field.clear();
00072     return value;
00073 }
00074 
00075 
00076 template<class Type>
00077 Type Foam::sampledSurface::average(const Field<Type>& field) const
00078 {
00079     Type value = pTraits<Type>::zero;
00080 
00081     if (checkFieldSize(field))
00082     {
00083         value = sum(field * magSf());
00084     }
00085 
00086     reduce(value, sumOp<Type>());
00087 
00088     // avoid divide-by-zero
00089     if (area())
00090     {
00091         return value / area();
00092     }
00093     else
00094     {
00095         return pTraits<Type>::zero;
00096     }
00097 }
00098 
00099 
00100 template<class Type>
00101 Type Foam::sampledSurface::average(const tmp<Field<Type> >& field) const
00102 {
00103     Type value = average(field());
00104     field.clear();
00105     return value;
00106 }
00107 
00108 
00109 template<class ReturnType, class Type>
00110 void Foam::sampledSurface::project
00111 (
00112     Field<ReturnType>& res,
00113     const Field<Type>& field
00114 ) const
00115 {
00116     if (checkFieldSize(field))
00117     {
00118         const vectorField& norm = Sf();
00119 
00120         forAll(norm, faceI)
00121         {
00122             res[faceI] = field[faceI] & (norm[faceI] / mag(norm[faceI]));
00123         }
00124     }
00125     else
00126     {
00127         res.clear();
00128     }
00129 }
00130 
00131 
00132 template<class ReturnType, class Type>
00133 void Foam::sampledSurface::project
00134 (
00135     Field<ReturnType>& res,
00136     const tmp<Field<Type> >& field
00137 ) const
00138 {
00139     project(res, field());
00140     field.clear();
00141 }
00142 
00143 
00144 template<class ReturnType, class Type>
00145 Foam::tmp<Foam::Field<ReturnType> >
00146 Foam::sampledSurface::project
00147 (
00148     const tmp<Field<Type> >& field
00149 ) const
00150 {
00151     tmp<Field<ReturnType> > tRes(new Field<ReturnType>(faces().size()));
00152     project(tRes(), field);
00153     return tRes;
00154 }
00155 
00156 
00157 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines