FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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