AbstractMesh.hpp

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 
00029 #ifndef ABSTRACTMESH_HPP_
00030 #define ABSTRACTMESH_HPP_
00031 
00032 #include <boost/serialization/access.hpp>
00033 #include <boost/serialization/is_abstract.hpp>
00034 
00035 #include <vector>
00036 #include <string>
00037 #include <cassert>
00038 
00039 #include "Node.hpp"
00040 #include "DistributedVectorFactory.hpp"
00041 
00045 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00046 class AbstractMesh
00047 {
00048 private:
00057     virtual unsigned SolveNodeMapping(unsigned index) const = 0;
00058 
00060     friend class boost::serialization::access;
00067     template<class Archive>
00068     void serialize(Archive & archive, const unsigned int version)
00069     {
00070         archive & mMeshChangesDuringSimulation;
00071     }
00072 
00073 protected:  // Give access of these variables to subclasses
00074 
00076     std::vector<Node<SPACE_DIM> *> mNodes;
00077 
00079     std::vector<Node<SPACE_DIM> *> mBoundaryNodes;
00080 
00082     DistributedVectorFactory *mpDistributedVectorFactory;
00083 
00085     std::vector<unsigned> mNodesPermutation;
00086 
00091     std::string mMeshFileBaseName;
00092 
00096     bool mMeshChangesDuringSimulation;
00097 
00098 public:
00099 
00101     //                            Iterators                             //
00103 
00105     typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator BoundaryNodeIterator;
00106 
00108     class NodeIterator;
00109 
00115     inline NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true);
00116 
00120     inline NodeIterator GetNodeIteratorEnd();
00121 
00123     //                             Methods                              //
00125 
00129     AbstractMesh();
00130 
00134     virtual ~AbstractMesh();
00135 
00141     virtual unsigned GetNumNodes() const;
00142 
00146     unsigned GetNumBoundaryNodes() const;
00147 
00151     unsigned GetNumAllNodes() const;
00152 
00159     Node<SPACE_DIM>* GetNode(unsigned index) const;
00160 
00166     virtual void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00167 
00171     DistributedVectorFactory * GetDistributedVectorFactory();
00172 
00177     virtual void PermuteNodes();
00178 
00182     BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const;
00183 
00188     BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const;
00189 
00193     std::string GetMeshFileBaseName() const;
00194 
00198     const std::vector<unsigned>& rGetNodePermutation() const;
00199 
00210     virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA,
00211                                                           const c_vector<double, SPACE_DIM>& rLocationB);
00212 
00224     double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
00225 
00234     virtual double GetWidth(const unsigned& rDimension) const;
00235 
00242     c_vector<double,2> GetWidthExtremes(const unsigned& rDimension) const;
00243 
00251     void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00252 
00257     virtual void RefreshMesh();
00258 
00262     bool IsMeshChanging() const;
00263 
00265     //                         Nested classes                           //
00267 
00271     class NodeIterator
00272     {
00273     public:
00279         inline Node<SPACE_DIM>& operator*();
00280 
00284         inline Node<SPACE_DIM>* operator->();
00285 
00291         inline bool operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther);
00292 
00296         inline NodeIterator& operator++();
00297 
00308         NodeIterator(AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00309                      typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00310                      bool skipDeletedNodes=true);
00311     private:
00313         AbstractMesh& mrMesh;
00314 
00316         typename std::vector<Node<SPACE_DIM> *>::iterator mNodeIter;
00317 
00319         bool mSkipDeletedNodes;
00320 
00324         inline bool IsAtEnd();
00325 
00329         inline bool IsAllowedNode();
00330     };
00331 
00332 
00333 };
00334 
00335 namespace boost
00336 {
00337 namespace serialization
00338 {
00344 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00345 struct is_abstract<AbstractMesh<ELEMENT_DIM, SPACE_DIM> >
00346 {
00348     typedef mpl::bool_<true> type;
00350     BOOST_STATIC_CONSTANT(bool, value=true);
00351 };
00352 }
00353 }
00354 
00356 //      NodeIterator class implementation - most methods are inlined        //
00358 
00359 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00360 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorBegin(
00361         bool skipDeletedNodes)
00362 {
00363     return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
00364 }
00365 
00366 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00367 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorEnd()
00368 {
00369     return NodeIterator(*this, mNodes.end());
00370 }
00371 
00372 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00373 Node<SPACE_DIM>& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator*()
00374 {
00375     assert(!IsAtEnd());
00376     return **mNodeIter;
00377 }
00378 
00379 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00380 Node<SPACE_DIM>* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator->()
00381 {
00382     assert(!IsAtEnd());
00383     return *mNodeIter;
00384 }
00385 
00386 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00387 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther)
00388 {
00389     return mNodeIter != rOther.mNodeIter;
00390 }
00391 
00392 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00393 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator++()
00394 {
00395     do
00396     {
00397         ++mNodeIter;
00398     }
00399     while (!IsAtEnd() && !IsAllowedNode());
00400 
00401     return (*this);
00402 }
00403 
00404 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00405 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::NodeIterator(
00406         AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00407         typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00408         bool skipDeletedNodes)
00409     : mrMesh(rMesh),
00410       mNodeIter(nodeIter),
00411       mSkipDeletedNodes(skipDeletedNodes)
00412 {
00413     if (mrMesh.mNodes.size() == 0)
00414     {
00415         // Cope with empty meshes
00416         mNodeIter = mrMesh.mNodes.end();
00417     }
00418     else
00419     {
00420         // Make sure we start at an allowed node
00421         if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
00422         {
00423             ++(*this);
00424         }
00425     }
00426 }
00427 
00428 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00429 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAtEnd()
00430 {
00431     return mNodeIter == mrMesh.mNodes.end();
00432 }
00433 
00434 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00435 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAllowedNode()
00436 {
00437     return !(mSkipDeletedNodes && (*this)->IsDeleted());
00438 }
00439 
00440 
00441 #endif /*ABSTRACTMESH_HPP_*/

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5