[MOAB-dev] r1897 - MOAB/trunk/tools/iMesh
tautges at mcs.anl.gov
tautges at mcs.anl.gov
Fri Jun 13 15:19:20 CDT 2008
Author: tautges
Date: 2008-06-13 15:19:20 -0500 (Fri, 13 Jun 2008)
New Revision: 1897
Modified:
MOAB/trunk/tools/iMesh/iMesh.h
MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
Log:
Committing initial implementation of setAdjTable. This implementation does nothing with the off-diagonal entries, and initializes the adj table so that vert-ent, ent-vert, vert-vert and 3dent-3dent adj entries are one (i.e. the diagonal entries for edges and faces are zero, the others are one).
Passes make check.
Modified: MOAB/trunk/tools/iMesh/iMesh.h
===================================================================
--- MOAB/trunk/tools/iMesh/iMesh.h 2008-06-13 19:16:47 UTC (rev 1896)
+++ MOAB/trunk/tools/iMesh/iMesh.h 2008-06-13 20:19:20 UTC (rev 1897)
@@ -262,6 +262,26 @@
/*out*/ int* adjacency_table_size,
/*out*/ int *err);
+ /**\brief Set the adjacency table and interior entity information for this implementation
+ *
+ * Set the adjacency table and interior entity information for this
+ * implementation. This table
+ * is a 4x4 array, with indices 0-based, where A(i,j) (i=row, j=column)
+ * non-zero requests that adjacencies be stored explicitly from type i
+ * to type j. Non-zero diagonal elements request that interior entities
+ * of that dimension be represented explicitly, and created along with
+ * higher-dimensional entities.
+ * \param instance iMesh instance handle
+ * \param *adjacency_table Array representing adjacency table
+ * passed to function
+ * \param adjacency_table_size Size of adjacency table (should be 16)
+ * \param *err Pointer to error type returned from function
+ */
+ void iMesh_setAdjTable (iMesh_Instance instance,
+ /*in*/ int* adjacency_table,
+ /*in*/ int adjacency_table_size,
+ /*out*/ int *err);
+
/**\brief Get the number of entities with the specified type in the instance or set
*
* Get the number of entities with the specified type in the instance
Modified: MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp 2008-06-13 19:16:47 UTC (rev 1896)
+++ MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp 2008-06-13 20:19:20 UTC (rev 1897)
@@ -10,6 +10,7 @@
#endif
#include <iostream>
+#include <cassert>
#define MIN(a,b) (a < b ? a : b)
class MBiMesh : public MBCore
@@ -17,9 +18,7 @@
private:
bool haveDeletedEntities;
public:
- MBiMesh(int proc_rank = 0, int proc_size = 1)
- : MBCore(proc_rank, proc_size), haveDeletedEntities(false)
- {}
+ MBiMesh(int proc_rank = 0, int proc_size = 1);
virtual ~MBiMesh();
bool have_deleted_ents( bool reset ) {
@@ -32,8 +31,17 @@
virtual MBErrorCode delete_mesh();
virtual MBErrorCode delete_entities( const MBEntityHandle*, const int );
virtual MBErrorCode delete_entities( const MBRange& );
+ int AdjTable[16];
};
+MBiMesh::MBiMesh(int proc_rank, int proc_size)
+ : MBCore(proc_rank, proc_size), haveDeletedEntities(false)
+{
+ memset(AdjTable, 0, 16*sizeof(int));
+ for (int i = 0; i < 4; i++) AdjTable[4*i] = AdjTable[i] = 1;
+ AdjTable[15] = 1;
+}
+
MBiMesh::~MBiMesh() {}
MBErrorCode MBiMesh::delete_mesh() {
@@ -55,6 +63,10 @@
return MBCore::delete_entities( r );
}
+MBErrorCode create_int_ents(MBInterface *instance,
+ MBRange &from_ents,
+ MBEntityHandle in_set = 0);
+
#define CHECK_SIZE(array, allocated, size, type, retval) \
if (0 != allocated && NULL != array && allocated < (size)) {\
iMesh_processError(iBase_MEMORY_ALLOCATION_FAILED, \
@@ -187,6 +199,7 @@
};
#define MBI reinterpret_cast<MBInterface*>(instance)
+#define MBimesh reinterpret_cast<MBiMesh*>(instance)
#define RETURN(a) {iMesh_LAST_ERROR.error_type = a; *err = a;return;}
#define iMesh_processError(a, b) {sprintf(iMesh_LAST_ERROR.description, "%s", b); iMesh_LAST_ERROR.error_type = a; *err = a;}
@@ -306,6 +319,15 @@
iMesh_processError(iBase_ERROR_MAP[result], msg.c_str());
}
+ // create interior edges/faces if requested
+ if (MBimesh->AdjTable[5] || MBimesh->AdjTable[10]) {
+ MBRange set_ents;
+ result = MBI->get_entities_by_handle(file_set, set_ents, true);
+ if (MB_SUCCESS != result) RETURN(iBase_ERROR_MAP[result]);
+ result = create_int_ents(MBI, set_ents, file_set);
+ if (MB_SUCCESS != result) RETURN(iBase_ERROR_MAP[result]);
+ }
+
RETURN(iBase_ERROR_MAP[result]);
}
@@ -360,12 +382,26 @@
/*inout*/ int* adjacency_table_allocated,
/*out*/ int* adjacency_table_size, int *err)
{
- *adjacency_table_allocated = 0;
- *adjacency_table_size = 0;
- *adjacency_table = NULL;
+ *adjacency_table_size = 16;
+ CHECK_SIZE(*adjacency_table, *adjacency_table_allocated,
+ *adjacency_table_size, int, iBase_MEMORY_ALLOCATION_FAILED);
+ memcpy(*adjacency_table, MBimesh->AdjTable, 16*sizeof(int));
RETURN(iBase_ERROR_MAP[MB_SUCCESS]);
}
+ void iMesh_setAdjTable (iMesh_Instance instance,
+ int* adj_table,
+ /*inout*/ int adj_table_size,
+ int *err)
+ {
+ if (16 != adj_table_size) {
+ RETURN(iBase_INVALID_ARGUMENT);
+ }
+
+ memcpy(MBimesh->AdjTable, adj_table, 16*sizeof(int));
+ RETURN(iBase_SUCCESS);
+ }
+
void iMesh_getNumOfType(iMesh_Instance instance,
/*in*/ const iBase_EntitySetHandle entity_set_handle,
/*in*/ const int entity_type,
@@ -1563,6 +1599,14 @@
*status_size = num_ents;
}
+ if (MBimesh->AdjTable[5] || MBimesh->AdjTable[10]) {
+ MBRange set_ents;
+ std::copy(HANDLE_ARRAY_PTR(*new_entity_handles),
+ HANDLE_ARRAY_PTR(*new_entity_handles)+*new_entity_handles_size,
+ mb_range_inserter(set_ents));
+ result = create_int_ents(MBI, set_ents);
+ }
+
RETURN(iBase_ERROR_MAP[result]);
}
@@ -2945,6 +2989,42 @@
return result;
}
+MBErrorCode create_int_ents(MBInterface *instance,
+ MBRange &from_ents,
+ MBEntityHandle in_set)
+{
+ assert(MBimesh->AdjTable[10] || MBimesh->AdjTable[5]);
+ MBRange int_ents;
+ MBErrorCode result;
+
+ if (MBimesh->AdjTable[10]) {
+ result = MBI->get_adjacencies(from_ents, 2, true, int_ents,
+ MBInterface::UNION);
+ if (MB_SUCCESS != result) return result;
+ unsigned int old_size = from_ents.size();
+ from_ents.merge(int_ents);
+ if (old_size != from_ents.size()) {
+ result = MBI->add_entities(in_set, int_ents);
+ if (MB_SUCCESS != result) return result;
+ }
+ }
+
+ if (MBimesh->AdjTable[5]) {
+ int_ents.clear();
+ result = MBI->get_adjacencies(from_ents, 1, true, int_ents,
+ MBInterface::UNION);
+ if (MB_SUCCESS != result) return result;
+ unsigned int old_size = from_ents.size();
+ from_ents.merge(int_ents);
+ if (old_size != from_ents.size()) {
+ result = MBI->add_entities(in_set, int_ents);
+ if (MB_SUCCESS != result) return result;
+ }
+ }
+
+ return MB_SUCCESS;
+}
+
void eatwhitespace(std::string &this_string)
{
std::string::size_type len = this_string.find_last_not_of(" ");
More information about the moab-dev
mailing list