MixedDimensionMesh.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 #ifndef MIXEDDIMENSIONMESH_HPP_
00030 #define MIXEDDIMENSIONMESH_HPP_
00031 
00032 #include "DistributedTetrahedralMesh.hpp"
00033 #include "AbstractMeshReader.hpp"
00034 
00035 #include "ChasteSerialization.hpp"
00036 #include <boost/serialization/base_object.hpp>
00037 
00043 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00044 class MixedDimensionMesh : public DistributedTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>
00045 {
00046 public:
00047 
00053     MixedDimensionMesh(DistributedTetrahedralMeshPartitionType::type partitioningMethod=DistributedTetrahedralMeshPartitionType::METIS_LIBRARY);
00054 
00059     ~MixedDimensionMesh();
00060 
00066     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00067 
00073     void RegisterCableElement(unsigned index);
00074 
00078     unsigned GetNumCableElements() const;
00079 
00083     unsigned GetNumLocalCableElements() const;
00084 
00091     Element<1u, SPACE_DIM>* GetCableElement(unsigned globalElementIndex) const;
00092 
00099      bool CalculateDesignatedOwnershipOfCableElement( unsigned globalElementIndex );
00100 
00101 
00102 private:
00104     std::vector<Element<1u, SPACE_DIM>*> mCableElements;
00106     unsigned mNumCableElements;
00108     std::map<unsigned, unsigned> mCableElementsMapping;
00109 
00111     friend class boost::serialization::access;
00118     template<class Archive>
00119     void serialize(Archive & archive, const unsigned int version)
00120     {
00121         archive & boost::serialization::base_object<DistributedTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00122     }
00123 
00124 public:
00125 
00127     //                            Iterators                             //
00129 
00131     typedef typename std::vector<Element<1, SPACE_DIM> *>::const_iterator CableElementIterator;
00132 
00136     CableElementIterator GetCableElementIteratorBegin() const;
00137 
00142     CableElementIterator GetCableElementIteratorEnd() const;
00143 
00144 
00145 };
00146 
00147 
00148 #include "SerializationExportWrapper.hpp"
00149 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MixedDimensionMesh)
00150 
00151 namespace boost
00152 {
00153 namespace serialization
00154 {
00158 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00159 inline void save_construct_data(
00160     Archive & ar, const MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00161 {
00162     unsigned num_procs = PetscTools::GetNumProcs();
00163     const DistributedTetrahedralMeshPartitionType::type partition_type = t->GetPartitionType();
00164     ar << num_procs;
00165     ar << partition_type;
00166 }
00167 
00172 template<class Archive, unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00173 inline void load_construct_data(
00174     Archive & ar, MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM> * t, const unsigned int file_version)
00175 {
00176     unsigned num_procs;
00177     DistributedTetrahedralMeshPartitionType::type partition_type;
00178 
00179     ar >> num_procs;
00180     ar >> partition_type;
00181 
00182     // Invoke inplace constructor to initialise instance
00184     //::new(t)MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>(partition_type);
00185     ::new(t)MixedDimensionMesh<ELEMENT_DIM, SPACE_DIM>(DistributedTetrahedralMeshPartitionType::DUMB);
00186 
00187     /*
00188      * The exception needs to be thrown after the call to ::new(t), or Boost will try
00189      * to free non-allocated memory when the exception is thrown.
00190      */
00191     if (DistributedVectorFactory::CheckNumberOfProcessesOnLoad() &&
00192         num_procs != PetscTools::GetNumProcs())
00193     {
00194         EXCEPTION("This archive was written for a different number of processors");
00195     }
00196 
00197 }
00198 }
00199 } // namespace ...
00200 
00201 #endif /*MIXEDDIMENSIONMESH_HPP_*/
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3