MOAB: Mesh Oriented datABase  (version 5.2.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, const unsigned int target_dimension,
00073                             std::vector< EntityHandle >& target_entities, const bool create_if_missing,
00074                             const int create_adjacency_option = -1 );
00075 
00076     //! get the vertices for a polyhedron (special implementation because for polyhedra
00077     //! connectivity array stores faces)
00078     ErrorCode get_polyhedron_vertices( const EntityHandle source_entity, std::vector< EntityHandle >& target_entities );
00079 
00080     //! get the meshsets that are in source_entitiy's adjacency vector
00081     ErrorCode get_associated_meshsets( EntityHandle source_entity, std::vector< EntityHandle >& target_entities );
00082 
00083     //! get the element defined by the vertices in vertex_list, of the
00084     //! type target_type, passing back in target_entity; if create_if_missing
00085     //! is true and no entity is found, one is created; if create_adjacency_option
00086     //! is >= 0, adjacencies from entities of that dimension to target_entity
00087     //! are created (only create_adjacency_option=0 is supported right now,
00088     //! so that never creates other ancillary entities); explicitly require
00089     //! the vertex_list_size for consistency, even though we could probably get
00090     //! it from target_type
00091     ErrorCode get_element( const EntityHandle* vertex_list, const int vertex_list_size, const EntityType target_type,
00092                            EntityHandle& target_entity, const bool create_if_missing,
00093                            const EntityHandle source_entity = 0, const int create_adjacency_option = -1 );
00094 
00095     /**\brief Get adjacent entities
00096      *
00097      *\param entity            The source entity for which to retrieve adjacent entities.
00098      *\param to_dimension      The adjacent entities to retrieve, specified by dimension.
00099      *\param create_if_missing Create adjacent entities that do not already exist.
00100      *\param adjacent_entities The resulting adjacent entities are appended to this
00101      *                         list.
00102      */
00103     ErrorCode get_adjacencies( const EntityHandle entity, const unsigned int to_dimension, bool create_if_missing,
00104                                std::vector< EntityHandle >& adjacent_entities );
00105 
00106     //! return const array * for adjacencies
00107     ErrorCode get_adjacencies( EntityHandle entity, const EntityHandle*& adjacent_entities, int& num_entities ) const;
00108 
00109     ErrorCode get_adjacencies( EntityHandle entity, std::vector< EntityHandle >*& adj_vec_ptr_out,
00110                                bool create_if_missing = false );
00111 
00112     //! returns the entities in sorted order
00113     ErrorCode get_adjacencies( EntityHandle entity, std::vector< EntityHandle >& adjacent_entities ) const;
00114 
00115     //! creates vertex to element adjacency information
00116     ErrorCode create_vert_elem_adjacencies();
00117 
00118     //! returns whether vertex to element adjacencies are being stored
00119     bool vert_elem_adjacencies() const
00120     {
00121         return mVertElemAdj;
00122     }
00123 
00124     //! calling code notifying this that an entity is getting deleted
00125     ErrorCode notify_delete_entity( EntityHandle entity );
00126 
00127     //! calling code notifying this that to update connectivity of 'entity'
00128     ErrorCode notify_create_entity( const EntityHandle entity, const EntityHandle* node_array, const int number_nodes );
00129 
00130     //! calling code notifying that an entity changed its connectivity
00131     ErrorCode notify_change_connectivity( EntityHandle entity, const EntityHandle* old_array,
00132                                           const EntityHandle* new_array, int number_nodes );
00133 
00134     //! return true if 2 entities are explicitly adjacent
00135     bool explicitly_adjacent( const EntityHandle ent1, const EntityHandle ent2 );
00136 
00137     //! in preparation for merging two entities, adjust adjacencies so that
00138     //! entity_to_keep will be adjacent to the "right" entities after merge
00139     //! (also checks for potential formation of equivalent entities and
00140     //! creates explicit adjacencies accordingly)
00141     ErrorCode merge_adjust_adjacencies( EntityHandle entity_to_keep, EntityHandle entity_to_remove );
00142 
00143     void get_memory_use( unsigned long long& total_entity_storage, unsigned long long& total_storage );
00144     ErrorCode get_memory_use( const Range& entities, unsigned long long& total_entity_storage,
00145                               unsigned long long& total_amortized_storage );
00146 
00147   private:
00148     ErrorCode get_adjacency_ptr( EntityHandle, std::vector< EntityHandle >*& );
00149     ErrorCode get_adjacency_ptr( EntityHandle, const std::vector< EntityHandle >*& ) const;
00150     ErrorCode set_adjacency_ptr( EntityHandle, std::vector< EntityHandle >* );
00151 
00152     ErrorCode get_vertices( EntityHandle h, const EntityHandle*& vect_out, int& count_out,
00153                             std::vector< EntityHandle >& storage );
00154 
00155     //! private constructor to prevent the construction of a default one
00156     AEntityFactory();
00157 
00158     //! interface associated with this tool
00159     Core* thisMB;
00160 
00161     //! whether vertex to element adjacencies are begin done
00162     bool mVertElemAdj;
00163 
00164     //! compare vertex_list to the vertices in this_entity,
00165     //!  and return true if they contain the same vertices
00166     bool entities_equivalent( const EntityHandle this_entity, const EntityHandle* vertex_list,
00167                               const int vertex_list_size, const EntityType target_type );
00168 
00169     ErrorCode get_zero_to_n_elements( EntityHandle source_entity, const unsigned int target_dimension,
00170                                       std::vector< EntityHandle >& target_entities, const bool create_if_missing,
00171                                       const int create_adjacency_option = -1 );
00172 
00173     ErrorCode get_down_adjacency_elements( EntityHandle source_entity, const unsigned int target_dimension,
00174                                            std::vector< EntityHandle >& target_entities, const bool create_if_missing,
00175                                            const int create_adjacency_option = -1 );
00176 
00177     ErrorCode get_down_adjacency_elements_poly( EntityHandle source_entity, const unsigned int target_dimension,
00178                                                 std::vector< EntityHandle >& target_entities,
00179                                                 const bool create_if_missing, const int create_adjacency_option = -1 );
00180 
00181     ErrorCode get_up_adjacency_elements( EntityHandle source_entity, const unsigned int target_dimension,
00182                                          std::vector< EntityHandle >& target_entities, const bool create_if_missing,
00183                                          const int create_adjacency_option = -1 );
00184 
00185     //! check for equivalent entities that may be formed when merging two entities, and
00186     //! create explicit adjacencies accordingly
00187     ErrorCode check_equiv_entities( EntityHandle entity_to_keep, EntityHandle entity_to_remove );
00188 
00189     //! create explicit adjacencies between this_ent and all adjacent entities of higher
00190     //! dimension
00191     ErrorCode create_explicit_adjs( EntityHandle this_ent );
00192 };
00193 
00194 }  // namespace moab
00195 
00196 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines