ChasteNodesList.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 
00029 
00030 #ifndef CHASTENODESLIST_HPP_
00031 #define CHASTENODESLIST_HPP_
00032 
00033 #include "ChasteSerialization.hpp"
00034 #include <boost/serialization/base_object.hpp>
00035 
00036 #include "AbstractChasteRegion.hpp"
00037 #include "Node.hpp"
00038 #include "ChastePoint.hpp"
00039 
00040 #include <vector>
00041 using namespace std;
00046 template <unsigned SPACE_DIM>
00047 class ChasteNodesList : public AbstractChasteRegion<SPACE_DIM>
00048 {
00050     friend class boost::serialization::access;
00057     template<class Archive>
00058     void serialize(Archive & archive, const unsigned int version)
00059     {
00060         archive & boost::serialization::base_object<AbstractChasteRegion<SPACE_DIM> >(*this);
00061     }
00062 
00063 private:
00064 
00066     std::vector< Node<SPACE_DIM>*> mListOfNodes;
00067 
00069     bool mOwnNodes;
00070 
00071 public:
00072 
00079     ChasteNodesList(const std::vector<Node<SPACE_DIM>*> rNodesList,
00080                     bool ownNodes=false);
00081 
00085     ~ChasteNodesList();
00086 
00088     const std::vector< Node<SPACE_DIM>*>& rGetNodesList() const;
00089 
00095     bool DoesContain(const ChastePoint<SPACE_DIM>& rPointToCheck) const;
00096 
00100     unsigned GetSize() const;
00101     
00102 };
00103 
00104 // Declare identifier for the serializer
00105 #include "SerializationExportWrapper.hpp"
00106 EXPORT_TEMPLATE_CLASS_SAME_DIMS(ChasteNodesList)
00107 
00108 namespace boost
00109 {
00110 namespace serialization
00111 {
00112 
00113 template<class Archive, unsigned SPACE_DIM>
00114 inline void save_construct_data(
00115     Archive & ar, const ChasteNodesList<SPACE_DIM> * t, const unsigned int file_version)
00116 {
00117     const std::vector<Node<SPACE_DIM>* > node_list = t->rGetNodesList();
00118 
00119     //archive the size first
00120     unsigned size = t->GetSize();
00121     ar & size;
00122 
00123     //The ChastePoints have to be at unique addresses, otherwise Boost thinks that the first archive is sufficient
00124     std::vector <ChastePoint<SPACE_DIM>* > point_list;
00125     
00126     for (unsigned i = 0; i < node_list.size(); i++)
00127     {
00128         c_vector<double, SPACE_DIM> loc =  node_list[i]->rGetLocation();
00129         point_list.push_back(new  ChastePoint<SPACE_DIM>(loc));
00130         ar & point_list[i];
00131         unsigned index = node_list[i]->GetIndex();
00132         ar & index;
00133     }
00134     //Clean memory
00135     for (unsigned i = 0; i < point_list.size(); i++)
00136     {
00137         delete point_list[i];
00138     }
00139 }
00140 
00145 template<class Archive, unsigned SPACE_DIM>
00146 inline void load_construct_data(
00147     Archive & ar, ChasteNodesList<SPACE_DIM> * t, const unsigned int file_version)
00148 {
00149     //unarchive the size
00150     unsigned size;
00151     ar & size;
00152 
00153     std::vector<Node<SPACE_DIM>* > node_list;
00154 
00155     //rebuild the node list based on the unarchived points and indices
00156     for (unsigned i = 0; i < size; i++)
00157     {
00158         ChastePoint<SPACE_DIM>* p_point;
00159         unsigned index;
00160         ar & p_point;
00161         ar & index;
00162 
00163         Node<SPACE_DIM>* p_node = new Node<SPACE_DIM>( index, *(p_point));
00164         node_list.push_back(p_node);
00165 
00166         delete p_point;//not needed any longer
00167     }
00168 
00169     ::new(t)ChasteNodesList<SPACE_DIM>(node_list, true);
00170 
00171 }
00172 }
00173 } // namespace ...
00174 
00175 #endif /*CHASTENODESLIST_HPP_*/

Generated on Tue May 31 14:31:48 2011 for Chaste by  doxygen 1.5.5