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

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