ESyS-Particle  4.0.1
DistConnections.h
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_LSMDISTCONNECTIONS_H
00015 #define ESYS_LSMDISTCONNECTIONS_H
00016 
00017 #include "Geometry/CircularNeighbourTable.h"
00018 #include "Geometry/BasicInteraction.h"
00019 
00020 #include <boost/shared_ptr.hpp>
00021 #include <boost/pool/object_pool.hpp>
00022 
00023 #include <set>
00024 #include <vector>
00025 #include <float.h>
00026 
00027 namespace esys
00028 {
00029   namespace lsm
00030   {
00034     template <typename TmplParticle, typename TmplConnection>
00035     class DistConnections
00036     {
00037     public:
00038       typedef TmplParticle   Particle;
00039       typedef TmplConnection Connection;
00040       typedef int            Tag;
00041 
00042       class Cmp
00043       {
00044       public:
00045         bool operator()(const Connection &c1, const Connection &c2) const
00046         {
00047           return
00048             (
00049               (c1.first() < c2.first())
00050               ||
00051               (
00052                 (c1.first() == c2.first())
00053                 &&
00054                 (
00055                   (c1.second() < c2.second())
00056                   ||
00057                   (
00058                     (c1.second() == c2.second())
00059                     &&
00060                     (c1.getTag() < c2.getTag())
00061                   )
00062                 )
00063               )
00064             );
00065         }
00066         bool operator()(const Connection *c1, const Connection *c2) const
00067         {
00068           return (*this)(*c1, *c2);
00069         }
00070       };
00071     public:
00072       typedef std::set<Connection *,Cmp>             ConnectionSet;
00073       typedef std::vector<Particle *>                ParticleVector;
00074       typedef CircularNeighbourTable<Particle>       NTable;
00075       typedef typename NTable::ParticleIterator      ParticleIterator;
00076       typedef typename NTable::ParticleConstIterator ParticleConstIterator;
00077       
00078     public:
00079       typedef typename NTable::BoolVector BoolVector;
00080 
00081       DistConnections(
00082         double maxDist,
00083         Tag defaultTag = 0,
00084         const BoundingBox &bBox = BoundingBox(Vec3(-10,-10,-10), Vec3(10,10,10)),
00085         const BoolVector  &circDimensions = BoolVector(3, false)
00086       );
00087 
00088       ~DistConnections();
00089 
00090       int getNumParticles() const;
00091 
00092       int getNumConnections() const;
00093 
00094       double getMinRadius() const;
00095 
00096       double getMaxRadius() const;
00097 
00098       ParticleConstIterator getParticleIterator() const;
00099 
00100       BoundingBox getParticleBBox() const;
00101 
00102       template<typename TmplParticleIterator>
00103       void create(TmplParticleIterator it);
00104 
00105       template<typename TmplParticleIterator>
00106       void create(TmplParticleIterator it, Tag tag);
00107 
00108       Tag getDefaultTag() const;
00109       void setDefaultTag(Tag defaultTag);
00110 
00111       typedef ForwardConstIterator<ConnectionSet> ConnectionConstIterator;
00112 
00113       class ConstIterator : public ConnectionConstIterator
00114       {
00115       public:
00116         typedef const Connection& value_type;
00117         typedef const Connection& reference;
00118         ConstIterator(const ConnectionSet &set)
00119          : ConnectionConstIterator(set)
00120         {
00121         }
00122 
00123         value_type next()
00124         {
00125           return *(ConnectionConstIterator::next());
00126         }
00127 
00128         value_type current() const
00129         {
00130           return *(ConnectionConstIterator::current());
00131         }
00132       };
00133       typedef ConstIterator Iterator;
00134 
00135       Iterator getIterator() const
00136       {
00137         return Iterator(m_connectionSet);
00138       }
00139 
00140     protected:
00141       void insert(Particle &p);
00142 
00143       void createConnection(const Particle &p1, const Particle &p2, Tag tag);
00144 
00145     private:
00146       typedef boost::shared_ptr<NTable>         NTablePtr;
00147       typedef boost::object_pool<Connection>    ConnectionPool;
00148       typedef boost::shared_ptr<ConnectionPool> ConnectionPoolPtr;
00149 
00150       ConnectionPoolPtr m_connectionPoolPtr;
00151       ConnectionSet     m_connectionSet;
00152       NTablePtr         m_nTablePtr;
00153       double            m_minRadius;
00154       double            m_maxRadius;
00155       double            m_maxDist;
00156       Vec3              m_minPt;
00157       Vec3              m_maxPt;
00158       Tag               m_defaultTag;
00159     };
00160   }
00161 }
00162 
00163 #include "Geometry/DistConnections.hpp"
00164 
00165 #endif