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 #ifndef ESYS_LSMGRAINCOLLECTION_H 00014 #define ESYS_LSMGRAINCOLLECTION_H 00015 00016 #include "Foundation/StlIterator.h" 00017 #include <boost/shared_ptr.hpp> 00018 #include <boost/pool/object_pool.hpp> 00019 00020 #include <vector> 00021 00022 namespace esys 00023 { 00024 namespace lsm 00025 { 00029 template <typename TmplGrain> 00030 class GrainCollection 00031 { 00032 public: 00033 typedef TmplGrain Grain; 00034 typedef typename Grain::Particle Particle; 00035 typedef typename Grain::ParticleCollection ParticleCollection; 00036 typedef typename ParticleCollection::ParticlePool ParticlePool; 00037 typedef typename ParticleCollection::ParticlePoolPtr ParticlePoolPtr; 00038 typedef typename ParticleCollection::ParticleIterator ParticleIterator; 00039 typedef typename ParticleCollection::ParticleConstIterator ParticleConstIterator; 00040 typedef boost::object_pool<Grain> GrainPool; 00041 typedef boost::shared_ptr<GrainPool> GrainPoolPtr; 00042 typedef std::vector<Grain *> GrainVector; 00043 00044 protected: 00045 typedef ForwardIterator<GrainVector> VectorIterator; 00046 typedef ForwardConstIterator<GrainVector> VectorConstIterator; 00047 00048 public: 00049 00050 class GrainIterator : public VectorIterator 00051 { 00052 public: 00053 typedef Grain& value_type; 00054 GrainIterator(const VectorIterator &it) 00055 : VectorIterator(it) 00056 { 00057 } 00058 00059 value_type next() 00060 { 00061 return *(VectorIterator::next()); 00062 } 00063 00064 value_type current() const 00065 { 00066 return *(VectorIterator::current()); 00067 } 00068 }; 00069 00070 class GrainConstIterator : public VectorConstIterator 00071 { 00072 public: 00073 typedef const Grain& value_type; 00074 GrainConstIterator (const VectorConstIterator &it) 00075 : VectorConstIterator(it) 00076 { 00077 } 00078 00079 GrainConstIterator (const VectorIterator &it) 00080 : VectorConstIterator(it) 00081 { 00082 } 00083 00084 value_type next() 00085 { 00086 return *(VectorConstIterator::next()); 00087 } 00088 00089 value_type current() const 00090 { 00091 return *(VectorConstIterator::current()); 00092 } 00093 }; 00094 00095 GrainCollection(); 00096 00097 GrainCollection(ParticlePoolPtr particlePoolPtr); 00098 00099 GrainCollection(ParticlePoolPtr particlePoolPtr, GrainPoolPtr grainPoolPtr); 00100 00101 virtual ~GrainCollection(); 00102 00106 int getNumGrains() const; 00107 00112 int getNumParticles() const; 00113 00121 void insertRef(Grain &g); 00122 00127 Grain &createGrain(); 00128 00134 Grain &createGrain(typename Grain::Id id); 00135 00141 Grain &createGrain(const Grain &g); 00142 00143 GrainIterator getGrainIterator(); 00144 00145 GrainConstIterator getGrainIterator() const; 00146 00147 protected: 00148 ParticlePoolPtr getParticlePoolPtr(); 00149 00150 GrainPoolPtr getGrainPoolPtr(); 00151 00152 private: 00153 ParticlePoolPtr m_particlePoolPtr; 00154 GrainPoolPtr m_grainPoolPtr; 00155 GrainVector m_grainVector; 00156 }; 00157 }; 00158 }; 00159 00160 #include "Geometry/GrainCollection.hpp" 00161 00162 #endif