1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "triSurface.H"
31 #include "IStringStream.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
40 bool triSurface::readGTS(const fileName& GTSfileName)
42 IFstream GTSfile(GTSfileName);
46 FatalErrorIn("triSurface::readGTS(const fileName&)")
47 << "Cannot read file " << GTSfileName
52 label nPoints, nEdges, nElems;
54 string line = getLineNoComment(GTSfile);
56 IStringStream lineStream(line);
57 lineStream >> nPoints >> nEdges >> nElems;
61 pointField& points_ = const_cast<pointField&>(points());
62 points_.setSize(nPoints);
64 forAll(points_, pointi)
67 line = getLineNoComment(GTSfile);
69 IStringStream lineStream(line);
70 lineStream >> x >> y >> z;
72 points_[pointi] = point(x, y, z);
75 // Read edges (Foam indexing)
76 edgeList edges(nEdges);
80 line = getLineNoComment(GTSfile);
82 IStringStream lineStream(line);
83 lineStream >> start >> end;
85 edges[edgei] = edge(start - 1, end - 1);
88 // Read triangles. Convert references to edges into pointlabels
90 forAll(*this, trianglei)
92 label e0Label, e1Label, e2Label;
95 line = getLineNoComment(GTSfile);
97 IStringStream lineStream(line);
98 lineStream >> e0Label >> e1Label >> e2Label;
100 // Optional region number: read first, then check state on stream
105 if (!lineStream.bad())
112 // Determine ordering of edges e0, e1
113 // common:common vertex, shared by e0 and e1
114 // e0Far:vertex on e0 which is not common
116 const edge& e0 = edges[e0Label - 1];
117 const edge& e1 = edges[e1Label - 1];
118 const edge& e2 = edges[e2Label - 1];
120 label common01 = e0.commonVertex(e1);
123 FatalErrorIn("triSurface::readGTS(const fileName&)")
124 << "Edges 0 and 1 of triangle " << trianglei
125 << " do not share a point.\n"
126 << " edge0:" << e0 << endl
131 label e0Far = e0.otherVertex(common01);
132 label e1Far = e1.otherVertex(common01);
134 label common12 = e1.commonVertex(e2);
137 FatalErrorIn("triSurface::readGTS(const fileName&)")
138 << "Edges 1 and 2 of triangle " << trianglei
139 << " do not share a point.\n"
140 << " edge1:" << e1 << endl
144 label e2Far = e2.otherVertex(common12);
146 // Does edge2 sit between edge1 and 0?
147 if ((common12 != e1Far) || (e2Far != e0Far))
149 FatalErrorIn("triSurface::readGTS(const fileName&)")
150 << "Edges of triangle " << trianglei
151 << " reference more than three points.\n"
152 << " edge0:" << e0 << endl
153 << " edge1:" << e1 << endl
154 << " edge2:" << e2 << endl
158 operator[](trianglei) = labelledTri(e0Far, common01, e1Far, region);
161 // Construct patch names
168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170 } // End namespace Foam
172 // ************************************************************************* //