AbstractCachedMeshReader.cpp
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
00030
00031
00032
00033
00034
00035
00036 #include "AbstractCachedMeshReader.hpp"
00037 #include "Exception.hpp"
00038
00039 #include <fstream>
00040
00042
00044
00045 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00046 AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::AbstractCachedMeshReader()
00047 : mNumNodeAttributes(0),
00048 mMaxNodeBdyMarker(0),
00049 mNumElementNodes(0),
00050 mNumElementAttributes(0),
00051 mMaxFaceBdyMarker(0),
00052 mIndexFromZero(false)
00053 {
00054
00055 }
00056
00057 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00058 std::vector<std::string> AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetRawDataFromFile(
00059 const std::string& rFileName)
00060 {
00061
00062
00063 std::vector<std::string> raw_data;
00064 std::ifstream data_file(rFileName.c_str());
00065
00066
00067
00068 if (!data_file.is_open())
00069 {
00070 EXCEPTION("Could not open data file " + rFileName);
00071 }
00072
00073
00074 std::string raw_line;
00075 getline(data_file, raw_line);
00076
00077 while (data_file)
00078 {
00079
00080
00081
00082 long hash_location = raw_line.find('#', 0);
00083 if (hash_location >= 0)
00084 {
00085 raw_line = raw_line.substr(0, hash_location);
00086 }
00087
00088
00089 long not_blank_location = raw_line.find_first_not_of(" \t", 0);
00090 if (not_blank_location >= 0)
00091 {
00092 raw_data.push_back(raw_line);
00093 }
00094
00095
00096 getline(data_file, raw_line);
00097 }
00098
00099 data_file.close();
00100 return raw_data;
00101 }
00102
00103 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00104 unsigned AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetMaxNodeIndex()
00105 {
00106
00107 std::vector<std::vector<unsigned> >::iterator the_iterator;
00108
00109 unsigned max_node_index = 0;
00110
00111 for (the_iterator = mElementData.begin(); the_iterator < mElementData.end(); the_iterator++)
00112 {
00113 std::vector<unsigned> indices = *the_iterator;
00114
00115 for (unsigned i = 0; i < ELEMENT_DIM+1; i++)
00116 {
00117 if ( indices[i] > max_node_index)
00118 {
00119 max_node_index = indices[i];
00120 }
00121 }
00122 }
00123
00124 return max_node_index;
00125 }
00126
00127 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00128 unsigned AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetMinNodeIndex()
00129 {
00130
00131 std::vector<std::vector<unsigned> >::iterator the_iterator;
00132
00133 unsigned min_node_index = UINT_MAX;
00134
00135 for (the_iterator = mElementData.begin(); the_iterator < mElementData.end(); the_iterator++)
00136 {
00137 std::vector<unsigned> indices = *the_iterator;
00138
00139 for (unsigned i = 0; i < ELEMENT_DIM+1; i++)
00140 {
00141 if (indices[i] < min_node_index)
00142 {
00143 min_node_index = indices[i];
00144 }
00145 }
00146 }
00147
00148 return min_node_index;
00149 }
00150
00151 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00152 std::vector<double> AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetNextNode()
00153 {
00154
00155
00156 if (mpNodeIterator == mNodeData.end())
00157 {
00158 EXCEPTION("All nodes already got");
00159 }
00160
00161 std::vector<double> next_node = *mpNodeIterator;
00162
00163 mpNodeIterator++;
00164
00165 return next_node;
00166 }
00167
00168 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00169 ElementData AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetNextElementData()
00170 {
00171
00172
00173 if (mpElementIterator == mElementData.end())
00174 {
00175 EXCEPTION("All elements already got");
00176 }
00177
00178 ElementData ret;
00179 ret.NodeIndices = *mpElementIterator;
00180 ret.AttributeValue = 0;
00181
00182 mpElementIterator++;
00183
00184 return ret;
00185 }
00186
00187 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00188 void AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::Reset()
00189 {
00190 mpElementIterator = mElementData.begin();
00191 mpFaceIterator = mFaceData.begin();
00192 mpNodeIterator = mNodeData.begin();
00193 }
00194
00195 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00196 ElementData AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetNextFaceData()
00197 {
00198
00199
00200 if (mpFaceIterator == mFaceData.end())
00201 {
00202 EXCEPTION("All faces (or edges) already got");
00203 }
00204
00205 ElementData ret;
00206 ret.NodeIndices = *mpFaceIterator;
00207 ret.AttributeValue = 0;
00208
00209 mpFaceIterator++;
00210
00211 return ret;
00212 }
00213
00214
00215 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00216 unsigned AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetNumElements() const
00217 {
00218 return mElementData.size();
00219 }
00220
00221 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00222 unsigned AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetNumNodes() const
00223 {
00224 return mNodeData.size();
00225 }
00226
00227 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00228 unsigned AbstractCachedMeshReader<ELEMENT_DIM, SPACE_DIM>::GetNumFaces() const
00229 {
00230 return mFaceData.size();
00231 }
00232
00233
00235
00237
00238 template class AbstractCachedMeshReader<1,1>;
00239 template class AbstractCachedMeshReader<1,2>;
00240 template class AbstractCachedMeshReader<1,3>;
00241 template class AbstractCachedMeshReader<2,2>;
00242 template class AbstractCachedMeshReader<2,3>;
00243 template class AbstractCachedMeshReader<3,3>;