1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "scalarField.H"
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 // Calculate area in contact given displacement of vertices relative to
34 // the face plane. Positive displacement is above the face (no contact);
35 // negative is in contact
36 Foam::scalar Foam::face::areaInContact
38 const pointField& meshPoints,
42 // Assemble the vertex values
43 const labelList& labels = *this;
45 scalarField vertexValue(labels.size());
49 vertexValue[i] = v[labels[i]];
53 // Loop through vertexValue. If all greater that 0 return 0 (no contact);
54 // if all less than zero return 1
55 // all zeros is assumed to be in contact.
57 bool allPositive = true;
58 bool allNegative = true;
60 forAll (vertexValue, vI)
62 if (vertexValue[vI] > 0)
82 // There is a partial contact.
84 // Go through all edges. if both vertex values for the edge are
85 // positive, discard. If one is positive and one is negative,
86 // create a point and start the edge with it. If both are
87 // negative, add the edge into the new face. When finished,
88 // calculate area of new face and return relative area (0<x<1)
90 // Dimension new point list to max possible size
91 const labelList& faceLabels = *this;
93 pointField newFacePoints(2*size());
94 label nNewFacePoints = 0;
96 for (label vI = 0; vI < size() - 1; vI++)
98 if (vertexValue[vI] <= 0)
100 // This is a point in contact
101 newFacePoints[nNewFacePoints] = meshPoints[faceLabels[vI]];
107 (vertexValue[vI] > 0 && vertexValue[vI + 1] < 0)
108 || (vertexValue[vI] < 0 && vertexValue[vI + 1] > 0)
111 // Edge intersection. Calculate intersection point and add to list
113 meshPoints[faceLabels[vI]]
114 + vertexValue[vI]/(vertexValue[vI + 1] - vertexValue[vI])
115 *(meshPoints[faceLabels[vI]] - meshPoints[faceLabels[vI + 1]]);
117 newFacePoints[nNewFacePoints] = intersection;
122 // Do last point by hand
123 if (vertexValue[size() - 1] <= 0)
125 // This is a point in contact
126 newFacePoints[nNewFacePoints] = meshPoints[faceLabels[size() - 1]];
132 (vertexValue[size() - 1] > 0 && vertexValue[0] < 0)
133 || (vertexValue[size() - 1] < 0 && vertexValue[0] > 0)
136 // Edge intersection. Calculate intersection point and add to list
138 meshPoints[faceLabels[size() - 1]]
139 + vertexValue[size() - 1]/(vertexValue[0] - vertexValue[size() - 1])
140 *(meshPoints[faceLabels[size() - 1]] - meshPoints[faceLabels[0]]);
142 newFacePoints[nNewFacePoints] = intersection;
146 newFacePoints.setSize(nNewFacePoints);
148 // Make a labelList for the sub-face (points are ordered!)
149 labelList sfl(newFacePoints.size());
156 // Calculate relative area
157 return face(sfl).mag(newFacePoints)/(mag(meshPoints) + VSMALL);
161 // ************************************************************************* //