MutableVertexMesh.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 #ifndef MUTABLEVERTEXMESH_HPP_
00029 #define MUTABLEVERTEXMESH_HPP_
00030 
00031 // Forward declaration prevents circular include chain
00032 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00033 class VertexMeshWriter;
00034 
00035 #include <iostream>
00036 #include <map>
00037 #include <algorithm>
00038 
00039 #include "ChasteSerialization.hpp"
00040 #include <boost/serialization/vector.hpp>
00041 #include <boost/serialization/base_object.hpp>
00042 #include <boost/serialization/split_member.hpp>
00043 
00044 #include "VertexMesh.hpp"
00045 
00049 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00050 class MutableVertexMesh : public VertexMesh<ELEMENT_DIM, SPACE_DIM>
00051 {
00052     friend class TestMutableVertexMesh;
00053     friend class TestMutableVertexMeshReMesh;
00054 
00055 protected:
00056 
00058     double mCellRearrangementThreshold;
00059 
00064     double mCellRearrangementRatio;
00065 
00067     double mT2Threshold;
00068 
00070     bool mCheckForInternalIntersections;
00071 
00073     std::vector<unsigned> mDeletedNodeIndices;
00074 
00076     std::vector<unsigned> mDeletedElementIndices;
00077 
00082     std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT1Swaps;
00083 
00088     std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT3Swaps;
00089 
00102     unsigned DivideElement(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00103                            unsigned nodeAIndex,
00104                            unsigned nodeBIndex,
00105                            bool placeOriginalElementBelow=false);
00106 
00118     bool CheckForT1Swaps(VertexElementMap& rElementMap);
00119 
00132     bool CheckForT2Swaps(VertexElementMap& rElementMap);
00133 
00141     bool CheckForIntersections();
00142 
00154     void IdentifySwapType(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, VertexElementMap& rElementMap);
00155 
00163     void PerformNodeMerge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00164 
00174     void PerformT1Swap(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, std::set<unsigned>& rElementsContainingNodes);
00175 
00184     void PerformIntersectionSwap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
00185 
00193     void PerformT2Swap(VertexElement<ELEMENT_DIM,SPACE_DIM>& rElement);
00194 
00203     void PerformT3Swap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
00204 
00213     void PerformVoidRemoval(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, Node<SPACE_DIM>* pNodeC);
00214 
00216     friend class boost::serialization::access;
00217 
00228     template<class Archive>
00229     void serialize(Archive & archive, const unsigned int version)
00230     {
00231         // NOTE - Subclasses must archive their member variables BEFORE calling this method.
00232         archive & mCellRearrangementThreshold;
00233         archive & mCellRearrangementRatio;
00234         archive & mT2Threshold;
00235         archive & mCheckForInternalIntersections;
00236         archive & mDeletedNodeIndices;
00237         archive & mDeletedElementIndices;
00238 //        archive & mLocationsOfT1Swaps;
00239 //        archive & mLocationsOfT3Swaps;
00240 
00241         archive & boost::serialization::base_object<VertexMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00242     }
00243 
00244 public:
00245 
00256     MutableVertexMesh(std::vector<Node<SPACE_DIM>*> nodes,
00257                       std::vector<VertexElement<ELEMENT_DIM, SPACE_DIM>*> vertexElements,
00258                       double cellRearrangementThreshold=0.01,
00259                       double t2Threshold=0.001,
00260                       double cellRearrangementRatio=1.5);
00261 
00265     MutableVertexMesh();
00266 
00270     virtual ~MutableVertexMesh();
00271 
00277     void SetCellRearrangementThreshold(double cellRearrangementThreshold);
00278 
00284     void SetT2Threshold(double t2Threshold);
00285 
00291     void SetCellRearrangementRatio(double cellRearrangementRatio);
00292 
00299     virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point);
00300 
00306     void SetCheckForInternalIntersections(bool checkForInternalIntersections);
00307 
00311     double GetCellRearrangementThreshold() const;
00312 
00316     double GetT2Threshold() const;
00317 
00321     double GetCellRearrangementRatio() const;
00322 
00326     unsigned GetNumNodes() const;
00327 
00331     unsigned GetNumElements() const;
00332 
00336     bool GetCheckForInternalIntersections() const;
00337 
00341     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT1Swaps();
00342 
00346     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT3Swaps();
00347 
00351     void ClearLocationsOfT1Swaps();
00352 
00356     void ClearLocationsOfT3Swaps();
00357 
00358 
00367     unsigned AddNode(Node<SPACE_DIM>* pNewNode);
00368 
00376     void DeleteElementPriorToReMesh(unsigned index);
00377 
00385     void DeleteNodePriorToReMesh(unsigned index);
00386 
00397     unsigned DivideElementAlongShortAxis(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00398                                          bool placeOriginalElementBelow=false);
00399 
00415     unsigned DivideElementAlongGivenAxis(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00416                                          c_vector<double, SPACE_DIM> axisOfDivision,
00417                                          bool placeOriginalElementBelow=false);
00418 
00426     unsigned AddElement(VertexElement<ELEMENT_DIM, SPACE_DIM>* pNewElement);
00427 
00431     void Clear();
00432 
00439     void DivideEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00440 
00449     void RemoveDeletedNodesAndElements(VertexElementMap& rElementMap);
00450 
00454     void RemoveDeletedNodes();
00455 
00463     void ReMesh(VertexElementMap& rElementMap);
00464 
00469     void ReMesh();
00470 };
00471 
00472 #include "SerializationExportWrapper.hpp"
00473 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MutableVertexMesh);
00474 
00475 #endif /*MUTABLEVERTEXMESH_HPP_*/
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3