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

midPointAndFaceSet.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 "midPointAndFaceSet.H"
00027 #include <OpenFOAM/polyMesh.H>
00028 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00029 
00030 
00031 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035     defineTypeNameAndDebug(midPointAndFaceSet, 0);
00036     addToRunTimeSelectionTable(sampledSet, midPointAndFaceSet, word);
00037 }
00038 
00039 
00040 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00041 
00042 // Rework faceOnlySet samples.
00043 // Take two consecutive samples
00044 void Foam::midPointAndFaceSet::genSamples()
00045 {
00046     // Generate midpoints and add to face points
00047 
00048     List<point> newSamplePoints(3*size());
00049     labelList newSampleCells(3*size());
00050     labelList newSampleFaces(3*size());
00051     labelList newSampleSegments(3*size());
00052     scalarList newSampleCurveDist(3*size());
00053 
00054     label newSampleI = 0;
00055 
00056     label sampleI = 0;
00057 
00058     while(true && size()>0)
00059     {
00060         // sampleI is start of segment
00061 
00062         // Add sampleI
00063         newSamplePoints[newSampleI] = operator[](sampleI);
00064         newSampleCells[newSampleI] = cells_[sampleI];
00065         newSampleFaces[newSampleI] = faces_[sampleI];
00066         newSampleSegments[newSampleI] = segments_[sampleI];
00067         newSampleCurveDist[newSampleI] = curveDist_[sampleI];
00068         newSampleI++;
00069 
00070         while
00071         (
00072             (sampleI < size() - 1)
00073          && (segments_[sampleI] == segments_[sampleI+1])
00074         )
00075         {
00076             // Add mid point
00077             const point mid = 0.5*(operator[](sampleI) + operator[](sampleI+1));
00078 
00079             label cell1 = getCell(faces_[sampleI], mid);
00080             label cell2 = getCell(faces_[sampleI+1], mid);
00081 
00082             if (cell1 != cell2)
00083             {
00084                 FatalErrorIn("midPointAndFaceSet::genSamples()")
00085                     << "  sampleI:" << sampleI
00086                     << "  newSampleI:" << newSampleI
00087                     << "  pts[sampleI]:" << operator[](sampleI)
00088                     << "  face[sampleI]:" << faces_[sampleI]
00089                     << "  pts[sampleI+1]:" << operator[](sampleI+1)
00090                     << "  face[sampleI+1]:" << faces_[sampleI+1]
00091                     << "  cell1:" << cell1
00092                     << "  cell2:" << cell2
00093                     << abort(FatalError);
00094             }
00095 
00096             newSamplePoints[newSampleI] = mid;
00097             newSampleCells[newSampleI] = cell1;
00098             newSampleFaces[newSampleI] = -1;
00099             newSampleSegments[newSampleI] = segments_[sampleI];
00100             newSampleCurveDist[newSampleI] =
00101                 mag(newSamplePoints[newSampleI] - start());
00102 
00103             newSampleI++;
00104 
00105             // Add sampleI+1
00106             newSamplePoints[newSampleI] = operator[](sampleI+1);
00107             newSampleCells[newSampleI] = cells_[sampleI+1];
00108             newSampleFaces[newSampleI] = faces_[sampleI+1];
00109             newSampleSegments[newSampleI] = segments_[sampleI+1];
00110             newSampleCurveDist[newSampleI] =
00111                 mag(newSamplePoints[newSampleI] - start());
00112 
00113             newSampleI++;
00114 
00115             sampleI++;
00116         }
00117 
00118         if (sampleI == size() - 1)
00119         {
00120             break;
00121         }
00122         sampleI++;
00123     }
00124 
00125     newSamplePoints.setSize(newSampleI);
00126     newSampleCells.setSize(newSampleI);
00127     newSampleFaces.setSize(newSampleI);
00128     newSampleSegments.setSize(newSampleI);
00129     newSampleCurveDist.setSize(newSampleI);
00130 
00131     setSamples
00132     (
00133         newSamplePoints,
00134         newSampleCells,
00135         newSampleFaces,
00136         newSampleSegments,
00137         newSampleCurveDist
00138     );
00139 }
00140 
00141 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00142 
00143 Foam::midPointAndFaceSet::midPointAndFaceSet
00144 (
00145     const word& name,
00146     const polyMesh& mesh,
00147     meshSearch& searchEngine,
00148     const word& axis,
00149     const point& start,
00150     const point& end
00151 )
00152 :
00153     faceOnlySet(name, mesh, searchEngine, axis, start, end)
00154 {
00155     genSamples();
00156 
00157     if (debug)
00158     {
00159         write(Info);
00160     }
00161 }
00162 
00163 
00164 Foam::midPointAndFaceSet::midPointAndFaceSet
00165 (
00166     const word& name,
00167     const polyMesh& mesh,
00168     meshSearch& searchEngine,
00169     const dictionary& dict
00170 )
00171 :
00172     faceOnlySet(name, mesh, searchEngine, dict)
00173 {
00174     genSamples();
00175 
00176     if (debug)
00177     {
00178         write(Info);
00179     }
00180 }
00181 
00182 
00183 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00184 
00185 Foam::midPointAndFaceSet::~midPointAndFaceSet()
00186 {}
00187 
00188 
00189 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines