MOAB: Mesh Oriented datABase  (version 5.4.1)
AEntityFactory.hpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifndef AENTITY_FACTORY_HPP
00017 #define AENTITY_FACTORY_HPP
00018 
00019 #ifndef IS_BUILDING_MB
00020 #error "AEntityFactory.hpp isn't supposed to be included into an application"
00021 #endif
00022 
00023 #include "moab/Forward.hpp"
00024 #include <vector>
00025 
00026 namespace moab
00027 {
00028 
00029 typedef std::vector< EntityHandle > AdjacencyVector;
00030 class Core;
00031 
00032 //! class AEntityFactory
00033 class AEntityFactory
00034 {
00035   public:
00036     //! require an Interface object in order to access tags on that interface
00037     AEntityFactory( Core* mdb );
00038 
00039     //! destructor
00040     ~AEntityFactory();
00041 
00042     //! add an adjacency from from_ent to to_ent; if both_ways is true, add one
00043     //! in reverse too
00044     //! NOTE: this function is defined even though we may only be implementing
00045     //! vertex-based up-adjacencies
00046     ErrorCode add_adjacency( EntityHandle from_ent, EntityHandle to_ent, const bool both_ways = false );
00047 
00048     //! remove an adjacency from from the base_entity.
00049     ErrorCode remove_adjacency( EntityHandle base_entity, EntityHandle adjacency_to_remove );
00050 
00051     //! remove all adjacencies from from the base_entity.
00052     ErrorCode remove_all_adjacencies( EntityHandle base_entity, const bool delete_adj_list = false );
00053 
00054     /**\brief Get adjacencies for a single source entity.
00055      *
00056      * Get adjacent entities.
00057      *
00058      *\param source_entity    The entity for which to retrieve the adjacencies.
00059      *\param target_dimension Retrieve adjacent entities of this dimension.  Must
00060      *                        be in the range [1,3], where 4 is used to indicated entity sets.
00061      *\param target_entities  Requested adjacent entities will be appended to this list.
00062      *\param create_if_missing If true, adjacent elements of the specified dimension will
00063      *                        be created if they do not already exist.  If the target dimension
00064      *                        is less than the dimension of the input entity and greater than zero,
00065      *the elements will be created as required to represent the "sides" of the source element.  If
00066      *the target dimension is greater than that of the source entity and less than 3, then sides of
00067      *the specified dimension on that are a) of greater dimension and b) adjacent to the input
00068      *entity will be created. \param create_adjacency_option If create_adjacency_option is >= 0,
00069      *adjacencies from entities of that dimension to each target_entity are created (this function
00070      *uses AEntityFactory::get_element for each element)
00071      */
00072     ErrorCode get_elements( EntityHandle source_entity,
00073                             const unsigned int target_dimension,
00074                             std::vector< EntityHandle >& target_entities,
00075                             const bool create_if_missing,
00076                             const int create_adjacency_option = -1 );
00077 
00078     //! get the vertices for a polyhedron (special implementation because for polyhedra
00079     //! connectivity array stores faces)
00080     ErrorCode get_polyhedron_vertices( const EntityHandle source_entity, std::vector< EntityHandle >& target_entities );
00081 
00082     //! get the meshsets that are in source_entitiy's adjacency vector
00083     ErrorCode get_associated_meshsets( EntityHandle source_entity, std::vector< EntityHandle >& target_entities );
00084 
00085     //! get the element defined by the vertices in vertex_list, of the
00086     //! type target_type, passing back in target_entity; if create_if_missing
00087     //! is true and no entity is found, one is created; if create_adjacency_option
00088     //! is >= 0, adjacencies from entities of that dimension to target_entity
00089     //! are created (only create_adjacency_option=0 is supported right now,
00090     //! so that never creates other ancillary entities); explicitly require
00091     //! the vertex_list_size for consistency, even though we could probably get
00092     //! it from target_type
00093     ErrorCode get_element( const EntityHandle* vertex_list,
00094                            const int vertex_list_size,
00095                            const EntityType target_type,
00096                            EntityHandle& target_entity,
00097                            const bool create_if_missing,
00098                            const EntityHandle source_entity  = 0,
00099                            const int create_adjacency_option = -1 );
00100 
00101     /**\brief Get adjacent entities
00102      *
00103      *\param entity            The source entity for which to retrieve adjacent entities.
00104      *\param to_dimension      The adjacent entities to retrieve, specified by dimension.
00105      *\param create_if_missing Create adjacent entities that do not already exist.
00106      *\param adjacent_entities The resulting adjacent entities are appended to this
00107      *                         list.
00108      */
00109     ErrorCode get_adjacencies( const EntityHandle entity,
00110                                const unsigned int to_dimension,
00111                                bool create_if_missing,
00112                                std::vector< EntityHandle >& adjacent_entities );
00113 
00114     //! return const array * for adjacencies
00115     ErrorCode get_adjacencies( EntityHandle entity, const EntityHandle*& adjacent_entities, int& num_entities ) const;
00116 
00117     ErrorCode get_adjacencies( EntityHandle entity,
00118                                std::vector< EntityHandle >*& adj_vec_ptr_out,
00119                                bool create_if_missing = false );
00120 
00121     //! returns the entities in sorted order
00122     ErrorCode get_adjacencies( EntityHandle entity, std::vector< EntityHandle >& adjacent_entities ) const;
00123 
00124     //! creates vertex to element adjacency information
00125     ErrorCode create_vert_elem_adjacencies();
00126 
00127     //! returns whether vertex to element adjacencies are being stored
00128     bool vert_elem_adjacencies() const
00129     {
00130         return mVertElemAdj;
00131     }
00132 
00133     //! calling code notifying this that an entity is getting deleted
00134     ErrorCode notify_delete_entity( EntityHandle entity );
00135 
00136     //! calling code notifying this that to update connectivity of 'entity'
00137     ErrorCode notify_create_entity( const EntityHandle entity, const EntityHandle* node_array, const int number_nodes );
00138 
00139     //! calling code notifying that an entity changed its connectivity
00140     ErrorCode notify_change_connectivity( EntityHandle entity,
00141                                           const EntityHandle* old_array,
00142                                           const EntityHandle* new_array,
00143                                           int number_nodes );
00144 
00145     //! return true if 2 entities are explicitly adjacent
00146     bool explicitly_adjacent( const EntityHandle ent1, const EntityHandle ent2 );
00147 
00148     //! in preparation for merging two entities, adjust adjacencies so that
00149     //! entity_to_keep will be adjacent to the "right" entities after merge
00150     //! (also checks for potential formation of equivalent entities and
00151     //! creates explicit adjacencies accordingly)
00152     ErrorCode merge_adjust_adjacencies( EntityHandle entity_to_keep, EntityHandle entity_to_remove );
00153 
00154     void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage );
00155     ErrorCode get_memory_use( const Range& entities,
00156                               unsigned long long& total_entity_storage,
00157                               unsigned long long& total_amortized_storage );
00158 
00159   private:
00160     ErrorCode get_adjacency_ptr( EntityHandle, std::vector< EntityHandle >*& );
00161     ErrorCode get_adjacency_ptr( EntityHandle, const std::vector< EntityHandle >*& ) const;
00162     ErrorCode set_adjacency_ptr( EntityHandle, std::vector< EntityHandle >* );
00163 
00164     ErrorCode get_vertices( EntityHandle h,
00165                             const EntityHandle*& vect_out,
00166                             int& count_out,
00167                             std::vector< EntityHandle >& storage );
00168 
00169     //! private constructor to prevent the construction of a default one
00170     AEntityFactory();
00171 
00172     //! interface associated with this tool
00173     Core* thisMB;
00174 
00175     //! whether vertex to element adjacencies are begin done
00176     bool mVertElemAdj;
00177 
00178     //! compare vertex_list to the vertices in this_entity,
00179     //!  and return true if they contain the same vertices
00180     bool entities_equivalent( const EntityHandle this_entity,
00181                               const EntityHandle* vertex_list,
00182                               const int vertex_list_size,
00183                               const EntityType target_type );
00184 
00185     ErrorCode get_zero_to_n_elements( EntityHandle source_entity,
00186                                       const unsigned int target_dimension,
00187                                       std::vector< EntityHandle >& target_entities,
00188                                       const bool create_if_missing,
00189                                       const int create_adjacency_option = -1 );
00190 
00191     ErrorCode get_down_adjacency_elements( EntityHandle source_entity,
00192                                            const unsigned int target_dimension,
00193                                            std::vector< EntityHandle >& target_entities,
00194                                            const bool create_if_missing,
00195                                            const int create_adjacency_option = -1 );
00196 
00197     ErrorCode get_down_adjacency_elements_poly( EntityHandle source_entity,
00198                                                 const unsigned int target_dimension,
00199                                                 std::vector< EntityHandle >& target_entities,
00200                                                 const bool create_if_missing,
00201                                                 const int create_adjacency_option = -1 );
00202 
00203     ErrorCode get_up_adjacency_elements( EntityHandle source_entity,
00204                                          const unsigned int target_dimension,
00205                                          std::vector< EntityHandle >& target_entities,
00206                                          const bool create_if_missing,
00207                                          const int create_adjacency_option = -1 );
00208 
00209     //! check for equivalent entities that may be formed when merging two entities, and
00210     //! create explicit adjacencies accordingly
00211     ErrorCode check_equiv_entities( EntityHandle entity_to_keep, EntityHandle entity_to_remove );
00212 
00213     //! create explicit adjacencies between this_ent and all adjacent entities of higher
00214     //! dimension
00215     ErrorCode create_explicit_adjs( EntityHandle this_ent );
00216 };
00217 
00218 }  // namespace moab
00219 
00220 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines