ESyS-Particle
4.0.1
|
00001 00002 // // 00003 // Copyright (c) 2003-2011 by The University of Queensland // 00004 // Earth Systems Science Computational Centre (ESSCC) // 00005 // http://www.uq.edu.au/esscc // 00006 // // 00007 // Primary Business: Brisbane, Queensland, Australia // 00008 // Licensed under the Open Software License version 3.0 // 00009 // http://www.opensource.org/licenses/osl-3.0.php // 00010 // // 00012 00013 00014 #ifndef ESYS_LSMGEOMETRYREADER_H 00015 #define ESYS_LSMGEOMETRYREADER_H 00016 00017 #include "Foundation/vec3.h" 00018 #include "Parallel/IterativeReader.h" 00019 #include "Geometry/GeometryInfo.h" 00020 #include "Geometry/SimpleParticleData.h" 00021 00022 #include <string> 00023 #include <vector> 00024 #include <iostream> 00025 00026 typedef std::vector<bool> BoolVector; 00027 typedef std::vector<int> IntVector; 00028 typedef std::vector<Vec3> Vec3Vector; 00029 00033 namespace esys 00034 { 00038 namespace lsm 00039 { 00040 class ParticleIterator : public IStreamIterator<SimpleParticleData> 00041 { 00042 public: 00043 typedef IStreamIterator<SimpleParticleData>::value_type value_type; 00044 00045 ParticleIterator(std::istream &iStream, int numElements, bool is2d = true) 00046 : IStreamIterator<SimpleParticleData>(iStream, numElements), 00047 m_is2d(is2d) 00048 { 00049 } 00050 00051 protected: 00052 virtual void readDataFromStream() 00053 { 00054 IStreamIterator<SimpleParticleData>::readDataFromStream(); 00055 00056 double mass = m_data.getRadius() * m_data.getRadius(); 00057 if (!m_is2d) 00058 { 00059 mass *= m_data.getRadius(); 00060 } 00061 m_data.setMass(mass); 00062 } 00063 00064 private: 00065 bool m_is2d; 00066 }; 00067 00071 class ParticleReader : public IterativeReader<ParticleIterator> 00072 { 00073 public: 00077 ParticleReader(std::istream &iStream, bool is2d); 00078 00084 virtual void initialise(); 00085 00089 const std::string &getParticleType(); 00090 00091 protected: 00092 virtual ParticleIterator *createNewIterator(); 00093 00094 private: 00095 std::string m_particleType; 00096 bool m_is2d; 00097 }; 00098 00102 class SimpleConnectionData 00103 { 00104 public: 00105 typedef SimpleParticleData::Id Id; 00106 typedef SimpleParticleData::Tag Tag; 00107 00108 SimpleConnectionData(); 00109 00110 SimpleConnectionData(Id p1Id, Id p2Id, Tag tag); 00111 00112 bool operator==(const SimpleConnectionData &particleData) const; 00113 00114 const Id &getP1Id() const; 00115 00116 const Id &getP2Id() const; 00117 00118 const Tag &getTag() const; 00119 00120 void read(std::istream &istream); 00121 00122 void write(std::ostream &write) const; 00123 00124 private: 00125 Id m_particle1Id; 00126 Id m_particle2Id; 00127 Tag m_tag; 00128 }; 00129 00130 std::istream &operator>>(std::istream &iStream, SimpleConnectionData &connectionData); 00131 std::ostream &operator<<(std::ostream &oStream, const SimpleConnectionData &connectionData); 00132 00136 class ConnectionReader : public IterativeReader<IStreamIterator<SimpleConnectionData> > 00137 { 00138 public: 00142 ConnectionReader(std::istream &iStream); 00143 00149 virtual void initialise(); 00150 00151 private: 00152 }; 00153 00158 class GeometryReader 00159 { 00160 public: 00161 typedef ParticleReader::Iterator ParticleIterator; 00162 typedef ConnectionReader::Iterator ConnectionIterator; 00171 GeometryReader(const std::string &fileName); 00172 00181 GeometryReader(std::istream &iStream); 00182 00186 virtual ~GeometryReader(); 00187 00192 const std::string &getFileName() const; 00193 00197 const std::string &getParticleType(); 00198 00203 const GeometryInfo &getGeometryInfo() const; 00204 00208 ParticleIterator &getParticleIterator(); 00209 00213 ConnectionIterator &getConnectionIterator(); 00214 00215 protected: 00219 void initialise(); 00220 00221 private: 00222 GeometryReader(const GeometryReader &geoReader); 00223 GeometryReader &operator=(const GeometryReader &geoReader) const; 00224 00225 class Impl; 00226 00227 Impl *m_pImpl; 00228 }; 00229 }; // namespace lsm 00230 }; // namespace esys 00231 00232 #endif