MutableVertexMesh.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2014, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 #ifndef MUTABLEVERTEXMESH_HPP_
00036 #define MUTABLEVERTEXMESH_HPP_
00037 
00038 // Forward declaration prevents circular include chain
00039 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00040 class VertexMeshWriter;
00041 
00042 #include <iostream>
00043 #include <map>
00044 #include <algorithm>
00045 
00046 #include "ChasteSerialization.hpp"
00047 #include <boost/serialization/vector.hpp>
00048 #include <boost/serialization/base_object.hpp>
00049 #include <boost/serialization/split_member.hpp>
00050 
00051 #include "VertexMesh.hpp"
00052 
00063 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00064 class MutableVertexMesh : public VertexMesh<ELEMENT_DIM, SPACE_DIM>
00065 {
00066     friend class TestMutableVertexMesh;
00067     friend class TestMutableVertexMeshReMesh;
00068 
00069 protected:
00070 
00072     double mCellRearrangementThreshold;
00073 
00078     double mCellRearrangementRatio;
00079 
00081     double mT2Threshold;
00082 
00084     bool mCheckForInternalIntersections;
00085 
00087     std::vector<unsigned> mDeletedNodeIndices;
00088 
00090     std::vector<unsigned> mDeletedElementIndices;
00091 
00096     std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT1Swaps;
00097 
00102     std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT2Swaps;
00103 
00108     std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT3Swaps;
00109 
00122     unsigned DivideElement(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00123                            unsigned nodeAIndex,
00124                            unsigned nodeBIndex,
00125                            bool placeOriginalElementBelow=false);
00126 
00142     bool CheckForSwapsFromShortEdges(VertexElementMap& rElementMap);
00143 
00152     bool CheckForIntersections();
00153 
00167     virtual void IdentifySwapType(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, VertexElementMap& rElementMap);
00168 
00179     void PerformNodeMerge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00180 
00194     void PerformT1Swap(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, std::set<unsigned>& rElementsContainingNodes);
00195 
00205     void PerformIntersectionSwap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
00206 
00216     void PerformT2Swap(VertexElement<ELEMENT_DIM,SPACE_DIM>& rElement);
00217 
00228     void PerformT3Swap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
00229 
00240     void PerformVoidRemoval(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, Node<SPACE_DIM>* pNodeC);
00241 
00243     friend class boost::serialization::access;
00244 
00255     template<class Archive>
00256     void serialize(Archive & archive, const unsigned int version)
00257     {
00258         // NOTE - Subclasses must archive their member variables BEFORE calling this method.
00259         archive & mCellRearrangementThreshold;
00260         archive & mCellRearrangementRatio;
00261         archive & mT2Threshold;
00262         archive & mCheckForInternalIntersections;
00263         archive & mDeletedNodeIndices;
00264         archive & mDeletedElementIndices;
00266 
00267         archive & boost::serialization::base_object<VertexMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00268     }
00269 
00270 public:
00271 
00282     MutableVertexMesh(std::vector<Node<SPACE_DIM>*> nodes,
00283                       std::vector<VertexElement<ELEMENT_DIM, SPACE_DIM>*> vertexElements,
00284                       double cellRearrangementThreshold=0.01,
00285                       double t2Threshold=0.001,
00286                       double cellRearrangementRatio=1.5);
00287 
00291     MutableVertexMesh();
00292 
00296     virtual ~MutableVertexMesh();
00297 
00303     void SetCellRearrangementThreshold(double cellRearrangementThreshold);
00304 
00310     void SetT2Threshold(double t2Threshold);
00311 
00317     void SetCellRearrangementRatio(double cellRearrangementRatio);
00318 
00325     virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point);
00326 
00332     void SetCheckForInternalIntersections(bool checkForInternalIntersections);
00333 
00337     double GetCellRearrangementThreshold() const;
00338 
00342     double GetT2Threshold() const;
00343 
00347     double GetCellRearrangementRatio() const;
00348 
00352     unsigned GetNumNodes() const;
00353 
00357     unsigned GetNumElements() const;
00358 
00362     bool GetCheckForInternalIntersections() const;
00363 
00367     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT1Swaps();
00368 
00372     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT2Swaps();
00373 
00377     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT3Swaps();
00378 
00382     void ClearLocationsOfT1Swaps();
00383 
00387     void ClearLocationsOfT2Swaps();
00388 
00392     void ClearLocationsOfT3Swaps();
00393 
00402     unsigned AddNode(Node<SPACE_DIM>* pNewNode);
00403 
00411     void DeleteElementPriorToReMesh(unsigned index);
00412 
00420     void DeleteNodePriorToReMesh(unsigned index);
00421 
00430     unsigned DivideElementAlongShortAxis(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00431                                          bool placeOriginalElementBelow=false);
00432 
00446     unsigned DivideElementAlongGivenAxis(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00447                                          c_vector<double, SPACE_DIM> axisOfDivision,
00448                                          bool placeOriginalElementBelow=false);
00449 
00457     unsigned AddElement(VertexElement<ELEMENT_DIM, SPACE_DIM>* pNewElement);
00458 
00471     bool CheckForT2Swaps(VertexElementMap& rElementMap);
00472 
00476     void Clear();
00477 
00484     void DivideEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00485 
00494     void RemoveDeletedNodesAndElements(VertexElementMap& rElementMap);
00495 
00499     void RemoveDeletedNodes();
00500 
00513     virtual void ReMesh(VertexElementMap& rElementMap);
00514 
00521     void ReMesh();
00522 };
00523 
00524 #include "SerializationExportWrapper.hpp"
00525 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MutableVertexMesh)
00526 
00527 #endif /*MUTABLEVERTEXMESH_HPP_*/

Generated by  doxygen 1.6.2