MOAB: Mesh Oriented datABase  (version 5.2.1)
ReorderTool.hpp
Go to the documentation of this file.
00001 /** \file   ReorderTool.hpp
00002  *  \author Jason Kraftcheck
00003  *  \date   2011-05-23
00004  */
00005 
00006 #ifndef moab_REORDER_TOOL_HPP
00007 #define moab_REORDER_TOOL_HPP
00008 
00009 #include "moab/Types.hpp"
00010 #include <vector>
00011 
00012 namespace moab
00013 {
00014 
00015 class Core;
00016 class Range;
00017 
00018 class ReorderTool
00019 {
00020   public:
00021     ReorderTool( Core* moab ) : mMB( moab ) {}
00022 
00023     /**\brief Calculate new handle order by tag value.
00024      *
00025      * Given a tag containing integer values, calculate new order for entities
00026      * in the database (except entity sets) such that all entities
00027      * with tag value A occur before all entities with tag value B
00028      * in the handle space where A < B.  Ordering will be stable for
00029      * entities with the same tag value.
00030      *
00031      *\param ordering_tag  Sinlge integer tag, where value on each entity
00032      *                     determines the new position in the handle ordering.
00033      *                     Entities may have duplicate values.
00034      *\param ordering_tag_skip_value Do not reorder entities with this tag
00035      *                     value. This is typically the default value of
00036      *                     ordering_tag.  Specifying this limits the re-ordering
00037      *                     to only those entities for which ordering_tag has
00038      *                     been set.
00039      *\param new_handle_tag_out  Passed back new tag handle containing the
00040      *                     entity mapping.  The returned tag will be anonymous.
00041      *                     The caller is responsible for releasing the tag.
00042      *                     The value of this tag on each handle is the new
00043      *                     handle that the entity will will be moved to. The
00044      *                     tag value will be zero for entities that were not
00045      *                     re-ordered.
00046      */
00047     ErrorCode handle_order_from_int_tag( Tag ordering_tag, int ordering_tag_skip_value, Tag& new_handle_tag_out );
00048 
00049     /**\brief Calculate new handle order by tag value.
00050      *
00051      * Given a tag containing integer values, calculate new order for entities
00052      * in the database (except entity sets) such that all entities
00053      * with tag value A occur before all entities with tag value B
00054      * in the handle space where A < B.  Ordering will be stable for
00055      * entities with the same tag value.
00056      *
00057      *\param type          Entity type for which to calculate re-ordering.
00058      *\param vals_per_ent  Zero for vertices.  Connectivity length for elements.
00059      *\param ordering_tag  Sinlge integer tag, where value on each entity
00060      *                     determines the new position in the handle ordering.
00061      *                     Entities may have duplicate values.
00062      *\param ordering_tag_skip_value Do not reorder entities with this tag
00063      *                     value. This is typically the default value of
00064      *                     ordering_tag.  Specifying this limits the re-ordering
00065      *                     to only those entities for which ordering_tag has
00066      *                     been set.
00067      *\param new_handle_tag Tag into which to store new handle for each
00068      *                     entity.  Tag must be defined to store a single
00069      *                     entity handle and must have a default value of
00070      *                     zero.
00071      */
00072     ErrorCode handle_order_from_int_tag( EntityType type, int vals_per_ent, Tag ordering_tag,
00073                                          int ordering_tag_skip_value, Tag new_handle_tag );
00074 
00075     /**\brief Calculate new handle order by set containment
00076      *
00077      * Given a list of sets, re-order entities such that handles are
00078      * grouped contiguously by set.  Will also group all adjacent mesh
00079      * entities, such that entities that are are adjacent to members of
00080      * two or more of the input sets will ge grouped by the combined
00081      * list of sets (e.g. if the input sets contain elements then all
00082      * vertices that are adjacent to only elements in the first two sets
00083      * will be grouped together).
00084      *
00085      *\param sets          Entity sets by which to group entities.
00086      *\param new_handle_tag_out  Passed back new tag handle containing the
00087      *                     entity mapping.  The returned tag will be anonymous.
00088      *                     The caller is responsible for releasing the tag.
00089      *                     The value of this tag on each handle is the new
00090      *                     handle that the entity will will be moved to. The
00091      *                     tag value will be zero for entities that were not
00092      *                     re-ordered.
00093      */
00094     ErrorCode handle_order_from_sets_and_adj( const Range& sets, Tag& new_handle_tag_out );
00095 
00096     /**\brief Do the re-ordering indicated by the passed handle tag.
00097      *
00098      * The specified re-ordering must be a permutation.  Each existing
00099      * entity must be moved to a new, existing handle such that no
00100      * two entities are moved to the same new handle.
00101      *
00102      * Given a tag storing handles that define a permution, apply the
00103      * described re-ordering.  The passed tag must contain one entity
00104      * handle per entity.  The value of the tag must be zero for all
00105      * entities that are not to be re-ordered.  For entities to be
00106      * re-ordered, the tag must contain the new handle that the entity
00107      * is to be moved to.  No two entities may have the same value for
00108      * this tag (other than a value of zero.)
00109      *
00110      *\param new_handle_tag Tag containing new handles for entities to
00111      *                      reorder.  Typically the output of
00112      *                      handle_order_from_int_tag or similar.
00113      */
00114     ErrorCode reorder_entities( Tag new_handle_tag );
00115 
00116   private:
00117     /**\brief helper function for reorder_entities
00118      *
00119      * Reorder tag data for all entities of specified type.
00120      *
00121      * Also updates tag values for MB_TYPE_HANDLE tags.
00122      *\param type  Entity type to reorder
00123      *\param new_handles Tag containing old->new handle mapping
00124      *\param reorder_tag The tag data to reorder
00125      */
00126     ErrorCode reorder_tag_data( EntityType type, Tag new_handles, Tag reorder_tag );
00127 
00128     /**\brief helper function for reorder_entities
00129      *
00130      * Update set contents for changed handles.
00131      *\param new_handles Tag containing old->new handle mapping
00132      */
00133     ErrorCode update_set_contents( Tag new_handles );
00134 
00135     /**\brief Get all entities of specified type and size
00136      *\param t the type of entity to retreive
00137      *\param vals_per_ent entity size (connectivity length for elements,
00138      *         dimension for vertices)
00139      */
00140     void get_entities( EntityType t, int vals_per_ent, Range& result );
00141 
00142     /**\brief Get new handles corresponding to old handles
00143      *\param tag Tag containing old->new mapping
00144      */
00145     ErrorCode get_reordered_handles( Tag tag, const Range& old_handles, std::vector< EntityHandle >& new_handles );
00146 
00147     /**\brief Get new handles corresponding to old handles
00148      *\param tag Tag containing old->new mapping
00149      */
00150     ErrorCode get_reordered_handles( Tag tag, const std::vector< EntityHandle >& old_handles,
00151                                      std::vector< EntityHandle >& new_handles );
00152 
00153     /**\brief Get new handles corresponding to old handles
00154      *\param tag Tag containing old->new mapping
00155      */
00156     ErrorCode get_reordered_handles( Tag tag, const EntityHandle* old_handles, EntityHandle* new_handles,
00157                                      size_t num_handles );
00158 
00159     /**\brief Remove any non-ordered handles and return new handles for remaining
00160      *\param tag Tag containing old->new mapping
00161      */
00162     ErrorCode get_new_handles( Tag tag, Range& old_handles, std::vector< EntityHandle >& newhandles );
00163 
00164     /**\brief convert from input for \c handle_order_from_sets_and_adj to
00165      *        \c input for handle_order_from_int_tag
00166      */
00167     ErrorCode int_order_from_sets_and_adj( const Range& sets, Tag order_tag, int skip_val,
00168                                            std::vector< std::vector< EntityHandle >* >& data );
00169 
00170     Core* mMB;
00171 };
00172 
00173 }  // namespace moab
00174 
00175 #endif  // moab_REORDER_TOOL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines