TetrahedralMesh.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 _TETRAHEDRALMESH_HPP_
00030 #define _TETRAHEDRALMESH_HPP_
00031 
00032 #include "ChasteSerialization.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 
00047 class triangulateio; 
00049 
00050 //   DECLARATION
00052 
00056 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00057 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00058 {
00059     friend class TestTetrahedralMesh; // to give access to private methods (not variables)
00060     friend class TestCryptSimulation2d; // to give access to private methods (not variables)
00061 
00062 private:
00064     friend class boost::serialization::access;
00071     template<class Archive>
00072     void serialize(Archive & archive, const unsigned int version)
00073     {
00074        archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00075     }
00076 
00077 protected:
00078 
00084     unsigned SolveNodeMapping(unsigned index) const;
00085 
00091     unsigned SolveElementMapping(unsigned index) const;
00092 
00098     unsigned SolveBoundaryElementMapping(unsigned index) const;
00099 
00101     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00102 
00104     std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00105 
00107     std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00108 
00110     std::vector<double> mElementJacobianDeterminants;
00111 
00113     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00114 
00116     std::vector<double> mBoundaryElementJacobianDeterminants;
00117     
00134     template <class MESHER_IO>
00135     void ExportToMesher(NodeMap& map, MESHER_IO& mesherInput, int *elementList=NULL);
00136 
00153     template <class MESHER_IO>
00154     void ImportFromMesher(MESHER_IO& mesherOutput, unsigned numberOfElements, int *elementList, unsigned numberOfFaces, int *faceList, int *edgeMarkerList);
00155 
00156 
00161     void InitialiseTriangulateIo(triangulateio& mesherIo);
00162     
00167     void FreeTriangulateIo(triangulateio& mesherIo);
00168 
00169 public:
00170 
00174     TetrahedralMesh();
00175 
00181     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00182 
00188     void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00189 
00202     bool CheckIsConforming();
00203 
00208     double GetVolume();
00209 
00213     double GetSurfaceArea();
00214 
00218     void RefreshMesh();
00219 
00224     void PermuteNodes();
00225 
00231     void PermuteNodes(const std::vector<unsigned>& perm);
00232 
00245     unsigned GetContainingElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint,
00246                                        bool strict=false,
00247                                        std::set<unsigned> testElements=std::set<unsigned>(),
00248                                        bool onlyTryWithTestElements = false);
00249 
00250 
00260     unsigned GetContainingElementIndexWithInitialGuess(const ChastePoint<SPACE_DIM>& rTestPoint, unsigned startingElementGuess, bool strict=false);
00261 
00270     unsigned GetNearestElementIndex(const ChastePoint<SPACE_DIM>& rTestPoint);
00271 
00276     unsigned GetNearestElementIndexFromTestElements(const ChastePoint<SPACE_DIM>& rTestPoint,
00277                                                     std::set<unsigned> testElements);
00278 
00279 
00285     std::vector<unsigned> GetContainingElementIndices(const ChastePoint<SPACE_DIM>& rTestPoint);
00286 
00287 //    /*
00288 //     * Sets the ownership of each element according to which nodes are owned by the
00289 //     * process.
00290 //     * @param lo is the lowest node number owned by the process
00291 //     * @param hi is one higher than the highest node number owned by the process
00292 //     * ie. this process owns nodes [lo..hi)
00293 //     * and element is "owned" if one or more of its nodes are owned
00294 //     */
00295 //    void SetElementOwnerships(unsigned lo, unsigned hi);
00296 
00300     virtual void Clear();
00301 
00305     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00306 
00314     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00315 
00319     void UnflagAllElements();
00320 
00326     void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00327 
00329     virtual void RefreshJacobianCachedData();
00330 
00338     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00339 
00348     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00349 
00357     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00358 
00366     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00367 
00374     class EdgeIterator
00375     {
00376     public:
00380         Node<SPACE_DIM>* GetNodeA();
00384         Node<SPACE_DIM>* GetNodeB();
00385 
00391         bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00392 
00396         EdgeIterator& operator++();
00397 
00404         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00405         
00406         
00407         
00408 
00409     private:
00413         std::set< std::pair<unsigned, unsigned> > mEdgesVisited;
00414 
00415         TetrahedralMesh& mrMesh;   
00417         unsigned mElemIndex;       
00418         unsigned mNodeALocalIndex; 
00419         unsigned mNodeBLocalIndex; 
00421     };
00422 
00426     EdgeIterator EdgesBegin();
00427 
00432     EdgeIterator EdgesEnd();
00433 };
00434 
00435 #include "SerializationExportWrapper.hpp"
00436 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh)
00437 
00438 #endif //_TETRAHEDRALMESH_HPP_

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