Branch data Line data Source code
1 : : // *****************************************************************************
2 : : /*!
3 : : \file src/Mesh/Around.hpp
4 : : \copyright 2012-2015 J. Bakosi,
5 : : 2016-2018 Los Alamos National Security, LLC.,
6 : : 2019-2021 Triad National Security, LLC.,
7 : : 2022-2025 J. Bakosi
8 : : All rights reserved. See the LICENSE file for details.
9 : : \brief Helper class for iterating through linked lists of derived data
10 : : \details Helper class for iterating through every item in a linked list data
11 : : structure derived from unstructured mesh connectivity.
12 : : \see src/Mesh/DerivedData.h
13 : : */
14 : : // *****************************************************************************
15 : : #ifndef Around_h
16 : : #define Around_h
17 : :
18 : : #include <vector>
19 : : #include <map>
20 : : #include <utility>
21 : : #include <cstddef>
22 : : #include "Types.hpp"
23 : : #include "Fields.hpp"
24 : : #include "UnsMesh.hpp"
25 : :
26 : : namespace tk {
27 : :
28 : : //! \brief Helper class simplifying client code for iterating on entries
29 : : //! surrounding entries via linked lists derived from unstructured mesh
30 : : //! connectivity
31 : : class Around {
32 : :
33 : : private:
34 : : //! Linked list type: T1: item list, T2: index list
35 : : using List =
36 : : std::pair< std::vector< std::size_t >, std::vector< std::size_t > >;
37 : :
38 : : //! Non-const iterator to the item list in List::T1
39 : : using iterator = List::first_type::iterator;
40 : :
41 : : //! Const iterator to the item list in List::T1
42 : : using const_iterator = List::first_type::const_iterator;
43 : :
44 : : //! Difference type for iterator/pointer arithmetics
45 : : using diff_type = List::first_type::difference_type;
46 : :
47 : : public:
48 : : //! Constructor
49 : : //! \param[in] list Linked list (vectors) storing derived data
50 : : //! \param[in] idx Index of entry whose surrounding items we will iterate on
51 : : explicit Around( const List& list, std::size_t idx ) :
52 : : m_list( list ), m_idx( idx ) {}
53 : :
54 : : //! Const iterator to the beginning of the entries of surrounding entries
55 : : //! \return Iterator to the beginning of the entries of surrounding entries
56 : : //! \note This class does not allow modifing the underlying linked list, so
57 : : //! the begin/end iterators are aliased to cbegin/cend.
58 : : const_iterator begin() const noexcept { return this->cbegin(); }
59 : :
60 : : //! Const iterator to the entry after the last of the surrounding entries
61 : : //! \return Iterator to the entry after the last of the surrounding entries
62 : : //! \note This class does not allow modifing the underlying linked list, so
63 : : //! the begin/end iterators are aliased to cbegin/cend.
64 : : const_iterator end() const noexcept { return this->cend(); }
65 : :
66 : : //! Iterator to the beginning of the entries of surrounding entries
67 : : //! \return Iterator to the beginning of the entries of surrounding entries
68 : : const_iterator cbegin() const noexcept {
69 : : return m_list.first.cbegin() +
70 [ + - ][ + - ]: 942540 : static_cast< diff_type >( m_list.second[m_idx] + 1 );
[ + - ][ + - ]
71 : : }
72 : :
73 : : //! Iterator to the entry after the last of the surrounding entries
74 : : //! \return Iterator to the entry after the last of the surrounding entries
75 : : const_iterator cend() const noexcept {
76 : : return m_list.first.cbegin() +
77 [ + - ][ + - ]: 942540 : static_cast< diff_type >( m_list.second[m_idx+1] + 1 );
[ + - ][ + - ]
78 : : }
79 : :
80 : : private:
81 : : const List& m_list; //!< Linked list to iterate in
82 : : std::size_t m_idx; //!< Index whose surrounding entries to iterate on
83 : : };
84 : :
85 : : } // tk::
86 : :
87 : : #endif // Around_h
|