TetrahedralMesh.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 
00030 #ifndef _TETRAHEDRALMESH_HPP_
00031 #define _TETRAHEDRALMESH_HPP_
00032 
00033 #include <iostream>
00034 #include <vector>
00035 #include <map>
00036 #include <set>
00037 #include <algorithm>
00038 
00039 #include <boost/serialization/access.hpp>
00040 
00041 //Jonathan Shewchuk's triangle
00042 #define REAL double
00043 #define VOID void
00044 #include "triangle.h"
00045 #undef REAL
00046 
00047 #include "AbstractMesh.hpp"
00048 #include "AbstractMeshReader.hpp"
00049 #include "TrianglesMeshReader.hpp"
00050 #include "Element.hpp"
00051 #include "BoundaryElement.hpp"
00052 #include "Node.hpp"
00053 #include "NodeMap.hpp"
00054 #include "Exception.hpp"
00055 #include "OutputFileHandler.hpp"
00056 #include "RandomNumberGenerator.hpp"
00057 #include "PetscTools.hpp"
00058 
00059 #include <boost/serialization/export.hpp>
00060 
00062 //   DECLARATION
00064 
00065 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00066 class TetrahedralMesh : public AbstractMesh< ELEMENT_DIM, SPACE_DIM>
00067 {
00068     friend class TestTetrahedralMesh; // to give access to private methods (not variables)
00069     friend class TestCryptSimulation2d; // to give access to private methods (not variables)
00070 
00071 private:
00072     friend class boost::serialization::access;
00073     template<class Archive>
00074     void serialize(Archive & archive, const unsigned int version)
00075     {
00076        // Don't do anything - this is just so subclasses can archive member variables.
00077     }        
00078 
00079 //    std::vector<unsigned> mNodesPerProcessor;
00080 
00081     unsigned SolveNodeMapping(unsigned index) const;
00082     unsigned SolveElementMapping(unsigned index) const;
00083     unsigned SolveBoundaryElementMapping(unsigned index) const;    
00084 
00085 protected:
00086     
00087     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections; 
00088     std::vector< c_matrix<double, SPACE_DIM, SPACE_DIM> > mElementJacobians;    
00089     std::vector< c_matrix<double, SPACE_DIM, SPACE_DIM> > mElementInverseJacobians;
00090     std::vector<double> mElementJacobianDeterminants;
00091 
00092     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00093     std::vector<double> mBoundaryElementJacobianDeterminants;
00094             
00095 public:
00096 
00097     TetrahedralMesh();
00098     TetrahedralMesh(unsigned numElements);
00099     //TetrahedralMesh(std::vector<Node<SPACE_DIM> *> nodes);
00100 
00101     //virtual ~TetrahedralMesh();
00102 
00103     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM> &rMeshReader,
00104                                  bool cullInternalFaces=false);
00105 
00106     void ReadNodesPerProcessorFile(const std::string& nodesPerProcessorFile);
00107 
00112     double CalculateVolume();
00113     double CalculateSurfaceArea();
00114 
00115     void Translate(c_vector<double, SPACE_DIM> displacement);
00116     void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
00117     void Scale(const double xFactor=1.0, const double yFactor=1.0, const double zFactor=1.0);
00118     void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotation_matrix);
00119     void Rotate(c_vector<double,3> axis, double angle);
00120     void RotateX(const double theta);
00121     void RotateY(const double theta);
00122     void RotateZ(const double theta);
00124     void Rotate(double theta)
00125     {
00126         RotateZ(theta);
00127     }
00128 
00129     void RefreshMesh(void);
00130 
00136     void PermuteNodes();
00137 
00144     void PermuteNodesWithMetisBinaries(unsigned numProcs);
00145 
00151     void PermuteNodes(std::vector<unsigned>& perm);
00152 
00153     void ConstructLinearMesh(unsigned width);
00154 
00160     void ConstructRectangularMesh(unsigned width, unsigned height, bool stagger=true);
00161 
00169     void ConstructCuboid(unsigned width, unsigned height, unsigned depth, bool stagger=false);
00170 
00179     unsigned GetContainingElementIndex(ChastePoint<SPACE_DIM> testPoint, bool strict=false, std::set<unsigned> testElements=std::set<unsigned>());
00180 
00188     unsigned GetNearestElementIndex(ChastePoint<SPACE_DIM> testPoint);
00189 
00194     std::vector<unsigned> GetContainingElementIndices(ChastePoint<SPACE_DIM> testPoint);
00195 
00196 
00197 //    /**
00198 //     * Sets the ownership of each element according to which nodes are owned by the
00199 //     * process.
00200 //     * @param lo is the lowest node number owned by the process
00201 //     * @param hi is one higher than the highest node number owned by the process
00202 //     * ie. this process owns nodes [lo..hi)
00203 //     * and element is "owned" if one or more of its nodes are owned
00204 //     */
00205 //    void SetElementOwnerships(unsigned lo, unsigned hi);
00206 
00210     virtual void Clear();
00211 
00215     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00216 
00230     double GetDistanceBetweenNodes(unsigned indexA, unsigned indexB);
00231 
00244     virtual c_vector<double, SPACE_DIM> GetVectorFromAtoB(const c_vector<double, SPACE_DIM>& rLocationA, const c_vector<double, SPACE_DIM>& rLocationB);
00245 
00250     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00251 
00260     virtual double GetWidth(const unsigned& rDimension) const;
00261 
00269     c_vector<double,2> GetWidthExtremes(const unsigned& rDimension) const;
00270 
00271     void UnflagAllElements();
00272 
00273 
00277     void FlagElementsNotContainingNodes(std::set<unsigned> nodesList);
00278 
00279     void RefreshJacobianCachedData();
00280 
00281     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double &rJacobianDeterminant) const;
00282     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double &rJacobianDeterminant, c_matrix<double, SPACE_DIM, SPACE_DIM>& rInverseJacobian) const;     
00283     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double &rJacobianDeterminant) const;
00284     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double &rJacobianDeterminant) const;
00285 
00286 
00287 //    void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian) const;    
00288 //    void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rInverseJacobian) const;
00289 //    void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection) const;
00290 //    double GetJacobianDeterminantForElement(unsigned elementIndex) const;    
00291 //
00292 //    void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection) const;       
00293 //    double GetJacobianDeterminantForBoundaryElement(unsigned elementIndex) const;
00294 
00300     class EdgeIterator
00301     {
00302     public:
00306         Node<SPACE_DIM>* GetNodeA();
00310         Node<SPACE_DIM>* GetNodeB();
00311 
00312         bool operator!=(const EdgeIterator& other);
00313 
00317         EdgeIterator& operator++();
00318 
00322         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00323 
00324     private:
00326         std::set<std::set<unsigned> > mEdgesVisited;
00327 
00328         TetrahedralMesh& mrMesh;
00329 
00330         unsigned mElemIndex;
00331         unsigned mNodeALocalIndex;
00332         unsigned mNodeBLocalIndex;
00333         unsigned mCellIndex;
00334         unsigned mNodeIndex;
00335         
00336     };
00337 
00341     EdgeIterator EdgesBegin();
00342 
00347     EdgeIterator EdgesEnd();
00348 };
00349 
00350 
00351 
00352 #endif //_TETRAHEDRALMESH_HPP_

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5