00001 /* 00002 00003 Copyright (C) University of Oxford, 2005-2009 00004 00005 University of Oxford means the Chancellor, Masters and Scholars of the 00006 University of Oxford, having an administrative office at Wellington 00007 Square, Oxford OX1 2JD, UK. 00008 00009 This file is part of Chaste. 00010 00011 Chaste is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU Lesser General Public License as published 00013 by the Free Software Foundation, either version 2.1 of the License, or 00014 (at your option) any later version. 00015 00016 Chaste is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00019 License for more details. The offer of Chaste under the terms of the 00020 License is subject to the License being interpreted in accordance with 00021 English Law and subject to any action against the University of Oxford 00022 being under the jurisdiction of the English Courts. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>. 00026 00027 */ 00028 #ifndef NODEBOXCOLLECTION_HPP_ 00029 #define NODEBOXCOLLECTION_HPP_ 00030 00031 #include "Node.hpp" 00032 00033 00038 template<unsigned DIM> 00039 class NodeBox 00040 { 00041 private: 00042 00044 c_vector<double, 2*DIM> mMinAndMaxValues; 00045 00047 std::set< Node<DIM>* > mNodesContained; 00048 00049 public: 00050 00056 NodeBox(c_vector<double, 2*DIM> minAndMaxValues); 00057 00059 c_vector<double, 2*DIM>& rGetMinAndMaxValues(); 00060 00066 void AddNode(Node<DIM>* pNode); 00067 00073 void RemoveNode(Node<DIM>* pNode); 00074 00076 std::set< Node<DIM>* >& rGetNodesContained(); 00077 }; 00078 00079 00085 template<unsigned DIM> 00086 class NodeBoxCollection 00087 { 00088 private: 00089 00091 std::vector< NodeBox<DIM> > mBoxes; 00092 00094 c_vector<double,2*DIM> mDomainSize; 00095 00097 double mCutOffLength; 00098 00100 c_vector<unsigned,DIM> mNumBoxesEachDirection; 00101 00103 std::vector< std::set<unsigned> > mLocalBoxes; 00104 00111 bool IsBottomRow(unsigned boxIndex) 00112 { 00113 return boxIndex % mNumBoxesEachDirection(1)==0; 00114 } 00115 00122 bool IsTopRow(unsigned boxIndex) 00123 { 00124 return boxIndex % mNumBoxesEachDirection(1)==mNumBoxesEachDirection(1)-1; 00125 } 00126 00133 bool IsLeftColumn(unsigned boxIndex) 00134 { 00135 return boxIndex < mNumBoxesEachDirection(1); 00136 } 00137 00144 bool IsRightColumn(unsigned boxIndex) 00145 { 00146 return boxIndex >= mBoxes.size() - mNumBoxesEachDirection(1); 00147 } 00148 00149 public: 00150 00157 NodeBoxCollection(double cutOffLength, c_vector<double, 2*DIM> domainSize); 00158 00164 unsigned CalculateContainingBox(Node<DIM>* pNode); 00165 00172 NodeBox<DIM>& rGetBox(unsigned boxIndex); 00173 00175 unsigned GetNumBoxes(); 00176 00178 void CalculateLocalBoxes(); 00179 00185 std::set<unsigned> GetLocalBoxes(unsigned boxIndex); 00186 00196 void CalculateNodePairs(std::vector<Node<DIM>*>& rNodes, std::set<std::pair<Node<DIM>*, Node<DIM>*> >& rNodePairs); 00197 }; 00198 00199 00200 #endif /*NODEBOXCOLLECTION_HPP_*/