MutableVertexMesh.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 
00101     c_vector<double, SPACE_DIM> mLastT2SwapLocation;
00102 
00107     std::vector< c_vector<double, SPACE_DIM> > mLocationsOfT3Swaps;
00108 
00121     unsigned DivideElement(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00122                            unsigned nodeAIndex,
00123                            unsigned nodeBIndex,
00124                            bool placeOriginalElementBelow=false);
00125 
00137     bool CheckForSwapsFromShortEdges();
00138 
00147     bool CheckForIntersections();
00148 
00159     virtual void IdentifySwapType(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00160 
00171     void PerformNodeMerge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00172 
00186     void PerformT1Swap(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, std::set<unsigned>& rElementsContainingNodes);
00187 
00197     void PerformIntersectionSwap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
00198 
00208     void PerformT2Swap(VertexElement<ELEMENT_DIM,SPACE_DIM>& rElement);
00209 
00220     void PerformT3Swap(Node<SPACE_DIM>* pNode, unsigned elementIndex);
00221 
00232     void PerformVoidRemoval(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB, Node<SPACE_DIM>* pNodeC);
00233 
00246     c_vector<double, 2> WidenEdgeOrCorrectIntersectionLocationIfNecessary(unsigned indexA, unsigned indexB, c_vector<double,2> intersection);
00247 
00249     friend class boost::serialization::access;
00250 
00261     template<class Archive>
00262     void serialize(Archive & archive, const unsigned int version)
00263     {
00264         // NOTE - Subclasses must archive their member variables BEFORE calling this method.
00265         archive & mCellRearrangementThreshold;
00266         archive & mCellRearrangementRatio;
00267         archive & mT2Threshold;
00268         archive & mCheckForInternalIntersections;
00269         archive & mDeletedNodeIndices;
00270         archive & mDeletedElementIndices;
00272 
00273         archive & boost::serialization::base_object<VertexMesh<ELEMENT_DIM, SPACE_DIM> >(*this);
00274     }
00275 
00276 public:
00277 
00288     MutableVertexMesh(std::vector<Node<SPACE_DIM>*> nodes,
00289                       std::vector<VertexElement<ELEMENT_DIM, SPACE_DIM>*> vertexElements,
00290                       double cellRearrangementThreshold=0.01,
00291                       double t2Threshold=0.001,
00292                       double cellRearrangementRatio=1.5);
00293 
00297     MutableVertexMesh();
00298 
00302     virtual ~MutableVertexMesh();
00303 
00309     void SetCellRearrangementThreshold(double cellRearrangementThreshold);
00310 
00316     void SetT2Threshold(double t2Threshold);
00317 
00323     void SetCellRearrangementRatio(double cellRearrangementRatio);
00324 
00331     virtual void SetNode(unsigned nodeIndex, ChastePoint<SPACE_DIM> point);
00332 
00338     void SetCheckForInternalIntersections(bool checkForInternalIntersections);
00339 
00343     double GetCellRearrangementThreshold() const;
00344 
00348     double GetT2Threshold() const;
00349 
00353     double GetCellRearrangementRatio() const;
00354 
00358     unsigned GetNumNodes() const;
00359 
00363     unsigned GetNumElements() const;
00364 
00368     bool GetCheckForInternalIntersections() const;
00369 
00373     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT1Swaps();
00374 
00378     c_vector<double, SPACE_DIM> GetLastT2SwapLocation();
00379 
00383     std::vector< c_vector<double, SPACE_DIM> > GetLocationsOfT3Swaps();
00384 
00388     void ClearLocationsOfT1Swaps();
00389 
00393     void ClearLocationsOfT3Swaps();
00394 
00403     unsigned AddNode(Node<SPACE_DIM>* pNewNode);
00404 
00412     void DeleteElementPriorToReMesh(unsigned index);
00413 
00421     void DeleteNodePriorToReMesh(unsigned index);
00422 
00431     unsigned DivideElementAlongShortAxis(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00432                                          bool placeOriginalElementBelow=false);
00433 
00447     unsigned DivideElementAlongGivenAxis(VertexElement<ELEMENT_DIM,SPACE_DIM>* pElement,
00448                                          c_vector<double, SPACE_DIM> axisOfDivision,
00449                                          bool placeOriginalElementBelow=false);
00450 
00458     unsigned AddElement(VertexElement<ELEMENT_DIM, SPACE_DIM>* pNewElement);
00459 
00472     bool CheckForT2Swaps(VertexElementMap& rElementMap);
00473 
00477     void Clear();
00478 
00485     void DivideEdge(Node<SPACE_DIM>* pNodeA, Node<SPACE_DIM>* pNodeB);
00486 
00495     void RemoveDeletedNodesAndElements(VertexElementMap& rElementMap);
00496 
00500     void RemoveDeletedNodes();
00501 
00514     virtual void ReMesh(VertexElementMap& rElementMap);
00515 
00522     void ReMesh();
00523 };
00524 
00525 #include "SerializationExportWrapper.hpp"
00526 EXPORT_TEMPLATE_CLASS_ALL_DIMS(MutableVertexMesh)
00527 
00528 #endif /*MUTABLEVERTEXMESH_HPP_*/

Generated by  doxygen 1.6.2