initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / sampling / sampledSet / midPoint / midPointSet.C
blob0ec01f6571bc5e614b298d4c74f9408ad6b4c1a7
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "midPointSet.H"
28 #include "polyMesh.H"
29 #include "addToRunTimeSelectionTable.H"
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 namespace Foam
35     defineTypeNameAndDebug(midPointSet, 0);
36     addToRunTimeSelectionTable(sampledSet, midPointSet, word);
40 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
42 // Rework faceOnlySet samples.
43 // Take two consecutive samples
44 void Foam::midPointSet::genSamples()
46     // Generate midpoints.
48     List<point> midPoints(2*size());
49     labelList midCells(2*size());
50     labelList midSegments(2*size());
51     scalarList midCurveDist(2*size());
53     label midI = 0;
55     label sampleI = 0;
57     while(true)
58     {
59         // calculate midpoint between sampleI and sampleI+1 (if in same segment)
60         while
61         (
62             (sampleI < size() - 1)
63          && (segments_[sampleI] == segments_[sampleI+1])
64         )
65         {
66             midPoints[midI] =
67                 0.5*(operator[](sampleI) + operator[](sampleI+1));
69             label cell1 = getCell(faces_[sampleI], midPoints[midI]);
70             label cell2 = getCell(faces_[sampleI+1], midPoints[midI]);
72             if (cell1 != cell2)
73             {
74                 FatalErrorIn("midPointSet::genSamples()")
75                     << "  sampleI:" << sampleI
76                     << "  midI:" << midI
77                     << "  sampleI:" << sampleI
78                     << "  pts[sampleI]:" << operator[](sampleI)
79                     << "  face[sampleI]:" << faces_[sampleI]
80                     << "  pts[sampleI+1]:" << operator[](sampleI+1)
81                     << "  face[sampleI+1]:" << faces_[sampleI+1]
82                     << "  cell1:" << cell1
83                     << "  cell2:" << cell2
84                     << abort(FatalError);
85             }
87             midCells[midI] = cell1;
88             midSegments[midI] = segments_[sampleI];
89             midCurveDist[midI] = mag(midPoints[midI] - start());
91             midI++;
92             sampleI++;
93         }
95         if (sampleI == size() - 1)
96         {
97             break;
98         }
99         sampleI++;
100     }
102     midPoints.setSize(midI);
103     midCells.setSize(midI);
104     midSegments.setSize(midI);
105     midCurveDist.setSize(midI);
106     setSamples
107     (
108         midPoints,
109         midCells,
110         labelList(midCells.size(), -1),
111         midSegments,
112         midCurveDist
113     );
116 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
118 Foam::midPointSet::midPointSet
120     const word& name,
121     const polyMesh& mesh,
122     meshSearch& searchEngine,
123     const word& axis,
124     const point& start,
125     const point& end
128     faceOnlySet(name, mesh, searchEngine, axis, start, end)
130     genSamples();
132     if (debug)
133     {
134         write(Info);
135     }
139 Foam::midPointSet::midPointSet
141     const word& name,
142     const polyMesh& mesh,
143     meshSearch& searchEngine,
144     const dictionary& dict
147     faceOnlySet(name, mesh, searchEngine, dict)
149     genSamples();
151     if (debug)
152     {
153         write(Info);
154     }
158 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
160 Foam::midPointSet::~midPointSet()
164 // ************************************************************************* //