moab
SetsNTags.cpp
Go to the documentation of this file.
00001 
00009 #include "moab/Core.hpp"
00010 #include "moab/Interface.hpp"
00011 #include "moab/Range.hpp"
00012 #include "MBTagConventions.hpp"
00013 
00014 #include <iostream>
00015 
00016 using namespace moab;
00017 using namespace std;
00018 
00019 #ifndef MESH_DIR
00020 #define MESH_DIR "."
00021 #endif
00022 
00023 string test_file_name = string(MESH_DIR) + string("/1hex.g");
00024 
00025 // tag names for these conventional tags come from MBTagConventions.hpp
00026 const char *tag_nms[] = {MATERIAL_SET_TAG_NAME, DIRICHLET_SET_TAG_NAME, NEUMANN_SET_TAG_NAME};
00027 
00028 int main(int argc, char **argv) {
00029     // get the material set tag handle
00030   Tag mtag;
00031   ErrorCode rval;
00032   Range sets, set_ents;
00033 
00034     // instantiate & load a file
00035   Interface *mb = new Core();
00036 
00037     // need option handling here for input filename
00038   if (argc > 1){
00039     //user has input a mesh file
00040     test_file_name = argv[1];
00041   }  
00042 
00043   rval = mb->load_file(test_file_name.c_str());
00044   if (MB_SUCCESS != rval) return 1;
00045 
00046     // loop over set types
00047   for (int i = 0; i < 3; i++) {
00048       // get the tag handle for this tag name; tag should already exist (it was created during file read)
00049     rval = mb->tag_get_handle(tag_nms[i], 1, MB_TYPE_INTEGER, mtag);
00050     if (MB_SUCCESS != rval) return 1;
00051 
00052       // get all the sets having that tag (with any value for that tag)
00053     sets.clear();
00054     rval = mb->get_entities_by_type_and_tag(0, MBENTITYSET, &mtag, NULL, 1, sets);
00055     if (MB_SUCCESS != rval) return 1;
00056 
00057       // iterate over each set, getting the entities and printing them
00058     Range::iterator set_it;
00059     for (set_it = sets.begin(); set_it != sets.end(); set_it++)  {
00060         // get the id for this set
00061       int set_id;
00062       rval = mb->tag_get_data(mtag, &(*set_it), 1, &set_id);
00063       if (MB_SUCCESS != rval) return 1;
00064 
00065         // get the entities in the set, recursively
00066       rval = mb->get_entities_by_handle(*set_it, set_ents, true);
00067       if (MB_SUCCESS != rval) return 1;
00068 
00069       cout << tag_nms[i] << " " << set_id << " has " 
00070                 << set_ents.size() << " entities:" << endl;
00071       set_ents.print("   ");
00072       set_ents.clear();
00073     }
00074   }
00075 
00076   delete mb;
00077 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines