Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / src / sampling / sampledSet / midPointAndFace / midPointAndFaceSet.C
blob33e1a5f4067d7946c776e24bc9225f0b6126cdc7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "midPointAndFaceSet.H"
27 #include "polyMesh.H"
28 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(midPointAndFaceSet, 0);
36     addToRunTimeSelectionTable(sampledSet, midPointAndFaceSet, word);
40 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
42 // Rework faceOnlySet samples.
43 // Take two consecutive samples
44 void Foam::midPointAndFaceSet::genSamples()
46     // Generate midpoints and add to face points
48     List<point> newSamplePoints(3*size());
49     labelList newSampleCells(3*size());
50     labelList newSampleFaces(3*size());
51     labelList newSampleSegments(3*size());
52     scalarList newSampleCurveDist(3*size());
54     label newSampleI = 0;
56     label sampleI = 0;
58     while(true && size()>0)
59     {
60         // sampleI is start of segment
62         // Add sampleI
63         newSamplePoints[newSampleI] = operator[](sampleI);
64         newSampleCells[newSampleI] = cells_[sampleI];
65         newSampleFaces[newSampleI] = faces_[sampleI];
66         newSampleSegments[newSampleI] = segments_[sampleI];
67         newSampleCurveDist[newSampleI] = curveDist_[sampleI];
68         newSampleI++;
70         while
71         (
72             (sampleI < size() - 1)
73          && (segments_[sampleI] == segments_[sampleI+1])
74         )
75         {
76             // Add mid point
77             const point mid = 0.5*(operator[](sampleI) + operator[](sampleI+1));
79             label cell1 = getCell(faces_[sampleI], mid);
80             label cell2 = getCell(faces_[sampleI+1], mid);
82             if (cell1 != cell2)
83             {
84                 FatalErrorIn("midPointAndFaceSet::genSamples()")
85                     << "  sampleI:" << sampleI
86                     << "  newSampleI:" << newSampleI
87                     << "  pts[sampleI]:" << operator[](sampleI)
88                     << "  face[sampleI]:" << faces_[sampleI]
89                     << "  pts[sampleI+1]:" << operator[](sampleI+1)
90                     << "  face[sampleI+1]:" << faces_[sampleI+1]
91                     << "  cell1:" << cell1
92                     << "  cell2:" << cell2
93                     << abort(FatalError);
94             }
96             newSamplePoints[newSampleI] = mid;
97             newSampleCells[newSampleI] = cell1;
98             newSampleFaces[newSampleI] = -1;
99             newSampleSegments[newSampleI] = segments_[sampleI];
100             newSampleCurveDist[newSampleI] =
101                 mag(newSamplePoints[newSampleI] - start());
103             newSampleI++;
105             // Add sampleI+1
106             newSamplePoints[newSampleI] = operator[](sampleI+1);
107             newSampleCells[newSampleI] = cells_[sampleI+1];
108             newSampleFaces[newSampleI] = faces_[sampleI+1];
109             newSampleSegments[newSampleI] = segments_[sampleI+1];
110             newSampleCurveDist[newSampleI] =
111                 mag(newSamplePoints[newSampleI] - start());
113             newSampleI++;
115             sampleI++;
116         }
118         if (sampleI == size() - 1)
119         {
120             break;
121         }
122         sampleI++;
123     }
125     newSamplePoints.setSize(newSampleI);
126     newSampleCells.setSize(newSampleI);
127     newSampleFaces.setSize(newSampleI);
128     newSampleSegments.setSize(newSampleI);
129     newSampleCurveDist.setSize(newSampleI);
131     setSamples
132     (
133         newSamplePoints,
134         newSampleCells,
135         newSampleFaces,
136         newSampleSegments,
137         newSampleCurveDist
138     );
141 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
143 Foam::midPointAndFaceSet::midPointAndFaceSet
145     const word& name,
146     const polyMesh& mesh,
147     meshSearch& searchEngine,
148     const word& axis,
149     const point& start,
150     const point& end
153     faceOnlySet(name, mesh, searchEngine, axis, start, end)
155     genSamples();
157     if (debug)
158     {
159         write(Info);
160     }
164 Foam::midPointAndFaceSet::midPointAndFaceSet
166     const word& name,
167     const polyMesh& mesh,
168     meshSearch& searchEngine,
169     const dictionary& dict
172     faceOnlySet(name, mesh, searchEngine, dict)
174     genSamples();
176     if (debug)
177     {
178         write(Info);
179     }
183 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
185 Foam::midPointAndFaceSet::~midPointAndFaceSet()
189 // ************************************************************************* //