DataTransferKit - Multiphysics Solution Transfer Services  2.0
DTK_BasicEntitySet.hpp
1 //---------------------------------------------------------------------------//
2 /*
3  Copyright (c) 2012, Stuart R. Slattery
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are
8  met:
9 
10  *: Redistributions of source code must retain the above copyright
11  notice, this list of conditions and the following disclaimer.
12 
13  *: Redistributions in binary form must reproduce the above copyright
14  notice, this list of conditions and the following disclaimer in the
15  documentation and/or other materials provided with the distribution.
16 
17  *: Neither the name of the University of Wisconsin - Madison nor the
18  names of its contributors may be used to endorse or promote products
19  derived from this software without specific prior written permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 //---------------------------------------------------------------------------//
39 //---------------------------------------------------------------------------//
40 
41 #ifndef DTK_BASICENTITYSET_HPP
42 #define DTK_BASICENTITYSET_HPP
43 
44 #include <unordered_map>
45 
46 #include "DTK_Entity.hpp"
47 #include "DTK_EntityIterator.hpp"
48 #include "DTK_EntitySet.hpp"
49 #include "DTK_Types.hpp"
50 
51 #include <Teuchos_Array.hpp>
52 #include <Teuchos_ArrayView.hpp>
53 #include <Teuchos_Comm.hpp>
54 #include <Teuchos_RCP.hpp>
55 
56 namespace DataTransferKit
57 {
58 //---------------------------------------------------------------------------//
64 {
65  public:
66  // Default constructor.
68 
69  // Constructor.
71  Teuchos::RCP<std::unordered_map<EntityId, Entity>> map,
72  const PredicateFunction &predicate );
73 
74  // Copy constructor.
76 
81 
82  // Pre-increment operator.
83  EntityIterator &operator++() override;
84 
85  // Dereference operator.
86  Entity &operator*(void)override;
87 
88  // Dereference operator.
89  Entity *operator->(void)override;
90 
91  // Equal comparison operator.
92  bool operator==( const EntityIterator &rhs ) const override;
93 
94  // Not equal comparison operator.
95  bool operator!=( const EntityIterator &rhs ) const override;
96 
97  // An iterator assigned to the beginning.
98  EntityIterator begin() const override;
99 
100  // An iterator assigned to the end.
101  EntityIterator end() const override;
102 
103  // Create a clone of the iterator. We need this for the copy constructor
104  // and assignment operator to pass along the underlying implementation.
105  std::unique_ptr<EntityIterator> clone() const override;
106 
107  private:
108  // Map to iterate over.
109  Teuchos::RCP<std::unordered_map<EntityId, Entity>> d_map;
110 
111  // Iterator over the entity map.
112  std::unordered_map<EntityId, Entity>::iterator d_map_it;
113 
114  // Pointer to the current entity.
115  Entity *d_entity;
116 };
117 
118 //---------------------------------------------------------------------------//
123 //---------------------------------------------------------------------------//
124 class BasicEntitySet : public EntitySet
125 {
126  public:
128  typedef std::pair<EntityId, Entity> EntityIdPair;
131 
135  BasicEntitySet( const Teuchos::RCP<const Teuchos::Comm<int>> comm,
136  const int physical_dimension );
137 
141  void addEntity( const Entity &entity );
142 
144 
149  Teuchos::RCP<const Teuchos::Comm<int>> communicator() const override;
151 
153 
158  int physicalDimension() const override;
160 
162 
170  void getEntity( const EntityId entity_id, const int topological_dimension,
171  Entity &entity ) const override;
172 
181  EntityIterator entityIterator( const int topological_dimension,
182  const PredicateFunction &predicate =
183  EntitySet::selectAll ) const override;
184 
189  virtual void getAdjacentEntities(
190  const Entity &entity, const int adjacent_dimension,
191  Teuchos::Array<Entity> &adjacent_entities ) const override;
193 
194  private:
195  // Given a parametric dimension, get an id-to-entity map.
196  std::unordered_map<EntityId, Entity> &
197  getEntityMap( const int parametric_dimension );
198 
199  private:
200  // Parallel communicator.
201  Teuchos::RCP<const Teuchos::Comm<int>> d_comm;
202 
203  // Physical dimension.
204  int d_physical_dim;
205 
206  // Id-to-entity maps.
207  mutable Teuchos::Array<std::unordered_map<EntityId, Entity>> d_entities;
208 };
209 
210 //---------------------------------------------------------------------------//
211 
212 } // end namespace DataTransferKit
213 
214 #endif // end DTK_BASICENTITYSET_HPP
215 
216 //---------------------------------------------------------------------------//
217 // end DTK_BasicEntitySet.hpp
218 //---------------------------------------------------------------------------//
Geometric entity interface definition.
Definition: DTK_Entity.hpp:61
Entity iterator interface.
static bool selectAll(Entity)
Select all entities predicate.
ementation of iterator over entities in a basic set.
Geometric entity set interface definition.
std::pair< EntityId, Entity > EntityIdPair
Entity map typedefs.
std::function< bool(Entity)> PredicateFunction
Predicate function typedef.
Definition: DTK_Types.hpp:64
unsigned long int EntityId
Entity id type.
Definition: DTK_Types.hpp:50
Basic implementation of the entity set interface.
BasicEntitySetIterator & operator=(const BasicEntitySetIterator &rhs)
Assignment operator.
DTK_BasicEntitySet.cpp.