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

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