[MOAB-dev] r1841 - MOAB/trunk
tautges at mcs.anl.gov
tautges at mcs.anl.gov
Fri May 23 12:37:03 CDT 2008
Author: tautges
Date: 2008-05-23 12:37:03 -0500 (Fri, 23 May 2008)
New Revision: 1841
Modified:
MOAB/trunk/MBCN.cpp
MOAB/trunk/MBCN.hpp
MOAB/trunk/MBTest.cpp
Log:
Adding permutation functionality.
Modified: MOAB/trunk/MBCN.cpp
===================================================================
--- MOAB/trunk/MBCN.cpp 2008-05-23 16:38:10 UTC (rev 1840)
+++ MOAB/trunk/MBCN.cpp 2008-05-23 17:37:03 UTC (rev 1841)
@@ -35,7 +35,7 @@
"MaxType"
};
-int MBCN::numberBasis = 0;
+short int MBCN::numberBasis = 0;
const MBDimensionPair MBCN::TypeDimensionMap[] =
{
@@ -90,7 +90,7 @@
//}
//! given an entity and a target dimension & side number, get that entity
-int MBCN::AdjacentSubEntities(const MBEntityType this_type,
+short int MBCN::AdjacentSubEntities(const MBEntityType this_type,
const int *source_indices,
const int num_source_indices,
const int source_dim,
@@ -167,7 +167,7 @@
}
template <typename T>
-int side_number(const T *parent_conn,
+short int side_number(const T *parent_conn,
const MBEntityType parent_type,
const T *child_conn,
const int child_num_verts,
@@ -189,7 +189,7 @@
child_dim, side_no, sense, offset);
}
-int MBCN::SideNumber(const int *parent_conn, const MBEntityType parent_type,
+short int MBCN::SideNumber(const MBEntityType parent_type, const int *parent_conn,
const int *child_conn, const int child_num_verts,
const int child_dim,
int &side_no, int &sense, int &offset)
@@ -198,7 +198,7 @@
child_dim, side_no, sense, offset);
}
-int MBCN::SideNumber(const unsigned int *parent_conn, const MBEntityType parent_type,
+short int MBCN::SideNumber(const MBEntityType parent_type, const unsigned int *parent_conn,
const unsigned int *child_conn, const int child_num_verts,
const int child_dim,
int &side_no, int &sense, int &offset)
@@ -206,7 +206,7 @@
return side_number(parent_conn, parent_type, child_conn, child_num_verts,
child_dim, side_no, sense, offset);
}
-int MBCN::SideNumber(const long *parent_conn, const MBEntityType parent_type,
+short int MBCN::SideNumber(const MBEntityType parent_type, const long *parent_conn,
const long *child_conn, const int child_num_verts,
const int child_dim,
int &side_no, int &sense, int &offset)
@@ -214,7 +214,7 @@
return side_number(parent_conn, parent_type, child_conn, child_num_verts,
child_dim, side_no, sense, offset);
}
-int MBCN::SideNumber(const unsigned long *parent_conn, const MBEntityType parent_type,
+short int MBCN::SideNumber(const MBEntityType parent_type, const unsigned long *parent_conn,
const unsigned long *child_conn, const int child_num_verts,
const int child_dim,
int &side_no, int &sense, int &offset)
@@ -222,7 +222,7 @@
return side_number(parent_conn, parent_type, child_conn, child_num_verts,
child_dim, side_no, sense, offset);
}
-int MBCN::SideNumber(void * const *parent_conn, const MBEntityType parent_type,
+short int MBCN::SideNumber(const MBEntityType parent_type, void * const *parent_conn,
void * const *child_conn, const int child_num_verts,
const int child_dim,
int &side_no, int &sense, int &offset)
@@ -231,7 +231,7 @@
child_dim, side_no, sense, offset);
}
-int MBCN::SideNumber( const MBEntityType parent_type,
+short int MBCN::SideNumber( const MBEntityType parent_type,
const int *child_conn_indices,
const int child_num_verts,
const int child_dim,
@@ -301,7 +301,7 @@
//! \param child_index The index of the child element
//! \param opposite_index The index of the opposite element
//! \return status Returns 0 if successful, -1 if not
-int MBCN::OppositeSide(const MBEntityType parent_type,
+short int MBCN::OppositeSide(const MBEntityType parent_type,
const int child_index,
const int child_dim,
int &opposite_index,
@@ -485,7 +485,7 @@
//! for an entity of this type and a specified subfacet (dimension and index), return
//! the index of the higher order node for that entity in this entity's connectivity array
-int MBCN::HONodeIndex(const MBEntityType this_type, const int num_verts,
+short int MBCN::HONodeIndex(const MBEntityType this_type, const int num_verts,
const int subfacet_dim, const int subfacet_index)
{
int i;
@@ -890,3 +890,76 @@
*rval = MBCN::HONodeIndex((MBEntityType)this_type, num_verts, subfacet_dim, subfacet_index);
}
+
+template <typename T>
+inline int permute_this(MBEntityType t,
+ const int dim,
+ T* conn,
+ const int indices_per_ent,
+ const int num_entries)
+{
+ static T tmp_conn[MB_MAX_SUB_ENTITIES];
+ assert(indices_per_ent <= MBCN::permuteVec[t][dim][MB_MAX_SUB_ENTITIES]);
+ if (indices_per_ent > MBCN::permuteVec[t][dim][MB_MAX_SUB_ENTITIES]) return 1;
+ short int *tvec = MBCN::permuteVec[t][dim];
+ T *pvec = conn;
+ for (int j = 0; j < num_entries; j++) {
+ for (int i = 0; i < indices_per_ent; i++)
+ tmp_conn[tvec[i]] = pvec[i];
+ memcpy(pvec, tmp_conn, indices_per_ent*sizeof(T));
+ pvec += indices_per_ent;
+ }
+
+ return 0;
+}
+
+template <typename T>
+inline int rev_permute_this(MBEntityType t,
+ const int dim,
+ T* conn,
+ const int indices_per_ent,
+ const int num_entries)
+{
+ static T tmp_conn[MB_MAX_SUB_ENTITIES];
+ assert(indices_per_ent <= MBCN::revPermuteVec[t][dim][MB_MAX_SUB_ENTITIES]);
+ if (indices_per_ent > MBCN::revPermuteVec[t][dim][MB_MAX_SUB_ENTITIES]) return 1;
+ short int *tvec = MBCN::revPermuteVec[t][dim];
+ T *pvec = conn;
+ for (int j = 0; j < num_entries; j++) {
+ for (int i = 0; i < indices_per_ent; i++)
+ tmp_conn[i] = pvec[tvec[i]];
+ memcpy(pvec, tmp_conn, indices_per_ent*sizeof(T));
+ pvec += indices_per_ent;
+ }
+
+ return 0;
+}
+
+//! Permute this vector
+inline int MBCN::permuteThis(const MBEntityType t, const int dim, int *pvec,
+ const int num_indices, const int num_entries)
+{return permute_this(t, dim, pvec, num_indices, num_entries);}
+inline int MBCN::permuteThis(const MBEntityType t, const int dim, unsigned int *pvec,
+ const int num_indices, const int num_entries)
+{return permute_this(t, dim, pvec, num_indices, num_entries);}
+inline int MBCN::permuteThis(const MBEntityType t, const int dim, long *pvec,
+ const int num_indices, const int num_entries)
+{return permute_this(t, dim, pvec, num_indices, num_entries);}
+inline int MBCN::permuteThis(const MBEntityType t, const int dim, void **pvec,
+ const int num_indices, const int num_entries)
+{return permute_this(t, dim, pvec, num_indices, num_entries);}
+
+//! Reverse permute this vector
+inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, int *pvec,
+ const int num_indices, const int num_entries)
+{return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
+inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, unsigned int *pvec,
+ const int num_indices, const int num_entries)
+{return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
+inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, long *pvec,
+ const int num_indices, const int num_entries)
+{return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
+inline int MBCN::revPermuteThis(const MBEntityType t, const int dim, void **pvec,
+ const int num_indices, const int num_entries)
+{return rev_permute_this(t, dim, pvec, num_indices, num_entries);}
+
Modified: MOAB/trunk/MBCN.hpp
===================================================================
--- MOAB/trunk/MBCN.hpp 2008-05-23 16:38:10 UTC (rev 1840)
+++ MOAB/trunk/MBCN.hpp 2008-05-23 17:37:03 UTC (rev 1841)
@@ -60,7 +60,7 @@
MBCN();
//! the basis of the numbering system (normally 0 or 1, 0 by default)
- static int numberBasis;
+ static short int numberBasis;
//! switch the basis
static void SwitchBasis(const int old_basis, const int new_basis);
@@ -76,19 +76,19 @@
struct ConnMap
{
// Topological dimension of this entry
- int topo_dimension;
+ short int topo_dimension;
// Number of sub-elements of this dimension
- int num_sub_elements;
+ short int num_sub_elements;
// Number of nodes in each sub-element of this dimension
- int num_nodes_per_sub_element[MB_MAX_SUB_ENTITIES];
+ short int num_nodes_per_sub_element[MB_MAX_SUB_ENTITIES];
// Type of each sub-element
MBEntityType target_type[MB_MAX_SUB_ENTITIES];
// Connectivity of each of the sub-elements
- int conn[MB_MAX_SUB_ENTITIES][MB_MAX_SUB_ENTITY_VERTICES];
+ short int conn[MB_MAX_SUB_ENTITIES][MB_MAX_SUB_ENTITY_VERTICES];
};
// mConnectivityMap[i=entity type][j=0,1,2]:
@@ -106,10 +106,10 @@
struct UpConnMap
{
// Number of higher-dimensional entities using each sub-entity
- int num_targets_per_source_element[MB_MAX_SUB_ENTITIES];
+ short int num_targets_per_source_element[MB_MAX_SUB_ENTITIES];
// Higher-dimensional entities using each sub-entity
- int targets_per_source_element[MB_MAX_SUB_ENTITIES][MB_MAX_SUB_ENTITIES];
+ short int targets_per_source_element[MB_MAX_SUB_ENTITIES][MB_MAX_SUB_ENTITIES];
};
// Reverse canonical numbering, duplicates data in mConnectivityMap, but
@@ -118,13 +118,17 @@
// (not documented with Doxygen)
static const UpConnMap mUpConnMap[MBMAXTYPE][4][4];
+ //! Permutation and reverse permutation vectors
+ static short int permuteVec[MBMAXTYPE][3][MB_MAX_SUB_ENTITIES+1];
+ static short int revPermuteVec[MBMAXTYPE][3][MB_MAX_SUB_ENTITIES+1];
+
//! this const vector defines the starting and ending MBEntityType for
//! each dimension, e.g. TypeDimensionMap[2] returns a pair of MBEntityTypes
//! bounding dimension 2.
static const MBDimensionPair TypeDimensionMap[];
//! get the basis of the numbering system
- static int GetBasis();
+ static short int GetBasis();
//! set the basis of the numbering system
static void SetBasis(const int in_basis);
@@ -136,13 +140,13 @@
static MBEntityType EntityTypeFromName(const char *name);
//! return the topological entity dimension
- static int Dimension(const MBEntityType t);
+ static short int Dimension(const MBEntityType t);
//! return the number of (corner) vertices contained in the specified type.
- static int VerticesPerEntity(const MBEntityType t);
+ static short int VerticesPerEntity(const MBEntityType t);
//! return the number of sub-entities bounding the entity.
- static int NumSubEntities(const MBEntityType t, const int d);
+ static short int NumSubEntities(const MBEntityType t, const int d);
//! return the type of a particular sub-entity.
//! \param this_type Type of entity for which sub-entity type is being queried
@@ -150,8 +154,8 @@
//! \param index Index of sub-entity whose type is being queried
//! \return type Entity type of sub-entity with specified dimension and index
static MBEntityType SubEntityType(const MBEntityType this_type,
- const int sub_dimension,
- const int index);
+ const int sub_dimension,
+ const int index);
//! return the vertex indices of the specified sub-entity.
//! \param this_type Type of entity for which sub-entity connectivity is being queried
@@ -186,7 +190,7 @@
//! \param index_list Indices of target entities (returned)
//! \param operation_type Specify either MBCN::INTERSECT or MBCN::UNION to get intersection
//! or union of target entity lists over source entities
- static int AdjacentSubEntities(const MBEntityType this_type,
+ static short int AdjacentSubEntities(const MBEntityType this_type,
const int *source_indices,
const int num_source_indices,
const int source_dim,
@@ -205,23 +209,23 @@
//! \param sense Sense of child entity with respect to order in <em>child_conn</em> (returned)
//! \param offset Offset of <em>child_conn</em> with respect to canonical ordering data (returned)
//! \return status Returns zero if successful, -1 if not
- static int SideNumber(const int *parent_conn, const MBEntityType parent_type,
- const int *child_conn, const int child_num_verts,
- const int child_dim,
+ static short int SideNumber(const MBEntityType parent_type, const int *parent_conn,
+ const int *child_conn, const int child_num_verts,
+ const int child_dim,
int &side_number, int &sense, int &offset);
- static int SideNumber(const unsigned int *parent_conn, const MBEntityType parent_type,
+ static short int SideNumber(const MBEntityType parent_type, const unsigned int *parent_conn,
const unsigned int *child_conn, const int child_num_verts,
const int child_dim,
int &side_number, int &sense, int &offset);
- static int SideNumber(const long *parent_conn, const MBEntityType parent_type,
+ static short int SideNumber(const MBEntityType parent_type, const long *parent_conn,
const long *child_conn, const int child_num_verts,
const int child_dim,
int &side_number, int &sense, int &offset);
- static int SideNumber(const unsigned long *parent_conn, const MBEntityType parent_type,
+ static short int SideNumber(const MBEntityType parent_type, const unsigned long *parent_conn,
const unsigned long *child_conn, const int child_num_verts,
const int child_dim,
int &side_number, int &sense, int &offset);
- static int SideNumber(void * const *parent_conn, const MBEntityType parent_type,
+ static short int SideNumber(const MBEntityType parent_type, void * const *parent_conn,
void * const *child_conn, const int child_num_verts,
const int child_dim,
int &side_number, int &sense, int &offset);
@@ -236,7 +240,7 @@
//! \param sense Sense of child entity with respect to order in <em>child_conn</em> (returned)
//! \param offset Offset of <em>child_conn</em> with respect to canonical ordering data (returned)
//! \return status Returns zero if successful, -1 if not
- static int SideNumber(const MBEntityType parent_type,
+ static short int SideNumber(const MBEntityType parent_type,
const int *child_conn_indices, const int child_num_verts,
const int child_dim,
int &side_number, int &sense, int &offset);
@@ -254,7 +258,7 @@
//! \param child_index The index of the child element
//! \param opposite_index The index of the opposite element
//! \return status Returns 0 if successful, -1 if not
- static int OppositeSide(const MBEntityType parent_type,
+ static short int OppositeSide(const MBEntityType parent_type,
const int child_index,
const int child_dim,
int &opposite_index,
@@ -288,6 +292,56 @@
const int num_vertices,
int& direct, int& offset );
+ //! Set permutation or reverse permutation vector
+ //! Forward permutation is from MBCN's numbering into application's ordering;
+ //! that is, if i is MBCN's index, pvec[i] is application's index. This
+ //! function stores the permutation vector for this type and facet dimension,
+ //! which then is used in calls to permuteThis or revPermuteThis.
+ //! \param t EntityType for which to set permutation
+ //! \param dim Dimension of facets whose permutation array is being set
+ //! \param pvec Permutation array
+ //! \param num_entries Number of indicies in permutation array
+ //! \param is_reverse Array is reverse permutation
+ static void setPermutation(const MBEntityType t, const int dim, int *pvec, const int num_entries,
+ const bool is_reverse = false);
+
+ //! Reset permutation or reverse permutation vector
+ //! \param t EntityType whose permutation vector is being reset
+ //! \param dim Dimension of facets being reset; if -1 is input, all dimensions are reset
+ static void resetPermutation(const MBEntityType t, const int dim);
+
+ //! Permute a handle array according to permutation vector set with setPermute;
+ //! permutation is done in-place
+ //! \param t EntityType of handles in pvec
+ //! \param dim Dimension of handles in pvec
+ //! \param pvec Handle array being permuted
+ //! \param indices_per_ent Number of indices per entity
+ //! \param num_entries Number of entities in pvec
+ static int permuteThis(const MBEntityType t, const int dim, int *pvec,
+ const int indices_per_ent, const int num_entries);
+ static int permuteThis(const MBEntityType t, const int dim, unsigned int *pvec,
+ const int indices_per_ent, const int num_entries);
+ static int permuteThis(const MBEntityType t, const int dim, long *pvec,
+ const int indices_per_ent, const int num_entries);
+ static int permuteThis(const MBEntityType t, const int dim, void **pvec,
+ const int indices_per_ent, const int num_entries);
+
+ //! Reverse permute a handle array according to reverse permutation vector set with setPermute;
+ //! reverse permutation is done in-place
+ //! \param t EntityType of handles in pvec
+ //! \param dim Dimension of handles in pvec
+ //! \param pvec Handle array being reverse permuted
+ //! \param indices_per_ent Number of indices per entity
+ //! \param num_entries Number of entities in pvec
+ static int revPermuteThis(const MBEntityType t, const int dim, int *pvec,
+ const int indices_per_ent, const int num_entries);
+ static int revPermuteThis(const MBEntityType t, const int dim, unsigned int *pvec,
+ const int indices_per_ent, const int num_entries);
+ static int revPermuteThis(const MBEntityType t, const int dim, long *pvec,
+ const int indices_per_ent, const int num_entries);
+ static int revPermuteThis(const MBEntityType t, const int dim, void **pvec,
+ const int indices_per_ent, const int num_entries);
+
//! true if entities of a given type and number of nodes indicates mid edge nodes are present.
//! \param this_type Type of entity for which sub-entity connectivity is being queried
//! \param num_verts Number of nodes defining entity
@@ -345,29 +399,29 @@
//! \param subfacet_dim Dimension of sub-entity being queried
//! \param subfacet_index Index of sub-entity being queried
//! \return index Index of sub-entity's higher-order node
- static int HONodeIndex(const MBEntityType this_type, const int num_verts,
+ static short int HONodeIndex(const MBEntityType this_type, const int num_verts,
const int subfacet_dim, const int subfacet_index);
};
//! get the basis of the numbering system
-inline int MBCN::GetBasis() {return numberBasis;}
+inline short int MBCN::GetBasis() {return numberBasis;}
inline const char *MBCN::EntityTypeName(const MBEntityType this_type)
{
return entityTypeNames[this_type];
}
-inline int MBCN::Dimension(const MBEntityType t)
+inline short int MBCN::Dimension(const MBEntityType t)
{
return mConnectivityMap[t][0].topo_dimension;
}
-inline int MBCN::VerticesPerEntity(const MBEntityType t)
+inline short int MBCN::VerticesPerEntity(const MBEntityType t)
{
return (MBVERTEX == t ? 1 : mConnectivityMap[t][mConnectivityMap[t][0].topo_dimension-1].num_nodes_per_sub_element[0]);
}
-inline int MBCN::NumSubEntities(const MBEntityType t, const int d)
+inline short int MBCN::NumSubEntities(const MBEntityType t, const int d)
{
return (t != MBVERTEX && d > 0 ? mConnectivityMap[t][d-1].num_sub_elements :
(d ? -1 : VerticesPerEntity(t)));
@@ -469,6 +523,41 @@
mid_nodes[3] = HasMidRegionNodes(this_type, num_nodes);
}
+//! Set permutation or reverse permutation vector
+inline void MBCN::setPermutation(const MBEntityType t, const int dim, int *pvec,
+ const int num_entries, const bool is_reverse)
+{
+ short int *this_vec = permuteVec[t][dim], *that_vec = revPermuteVec[t][dim];
+ if (is_reverse) {
+ this_vec = revPermuteVec[t][dim];
+ that_vec = permuteVec[t][dim];
+ }
+
+ for (int i = 0; i < num_entries; i++) {
+ this_vec[i] = pvec[i];
+ that_vec[pvec[i]] = i;
+ }
+
+ this_vec[MB_MAX_SUB_ENTITIES] = that_vec[MB_MAX_SUB_ENTITIES] = num_entries;
+}
+
+//! Reset permutation or reverse permutation vector
+inline void MBCN::resetPermutation(const MBEntityType t, const int dim)
+{
+ if (-1 == dim) {
+ for (unsigned int i = 0; i < 3; i++) resetPermutation(t, i);
+ return;
+ }
+
+ for (unsigned int i = 0; i < MB_MAX_SUB_ENTITIES; i++) {
+ revPermuteVec[t][dim][i] = permuteVec[t][dim][i] = i;
+ }
+
+ revPermuteVec[t][dim][MB_MAX_SUB_ENTITIES] =
+ permuteVec[t][dim][MB_MAX_SUB_ENTITIES] = MB_MAX_SUB_ENTITIES+1;
+}
+
+
#endif
#ifdef __cplusplus
@@ -566,6 +655,35 @@
const int num_vertices,
int* direct, int* offset , int *rval);
+ void MBCN_setPermutation(const MBEntityType t, const int dim, int *pvec,
+ const int num_entries, const int is_reverse);
+
+ void MBCN_resetPermutation(const MBEntityType t, const int dim);
+
+ void MBCN_permuteThisInt(const MBEntityType t, const int dim, int *pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_permuteThisUint(const MBEntityType t, const int dim, unsigned int *pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_permuteThisLong(const MBEntityType t, const int dim, long *pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_permuteThisVoid(const MBEntityType t, const int dim, void **pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_revPermuteThisInt(const MBEntityType t, const int dim, int *pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_revPermuteThisUint(const MBEntityType t, const int dim, unsigned int *pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_revPermuteThisLong(const MBEntityType t, const int dim, long *pvec,
+ const int num_indices, const int num_entries, int *rval);
+
+ void MBCN_revPermuteThisVoid(const MBEntityType t, const int dim, void **pvec,
+ const int num_indices, const int num_entries, int *rval);
+
void MBCN_HasMidEdgeNodes(const int this_type,
const int num_verts, int *rval);
Modified: MOAB/trunk/MBTest.cpp
===================================================================
--- MOAB/trunk/MBTest.cpp 2008-05-23 16:38:10 UTC (rev 1840)
+++ MOAB/trunk/MBTest.cpp 2008-05-23 17:37:03 UTC (rev 1841)
@@ -4192,12 +4192,14 @@
for (int dim = 1; dim <= MBCN::Dimension(this_type); dim++) {
// for each side of this dimension
const MBCN::ConnMap &cm = MBCN::mConnectivityMap[this_type][dim-1];
+ int tmp_conn[MB_MAX_SUB_ENTITY_VERTICES];
for (int side_no = 0; side_no < MBCN::NumSubEntities(this_type, dim); side_no++) {
+ for (int j = 0; j < MB_MAX_SUB_ENTITY_VERTICES; j++) tmp_conn[j] = cm.conn[side_no][j];
int temp_result =
MBCN::SideNumber(this_type,
- cm.conn[side_no],
+ tmp_conn,
MBCN::VerticesPerEntity(MBCN::SubEntityType(this_type, dim, side_no)),
dim, side, sense, offset);
if (0 != temp_result) {
More information about the moab-dev
mailing list