Chaste Commit::1fd4e48e3990e67db148bc1bc4cf6991a0049d0c
AbstractMeshReader.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
37#ifndef _ABSTRACTMESHREADER_HPP_
38#define _ABSTRACTMESHREADER_HPP_
39
40#include <string>
41#include <vector>
42#include <set>
43#include <cassert>
44#include <boost/iterator/iterator_facade.hpp>
45#include "Exception.hpp"
46
52{
53 // Constructor to initialise default values, to prevent -Werror=maybe-uninitialized on some compilers
55 : NodeIndices(std::vector<unsigned>()),
58 std::vector<unsigned> NodeIndices;
61};
62
75template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
77{
78
79public:
80
81 virtual ~AbstractMeshReader()
82 {}
83
85 virtual unsigned GetNumElements() const =0;
86
88 virtual unsigned GetNumNodes() const =0;
89
91 virtual unsigned GetNumFaces() const =0;
92
94 virtual unsigned GetNumCableElements() const;
95
97 virtual unsigned GetNumElementAttributes() const;
98
100 virtual unsigned GetNumFaceAttributes() const;
101
103 virtual unsigned GetNumCableElementAttributes() const;
104
112 virtual std::vector<double> GetNodeAttributes();
113
115 unsigned GetNumEdges() const;
116
118 virtual std::vector<double> GetNextNode()=0;
119
121 virtual void Reset()=0;
122
125
128
131
134
135
142 virtual std::vector<double> GetNode(unsigned index);
143
150 virtual ElementData GetElementData(unsigned index);
151
158 virtual ElementData GetFaceData(unsigned index);
159
166 ElementData GetEdgeData(unsigned index);
167
175 virtual std::vector<unsigned> GetContainingElementIndices(unsigned index);
176
180 virtual std::string GetMeshFileBaseName();
181
185 virtual unsigned GetOrderOfElements();
186
190 virtual unsigned GetOrderOfBoundaryElements();
191
196
197
204 virtual bool IsFileFormatBinary();
205
212 virtual bool HasNclFile();
213
220 virtual bool HasNodePermutation();
221
228 virtual const std::vector<unsigned>& rGetNodePermutation();
229
230
231 // Iterator classes
232
236 class ElementIterator : public boost::iterator_facade<ElementIterator, const ElementData,
237 boost::single_pass_traversal_tag>
238 {
239 public:
251 : mIndex(index),
252 mpIndices(nullptr),
253 mpReader(pReader)
254 {
255 CacheData(mIndex, true);
256 }
257
265 ElementIterator(const std::set<unsigned>& rIndices,
267
271 unsigned GetIndex() const
272 {
273 return mIndex;
274 }
275
276 private:
277 friend class boost::iterator_core_access;
278
286 void CacheData(unsigned index, bool firstRead = false);
287
291 void increment();
292
297 bool equal(const ElementIterator& rOther) const
298 {
299 return mIndex == rOther.mIndex;
300 }
301
310 {
311 assert(mpReader);
312 assert(mIndex < mpReader->GetNumElements());
313 // This was cached in increment()
314 return mLastDataRead;
315 }
316
318 unsigned mIndex;
319
321 const std::set<unsigned>* mpIndices;
322
324 std::set<unsigned>::const_iterator mIndicesIterator;
325
328
331 };
332
341
351 ElementIterator GetElementIteratorBegin(const std::set<unsigned>& rIndices);
352
357
358
363 class NodeIterator : public boost::iterator_facade<NodeIterator, const std::vector<double>,
364 boost::single_pass_traversal_tag>
365 {
366 public:
378 : mIndex(index),
379 mpIndices(nullptr),
380 mpReader(pReader)
381 {
382 CacheData(mIndex, true);
383 }
384
392 NodeIterator(const std::set<unsigned>& rIndices,
394
398 unsigned GetIndex() const
399 {
400 return mIndex;
401 }
402
403 private:
404 friend class boost::iterator_core_access;
405
413 void CacheData(unsigned index, bool firstRead = false);
414
418 void increment();
419
424 bool equal(const NodeIterator& rOther) const
425 {
426 return mIndex == rOther.mIndex;
427 }
428
435 const std::vector<double>& dereference() const
436 {
437 assert(mpReader);
438 assert(mIndex < mpReader->GetNumNodes());
439 // This was cached in increment()
440 return mLastDataRead;
441 }
442
444 unsigned mIndex;
445
447 const std::set<unsigned>* mpIndices;
448
450 std::set<unsigned>::const_iterator mIndicesIterator;
451
454
456 std::vector<double> mLastDataRead;
457 };
458
467
477 NodeIterator GetNodeIteratorBegin(const std::set<unsigned>& rIndices);
478
483};
484
485#endif //_ABSTRACTMESHREADER_HPP_
const double DOUBLE_UNSET
Definition Exception.hpp:57
const unsigned UNSIGNED_UNSET
Definition Exception.hpp:53
AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > * mpReader
ElementIterator(unsigned index, AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > *pReader)
bool equal(const ElementIterator &rOther) const
void CacheData(unsigned index, bool firstRead=false)
std::set< unsigned >::const_iterator mIndicesIterator
const std::set< unsigned > * mpIndices
const ElementData & dereference() const
const std::set< unsigned > * mpIndices
AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > * mpReader
std::set< unsigned >::const_iterator mIndicesIterator
NodeIterator(unsigned index, AbstractMeshReader< ELEMENT_DIM, SPACE_DIM > *pReader)
const std::vector< double > & dereference() const
void CacheData(unsigned index, bool firstRead=false)
bool equal(const NodeIterator &rOther) const
ElementIterator GetElementIteratorBegin()
virtual unsigned GetNumCableElementAttributes() const
ElementData GetEdgeData(unsigned index)
ElementData GetNextEdgeData()
virtual void Reset()=0
virtual unsigned GetNumElements() const =0
virtual std::vector< unsigned > GetContainingElementIndices(unsigned index)
virtual ElementData GetNextElementData()=0
virtual bool GetReadContainingElementOfBoundaryElement()
virtual unsigned GetOrderOfBoundaryElements()
virtual std::string GetMeshFileBaseName()
virtual unsigned GetNumFaces() const =0
NodeIterator GetNodeIteratorEnd()
virtual unsigned GetNumElementAttributes() const
virtual std::vector< double > GetNode(unsigned index)
virtual std::vector< double > GetNextNode()=0
virtual const std::vector< unsigned > & rGetNodePermutation()
virtual ElementData GetNextCableElementData()
unsigned GetNumEdges() const
virtual unsigned GetNumCableElements() const
virtual std::vector< double > GetNodeAttributes()
virtual ElementData GetFaceData(unsigned index)
virtual unsigned GetNumFaceAttributes() const
virtual bool HasNodePermutation()
virtual bool IsFileFormatBinary()
virtual unsigned GetNumNodes() const =0
virtual ElementData GetNextFaceData()=0
NodeIterator GetNodeIteratorBegin()
virtual ElementData GetElementData(unsigned index)
ElementIterator GetElementIteratorEnd()
virtual unsigned GetOrderOfElements()
unsigned ContainingElement
std::vector< unsigned > NodeIndices