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 #ifndef _TETRAHEDRALMESH_HPP_
00030 #define _TETRAHEDRALMESH_HPP_
00031 
00032 #include <boost/serialization/access.hpp>
00033 #include <boost/serialization/base_object.hpp>
00034 
00035 #include "UblasVectorInclude.hpp"
00036 #include "UblasMatrixInclude.hpp"
00037 
00038 #include <vector>
00039 #include <string>
00040 #include <set>
00041 
00042 #include "AbstractTetrahedralMesh.hpp"
00043 #include "AbstractMeshReader.hpp"
00044 #include "ChastePoint.hpp"
00045 
00046 #include <boost/serialization/export.hpp>
00048 //   DECLARATION
00050 
00054 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00055 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00056 {
00057     friend class TestTetrahedralMesh; // to give access to private methods (not variables)
00058     friend class TestCryptSimulation2d; // to give access to private methods (not variables)
00059 
00060 private:
00062     friend class boost::serialization::access;
00069     template<class Archive>
00070     void serialize(Archive & archive, const unsigned int version)
00071     {
00072        archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00073     }
00074 
00075 protected:
00076 
00082     unsigned SolveNodeMapping(unsigned index) const;
00083 
00089     unsigned SolveElementMapping(unsigned index) const;
00090 
00096     unsigned SolveBoundaryElementMapping(unsigned index) const;
00097 
00099     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00100 
00102     std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00103 
00105     std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00106 
00108     std::vector<double> mElementJacobianDeterminants;
00109 
00111     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00112 
00114     std::vector<double> mBoundaryElementJacobianDeterminants;
00115 
00116 public:
00117 
00121     TetrahedralMesh();
00122 
00128     TetrahedralMesh(unsigned numElements);
00129     //TetrahedralMesh(std::vector<Node<SPACE_DIM> *> nodes);
00130 
00131     //virtual ~TetrahedralMesh();
00132 
00139     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader,
00140                                  bool cullInternalFaces=false);
00141 
00147     void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00148 
00153     double GetVolume();
00154 
00158     double GetSurfaceArea();
00159 
00167     void Translate(c_vector<double, SPACE_DIM> displacement);
00168 
00176     void Translate(const double xMovement=0.0, const double yMovement=0.0, const double zMovement=0.0);
00177 
00184     void Rotate(c_matrix<double , SPACE_DIM, SPACE_DIM> rotationMatrix);
00185 
00192     void Rotate(c_vector<double,3> axis, double angle);
00193 
00199     void RotateX(const double theta);
00200 
00206     void RotateY(const double theta);
00207 
00213     void RotateZ(const double theta);
00214 
00220     void Rotate(double theta);
00221 
00225     void RefreshMesh();
00226 
00231     void PermuteNodes();
00232 
00239     void PermuteNodesWithMetisBinaries(unsigned numProcs);
00240 
00246     void PermuteNodes(std::vector<unsigned>& perm);
00247 
00253     void ConstructLinearMesh(unsigned width);
00254 
00265     void ConstructRectangularMesh(unsigned width, unsigned height, bool stagger=true);
00266 
00278     void ConstructCuboid(unsigned width, unsigned height, unsigned depth, bool stagger=false);
00279 
00289     unsigned GetContainingElementIndex(ChastePoint<SPACE_DIM> testPoint, bool strict=false, std::set<unsigned> testElements=std::set<unsigned>());
00290 
00299     unsigned GetNearestElementIndex(ChastePoint<SPACE_DIM> testPoint);
00300 
00306     std::vector<unsigned> GetContainingElementIndices(ChastePoint<SPACE_DIM> testPoint);
00307 
00308 //    /*
00309 //     * Sets the ownership of each element according to which nodes are owned by the
00310 //     * process.
00311 //     * @param lo is the lowest node number owned by the process
00312 //     * @param hi is one higher than the highest node number owned by the process
00313 //     * ie. this process owns nodes [lo..hi)
00314 //     * and element is "owned" if one or more of its nodes are owned
00315 //     */
00316 //    void SetElementOwnerships(unsigned lo, unsigned hi);
00317 
00321     virtual void Clear();
00322 
00326     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00327 
00335     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00336 
00340     void UnflagAllElements();
00341 
00348     void FlagElementsNotContainingNodes(std::set<unsigned> nodes);
00349 
00351     virtual void RefreshJacobianCachedData();
00352 
00360     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00361 
00370     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00371 
00379     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00380 
00388     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00389 
00395     class EdgeIterator
00396     {
00397     public:
00401         Node<SPACE_DIM>* GetNodeA();
00405         Node<SPACE_DIM>* GetNodeB();
00406 
00412         bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00413 
00417         EdgeIterator& operator++();
00418 
00425         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00426 
00427     private:
00429         std::set<std::set<unsigned> > mEdgesVisited;
00430 
00431         TetrahedralMesh& mrMesh;   
00433         unsigned mElemIndex;       
00434         unsigned mNodeALocalIndex; 
00435         unsigned mNodeBLocalIndex; 
00436         unsigned mCellIndex;       
00437         unsigned mNodeIndex;       
00439     };
00440 
00444     EdgeIterator EdgesBegin();
00445 
00450     EdgeIterator EdgesEnd();
00451 };
00452 
00453 #include "TemplatedExport.hpp"
00454 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh);
00455 
00456 #endif //_TETRAHEDRALMESH_HPP_

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