AbstractMesh.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
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 private:
00064     virtual unsigned SolveNodeMapping(unsigned index) const = 0;
00065 
00067     friend class boost::serialization::access;
00074     template<class Archive>
00075     void serialize(Archive & archive, const unsigned int version)
00076     {
00077         archive & mMeshChangesDuringSimulation;
00078         (*ProcessSpecificArchive<Archive>::Get()) & mpDistributedVectorFactory;
00079     }
00080 
00081 protected:  // Give access of these variables to subclasses
00082 
00084     std::vector<Node<SPACE_DIM> *> mNodes;
00085 
00087     std::vector<Node<SPACE_DIM> *> mBoundaryNodes;
00088 
00090     DistributedVectorFactory* mpDistributedVectorFactory;
00091 
00097     std::vector<unsigned> mNodesPermutation;
00098 
00103     std::string mMeshFileBaseName;
00104 
00108     bool mMeshChangesDuringSimulation;
00109 
00110 public:
00111 
00113     //                            Iterators                             //
00115 
00117     typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator BoundaryNodeIterator;
00118 
00120     class NodeIterator;
00121 
00127     inline NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true);
00128 
00132     inline NodeIterator GetNodeIteratorEnd();
00133 
00135     //                             Methods                              //
00137 
00141     AbstractMesh();
00142 
00146     virtual ~AbstractMesh();
00147 
00153     virtual unsigned GetNumNodes() const;
00154 
00158     unsigned GetNumBoundaryNodes() const;
00159 
00163     virtual unsigned GetNumAllNodes() const;
00164 
00171     Node<SPACE_DIM>* GetNode(unsigned index) const;
00172 
00179     virtual Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
00180 
00195     Node<SPACE_DIM>* GetNodeFromPrePermutationIndex(unsigned index) const;
00196 
00202     virtual void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00203 
00207     DistributedVectorFactory * GetDistributedVectorFactory();
00208 
00217     virtual void SetDistributedVectorFactory(DistributedVectorFactory* pFactory);
00218 
00223     virtual void PermuteNodes();
00224 
00228     BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const;
00229 
00234     BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const;
00235 
00239     std::string GetMeshFileBaseName() const;
00240 
00249     const std::vector<unsigned>& rGetNodePermutation() const;
00250 
00261     virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA,
00262                                                           const c_vector<double, SPACE_DIM>& rLocationB);
00263 
00275     double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
00276 
00285     virtual double GetWidth(const unsigned& rDimension) const;
00286 
00294     virtual ChasteCuboid<SPACE_DIM> CalculateBoundingBox() const;
00295 
00303     virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00304 
00311      void Translate(const c_vector<double, SPACE_DIM>& rDisplacement);
00312 
00320      void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
00321 
00328      void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotationMatrix);
00329 
00336      void Rotate(c_vector<double,3> axis, double angle);
00337 
00343      void RotateX(const double theta);
00344 
00350      void RotateY(const double theta);
00351 
00357      void RotateZ(const double theta);
00358 
00364      void Rotate(double theta);
00365 
00370     virtual void RefreshMesh();
00371 
00375     bool IsMeshChanging() const;
00376 
00377 
00382     unsigned CalculateMaximumContainingElementsPerProcess() const;
00383 
00389     void SetMeshHasChangedSinceLoading();
00390 
00392     //                         Nested classes                           //
00394 
00398     class NodeIterator
00399     {
00400     public:
00406         inline Node<SPACE_DIM>& operator*();
00407 
00411         inline Node<SPACE_DIM>* operator->();
00412 
00418         inline bool operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther);
00419 
00423         inline NodeIterator& operator++();
00424 
00435         NodeIterator(AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00436                      typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00437                      bool skipDeletedNodes=true);
00438     private:
00440         AbstractMesh& mrMesh;
00441 
00443         typename std::vector<Node<SPACE_DIM> *>::iterator mNodeIter;
00444 
00446         bool mSkipDeletedNodes;
00447 
00451         inline bool IsAtEnd();
00452 
00456         inline bool IsAllowedNode();
00457     };
00458 
00459 
00460 };
00461 
00462 TEMPLATED_CLASS_IS_ABSTRACT_2_UNSIGNED(AbstractMesh)
00463 
00464 
00465 //      NodeIterator class implementation - most methods are inlined        //
00467 
00468 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00469 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorBegin(
00470         bool skipDeletedNodes)
00471 {
00472     return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
00473 }
00474 
00475 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00476 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorEnd()
00477 {
00478     return NodeIterator(*this, mNodes.end());
00479 }
00480 
00481 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00482 Node<SPACE_DIM>& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator*()
00483 {
00484     assert(!IsAtEnd());
00485     return **mNodeIter;
00486 }
00487 
00488 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00489 Node<SPACE_DIM>* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator->()
00490 {
00491     assert(!IsAtEnd());
00492     return *mNodeIter;
00493 }
00494 
00495 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00496 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther)
00497 {
00498     return mNodeIter != rOther.mNodeIter;
00499 }
00500 
00501 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00502 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator++()
00503 {
00504     do
00505     {
00506         ++mNodeIter;
00507     }
00508     while (!IsAtEnd() && !IsAllowedNode());
00509 
00510     return (*this);
00511 }
00512 
00513 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00514 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::NodeIterator(
00515         AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00516         typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00517         bool skipDeletedNodes)
00518     : mrMesh(rMesh),
00519       mNodeIter(nodeIter),
00520       mSkipDeletedNodes(skipDeletedNodes)
00521 {
00522     if (mrMesh.mNodes.size() == 0)
00523     {
00524         // Cope with empty meshes
00525         mNodeIter = mrMesh.mNodes.end();
00526     }
00527     else
00528     {
00529         // Make sure we start at an allowed node
00530         if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
00531         {
00532             ++(*this);
00533         }
00534     }
00535 }
00536 
00537 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00538 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAtEnd()
00539 {
00540     return mNodeIter == mrMesh.mNodes.end();
00541 }
00542 
00543 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00544 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAllowedNode()
00545 {
00546     return !(mSkipDeletedNodes && (*this)->IsDeleted());
00547 }
00548 
00549 
00550 #endif /*ABSTRACTMESH_HPP_*/

Generated on Mon Nov 1 12:35:23 2010 for Chaste by  doxygen 1.5.5