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

readGTS.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 Description
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 #include "triSurface.H"
00030 #include "IFstream.H"
00031 #include "IStringStream.H"
00032 
00033 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00034 
00035 namespace Foam
00036 {
00037 
00038 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00039 
00040 bool triSurface::readGTS(const fileName& GTSfileName)
00041 {
00042     IFstream GTSfile(GTSfileName);
00043 
00044     if (!GTSfile.good())
00045     {
00046         FatalErrorIn("triSurface::readGTS(const fileName&)")
00047             << "Cannot read file " << GTSfileName
00048             << exit(FatalError);
00049     }
00050 
00051     // Read header
00052     label nPoints, nEdges, nElems;
00053 
00054     string line = getLineNoComment(GTSfile);
00055     {
00056         IStringStream lineStream(line);
00057         lineStream >> nPoints >> nEdges >> nElems;
00058     }
00059 
00060     // Read points
00061     pointField& points_ = const_cast<pointField&>(points());
00062     points_.setSize(nPoints);
00063 
00064     forAll(points_, pointi)
00065     {
00066         scalar x, y, z;
00067         line = getLineNoComment(GTSfile);
00068         {
00069             IStringStream lineStream(line);
00070             lineStream >> x >> y >> z;
00071         }
00072         points_[pointi] = point(x, y, z);
00073     }
00074 
00075     // Read edges (Foam indexing)
00076     edgeList edges(nEdges);
00077     forAll(edges, edgei)
00078     {
00079         label start, end;
00080         line = getLineNoComment(GTSfile);
00081         {
00082             IStringStream lineStream(line);
00083             lineStream >> start >> end;
00084         }
00085         edges[edgei] = edge(start - 1, end - 1);
00086     }
00087 
00088     // Read triangles. Convert references to edges into pointlabels
00089     setSize(nElems);
00090     forAll(*this, trianglei)
00091     {
00092         label e0Label, e1Label, e2Label;
00093         label region = 0;
00094 
00095         line = getLineNoComment(GTSfile);
00096         {
00097             IStringStream lineStream(line);
00098             lineStream >> e0Label >> e1Label >> e2Label;
00099 
00100             // Optional region number: read first, then check state on stream
00101             if (lineStream)
00102             {
00103                 label num;
00104                 lineStream >> num;
00105                 if (!lineStream.bad())
00106                 {
00107                     region = num;
00108                 }
00109             }
00110         }
00111 
00112         // Determine ordering of edges e0, e1
00113         //  common:common vertex, shared by e0 and e1
00114         //  e0Far:vertex on e0 which is not common
00115         //  e1Far: ,,       e1  ,,
00116         const edge& e0 = edges[e0Label - 1];
00117         const edge& e1 = edges[e1Label - 1];
00118         const edge& e2 = edges[e2Label - 1];
00119 
00120         label common01 = e0.commonVertex(e1);
00121         if (common01 == -1)
00122         {
00123             FatalErrorIn("triSurface::readGTS(const fileName&)")
00124                 << "Edges 0 and 1 of triangle " << trianglei
00125                 << " do not share a point.\n"
00126                 << "    edge0:" << e0 << endl
00127                 << "    edge1:" << e1
00128                 << exit(FatalError);
00129         }
00130 
00131         label e0Far = e0.otherVertex(common01);
00132         label e1Far = e1.otherVertex(common01);
00133 
00134         label common12 = e1.commonVertex(e2);
00135         if (common12 == -1)
00136         {
00137             FatalErrorIn("triSurface::readGTS(const fileName&)")
00138                 << "Edges 1 and 2 of triangle " << trianglei
00139                 << " do not share a point.\n"
00140                 << "    edge1:" << e1 << endl
00141                 << "    edge2:" << e2
00142                 << exit(FatalError);
00143         }
00144         label e2Far = e2.otherVertex(common12);
00145 
00146         // Does edge2 sit between edge1 and 0?
00147         if ((common12 != e1Far) || (e2Far != e0Far))
00148         {
00149             FatalErrorIn("triSurface::readGTS(const fileName&)")
00150                 << "Edges of triangle " << trianglei
00151                 << " reference more than three points.\n"
00152                 << "    edge0:" << e0 << endl
00153                 << "    edge1:" << e1 << endl
00154                 << "    edge2:" << e2 << endl
00155                 << exit(FatalError);
00156         }
00157 
00158         operator[](trianglei) = labelledTri(e0Far, common01, e1Far, region);
00159     }
00160 
00161     // Construct patch names
00162     setDefaultPatches();
00163 
00164     return true;
00165 }
00166 
00167 
00168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00169 
00170 } // End namespace Foam
00171 
00172 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd