[MOAB-dev] r2561 - MOAB/trunk
kraftche at mcs.anl.gov
kraftche at mcs.anl.gov
Tue Jan 20 16:43:42 CST 2009
Author: kraftche
Date: 2009-01-20 16:43:42 -0600 (Tue, 20 Jan 2009)
New Revision: 2561
Modified:
MOAB/trunk/MBReadUtilIface.hpp
MOAB/trunk/MBWriteUtilIface.hpp
MOAB/trunk/Makefile.am
MOAB/trunk/ReadNCDF.cpp
MOAB/trunk/Tqdcfr.cpp
MOAB/trunk/WriteNCDF.cpp
Log:
use ExodusII ordering map to re-order connectivity for Cub and ExodusII files
Modified: MOAB/trunk/MBReadUtilIface.hpp
===================================================================
--- MOAB/trunk/MBReadUtilIface.hpp 2009-01-20 22:42:43 UTC (rev 2560)
+++ MOAB/trunk/MBReadUtilIface.hpp 2009-01-20 22:43:42 UTC (rev 2561)
@@ -110,6 +110,23 @@
) = 0;
+
+ /**\brief Re-order incomming element connectivity
+ *
+ * Permute the connectivity of each element such that the node
+ * order is that of MBCN rather than the target file format.
+ *\param order The permutation to use. Must be an array of 'node_per_elem'
+ * integers and be a permutation of the values [0..node_per_elem-1].
+ * Such that for a single element:
+ * mbcn_conn[order[i]] == target_conn[i]
+ *\param conn The connectivty array to re-order
+ *\param num_elem The number of elements in the connectivity array
+ *\param node_per_elem The number of nodes in each element's connectivity list.
+ */
+ static inline
+ void reorder( const int* order, MBEntityHandle* conn,
+ int num_elem, int node_per_elem );
+
//! if an error occured when reading the mesh, report it to MOAB
//! it makes sense to have this as long as MBInterface has a load_mesh function
virtual MBErrorCode report_error( const std::string& error ) = 0;
@@ -131,6 +148,20 @@
MBEntityType &etype) = 0;
};
+inline
+void MBReadUtilIface::reorder( const int* order, MBEntityHandle* conn,
+ int num_elem, int node_per_elem )
+{
+ std::vector<MBEntityHandle> elem(node_per_elem);
+ MBEntityHandle* const end = conn + num_elem*node_per_elem;
+ while (conn != end) {
+ std::copy( conn, conn+node_per_elem, elem.begin() );
+ for (int j = 0; j < node_per_elem; ++j)
+ conn[order[j]] = elem[j];
+ conn += node_per_elem;
+ }
+}
+
#endif
Modified: MOAB/trunk/MBWriteUtilIface.hpp
===================================================================
--- MOAB/trunk/MBWriteUtilIface.hpp 2009-01-20 22:42:43 UTC (rev 2560)
+++ MOAB/trunk/MBWriteUtilIface.hpp 2009-01-20 22:43:42 UTC (rev 2561)
@@ -283,6 +283,22 @@
const MBEntityHandle*& adj_array,
int& num_adj ) = 0;
+
+ /**\brief Re-order outgoing element connectivity
+ *
+ * Permute the connectivity of each element such that the node
+ * order is that of the target file format rather than that of MBCN.
+ *\param order The permutation to use. Must be an array of 'node_per_elem'
+ * integers and be a permutation of the values [0..node_per_elem-1].
+ * Such that for a single element:
+ * target_conn[i] == mbcn_conn[order[i]]
+ *\param conn The connectivty array to re-order
+ *\param num_elem The number of elements in the connectivity array
+ *\param node_per_elem The number of nodes in each element's connectivity list.
+ */
+ template <typename T> static inline
+ void reorder( const int* order, T* conn, int num_elem, int node_per_elem );
+
//! if an error occured when reading the mesh, report it to MB
//! it makes sense to have this as long as MBInterface has a write_mesh function
//! \return status Return status
@@ -298,6 +314,20 @@
};
+
+template <typename T> inline
+void MBWriteUtilIface::reorder( const int* order, T* conn,
+ int num_elem, int node_per_elem )
+{
+ std::vector<T> elem(node_per_elem);
+ T* const end = conn + num_elem*node_per_elem;
+ while (conn != end) {
+ std::copy( conn, conn+node_per_elem, elem.begin() );
+ for (int j = 0; j < node_per_elem; ++j, ++conn)
+ *conn = elem[order[j]];
+ }
+}
+
#endif
Modified: MOAB/trunk/Makefile.am
===================================================================
--- MOAB/trunk/Makefile.am 2009-01-20 22:42:43 UTC (rev 2560)
+++ MOAB/trunk/Makefile.am 2009-01-20 22:43:42 UTC (rev 2561)
@@ -34,6 +34,7 @@
tag_test \
mesh_set_test \
cub_file_test \
+ exodus_test \
mbcn_test
# merge_test \ # input files no longer exist?
# test_tag_server \ # fails
@@ -99,6 +100,7 @@
ElementSequence.hpp \
EntitySequence.cpp \
EntitySequence.hpp \
+ exodus_order.hpp \
ExoIIUtil.cpp \
ExoIIUtil.hpp \
FileOptions.cpp \
@@ -148,6 +150,7 @@
MeshSetSequence.cpp \
MeshSetSequence.hpp \
MeshTopoUtil.cpp \
+ patran_order.h \
PolyElementSeq.cpp \
PolyElementSeq.hpp \
RangeMap.hpp \
@@ -347,6 +350,10 @@
cub_file_test_LDADD = $(top_builddir)/libMOAB.la
cub_file_test_DEPENDENCIES = $(tag_test_LDADD)
+exodus_test_SOURCES = TestUtil.hpp exodus_test.cc
+exodus_test_LDADD = $(top_builddir)/libMOAB.la
+exodus_test_DEPENDENCIES = $(tag_test_LDADD)
+
mbcn_test_SOURCES = MBCN.hpp MBCN.cpp mbcn_test.cc
mbcn_test_CPPFLAGS = -DSRCDIR=$(srcdir) # define anything to work around build issue
Modified: MOAB/trunk/ReadNCDF.cpp
===================================================================
--- MOAB/trunk/ReadNCDF.cpp 2009-01-20 22:42:43 UTC (rev 2560)
+++ MOAB/trunk/ReadNCDF.cpp 2009-01-20 22:43:42 UTC (rev 2561)
@@ -33,6 +33,7 @@
#include "MBTagConventions.hpp"
#include "MBInternals.hpp"
#include "MBReadUtilIface.hpp"
+#include "exodus_order.h"
#define INS_ID(stringvar, prefix, id) \
sprintf(stringvar, prefix, id)
@@ -789,6 +790,7 @@
return MB_SUCCESS;
}
+
MBErrorCode ReadNCDF::read_elements()
{
// read in elements
@@ -860,12 +862,13 @@
int verts_per_element = ExoIIUtil::VerticesPerElement[(*this_it).elemType];
int number_nodes = (*this_it).numElements*verts_per_element;
+ const MBEntityType mb_type = ExoIIUtil::ExoIIElementMBEntity[(*this_it).elemType];
// allocate an array to read in connectivity data
readMeshIface->get_element_array(
(*this_it).numElements,
verts_per_element,
- ExoIIUtil::ExoIIElementMBEntity[(*this_it).elemType],
+ mb_type,
(*this_it).startExoId,
(*this_it).startMBId,
conn);
@@ -887,7 +890,12 @@
if( mdbImpl->add_entities( ms_handle, new_range) != MB_SUCCESS )
return MB_FAILURE;
-
+
+ int mid_nodes[4];
+ MBCN::HasMidNodes( mb_type, verts_per_element, mid_nodes );
+ if( mdbImpl->tag_set_data( mHasMidNodesTag, &ms_handle, 1, mid_nodes ) != MB_SUCCESS )
+ return MB_FAILURE;
+
// just a check because the following code won't work if this case fails
assert(sizeof(MBEntityHandle) >= sizeof(int));
@@ -905,9 +913,21 @@
// Iterate backwards in case handles are larger than ints.
for (int i = number_nodes - 1; i >= 0; --i)
{
+ if ((unsigned)tmp_ptr[i] >= nodesInLoadedBlocks.size()) {
+ readMeshIface->report_error( "Invalid node ID in block connectivity\n");
+ delete [] temp_string;
+ return MB_FAILURE;
+ }
nodesInLoadedBlocks[tmp_ptr[i]] = 1;
conn[i] = static_cast<MBEntityHandle>(tmp_ptr[i]) + vertexOffset;
}
+
+ // Adjust connectivity order if necessary
+ const int* reorder = exodus_elem_order_map[mb_type][verts_per_element];
+ if (reorder)
+ MBReadUtilIface::reorder( reorder, conn, this_it->numElements, verts_per_element );
+
+
readMeshIface->update_adjacencies((*this_it).startMBId, (*this_it).numElements,
ExoIIUtil::VerticesPerElement[(*this_it).elemType], conn);
Modified: MOAB/trunk/Tqdcfr.cpp
===================================================================
--- MOAB/trunk/Tqdcfr.cpp 2009-01-20 22:42:43 UTC (rev 2560)
+++ MOAB/trunk/Tqdcfr.cpp 2009-01-20 22:43:42 UTC (rev 2561)
@@ -23,6 +23,7 @@
#include "MBInternals.hpp"
#include "FileOptions.hpp"
#include "HigherOrderFactory.hpp"
+#include "exodus_order.h"
#ifdef USE_MPI
#include "mpi.h"
@@ -87,38 +88,7 @@
// index into the MOAB node order for the corresponding vertex
// in the Cubit connectivity list. Thus for a 27-node hex:
// moab_conn[ cub_hex27_order[i] ] = cubit_conn[ i ];
-const int cub_tet8_order[] = { 0, 1, 2, 3, 4, 5, 7, 6 };
-const int cub_tet14_order[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 12 };
-const int cub_hex27_order[] = { 0, 1, 2, 3, 4, 5, 6, 7,
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- 26, 24, 25, 23, 21, 20, 22 };
-const int* cub_all_null_order[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-const int* cub_tet_order[] = { 0, 0, 0, 0, 0, 0, 0, 0,
- cub_tet8_order,
- 0, 0, 0, 0, 0,
- cub_tet14_order,
- 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0 };
-const int* cub_hex_order[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- cub_hex27_order };
-const int** cub_elem_order_map[] = {
- cub_all_null_order, // MBVERTEX
- cub_all_null_order, // MBEDGE
- cub_all_null_order, // MBTRI
- cub_all_null_order, // MBQUAD
- cub_all_null_order, // MBPOLYGON
- cub_tet_order, // MBTET
- cub_all_null_order, // MBPYRAMID
- cub_all_null_order, // MBPRISM
- cub_all_null_order, // MBKNIFE
- cub_hex_order, // MBHEX
- cub_all_null_order, // MBPOLYHEDRON
- cub_all_null_order
-};
+const int* const* const* const cub_elem_order_map = exodus_elem_order_map;
std::string Tqdcfr::BLOCK_NODESET_OFFSET_TAG_NAME = "BLOCK_NODESET_OFFSET";
std::string Tqdcfr::BLOCK_SIDESET_OFFSET_TAG_NAME = "BLOCK_SIDESET_OFFSET";
Modified: MOAB/trunk/WriteNCDF.cpp
===================================================================
--- MOAB/trunk/WriteNCDF.cpp 2009-01-20 22:42:43 UTC (rev 2560)
+++ MOAB/trunk/WriteNCDF.cpp 2009-01-20 22:43:42 UTC (rev 2561)
@@ -43,6 +43,7 @@
#include "MBInternals.hpp"
#include "ExoIIUtil.hpp"
#include "MBWriteUtilIface.hpp"
+#include "exodus_order.h"
const int TIME_STR_LEN = 11;
@@ -881,8 +882,6 @@
return MB_SUCCESS;
}
-
-
MBErrorCode WriteNCDF::write_elementblocks(std::vector<MaterialSetData> &block_data )
{
@@ -929,15 +928,28 @@
if(result != MB_SUCCESS) {
mWriteIface->report_error("Couldn't get element array to write from.");
+ delete [] connectivity;
return result;
}
+
+ // if necessary, convert from EXODUS to MBCN node order
+ const MBEntityType elem_type = ExoIIUtil::ExoIIElementMBEntity[block.element_type];
+ assert( block.elements.all_of_type( elem_type ) );
+ const int* reorder = exodus_elem_order_map[elem_type][block.number_nodes_per_element];
+ if (reorder)
+ MBWriteUtilIface::reorder( reorder, connectivity,
+ block.number_elements,
+ block.number_nodes_per_element );
exodus_id += num_elem;
char wname[80];
INS_ID(wname, "connect%d", i+1);
NcVar *conn = ncFile->get_var(wname);
- if (NULL == conn) return MB_FAILURE;
+ if (NULL == conn) {
+ delete [] connectivity;
+ return MB_FAILURE;
+ }
NcBool err = conn->put(connectivity, num_elem, num_nodes_per_elem);
delete [] connectivity;
if(!err)
More information about the moab-dev
mailing list