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 "starMesh.H"
00030 #include <OpenFOAM/IFstream.H>
00031 
00032 
00033 
00034 label starMesh::readVtxLabel(IFstream& is)
00035 {
00036     char lcs[16];
00037 
00038     for (int i=0; i<15; i++)
00039     {
00040         is.get(lcs[i]);
00041     }
00042 
00043     lcs[15] = '\0';
00044 
00045     return atoi(lcs);
00046 }
00047 
00048 
00049 scalar starMesh::readVtxCmpt(IFstream& is)
00050 {
00051     char lcs[17];
00052 
00053     for (int i=0; i<16; i++)
00054     {
00055         is.get(lcs[i]);
00056     }
00057 
00058     lcs[16] = '\0';
00059 
00060     return scalar(atof(lcs));
00061 }
00062 
00063 
00064 void starMesh::readToNl(IFstream& is)
00065 {
00066     char c;
00067     do
00068     {
00069         is.get(c);
00070     } while (is && c != '\n');
00071 }
00072 
00073 
00074 void starMesh::readPoints(const scalar scaleFactor)
00075 {
00076     label nPoints = 0;
00077     label maxLabel = -1;
00078 
00079     fileName pointsFileName(casePrefix_ + ".vrt");
00080 
00081     {
00082         IFstream pointsFile(pointsFileName);
00083 
00084         
00085 
00086         if (pointsFile.good())
00087         {
00088             label pointLabel;
00089             scalar x, y, z;
00090 
00091             maxLabel = -1;
00092             while (pointsFile)
00093             {
00094                 pointLabel = readVtxLabel(pointsFile);
00095 
00096                 if (!pointsFile) break;
00097                 
00098                 maxLabel = max(maxLabel, pointLabel);
00099 
00100                 x = readVtxCmpt(pointsFile);
00101                 y = readVtxCmpt(pointsFile);
00102                 z = readVtxCmpt(pointsFile);
00103 
00104                 readToNl(pointsFile);
00105 
00106                 nPoints++;
00107             }
00108         }
00109         else
00110         {
00111             FatalErrorIn("starMesh::readPoints()")
00112                 << "Cannot read file " << pointsFileName
00113                 << abort(FatalError);
00114         }
00115     }
00116 
00117     Info<< "Number of points = " << nPoints << endl << endl;
00118 
00119     points_.setSize(nPoints);
00120 
00121 #   ifdef starMesh_H
00122     starPointID_.setSize(nPoints);
00123 
00124     
00125     starPointID_ = -1;
00126 #   endif
00127 
00128     starPointLabelLookup_.setSize(maxLabel+1);
00129 
00130     
00131     starPointLabelLookup_ = -1;
00132 
00133     if (nPoints > 0)
00134     {
00135         
00136         
00137 
00138         IFstream pointsFile(pointsFileName);
00139         label pointLabel;
00140 
00141         forAll(points_, p)
00142         {
00143             pointLabel = readVtxLabel(pointsFile);
00144             points_[p].x() = readVtxCmpt(pointsFile);
00145             points_[p].y() = readVtxCmpt(pointsFile);
00146             points_[p].z() = readVtxCmpt(pointsFile);
00147 
00148             readToNl(pointsFile);
00149 
00150 #           ifdef starMesh_H
00151             starPointID_[p] = pointLabel;
00152 #           endif
00153 
00154             starPointLabelLookup_[pointLabel] = p;
00155         }
00156 
00157         if (scaleFactor > 1.0 + SMALL || scaleFactor < 1.0 - SMALL)
00158         {
00159             points_ *= scaleFactor;
00160         }
00161     }
00162     else
00163     {
00164         FatalError
00165             << "void starMesh::readPoints() : "
00166             << "no points in file "
00167             << pointsFileName
00168             << abort(FatalError);
00169     }
00170 }
00171 
00172 
00173