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