AbstractMesh.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 ABSTRACTMESH_HPP_
00030 #define ABSTRACTMESH_HPP_
00031 
00032 #include "ChasteSerialization.hpp"
00033 #include "ClassIsAbstract.hpp"
00034 
00035 #include "UblasVectorInclude.hpp"
00036 #include "UblasMatrixInclude.hpp"
00037 
00038 #include <vector>
00039 #include <string>
00040 #include <cassert>
00041 
00042 #include "Node.hpp"
00043 #include "DistributedVectorFactory.hpp"
00044 #include "ProcessSpecificArchive.hpp"
00045 #include "ChasteCuboid.hpp"
00046 
00047 #include <boost/utility.hpp>
00048 
00052 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00053 class AbstractMesh : boost::noncopyable
00054 {
00055     template <unsigned A_DIMENSION> friend class NodesOnlyMesh; //NodesOnlyMesh is able to grab the node information in order to copy
00056 private:
00065     virtual unsigned SolveNodeMapping(unsigned index) const = 0;
00066 
00068     friend class boost::serialization::access;
00075     template<class Archive>
00076     void serialize(Archive & archive, const unsigned int version)
00077     {
00078         archive & mMeshChangesDuringSimulation;
00079         (*ProcessSpecificArchive<Archive>::Get()) & mpDistributedVectorFactory;
00080     }
00081 
00082 protected:  // Give access of these variables to subclasses
00083 
00085     std::vector<Node<SPACE_DIM> *> mNodes;
00086 
00088     std::vector<Node<SPACE_DIM> *> mBoundaryNodes;
00089 
00091     DistributedVectorFactory* mpDistributedVectorFactory;
00092 
00098     std::vector<unsigned> mNodesPermutation;
00099 
00104     std::string mMeshFileBaseName;
00105 
00109     bool mMeshChangesDuringSimulation;
00110 
00114     virtual void SetElementOwnerships();
00115 public:
00116 
00118     //                            Iterators                             //
00120 
00122     typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator BoundaryNodeIterator;
00123 
00125     class NodeIterator;
00126 
00132     inline NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true);
00133 
00137     inline NodeIterator GetNodeIteratorEnd();
00138 
00140     //                             Methods                              //
00142 
00146     AbstractMesh();
00147 
00151     virtual ~AbstractMesh();
00152 
00158     virtual unsigned GetNumNodes() const;
00159 
00163     unsigned GetNumBoundaryNodes() const;
00164 
00168     virtual unsigned GetNumAllNodes() const;
00169 
00176     Node<SPACE_DIM>* GetNode(unsigned index) const;
00177 
00184     virtual Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
00185 
00200     Node<SPACE_DIM>* GetNodeFromPrePermutationIndex(unsigned index) const;
00201 
00207     virtual void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00208 
00212     virtual DistributedVectorFactory * GetDistributedVectorFactory();
00213 
00222     virtual void SetDistributedVectorFactory(DistributedVectorFactory* pFactory);
00223 
00228     virtual void PermuteNodes();
00229 
00233     BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const;
00234 
00239     BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const;
00240 
00244     std::string GetMeshFileBaseName() const;
00245 
00251     bool IsMeshOnDisk() const;
00252 
00261     const std::vector<unsigned>& rGetNodePermutation() const;
00262 
00273     virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA,
00274                                                           const c_vector<double, SPACE_DIM>& rLocationB);
00275 
00287     double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
00288 
00297     virtual double GetWidth(const unsigned& rDimension) const;
00298 
00306     virtual ChasteCuboid<SPACE_DIM> CalculateBoundingBox() const;
00307 
00315     virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00316 
00323      void Translate(const c_vector<double, SPACE_DIM>& rDisplacement);
00324 
00332      void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
00333 
00340      void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotationMatrix);
00341 
00348      void Rotate(c_vector<double,3> axis, double angle);
00349 
00355      void RotateX(const double theta);
00356 
00362      void RotateY(const double theta);
00363 
00369      void RotateZ(const double theta);
00370 
00376      void Rotate(double theta);
00377 
00382     virtual void RefreshMesh();
00383 
00387     bool IsMeshChanging() const;
00388 
00393     unsigned CalculateMaximumContainingElementsPerProcess() const;
00394 
00400     void SetMeshHasChangedSinceLoading();
00401 
00403     //                         Nested classes                           //
00405 
00409     class NodeIterator
00410     {
00411     public:
00417         inline Node<SPACE_DIM>& operator*();
00418 
00422         inline Node<SPACE_DIM>* operator->();
00423 
00429         inline bool operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther);
00430 
00434         inline NodeIterator& operator++();
00435 
00446         NodeIterator(AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00447                      typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00448                      bool skipDeletedNodes=true);
00449     private:
00451         AbstractMesh& mrMesh;
00452 
00454         typename std::vector<Node<SPACE_DIM> *>::iterator mNodeIter;
00455 
00457         bool mSkipDeletedNodes;
00458 
00462         inline bool IsAtEnd();
00463 
00467         inline bool IsAllowedNode();
00468     };
00469 
00470 
00471 };
00472 
00473 TEMPLATED_CLASS_IS_ABSTRACT_2_UNSIGNED(AbstractMesh)
00474 
00475 
00476 //      NodeIterator class implementation - most methods are inlined        //
00478 
00479 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00480 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorBegin(
00481         bool skipDeletedNodes)
00482 {
00483     return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
00484 }
00485 
00486 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00487 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorEnd()
00488 {
00489     return NodeIterator(*this, mNodes.end());
00490 }
00491 
00492 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00493 Node<SPACE_DIM>& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator*()
00494 {
00495     assert(!IsAtEnd());
00496     return **mNodeIter;
00497 }
00498 
00499 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00500 Node<SPACE_DIM>* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator->()
00501 {
00502     assert(!IsAtEnd());
00503     return *mNodeIter;
00504 }
00505 
00506 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00507 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther)
00508 {
00509     return mNodeIter != rOther.mNodeIter;
00510 }
00511 
00512 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00513 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator++()
00514 {
00515     do
00516     {
00517         ++mNodeIter;
00518     }
00519     while (!IsAtEnd() && !IsAllowedNode());
00520 
00521     return (*this);
00522 }
00523 
00524 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00525 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::NodeIterator(
00526         AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00527         typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00528         bool skipDeletedNodes)
00529     : mrMesh(rMesh),
00530       mNodeIter(nodeIter),
00531       mSkipDeletedNodes(skipDeletedNodes)
00532 {
00533     if (mrMesh.mNodes.size() == 0)
00534     {
00535         // Cope with empty meshes
00536         mNodeIter = mrMesh.mNodes.end();
00537     }
00538     else
00539     {
00540         // Make sure we start at an allowed node
00541         if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
00542         {
00543             ++(*this);
00544         }
00545     }
00546 }
00547 
00548 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00549 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAtEnd()
00550 {
00551     return mNodeIter == mrMesh.mNodes.end();
00552 }
00553 
00554 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00555 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAllowedNode()
00556 {
00557     return !(mSkipDeletedNodes && (*this)->IsDeleted());
00558 }
00559 
00560 
00561 #endif /*ABSTRACTMESH_HPP_*/
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3