Chaste  Release::3.4
AbstractMeshReader.hpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, 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 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF 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  std::vector<unsigned> NodeIndices;
54  double AttributeValue;
55  unsigned ContainingElement;
56 };
57 
70 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
72 {
73 
74 public:
75 
76  virtual ~AbstractMeshReader()
77  {}
78 
80  virtual unsigned GetNumElements() const =0;
81 
83  virtual unsigned GetNumNodes() const =0;
84 
86  virtual unsigned GetNumFaces() const =0;
87 
89  virtual unsigned GetNumCableElements() const;
90 
92  virtual unsigned GetNumElementAttributes() const;
93 
95  virtual unsigned GetNumFaceAttributes() const;
96 
98  virtual unsigned GetNumCableElementAttributes() const;
99 
107  virtual std::vector<double> GetNodeAttributes();
108 
110  unsigned GetNumEdges() const;
111 
113  virtual std::vector<double> GetNextNode()=0;
114 
116  virtual void Reset()=0;
117 
119  virtual ElementData GetNextElementData()=0;
120 
122  virtual ElementData GetNextFaceData()=0;
123 
126 
129 
130 
137  virtual std::vector<double> GetNode(unsigned index);
138 
145  virtual ElementData GetElementData(unsigned index);
146 
153  virtual ElementData GetFaceData(unsigned index);
154 
161  ElementData GetEdgeData(unsigned index);
162 
170  virtual std::vector<unsigned> GetContainingElementIndices(unsigned index);
171 
175  virtual std::string GetMeshFileBaseName();
176 
180  virtual unsigned GetOrderOfElements();
181 
185  virtual unsigned GetOrderOfBoundaryElements();
186 
191 
192 
199  virtual bool IsFileFormatBinary();
200 
207  virtual bool HasNclFile();
208 
215  virtual bool HasNodePermutation();
216 
223  virtual const std::vector<unsigned>& rGetNodePermutation();
224 
225 
226  // Iterator classes
227 
231  class ElementIterator : public boost::iterator_facade<ElementIterator, const ElementData,
232  boost::single_pass_traversal_tag>
233  {
234  public:
240  mpIndices(NULL),
241  mpReader(NULL)
242  {
243  }
244 
255  ElementIterator(unsigned index, AbstractMeshReader* pReader)
256  : mIndex(index),
257  mpIndices(NULL),
258  mpReader(pReader)
259  {
260  CacheData(mIndex, true);
261  }
262 
270  ElementIterator(const std::set<unsigned>& rIndices,
271  AbstractMeshReader* pReader);
272 
276  unsigned GetIndex() const
277  {
278  return mIndex;
279  }
280 
281  private:
282  friend class boost::iterator_core_access;
283 
291  void CacheData(unsigned index, bool firstRead = false);
292 
296  void increment();
297 
302  bool equal(const ElementIterator& rOther) const
303  {
304  return mIndex == rOther.mIndex;
305  }
306 
314  const ElementData& dereference() const
315  {
316  assert(mpReader);
317  assert(mIndex < mpReader->GetNumElements());
318  // This was cached in increment()
319  return mLastDataRead;
320  }
321 
323  unsigned mIndex;
324 
326  const std::set<unsigned>* mpIndices;
327 
329  std::set<unsigned>::const_iterator mIndicesIterator;
330 
333 
336  };
337 
346 
356  ElementIterator GetElementIteratorBegin(const std::set<unsigned>& rIndices);
357 
362 
363 
367  class NodeIterator : public boost::iterator_facade<NodeIterator, const std::vector<double>,
369  boost::single_pass_traversal_tag>
370  {
371  public:
377  mpIndices(NULL),
378  mpReader(NULL)
379  {
380  }
381 
392  NodeIterator(unsigned index, AbstractMeshReader* pReader)
393  : mIndex(index),
394  mpIndices(NULL),
395  mpReader(pReader)
396  {
397  CacheData(mIndex, true);
398  }
399 
407  NodeIterator(const std::set<unsigned>& rIndices,
408  AbstractMeshReader* pReader);
409 
413  unsigned GetIndex() const
414  {
415  return mIndex;
416  }
417 
418  private:
419  friend class boost::iterator_core_access;
420 
428  void CacheData(unsigned index, bool firstRead = false);
429 
433  void increment();
434 
439  bool equal(const NodeIterator& rOther) const
440  {
441  return mIndex == rOther.mIndex;
442  }
443 
450  const std::vector<double>& dereference() const
451  {
452  assert(mpReader);
453  assert(mIndex < mpReader->GetNumNodes());
454  // This was cached in increment()
455  return mLastDataRead;
456  }
457 
459  unsigned mIndex;
460 
462  const std::set<unsigned>* mpIndices;
463 
465  std::set<unsigned>::const_iterator mIndicesIterator;
466 
469 
471  std::vector<double> mLastDataRead;
472  };
473 
482 
492  NodeIterator GetNodeIteratorBegin(const std::set<unsigned>& rIndices);
493 
498 };
499 
500 #endif //_ABSTRACTMESHREADER_HPP_
ElementIterator GetElementIteratorBegin()
std::set< unsigned >::const_iterator mIndicesIterator
std::set< unsigned >::const_iterator mIndicesIterator
virtual ElementData GetNextElementData()=0
virtual ElementData GetElementData(unsigned index)
virtual ElementData GetFaceData(unsigned index)
virtual unsigned GetNumCableElementAttributes() const
NodeIterator(unsigned index, AbstractMeshReader *pReader)
unsigned ContainingElement
bool equal(const NodeIterator &rOther) const
NodeIterator GetNodeIteratorEnd()
NodeIterator GetNodeIteratorBegin()
virtual unsigned GetOrderOfElements()
const std::set< unsigned > * mpIndices
virtual ElementData GetNextFaceData()=0
std::vector< unsigned > NodeIndices
virtual bool HasNodePermutation()
ElementIterator GetElementIteratorEnd()
virtual ElementData GetNextCableElementData()
virtual std::vector< double > GetNode(unsigned index)
virtual unsigned GetNumElements() const =0
ElementData GetEdgeData(unsigned index)
ElementData GetNextEdgeData()
virtual void Reset()=0
const ElementData & dereference() const
const unsigned UNSIGNED_UNSET
Definition: Exception.hpp:52
unsigned GetNumEdges() const
virtual unsigned GetNumFaceAttributes() const
virtual unsigned GetNumElementAttributes() const
virtual bool GetReadContainingElementOfBoundaryElement()
virtual bool IsFileFormatBinary()
virtual unsigned GetOrderOfBoundaryElements()
virtual unsigned GetNumCableElements() const
void CacheData(unsigned index, bool firstRead=false)
virtual std::vector< unsigned > GetContainingElementIndices(unsigned index)
virtual std::string GetMeshFileBaseName()
virtual std::vector< double > GetNextNode()=0
ElementIterator(unsigned index, AbstractMeshReader *pReader)
void CacheData(unsigned index, bool firstRead=false)
const std::set< unsigned > * mpIndices
const std::vector< double > & dereference() const
virtual unsigned GetNumNodes() const =0
virtual std::vector< double > GetNodeAttributes()
virtual unsigned GetNumFaces() const =0
virtual const std::vector< unsigned > & rGetNodePermutation()
bool equal(const ElementIterator &rOther) const