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

midPointSet.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 "midPointSet.H"
00028 #include "polyMesh.H"
00029 #include "addToRunTimeSelectionTable.H"
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(midPointSet, 0);
00036     addToRunTimeSelectionTable(sampledSet, midPointSet, word);
00037 }
00038 
00039 
00040 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00041 
00042 // Rework faceOnlySet samples.
00043 // Take two consecutive samples
00044 void Foam::midPointSet::genSamples()
00045 {
00046     // Generate midpoints.
00047 
00048     List<point> midPoints(2*size());
00049     labelList midCells(2*size());
00050     labelList midSegments(2*size());
00051     scalarList midCurveDist(2*size());
00052 
00053     label midI = 0;
00054 
00055     label sampleI = 0;
00056 
00057     while(true)
00058     {
00059         // calculate midpoint between sampleI and sampleI+1 (if in same segment)
00060         while
00061         (
00062             (sampleI < size() - 1)
00063          && (segments_[sampleI] == segments_[sampleI+1])
00064         )
00065         {
00066             midPoints[midI] =
00067                 0.5*(operator[](sampleI) + operator[](sampleI+1));
00068 
00069             label cell1 = getCell(faces_[sampleI], midPoints[midI]);
00070             label cell2 = getCell(faces_[sampleI+1], midPoints[midI]);
00071 
00072             if (cell1 != cell2)
00073             {
00074                 FatalErrorIn("midPointSet::genSamples()")
00075                     << "  sampleI:" << sampleI
00076                     << "  midI:" << midI
00077                     << "  sampleI:" << sampleI
00078                     << "  pts[sampleI]:" << operator[](sampleI)
00079                     << "  face[sampleI]:" << faces_[sampleI]
00080                     << "  pts[sampleI+1]:" << operator[](sampleI+1)
00081                     << "  face[sampleI+1]:" << faces_[sampleI+1]
00082                     << "  cell1:" << cell1
00083                     << "  cell2:" << cell2
00084                     << abort(FatalError);
00085             }
00086 
00087             midCells[midI] = cell1;
00088             midSegments[midI] = segments_[sampleI];
00089             midCurveDist[midI] = mag(midPoints[midI] - start());
00090 
00091             midI++;
00092             sampleI++;
00093         }
00094 
00095         if (sampleI == size() - 1)
00096         {
00097             break;
00098         }
00099         sampleI++;
00100     }
00101 
00102     midPoints.setSize(midI);
00103     midCells.setSize(midI);
00104     midSegments.setSize(midI);
00105     midCurveDist.setSize(midI);
00106     setSamples
00107     (
00108         midPoints,
00109         midCells,
00110         labelList(midCells.size(), -1),
00111         midSegments,
00112         midCurveDist
00113     );
00114 }
00115 
00116 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00117 
00118 Foam::midPointSet::midPointSet
00119 (
00120     const word& name,
00121     const polyMesh& mesh,
00122     meshSearch& searchEngine,
00123     const word& axis,
00124     const point& start,
00125     const point& end
00126 )
00127 :
00128     faceOnlySet(name, mesh, searchEngine, axis, start, end)
00129 {
00130     genSamples();
00131 
00132     if (debug)
00133     {
00134         write(Info);
00135     }
00136 }
00137 
00138 
00139 Foam::midPointSet::midPointSet
00140 (
00141     const word& name,
00142     const polyMesh& mesh,
00143     meshSearch& searchEngine,
00144     const dictionary& dict
00145 )
00146 :
00147     faceOnlySet(name, mesh, searchEngine, dict)
00148 {
00149     genSamples();
00150 
00151     if (debug)
00152     {
00153         write(Info);
00154     }
00155 }
00156 
00157 
00158 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00159 
00160 Foam::midPointSet::~midPointSet()
00161 {}
00162 
00163 
00164 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd