Mesh Oriented datABase  (version 5.5.0)
An array-based unstructured mesh library
AEntityFactory.hpp
Go to the documentation of this file.
1 /**
2  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
3  * storing and accessing finite element mesh data.
4  *
5  * Copyright 2004 Sandia Corporation. Under the terms of Contract
6  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7  * retains certain rights in this software.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  */
15 
16 #ifndef AENTITY_FACTORY_HPP
17 #define AENTITY_FACTORY_HPP
18 
19 #ifndef IS_BUILDING_MB
20 #error "AEntityFactory.hpp isn't supposed to be included into an application"
21 #endif
22 
23 #include "moab/Forward.hpp"
24 #include <vector>
25 
26 namespace moab
27 {
28 
29 typedef std::vector< EntityHandle > AdjacencyVector;
30 class Core;
31 
32 //! class AEntityFactory
34 {
35  public:
36  //! require an Interface object in order to access tags on that interface
37  AEntityFactory( Core* mdb );
38 
39  //! destructor
41 
42  //! add an adjacency from from_ent to to_ent; if both_ways is true, add one
43  //! in reverse too
44  //! NOTE: this function is defined even though we may only be implementing
45  //! vertex-based up-adjacencies
46  ErrorCode add_adjacency( EntityHandle from_ent, EntityHandle to_ent, const bool both_ways = false );
47 
48  //! remove an adjacency from from the base_entity.
49  ErrorCode remove_adjacency( EntityHandle base_entity, EntityHandle adjacency_to_remove );
50 
51  //! remove all adjacencies from from the base_entity.
52  ErrorCode remove_all_adjacencies( EntityHandle base_entity, const bool delete_adj_list = false );
53 
54  /**\brief Get adjacencies for a single source entity.
55  *
56  * Get adjacent entities.
57  *
58  *\param source_entity The entity for which to retrieve the adjacencies.
59  *\param target_dimension Retrieve adjacent entities of this dimension. Must
60  * be in the range [1,3], where 4 is used to indicated entity sets.
61  *\param target_entities Requested adjacent entities will be appended to this list.
62  *\param create_if_missing If true, adjacent elements of the specified dimension will
63  * be created if they do not already exist. If the target dimension
64  * is less than the dimension of the input entity and greater than zero,
65  *the elements will be created as required to represent the "sides" of the source element. If
66  *the target dimension is greater than that of the source entity and less than 3, then sides of
67  *the specified dimension on that are a) of greater dimension and b) adjacent to the input
68  *entity will be created. \param create_adjacency_option If create_adjacency_option is >= 0,
69  *adjacencies from entities of that dimension to each target_entity are created (this function
70  *uses AEntityFactory::get_element for each element)
71  */
72  ErrorCode get_elements( EntityHandle source_entity,
73  const unsigned int target_dimension,
74  std::vector< EntityHandle >& target_entities,
75  const bool create_if_missing,
76  const int create_adjacency_option = -1 );
77 
78  //! get the vertices for a polyhedron (special implementation because for polyhedra
79  //! connectivity array stores faces)
80  ErrorCode get_polyhedron_vertices( const EntityHandle source_entity, std::vector< EntityHandle >& target_entities );
81 
82  //! get the meshsets that are in source_entitiy's adjacency vector
83  ErrorCode get_associated_meshsets( EntityHandle source_entity, std::vector< EntityHandle >& target_entities );
84 
85  //! get the element defined by the vertices in vertex_list, of the
86  //! type target_type, passing back in target_entity; if create_if_missing
87  //! is true and no entity is found, one is created; if create_adjacency_option
88  //! is >= 0, adjacencies from entities of that dimension to target_entity
89  //! are created (only create_adjacency_option=0 is supported right now,
90  //! so that never creates other ancillary entities); explicitly require
91  //! the vertex_list_size for consistency, even though we could probably get
92  //! it from target_type
93  ErrorCode get_element( const EntityHandle* vertex_list,
94  const int vertex_list_size,
95  const EntityType target_type,
96  EntityHandle& target_entity,
97  const bool create_if_missing,
98  const EntityHandle source_entity = 0,
99  const int create_adjacency_option = -1 );
100 
101  /**\brief Get adjacent entities
102  *
103  *\param entity The source entity for which to retrieve adjacent entities.
104  *\param to_dimension The adjacent entities to retrieve, specified by dimension.
105  *\param create_if_missing Create adjacent entities that do not already exist.
106  *\param adjacent_entities The resulting adjacent entities are appended to this
107  * list.
108  */
109  ErrorCode get_adjacencies( const EntityHandle entity,
110  const unsigned int to_dimension,
111  bool create_if_missing,
112  std::vector< EntityHandle >& adjacent_entities );
113 
114  //! return const array * for adjacencies
115  ErrorCode get_adjacencies( EntityHandle entity, const EntityHandle*& adjacent_entities, int& num_entities ) const;
116 
118  std::vector< EntityHandle >*& adj_vec_ptr_out,
119  bool create_if_missing = false );
120 
121  //! returns the entities in sorted order
122  ErrorCode get_adjacencies( EntityHandle entity, std::vector< EntityHandle >& adjacent_entities ) const;
123 
124  //! creates vertex to element adjacency information
126 
127  //! returns whether vertex to element adjacencies are being stored
129  {
130  return mVertElemAdj;
131  }
132 
133  //! calling code notifying this that an entity is getting deleted
135 
136  //! calling code notifying this that to update connectivity of 'entity'
137  ErrorCode notify_create_entity( const EntityHandle entity, const EntityHandle* node_array, const int number_nodes );
138 
139  //! calling code notifying that an entity changed its connectivity
141  const EntityHandle* old_array,
142  const EntityHandle* new_array,
143  int number_nodes );
144 
145  //! return true if 2 entities are explicitly adjacent
146  bool explicitly_adjacent( const EntityHandle ent1, const EntityHandle ent2 );
147 
148  //! in preparation for merging two entities, adjust adjacencies so that
149  //! entity_to_keep will be adjacent to the "right" entities after merge
150  //! (also checks for potential formation of equivalent entities and
151  //! creates explicit adjacencies accordingly)
152  ErrorCode merge_adjust_adjacencies( EntityHandle entity_to_keep, EntityHandle entity_to_remove );
153 
154  void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage );
156  unsigned long long& total_entity_storage,
157  unsigned long long& total_amortized_storage );
158 
159  private:
160  ErrorCode get_adjacency_ptr( EntityHandle, std::vector< EntityHandle >*& );
161  ErrorCode get_adjacency_ptr( EntityHandle, const std::vector< EntityHandle >*& ) const;
162  ErrorCode set_adjacency_ptr( EntityHandle, std::vector< EntityHandle >* );
163 
165  const EntityHandle*& vect_out,
166  int& count_out,
167  std::vector< EntityHandle >& storage );
168 
169  //! private constructor to prevent the construction of a default one
171 
172  //! interface associated with this tool
174 
175  //! whether vertex to element adjacencies are begin done
177 
178  //! compare vertex_list to the vertices in this_entity,
179  //! and return true if they contain the same vertices
180  bool entities_equivalent( const EntityHandle this_entity,
181  const EntityHandle* vertex_list,
182  const int vertex_list_size,
183  const EntityType target_type );
184 
186  const unsigned int target_dimension,
187  std::vector< EntityHandle >& target_entities,
188  const bool create_if_missing,
189  const int create_adjacency_option = -1 );
190 
192  const unsigned int target_dimension,
193  std::vector< EntityHandle >& target_entities,
194  const bool create_if_missing,
195  const int create_adjacency_option = -1 );
196 
198  const unsigned int target_dimension,
199  std::vector< EntityHandle >& target_entities,
200  const bool create_if_missing,
201  const int create_adjacency_option = -1 );
202 
204  const unsigned int target_dimension,
205  std::vector< EntityHandle >& target_entities,
206  const bool create_if_missing,
207  const int create_adjacency_option = -1 );
208 
209  //! check for equivalent entities that may be formed when merging two entities, and
210  //! create explicit adjacencies accordingly
211  ErrorCode check_equiv_entities( EntityHandle entity_to_keep, EntityHandle entity_to_remove );
212 
213  //! create explicit adjacencies between this_ent and all adjacent entities of higher
214  //! dimension
216 };
217 
218 } // namespace moab
219 
220 #endif