Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
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,
00073                                          int vals_per_ent,
00074                                          Tag ordering_tag,
00075                                          int ordering_tag_skip_value,
00076                                          Tag new_handle_tag );
00077 
00078     /**\brief Calculate new handle order by set containment
00079      *
00080      * Given a list of sets, re-order entities such that handles are
00081      * grouped contiguously by set.  Will also group all adjacent mesh
00082      * entities, such that entities that are are adjacent to members of
00083      * two or more of the input sets will ge grouped by the combined
00084      * list of sets (e.g. if the input sets contain elements then all
00085      * vertices that are adjacent to only elements in the first two sets
00086      * will be grouped together).
00087      *
00088      *\param sets          Entity sets by which to group entities.
00089      *\param new_handle_tag_out  Passed back new tag handle containing the
00090      *                     entity mapping.  The returned tag will be anonymous.
00091      *                     The caller is responsible for releasing the tag.
00092      *                     The value of this tag on each handle is the new
00093      *                     handle that the entity will will be moved to. The
00094      *                     tag value will be zero for entities that were not
00095      *                     re-ordered.
00096      */
00097     ErrorCode handle_order_from_sets_and_adj( const Range& sets, Tag& new_handle_tag_out );
00098 
00099     /**\brief Do the re-ordering indicated by the passed handle tag.
00100      *
00101      * The specified re-ordering must be a permutation.  Each existing
00102      * entity must be moved to a new, existing handle such that no
00103      * two entities are moved to the same new handle.
00104      *
00105      * Given a tag storing handles that define a permution, apply the
00106      * described re-ordering.  The passed tag must contain one entity
00107      * handle per entity.  The value of the tag must be zero for all
00108      * entities that are not to be re-ordered.  For entities to be
00109      * re-ordered, the tag must contain the new handle that the entity
00110      * is to be moved to.  No two entities may have the same value for
00111      * this tag (other than a value of zero.)
00112      *
00113      *\param new_handle_tag Tag containing new handles for entities to
00114      *                      reorder.  Typically the output of
00115      *                      handle_order_from_int_tag or similar.
00116      */
00117     ErrorCode reorder_entities( Tag new_handle_tag );
00118 
00119   private:
00120     /**\brief helper function for reorder_entities
00121      *
00122      * Reorder tag data for all entities of specified type.
00123      *
00124      * Also updates tag values for MB_TYPE_HANDLE tags.
00125      *\param type  Entity type to reorder
00126      *\param new_handles Tag containing old->new handle mapping
00127      *\param reorder_tag The tag data to reorder
00128      */
00129     ErrorCode reorder_tag_data( EntityType type, Tag new_handles, Tag reorder_tag );
00130 
00131     /**\brief helper function for reorder_entities
00132      *
00133      * Update set contents for changed handles.
00134      *\param new_handles Tag containing old->new handle mapping
00135      */
00136     ErrorCode update_set_contents( Tag new_handles );
00137 
00138     /**\brief Get all entities of specified type and size
00139      *\param t the type of entity to retreive
00140      *\param vals_per_ent entity size (connectivity length for elements,
00141      *         dimension for vertices)
00142      */
00143     void get_entities( EntityType t, int vals_per_ent, Range& result );
00144 
00145     /**\brief Get new handles corresponding to old handles
00146      *\param tag Tag containing old->new mapping
00147      */
00148     ErrorCode get_reordered_handles( Tag tag, const Range& old_handles, std::vector< EntityHandle >& new_handles );
00149 
00150     /**\brief Get new handles corresponding to old handles
00151      *\param tag Tag containing old->new mapping
00152      */
00153     ErrorCode get_reordered_handles( Tag tag,
00154                                      const std::vector< EntityHandle >& old_handles,
00155                                      std::vector< EntityHandle >& new_handles );
00156 
00157     /**\brief Get new handles corresponding to old handles
00158      *\param tag Tag containing old->new mapping
00159      */
00160     ErrorCode get_reordered_handles( Tag tag,
00161                                      const EntityHandle* old_handles,
00162                                      EntityHandle* new_handles,
00163                                      size_t num_handles );
00164 
00165     /**\brief Remove any non-ordered handles and return new handles for remaining
00166      *\param tag Tag containing old->new mapping
00167      */
00168     ErrorCode get_new_handles( Tag tag, Range& old_handles, std::vector< EntityHandle >& newhandles );
00169 
00170     /**\brief convert from input for \c handle_order_from_sets_and_adj to
00171      *        \c input for handle_order_from_int_tag
00172      */
00173     ErrorCode int_order_from_sets_and_adj( const Range& sets,
00174                                            Tag order_tag,
00175                                            int skip_val,
00176                                            std::vector< std::vector< EntityHandle >* >& data );
00177 
00178     Core* mMB;
00179 };
00180 
00181 }  // namespace moab
00182 
00183 #endif  // moab_REORDER_TOOL_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines