Chaste Commit::f2ff7ee04e70ac9d06c57344df8d017dbb12b97b
PottsMesh.hpp
1/*
2
3Copyright (c) 2005-2024, University of Oxford.
4All rights reserved.
5
6University of Oxford means the Chancellor, Masters and Scholars of the
7University of Oxford, having an administrative office at Wellington
8Square, Oxford OX1 2JD, UK.
9
10This file is part of Chaste.
11
12Redistribution and use in source and binary forms, with or without
13modification, are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice,
15 this list of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19 * Neither the name of the University of Oxford nor the names of its
20 contributors may be used to endorse or promote products derived from this
21 software without specific prior written permission.
22
23THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34*/
35
36#ifndef POTTSMESH_HPP_
37#define POTTSMESH_HPP_
38
39// Forward declaration prevents circular include chain
40template<unsigned DIM>
41class PottsMeshWriter;
42
43#include <iostream>
44#include <map>
45#include <algorithm>
46
48#include <boost/serialization/vector.hpp>
49#include <boost/serialization/set.hpp>
50#include <boost/serialization/base_object.hpp>
51#include <boost/serialization/split_member.hpp>
52
53#include "AbstractMesh.hpp"
54#include "ArchiveLocationInfo.hpp"
55#include "PottsMeshReader.hpp"
56#include "PottsMeshWriter.hpp"
57#include "PottsElement.hpp"
58
62template<unsigned DIM>
63class PottsMesh : public AbstractMesh<DIM, DIM>
64{
65 friend class TestPottsMesh;
66
67protected:
69 std::vector<PottsElement<DIM>*> mElements;
70
75 std::vector<unsigned> mDeletedElementIndices;
76
78 std::vector< std::set<unsigned> > mVonNeumannNeighbouringNodeIndices;
79
81 std::vector< std::set<unsigned> > mMooreNeighbouringNodeIndices;
82
90 unsigned SolveNodeMapping(unsigned index) const;
91
99 unsigned SolveElementMapping(unsigned index) const;
100
108 unsigned SolveBoundaryElementMapping(unsigned index) const;
109
112
120 template<class Archive>
121 void save(Archive & archive, const unsigned int version) const
122 {
123 // NOTE - Subclasses must archive their member variables BEFORE calling this method.
124 archive & mDeletedElementIndices;
127 archive & boost::serialization::base_object<AbstractMesh<DIM, DIM> >(*this);
128
129 // Create a mesh writer pointing to the correct file and directory
132 false);
133 mesh_writer.WriteFilesUsingMesh(*(const_cast<PottsMesh<DIM>*>(this)));
134 }
135
142 template<class Archive>
143 void load(Archive & archive, const unsigned int version)
144 {
145 // NOTE - Subclasses must archive their member variables BEFORE calling this method.
146 archive & mDeletedElementIndices;
149 archive & boost::serialization::base_object<AbstractMesh<DIM, DIM> >(*this);
150
152 this->ConstructFromMeshReader(mesh_reader);
153 }
154 BOOST_SERIALIZATION_SPLIT_MEMBER()
155
156public:
157
159 // Iterators //
161
163 class PottsElementIterator;
164
170 inline PottsElementIterator GetElementIteratorBegin(bool skipDeletedElements=true);
171
175 inline PottsElementIterator GetElementIteratorEnd();
176
178 // Methods //
180
189 PottsMesh(std::vector<Node<DIM>*> nodes,
190 std::vector<PottsElement<DIM>*> pottsElements,
191 std::vector< std::set<unsigned> > vonNeumannNeighbouringNodeIndices,
192 std::vector< std::set<unsigned> > mooreNeighbouringNodeIndices);
193
197 PottsMesh();
198
202 virtual ~PottsMesh();
203
207 virtual unsigned GetNumNodes() const;
208
212 virtual unsigned GetNumElements() const;
213
217 unsigned GetNumAllElements() const;
218
224 PottsElement<DIM>* GetElement(unsigned index) const;
225
235 virtual c_vector<double, DIM> GetCentroidOfElement(unsigned index);
236
242 void ConstructFromMeshReader(AbstractMeshReader<DIM, DIM>& rMeshReader);
243
247 virtual void Clear();
248
258 virtual double GetVolumeOfElement(unsigned index);
259
269 virtual double GetSurfaceAreaOfElement(unsigned index);
270
277 std::set<unsigned> GetMooreNeighbouringNodeIndices(unsigned nodeIndex);
278
285 std::set<unsigned> GetVonNeumannNeighbouringNodeIndices(unsigned nodeIndex);
286
292 void DeleteNode(unsigned index);
293
300 void DeleteElement(unsigned index);
301
307
318 unsigned DivideElement(PottsElement<DIM>* pElement,
319 bool placeOriginalElementBelow=false);
320
328 unsigned AddElement(PottsElement<DIM>* pNewElement);
329
336 std::set<unsigned> GetNeighbouringElementIndices(unsigned elementIndex);
337
339 // Nested classes //
341
348 {
349 public:
356 inline PottsElement<DIM>& operator*();
357
362 inline PottsElement<DIM>* operator->();
363
370 inline bool operator!=(const typename PottsMesh<DIM>::PottsElementIterator& rOther);
371
376 inline PottsElementIterator& operator++();
377
388 PottsElementIterator(PottsMesh<DIM>& rMesh,
389 typename std::vector<PottsElement<DIM> *>::iterator elementIter,
390 bool skipDeletedElements=true);
391
392 private:
395
397 typename std::vector<PottsElement<DIM> *>::iterator mElementIter;
398
401
405 inline bool IsAtEnd();
406
410 inline bool IsAllowedElement();
411 };
412};
413
416
417
418// PottsElementIterator class implementation - most methods are inlined //
420
421template<unsigned DIM>
423 bool skipDeletedElements)
424{
425 return PottsElementIterator(*this, mElements.begin(), skipDeletedElements);
426}
427
428template<unsigned DIM>
433
434template<unsigned DIM>
440
441template<unsigned DIM>
443{
444 assert(!IsAtEnd());
445 return *mElementIter;
446}
447
448template<unsigned DIM>
450{
451 return mElementIter != rOther.mElementIter;
452}
453
454template<unsigned DIM>
456{
457 do
458 {
459 ++mElementIter;
460 }
461 while (!IsAtEnd() && !IsAllowedElement());
462
463 return (*this);
464}
465
466template<unsigned DIM>
468 PottsMesh<DIM>& rMesh,
469 typename std::vector<PottsElement<DIM>*>::iterator elementIter,
470 bool skipDeletedElements)
471 : mrMesh(rMesh),
472 mElementIter(elementIter),
473 mSkipDeletedElements(skipDeletedElements)
474{
475 if (mrMesh.mElements.empty())
476 {
477 // Cope with empty meshes
478 mElementIter = mrMesh.mElements.end();
479 }
480 else
481 {
482 // Make sure we start at an allowed element
483 if (mElementIter == mrMesh.mElements.begin() && !IsAllowedElement())
484 {
485 ++(*this);
486 }
487 }
488}
489
490template<unsigned DIM>
492{
493 return mElementIter == mrMesh.mElements.end();
494}
495
496template<unsigned DIM>
498{
499 return !(mSkipDeletedElements && (*this)->IsDeleted());
500}
501
502#endif /*POTTSMESH_HPP_*/
gcov doesn't like this file...
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
static std::string GetMeshFilename()
static std::string GetArchiveDirectory()
static std::string GetArchiveRelativePath()
Definition Node.hpp:59
void WriteFilesUsingMesh(PottsMesh< SPACE_DIM > &rMesh)
PottsElementIterator(PottsMesh< DIM > &rMesh, typename std::vector< PottsElement< DIM > * >::iterator elementIter, bool skipDeletedElements=true)
PottsElement< DIM > & operator*()
std::vector< PottsElement< DIM > * >::iterator mElementIter
bool operator!=(const typename PottsMesh< DIM >::PottsElementIterator &rOther)
PottsElement< DIM > * operator->()
PottsElementIterator & operator++()
unsigned SolveElementMapping(unsigned index) const
std::vector< std::set< unsigned > > mMooreNeighbouringNodeIndices
Definition PottsMesh.hpp:81
void save(Archive &archive, const unsigned int version) const
void ConstructFromMeshReader(AbstractMeshReader< DIM, DIM > &rMeshReader)
virtual void Clear()
virtual c_vector< double, DIM > GetCentroidOfElement(unsigned index)
std::vector< std::set< unsigned > > mVonNeumannNeighbouringNodeIndices
Definition PottsMesh.hpp:78
virtual double GetVolumeOfElement(unsigned index)
PottsElementIterator GetElementIteratorBegin(bool skipDeletedElements=true)
unsigned SolveBoundaryElementMapping(unsigned index) const
virtual double GetSurfaceAreaOfElement(unsigned index)
std::set< unsigned > GetMooreNeighbouringNodeIndices(unsigned nodeIndex)
virtual unsigned GetNumElements() const
virtual unsigned GetNumNodes() const
void RemoveDeletedElements()
std::vector< PottsElement< DIM > * > mElements
Definition PottsMesh.hpp:69
unsigned SolveNodeMapping(unsigned index) const
void DeleteElement(unsigned index)
std::vector< unsigned > mDeletedElementIndices
Definition PottsMesh.hpp:75
unsigned DivideElement(PottsElement< DIM > *pElement, bool placeOriginalElementBelow=false)
void DeleteNode(unsigned index)
friend class boost::serialization::access
unsigned AddElement(PottsElement< DIM > *pNewElement)
unsigned GetNumAllElements() const
PottsElementIterator GetElementIteratorEnd()
void load(Archive &archive, const unsigned int version)
std::set< unsigned > GetVonNeumannNeighbouringNodeIndices(unsigned nodeIndex)
std::set< unsigned > GetNeighbouringElementIndices(unsigned elementIndex)
PottsElement< DIM > * GetElement(unsigned index) const