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

faceTemplates.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 "face.H"
00027 #include <OpenFOAM/DynamicList.H>
00028 
00029 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00030 
00031 template<unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
00032 Foam::label Foam::face::triangles
00033 (
00034     const pointField& points,
00035     DynamicList<face, SizeInc, SizeMult, SizeDiv>& triFaces
00036 ) const
00037 {
00038     label triI = triFaces.size();
00039     label quadI = 0;
00040     faceList quadFaces;
00041 
00042     // adjust the addressable size (and allocate space if needed)
00043     triFaces.setSize(triI + nTriangles());
00044 
00045     return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces);
00046 }
00047 
00048 
00049 template<class Type>
00050 Type Foam::face::average
00051 (
00052     const pointField& meshPoints,
00053     const Field<Type>& f
00054 ) const
00055 {
00056     // Calculate the average by breaking the face into triangles and
00057     // area-weighted averaging their averages
00058 
00059     // If the face is a triangle, do a direct calculation
00060     if (size() == 3)
00061     {
00062         return
00063             (1.0/3.0)
00064            *(
00065                f[operator[](0)]
00066              + f[operator[](1)]
00067              + f[operator[](2)]
00068             );
00069     }
00070 
00071     label nPoints = size();
00072 
00073     point centrePoint = point::zero;
00074     Type cf = pTraits<Type>::zero;
00075 
00076     for (register label pI=0; pI<nPoints; pI++)
00077     {
00078         centrePoint += meshPoints[operator[](pI)];
00079         cf += f[operator[](pI)];
00080     }
00081 
00082     centrePoint /= nPoints;
00083     cf /= nPoints;
00084 
00085     scalar sumA = 0;
00086     Type sumAf = pTraits<Type>::zero;
00087 
00088     for (register label pI=0; pI<nPoints; pI++)
00089     {
00090         // Calculate 3*triangle centre field value
00091         Type ttcf  =
00092         (
00093             f[operator[](pI)]
00094           + f[operator[]((pI + 1) % nPoints)]
00095           + cf
00096         );
00097 
00098         // Calculate 2*triangle area
00099         scalar ta = Foam::mag
00100         (
00101             (meshPoints[operator[](pI)] - centrePoint)
00102           ^ (meshPoints[operator[]((pI + 1) % nPoints)] - centrePoint)
00103         );
00104 
00105         sumA += ta;
00106         sumAf += ta*ttcf;
00107     }
00108 
00109     if (sumA > VSMALL)
00110     {
00111         return sumAf/(3*sumA);
00112     }
00113     else
00114     {
00115         return cf;
00116     }
00117 }
00118 
00119 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines