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 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 
00113     virtual void SetElementOwnerships();
00114 public:
00115 
00117     //                            Iterators                             //
00119 
00121     typedef typename std::vector<Node<SPACE_DIM> *>::const_iterator BoundaryNodeIterator;
00122 
00124     class NodeIterator;
00125 
00131     inline NodeIterator GetNodeIteratorBegin(bool skipDeletedNodes=true);
00132 
00136     inline NodeIterator GetNodeIteratorEnd();
00137 
00139     //                             Methods                              //
00141 
00145     AbstractMesh();
00146 
00150     virtual ~AbstractMesh();
00151 
00157     virtual unsigned GetNumNodes() const;
00158 
00162     unsigned GetNumBoundaryNodes() const;
00163 
00167     virtual unsigned GetNumAllNodes() const;
00168 
00175     Node<SPACE_DIM>* GetNode(unsigned index) const;
00176 
00183     virtual Node<SPACE_DIM>* GetNodeOrHaloNode(unsigned index) const;
00184 
00199     Node<SPACE_DIM>* GetNodeFromPrePermutationIndex(unsigned index) const;
00200 
00206     virtual void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00207 
00211     virtual DistributedVectorFactory * GetDistributedVectorFactory();
00212 
00221     virtual void SetDistributedVectorFactory(DistributedVectorFactory* pFactory);
00222 
00227     virtual void PermuteNodes();
00228 
00232     BoundaryNodeIterator GetBoundaryNodeIteratorBegin() const;
00233 
00238     BoundaryNodeIterator GetBoundaryNodeIteratorEnd() const;
00239 
00243     std::string GetMeshFileBaseName() const;
00244 
00250     bool IsMeshOnDisk() const;
00251 
00260     const std::vector<unsigned>& rGetNodePermutation() const;
00261 
00272     virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA,
00273                                                           const c_vector<double, SPACE_DIM>& rLocationB);
00274 
00286     double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
00287 
00296     virtual double GetWidth(const unsigned& rDimension) const;
00297 
00305     virtual ChasteCuboid<SPACE_DIM> CalculateBoundingBox() const;
00306 
00314     virtual void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00315 
00322      void Translate(const c_vector<double, SPACE_DIM>& rDisplacement);
00323 
00331      void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
00332 
00339      void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotationMatrix);
00340 
00347      void Rotate(c_vector<double,3> axis, double angle);
00348 
00354      void RotateX(const double theta);
00355 
00361      void RotateY(const double theta);
00362 
00368      void RotateZ(const double theta);
00369 
00375      void Rotate(double theta);
00376 
00381     virtual void RefreshMesh();
00382 
00386     bool IsMeshChanging() const;
00387 
00392     unsigned CalculateMaximumContainingElementsPerProcess() const;
00393 
00399     void SetMeshHasChangedSinceLoading();
00400 
00402     //                         Nested classes                           //
00404 
00408     class NodeIterator
00409     {
00410     public:
00416         inline Node<SPACE_DIM>& operator*();
00417 
00421         inline Node<SPACE_DIM>* operator->();
00422 
00428         inline bool operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther);
00429 
00433         inline NodeIterator& operator++();
00434 
00445         NodeIterator(AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00446                      typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00447                      bool skipDeletedNodes=true);
00448     private:
00450         AbstractMesh& mrMesh;
00451 
00453         typename std::vector<Node<SPACE_DIM> *>::iterator mNodeIter;
00454 
00456         bool mSkipDeletedNodes;
00457 
00461         inline bool IsAtEnd();
00462 
00466         inline bool IsAllowedNode();
00467     };
00468 
00469 
00470 };
00471 
00472 TEMPLATED_CLASS_IS_ABSTRACT_2_UNSIGNED(AbstractMesh)
00473 
00474 
00475 //      NodeIterator class implementation - most methods are inlined        //
00477 
00478 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00479 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorBegin(
00480         bool skipDeletedNodes)
00481 {
00482     return NodeIterator(*this, mNodes.begin(), skipDeletedNodes);
00483 }
00484 
00485 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00486 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator AbstractMesh<ELEMENT_DIM, SPACE_DIM>::GetNodeIteratorEnd()
00487 {
00488     return NodeIterator(*this, mNodes.end());
00489 }
00490 
00491 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00492 Node<SPACE_DIM>& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator*()
00493 {
00494     assert(!IsAtEnd());
00495     return **mNodeIter;
00496 }
00497 
00498 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00499 Node<SPACE_DIM>* AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator->()
00500 {
00501     assert(!IsAtEnd());
00502     return *mNodeIter;
00503 }
00504 
00505 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00506 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator!=(const AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& rOther)
00507 {
00508     return mNodeIter != rOther.mNodeIter;
00509 }
00510 
00511 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00512 typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator& AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::operator++()
00513 {
00514     do
00515     {
00516         ++mNodeIter;
00517     }
00518     while (!IsAtEnd() && !IsAllowedNode());
00519 
00520     return (*this);
00521 }
00522 
00523 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00524 AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::NodeIterator(
00525         AbstractMesh<ELEMENT_DIM, SPACE_DIM>& rMesh,
00526         typename std::vector<Node<SPACE_DIM> *>::iterator nodeIter,
00527         bool skipDeletedNodes)
00528     : mrMesh(rMesh),
00529       mNodeIter(nodeIter),
00530       mSkipDeletedNodes(skipDeletedNodes)
00531 {
00532     if (mrMesh.mNodes.size() == 0)
00533     {
00534         // Cope with empty meshes
00535         mNodeIter = mrMesh.mNodes.end();
00536     }
00537     else
00538     {
00539         // Make sure we start at an allowed node
00540         if (mNodeIter == mrMesh.mNodes.begin() && !IsAllowedNode())
00541         {
00542             ++(*this);
00543         }
00544     }
00545 }
00546 
00547 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00548 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAtEnd()
00549 {
00550     return mNodeIter == mrMesh.mNodes.end();
00551 }
00552 
00553 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00554 bool AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator::IsAllowedNode()
00555 {
00556     return !(mSkipDeletedNodes && (*this)->IsDeleted());
00557 }
00558 
00559 
00560 #endif /*ABSTRACTMESH_HPP_*/

Generated on Mon Apr 18 11:35:35 2011 for Chaste by  doxygen 1.5.5