ESyS-Particle  4.0.1
BoxPacker.hpp
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 #include "Geometry/GridIterator.h"
00015 #include <float.h>
00016 
00017 namespace esys
00018 {
00019   namespace lsm
00020   {
00021     template <typename TmplPackerBase>
00022     BoxPacker<TmplPackerBase>::BoxPacker(
00023       ParticlePoolPtr   particlePoolPtr,
00024       NTablePtr         nTablePtr,
00025       const BoundingBox &bBox,
00026       const BoolVector  &periodicDimensions,
00027       double            tolerance
00028     ) : Inherited(particlePoolPtr, nTablePtr),
00029         m_bBox(bBox),
00030         m_periodicDimensions(periodicDimensions),
00031         m_tolerance(tolerance)
00032     {
00033     }
00034 
00035     template <typename TmplPackerBase>
00036     BoxPacker<TmplPackerBase>::~BoxPacker()
00037     {
00038     }
00039 
00040     template <typename TmplPackerBase>
00041     const BoundingBox &BoxPacker<TmplPackerBase>::getBBox() const
00042     {
00043       return m_bBox;
00044     }
00045 
00046     template <typename TmplPackerBase>
00047     double BoxPacker<TmplPackerBase>::getTolerance() const
00048     {
00049       return m_tolerance;
00050     }
00051 
00052     template <typename TmplPackerBase>
00053     bool BoxPacker<TmplPackerBase>::is2d() const
00054     {
00055       return ((getBBox().getMaxPt().Z() - getBBox().getMinPt().Z()) <= 0);
00056     }
00057 
00058     template <typename TmplPackerBase>
00059     const BoolVector &
00060     BoxPacker<TmplPackerBase>::getPeriodicDimensions() const
00061     {
00062       return m_periodicDimensions;
00063     }
00064 
00065     template <typename TmplPackerBase>
00066     bool BoxPacker<TmplPackerBase>::particleFitsInBBox(
00067       const Particle &particle
00068     ) const
00069     {
00070       return
00071         (
00072           (
00073             m_periodicDimensions[0]
00074             ||
00075             (
00076               m_bBox.contains(
00077                 particle.getPos() - Vec3(particle.getRad(), 0, 0),
00078                 getTolerance()
00079               )
00080               &&
00081               m_bBox.contains(
00082                 particle.getPos() + Vec3(particle.getRad(), 0, 0),
00083                 getTolerance()
00084               )
00085             )
00086           )
00087           &&
00088           (
00089             m_periodicDimensions[1]
00090             ||
00091             (
00092               m_bBox.contains(
00093                 particle.getPos() - Vec3(0, particle.getRad(), 0),
00094                 getTolerance()
00095               )
00096               &&
00097               m_bBox.contains(
00098                 particle.getPos() + Vec3(0, particle.getRad(), 0),
00099                 getTolerance()
00100               )
00101             )
00102           )
00103           &&
00104           (
00105             is2d() || m_periodicDimensions[2]
00106             ||
00107             (
00108               m_bBox.contains(
00109                 particle.getPos() - Vec3(0, 0, particle.getRad()),
00110                 getTolerance()
00111               )
00112               &&
00113               m_bBox.contains(
00114                 particle.getPos() + Vec3(0, 0, particle.getRad()),
00115                 getTolerance()
00116               )
00117             )
00118           )
00119         );
00120     }
00121 
00122     template <typename TmplPackerBase>
00123     bool BoxPacker<TmplPackerBase>::particleFitsWithNeighbours(
00124       const Particle &particle
00125     ) const
00126     {
00127       const typename NTable::ParticleVector neighbours = 
00128         this->getNTable().getNeighbourVector(
00129           particle.getPos(),
00130           particle.getRad() + getTolerance()
00131         );
00132       typename NTable::ParticleVector::const_iterator iter = neighbours.begin();
00133       for (; iter != neighbours.end(); iter++) {
00134         const double interCentreDistSqrd =
00135           (particle.getPos() - (*iter)->getPos()).norm2();
00136         const double radiusSum =
00137           ((particle.getRad() + (*iter)->getRad()) - getTolerance());
00138         if (interCentreDistSqrd < (radiusSum*radiusSum)) {
00139           return false;
00140         }
00141       }
00142       return true;
00143     }
00144 
00145     template <typename TmplPackerBase>
00146     bool BoxPacker<TmplPackerBase>::particleFitsInBBoxWithNeighbours(
00147       const Particle &particle
00148     ) const
00149     {
00150       return
00151         (
00152           particleFitsInBBox(particle)
00153           &&
00154           particleFitsWithNeighbours(particle)
00155         );
00156     }
00157   };
00158 };