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

faceAreaInContact.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 "scalarField.H"
00029 
00030 
00031 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00032 
00033 // Calculate area in contact given displacement of vertices relative to
00034 // the face plane. Positive displacement is above the face (no contact);
00035 // negative is in contact
00036 Foam::scalar Foam::face::areaInContact
00037 (
00038     const pointField& meshPoints,
00039     const scalarField& v
00040 ) const
00041 {
00042     // Assemble the vertex values
00043     const labelList& labels = *this;
00044 
00045     scalarField vertexValue(labels.size());
00046 
00047     forAll (labels, i)
00048     {
00049         vertexValue[i] = v[labels[i]];
00050     }
00051 
00052 
00053     // Loop through vertexValue. If all greater that 0 return 0 (no contact);
00054     // if all less than zero return 1
00055     // all zeros is assumed to be in contact.
00056 
00057     bool allPositive = true;
00058     bool allNegative = true;
00059 
00060     forAll (vertexValue, vI)
00061     {
00062         if (vertexValue[vI] > 0)
00063         {
00064             allNegative = false;
00065         }
00066         else
00067         {
00068             allPositive = false;
00069         }
00070     }
00071 
00072     if (allPositive)
00073     {
00074         return 0.0;
00075     }
00076 
00077     if (allNegative)
00078     {
00079         return 1.0;
00080     }
00081 
00082     // There is a partial contact.
00083     // Algorithm:
00084     // Go through all edges. if both vertex values for the edge are
00085     // positive, discard. If one is positive and one is negative,
00086     // create a point and start the edge with it. If both are
00087     // negative, add the edge into the new face.  When finished,
00088     // calculate area of new face and return relative area (0<x<1)
00089 
00090     // Dimension new point list to max possible size
00091     const labelList& faceLabels = *this;
00092 
00093     pointField newFacePoints(2*size());
00094     label nNewFacePoints = 0;
00095 
00096     for (label vI = 0; vI < size() - 1; vI++)
00097     {
00098         if (vertexValue[vI] <= 0)
00099         {
00100             // This is a point in contact
00101             newFacePoints[nNewFacePoints] = meshPoints[faceLabels[vI]];
00102             nNewFacePoints++;
00103         }
00104 
00105         if
00106         (
00107             (vertexValue[vI] > 0 && vertexValue[vI + 1] < 0)
00108          || (vertexValue[vI] < 0 && vertexValue[vI + 1] > 0)
00109         )
00110         {
00111             // Edge intersection. Calculate intersection point and add to list
00112             point intersection =
00113                 meshPoints[faceLabels[vI]]
00114               + vertexValue[vI]/(vertexValue[vI + 1] - vertexValue[vI])
00115                 *(meshPoints[faceLabels[vI]] - meshPoints[faceLabels[vI + 1]]);
00116 
00117             newFacePoints[nNewFacePoints] = intersection;
00118             nNewFacePoints++;
00119         }
00120     }
00121 
00122     // Do last point by hand
00123     if (vertexValue[size() - 1] <= 0)
00124     {
00125         // This is a point in contact
00126         newFacePoints[nNewFacePoints] = meshPoints[faceLabels[size() - 1]];
00127         nNewFacePoints++;
00128     }
00129 
00130     if
00131     (
00132         (vertexValue[size() - 1] > 0 && vertexValue[0] < 0)
00133      || (vertexValue[size() - 1] < 0 && vertexValue[0] > 0)
00134     )
00135     {
00136         // Edge intersection. Calculate intersection point and add to list
00137         point intersection =
00138             meshPoints[faceLabels[size() - 1]]
00139           + vertexValue[size() - 1]/(vertexValue[0] - vertexValue[size() - 1])
00140             *(meshPoints[faceLabels[size() - 1]] - meshPoints[faceLabels[0]]);
00141 
00142         newFacePoints[nNewFacePoints] = intersection;
00143         nNewFacePoints++;
00144     }
00145 
00146     newFacePoints.setSize(nNewFacePoints);
00147 
00148     // Make a labelList for the sub-face (points are ordered!)
00149     labelList sfl(newFacePoints.size());
00150 
00151     forAll (sfl, sflI)
00152     {
00153         sfl[sflI] = sflI;
00154     }
00155 
00156     // Calculate relative area
00157     return face(sfl).mag(newFacePoints)/(mag(meshPoints) + VSMALL);
00158 }
00159 
00160 
00161 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd