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 
00047 //   DECLARATION
00049 
00053 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00054 class TetrahedralMesh : public AbstractTetrahedralMesh< ELEMENT_DIM, SPACE_DIM>
00055 {
00056     friend class TestTetrahedralMesh; // to give access to private methods (not variables)
00057     friend class TestCryptSimulation2d; // to give access to private methods (not variables)
00058 
00059 private:
00061     friend class boost::serialization::access;
00068     template<class Archive>
00069     void serialize(Archive & archive, const unsigned int version)
00070     {
00071        archive & boost::serialization::base_object<AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00072     }
00073 
00074 protected:
00075 
00081     unsigned SolveNodeMapping(unsigned index) const;
00082 
00088     unsigned SolveElementMapping(unsigned index) const;
00089 
00095     unsigned SolveBoundaryElementMapping(unsigned index) const;
00096 
00098     std::vector< c_vector<double, SPACE_DIM> > mElementWeightedDirections;
00099 
00101     std::vector< c_matrix<double, SPACE_DIM, ELEMENT_DIM> > mElementJacobians;
00102 
00104     std::vector< c_matrix<double, ELEMENT_DIM, SPACE_DIM> > mElementInverseJacobians;
00105 
00107     std::vector<double> mElementJacobianDeterminants;
00108 
00110     std::vector< c_vector<double, SPACE_DIM> > mBoundaryElementWeightedDirections;
00111 
00113     std::vector<double> mBoundaryElementJacobianDeterminants;
00114 
00115 public:
00116 
00120     TetrahedralMesh();
00121 
00127     void ConstructFromMeshReader(AbstractMeshReader<ELEMENT_DIM,SPACE_DIM>& rMeshReader);
00128 
00134     void ReadNodesPerProcessorFile(const std::string& rNodesPerProcessorFile);
00135 
00148     bool CheckIsConforming();
00149 
00154     double GetVolume();
00155 
00159     double GetSurfaceArea();
00160 
00167     void Translate(const c_vector<double, SPACE_DIM>& rDisplacement);
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 
00260     unsigned GetContainingElementIndex(ChastePoint<SPACE_DIM> testPoint,
00261                                        bool strict=false,
00262                                        std::set<unsigned> testElements=std::set<unsigned>(),
00263                                        bool onlyTryWithTestElements = false);
00264 
00265 
00275     unsigned GetContainingElementIndexWithInitialGuess(ChastePoint<SPACE_DIM> testPoint, unsigned startingElementGuess, bool strict=false);
00276 
00285     unsigned GetNearestElementIndex(ChastePoint<SPACE_DIM> testPoint);
00286 
00291     unsigned GetNearestElementIndexFromTestElements(ChastePoint<SPACE_DIM> testPoint,
00292                                                     std::set<unsigned> testElements);
00293 
00294 
00300     std::vector<unsigned> GetContainingElementIndices(ChastePoint<SPACE_DIM> testPoint);
00301 
00302 //    /*
00303 //     * Sets the ownership of each element according to which nodes are owned by the
00304 //     * process.
00305 //     * @param lo is the lowest node number owned by the process
00306 //     * @param hi is one higher than the highest node number owned by the process
00307 //     * ie. this process owns nodes [lo..hi)
00308 //     * and element is "owned" if one or more of its nodes are owned
00309 //     */
00310 //    void SetElementOwnerships(unsigned lo, unsigned hi);
00311 
00315     virtual void Clear();
00316 
00320     std::set<unsigned> CalculateBoundaryOfFlaggedRegion();
00321 
00329     double GetAngleBetweenNodes(unsigned indexA, unsigned indexB);
00330 
00334     void UnflagAllElements();
00335 
00341     void FlagElementsNotContainingNodes(const std::set<unsigned> rNodes);
00342 
00344     virtual void RefreshJacobianCachedData();
00345 
00353     virtual void GetJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, SPACE_DIM>& rJacobian, double& rJacobianDeterminant) const;
00354 
00363     virtual void GetInverseJacobianForElement(unsigned elementIndex, c_matrix<double, SPACE_DIM, ELEMENT_DIM>& rJacobian, double& rJacobianDeterminant, c_matrix<double, ELEMENT_DIM, SPACE_DIM>& rInverseJacobian) const;
00364 
00372     virtual void GetWeightedDirectionForElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00373 
00381     virtual void GetWeightedDirectionForBoundaryElement(unsigned elementIndex, c_vector<double, SPACE_DIM>& rWeightedDirection, double& rJacobianDeterminant) const;
00382 
00388     class EdgeIterator
00389     {
00390     public:
00394         Node<SPACE_DIM>* GetNodeA();
00398         Node<SPACE_DIM>* GetNodeB();
00399 
00405         bool operator!=(const TetrahedralMesh<ELEMENT_DIM, SPACE_DIM>::EdgeIterator& rOther);
00406 
00410         EdgeIterator& operator++();
00411 
00418         EdgeIterator(TetrahedralMesh& rMesh, unsigned elemIndex);
00419 
00420     private:
00422         std::set<std::set<unsigned> > mEdgesVisited;
00423 
00424         TetrahedralMesh& mrMesh;   
00426         unsigned mElemIndex;       
00427         unsigned mNodeALocalIndex; 
00428         unsigned mNodeBLocalIndex; 
00430     };
00431 
00435     EdgeIterator EdgesBegin();
00436 
00441     EdgeIterator EdgesEnd();
00442 };
00443 
00444 #include "SerializationExportWrapper.hpp"
00445 EXPORT_TEMPLATE_CLASS_ALL_DIMS(TetrahedralMesh);
00446 
00447 #endif //_TETRAHEDRALMESH_HPP_

Generated by  doxygen 1.6.2