readGTS.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "triSurface.H"
00030 #include "IFstream.H"
00031 #include "IStringStream.H"
00032
00033
00034
00035 namespace Foam
00036 {
00037
00038
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
00052 label nPoints, nEdges, nElems;
00053
00054 string line = getLineNoComment(GTSfile);
00055 {
00056 IStringStream lineStream(line);
00057 lineStream >> nPoints >> nEdges >> nElems;
00058 }
00059
00060
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
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
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
00101 if (lineStream)
00102 {
00103 label num;
00104 lineStream >> num;
00105 if (!lineStream.bad())
00106 {
00107 region = num;
00108 }
00109 }
00110 }
00111
00112
00113
00114
00115
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
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
00162 setDefaultPatches();
00163
00164 return true;
00165 }
00166
00167
00168
00169
00170 }
00171
00172
Copyright © 2000-2009 OpenCFD Ltd