[MOAB-dev] r2950 - in MOAB/trunk: . tools
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Thu Jun 18 12:17:41 CDT 2009
Author: kraftche
Date: 2009-06-18 12:17:41 -0500 (Thu, 18 Jun 2009)
New Revision: 2950
Added:
MOAB/trunk/tools/depth.cpp
Modified:
MOAB/trunk/configure.ac
MOAB/trunk/tools/Makefile.am
Log:
Add tool that tags elements with their topological distance from
the mesh boundary. This is rather useful in combination with
Paraview's theshold filter to examin elements in the interior of a mesh.
Modified: MOAB/trunk/configure.ac
===================================================================
--- MOAB/trunk/configure.ac 2009-06-17 20:37:45 UTC (rev 2949)
+++ MOAB/trunk/configure.ac 2009-06-18 17:17:41 UTC (rev 2950)
@@ -310,6 +310,7 @@
MB_OPTIONAL_TOOL([mbzoltan], [no] )
MB_OPTIONAL_TOOL([dagmc], [yes])
MB_OPTIONAL_TOOL([gsets], [yes])
+MB_OPTIONAL_TOOL([mbdepth], [yes])
################################################################################
Modified: MOAB/trunk/tools/Makefile.am
===================================================================
--- MOAB/trunk/tools/Makefile.am 2009-06-17 20:37:45 UTC (rev 2949)
+++ MOAB/trunk/tools/Makefile.am 2009-06-18 17:17:41 UTC (rev 2950)
@@ -41,6 +41,10 @@
doc_DATA += README.mbskin
endif
+if ENABLE_mbdepth
+ bin_PROGRAMS += mbdepth
+endif
+
if ENABLE_mbtagprop
bin_PROGRAMS += mbtagprop
doc_DATA += README.mbtagprop
@@ -132,6 +136,9 @@
mbskin_SOURCES = skin.cpp
mbskin_DEPENDENCIES = $(top_builddir)/libMOAB.la
+mbdepth_SOURCES = depth.cpp
+mbdepth_DEPENDENCIES = $(top_builddir)/libMOAB.la
+
spheredecomp_SOURCES = SphereDecomp.hpp SphereDecomp.cpp main.cpp
spheredecomp_DEPENDENCIES = $(top_builddir)/libMOAB.la
Added: MOAB/trunk/tools/depth.cpp
===================================================================
--- MOAB/trunk/tools/depth.cpp (rev 0)
+++ MOAB/trunk/tools/depth.cpp 2009-06-18 17:17:41 UTC (rev 2950)
@@ -0,0 +1,156 @@
+#include "MBRange.hpp"
+#include "MBCore.hpp"
+#include "MBSkinner.hpp"
+#include <iostream>
+#include <stdlib.h>
+
+enum {
+ NO_ERROR= 0,
+ SYNTAX_ERROR = 1,
+ FILE_IO_ERROR = 2,
+ INTERNAL_ERROR = 3
+};
+
+const char* DEFAULT_TAG_NAME = "depth";
+
+void usage( const char* argv0 )
+{
+ std::cerr << "Usage: " << argv0 << "[-t <tag name] <input_file> <output_file>" << std::endl
+ << argv0 << "-h" << std::endl;
+ exit(SYNTAX_ERROR);
+}
+
+void help( const char* argv0 )
+{
+ std::cout << argv0 << "[-t <tag name] <input_file> <output_file>" << std::endl
+ << "Tag elements with integer depth from boundary" << std::endl
+ << "-t : tag in which to store depth (default: \"" << DEFAULT_TAG_NAME << "\")" << std::endl;
+ exit(NO_ERROR);
+}
+
+void check( MBErrorCode rval )
+{
+ if (MB_SUCCESS != rval) {
+ std::cerr << "Internal error. Aborting." << std::endl;
+ exit(INTERNAL_ERROR);
+ }
+}
+
+void tag_depth( MBInterface& moab, MBTag tag );
+
+int main( int argc, char* argv[] )
+{
+ const char *input = 0, *output = 0, *tagname = DEFAULT_TAG_NAME;
+ bool expect_tag_name = false;
+ for (int i = 1; i < argc; ++i) {
+ if (expect_tag_name) {
+ tagname = argv[i];
+ expect_tag_name = false;
+ }
+ else if (!strcmp("-t", argv[i]))
+ expect_tag_name = true;
+ else if (input == 0)
+ input = argv[i];
+ else if (output == 0)
+ output = argv[i];
+ else {
+ std::cerr << "Unexpected argument: '" << argv[i] << "'" << std::endl;
+ usage(argv[0]);
+ }
+ }
+
+ if (expect_tag_name) {
+ std::cerr << "Expected argument following '-t'" << std::endl;
+ usage(argv[0]);
+ }
+ if (!input) {
+ std::cerr << "No input file" << std::endl;
+ usage(argv[0]);
+ }
+ if (!output) {
+ std::cerr << "No output file" << std::endl;
+ usage(argv[0]);
+ }
+
+ MBCore moab;
+ MBInterface& mb = moab;
+
+ MBEntityHandle file;
+ MBErrorCode rval;
+ rval = mb.load_file( input, file );
+ if (MB_SUCCESS != rval) {
+ std::cerr << "Failed to load file: " << input << std::endl;
+ return FILE_IO_ERROR;
+ }
+
+ int init_val = -1;
+ MBTag tag;
+ rval = mb.tag_create( tagname, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &init_val );
+ if (MB_ALREADY_ALLOCATED == rval) {
+ rval = mb.tag_delete( tag ); check(rval);
+ rval = mb.tag_create( tagname, sizeof(int), MB_TAG_DENSE, MB_TYPE_INTEGER, tag, &init_val );
+ check(rval);
+ }
+
+ tag_depth( mb, tag );
+
+ rval = mb.write_file( output, 0, 0, &file, 1 );
+ if (rval == MB_SUCCESS)
+ std::cout << "Wrote file: " << output << std::endl;
+ else {
+ std::cerr << "Failed to write file: " << output << std::endl;
+ return FILE_IO_ERROR;
+ }
+
+ return NO_ERROR;
+}
+
+MBErrorCode get_adjacent_elems( MBInterface& mb, const MBRange& verts, MBRange& elems )
+{
+ elems.clear();
+ MBErrorCode rval;
+ for (int dim = 3; dim > 0; --dim) {
+ rval = mb.get_adjacencies( verts, dim, false, elems, MBInterface::UNION );
+ if (MB_SUCCESS != rval)
+ break;
+ }
+ return rval;
+}
+
+void tag_depth( MBInterface& mb, MBTag tag )
+{
+ MBErrorCode rval;
+ int dim;
+
+ MBSkinner tool(&mb);
+ MBRange verts, elems;
+ dim = 3;
+ while (elems.empty()) {
+ rval = mb.get_entities_by_dimension( 0, dim, elems ); check(rval);
+ if (--dim == 0)
+ return; // no elements
+ }
+ rval = tool.find_skin( elems, 0, verts ); check(rval);
+ rval = get_adjacent_elems( mb, verts, elems ); check(rval);
+
+ std::vector<int> data;
+ int val, depth = 0;
+ while (!elems.empty()) {
+ data.clear();
+ data.resize( elems.size(), depth++ );
+ rval = mb.tag_set_data( tag, elems, &data[0] ); check(rval);
+
+ verts.clear();
+ rval = mb.get_adjacencies( elems, 0, false, verts, MBInterface::UNION );
+ check(rval);
+
+ MBRange tmp;
+ rval = get_adjacent_elems( mb, verts, tmp ); check(rval);
+ elems.clear();
+ for (MBRange::reverse_iterator i = tmp.rbegin(); i != tmp.rend(); ++i) {
+ rval = mb.tag_get_data( tag, &*i, 1, &val ); check(rval);
+ if (val == -1)
+ elems.insert( *i );
+ }
+ }
+}
More information about the moab-dev
mailing list