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

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