[MOAB-dev] r3593 - in MOAB/trunk/examples: . GeomSetHierarchy GetEntities SetsNTags

tautges at mcs.anl.gov tautges at mcs.anl.gov
Thu Mar 11 13:46:49 CST 2010


Author: tautges
Date: 2010-03-11 13:46:49 -0600 (Thu, 11 Mar 2010)
New Revision: 3593

Added:
   MOAB/trunk/examples/GeomSetHierarchy/
   MOAB/trunk/examples/GeomSetHierarchy/GeomSetHierarchy.cpp
   MOAB/trunk/examples/GeomSetHierarchy/Makefile
   MOAB/trunk/examples/GetEntities/
   MOAB/trunk/examples/GetEntities/GetEntities.cpp
   MOAB/trunk/examples/GetEntities/Makefile
   MOAB/trunk/examples/SetsNTags/
   MOAB/trunk/examples/SetsNTags/Makefile
   MOAB/trunk/examples/SetsNTags/SetsNTags.cpp
Log:
Committing first few examples from getting started section of user's guide.



Added: MOAB/trunk/examples/GeomSetHierarchy/GeomSetHierarchy.cpp
===================================================================
--- MOAB/trunk/examples/GeomSetHierarchy/GeomSetHierarchy.cpp	                        (rev 0)
+++ MOAB/trunk/examples/GeomSetHierarchy/GeomSetHierarchy.cpp	2010-03-11 19:46:49 UTC (rev 3593)
@@ -0,0 +1,38 @@
+#include "moab/MBCore.hpp"
+#include "moab/MBRange.hpp"
+#include "moab/MBCN.hpp"
+#include <iostream>
+
+int main(int, char **argv) {
+    // instantiate & load a file
+  MBInterface *mb = new MBCore();
+  MBErrorCode rval = mb->load_file(argv[1]);
+
+    // get the geometric topology tag handle
+  MBTag geom_tag;
+  rval = mb->tag_get_handle("GEOM_DIMENSION", geom_tag);
+
+    // traverse the model, from dimension 3 downward
+  MBRange psets, chsets;
+  int dim;
+  void *dim_ptr = &dim;
+  for (dim = 3; dim >= 0; dim--) {
+      // get parents at this dimension
+    psets.clear();
+    rval = mb->get_entities_by_type_and_tag(0, MBENTITYSET, 
+                                            &geom_tag, &dim_ptr, 1, 
+                                            psets, 1, false);
+
+      // for each parent, get children and do something with them
+    MBRange::iterator par_it;
+    for (par_it = psets.begin(); par_it != psets.end(); par_it++) {
+        // get the children and put in child set list
+      chsets.clear();
+      rval = mb ->get_child_meshsets(*par_it, chsets);
+
+        // print # children
+      std::cout << "d=" << dim << " entity has " << chsets.size() 
+                << " children." << std::endl;
+    }
+  } 
+}

Added: MOAB/trunk/examples/GeomSetHierarchy/Makefile
===================================================================
--- MOAB/trunk/examples/GeomSetHierarchy/Makefile	                        (rev 0)
+++ MOAB/trunk/examples/GeomSetHierarchy/Makefile	2010-03-11 19:46:49 UTC (rev 3593)
@@ -0,0 +1,8 @@
+include ${MOAB_LIB_DIR}/moab.make
+
+GeomSetHierarchy : GeomSetHierarchy.o
+	${CXX} $< ${MOAB_LIBS_LINK} -o $@
+
+.cpp.o : 
+	${CXX} ${MOAB_INCLUDES} -c $<
+

Added: MOAB/trunk/examples/GetEntities/GetEntities.cpp
===================================================================
--- MOAB/trunk/examples/GetEntities/GetEntities.cpp	                        (rev 0)
+++ MOAB/trunk/examples/GetEntities/GetEntities.cpp	2010-03-11 19:46:49 UTC (rev 3593)
@@ -0,0 +1,22 @@
+#include "moab/MBCore.hpp"
+#include "moab/MBRange.hpp"
+#include <iostream>
+
+int main(int, char **argv) {
+    // instantiate & load a mesh from a file
+  MBCore *mb = new MBCore();
+  MBErrorCode rval = mb->load_mesh(argv[1]);
+
+  MBRange ents;
+
+    // iterate over dimensions
+  for (int d = 0; d <= 3; d++) {
+    rval = mb->get_entities_by_dimension(0, d, ents);
+    for (MBRange::iterator it = ents.begin(); it != ents.end(); it++) {
+      MBEntityHandle ent = *it;
+      std::cout << "Found d=" << d << " entity " 
+                << mb->id_from_handle(ent) << "." << std::endl;
+    }
+  }
+  return 0;
+}

Added: MOAB/trunk/examples/GetEntities/Makefile
===================================================================
--- MOAB/trunk/examples/GetEntities/Makefile	                        (rev 0)
+++ MOAB/trunk/examples/GetEntities/Makefile	2010-03-11 19:46:49 UTC (rev 3593)
@@ -0,0 +1,8 @@
+include ${MOAB_LIB_DIR}/moab.make
+
+GetEntities : GetEntities.o
+	${CXX} $< ${MOAB_LIBS_LINK} -o $@
+
+.cpp.o : 
+	${CXX} ${MOAB_INCLUDES} -c $<
+

Added: MOAB/trunk/examples/SetsNTags/Makefile
===================================================================
--- MOAB/trunk/examples/SetsNTags/Makefile	                        (rev 0)
+++ MOAB/trunk/examples/SetsNTags/Makefile	2010-03-11 19:46:49 UTC (rev 3593)
@@ -0,0 +1,8 @@
+include ${MOAB_LIB_DIR}/moab.make
+
+SetsNTags : SetsNTags.o
+	${CXX} $< ${MOAB_LIBS_LINK} -o $@
+
+.cpp.o : 
+	${CXX} ${MOAB_INCLUDES} -c $<
+

Added: MOAB/trunk/examples/SetsNTags/SetsNTags.cpp
===================================================================
--- MOAB/trunk/examples/SetsNTags/SetsNTags.cpp	                        (rev 0)
+++ MOAB/trunk/examples/SetsNTags/SetsNTags.cpp	2010-03-11 19:46:49 UTC (rev 3593)
@@ -0,0 +1,41 @@
+#include "moab/MBCore.hpp"
+#include "moab/MBRange.hpp"
+#include <iostream>
+
+int main(int, char **argv) {
+    // get the material set tag handle
+  MBTag mtag;
+  MBErrorCode rval;
+  const char *tag_nms[] = {"MATERIAL_SET", "DIRICHLET_SET", 
+                           "NEUMANN_SET"};
+  MBRange sets, set_ents;
+
+    // instantiate & load a file
+  MBInterface *mb = new MBCore();
+  rval = mb->load_file(argv[1]);
+
+    // loop over set types
+  for (int i = 0; i < 3; i++) {
+    rval = mb->tag_get_handle(tag_nms[i], mtag);
+
+      // get all the sets of that type in the mesh
+    rval = mb->get_entities_by_type_and_tag(0, MBENTITYSET, &mtag,
+                                            NULL, 1, sets);
+
+      // iterate over each set, getting entities
+    MBRange::iterator set_it;
+    for (set_it = sets.begin(); set_it != sets.end(); set_it++)  {
+      MBEntityHandle this_set = *set_it;
+
+        // get the id for this set
+      int set_id;
+      rval = mb->tag_get_data(mtag, &this_set, 1, &set_id);
+
+        // get the entities in the set, recursively
+      rval = mb->get_entities_by_handle(this_set, set_ents, true);
+
+      std::cout << tag_nms[i] << " " << set_id << " has " 
+                << set_ents.size() << " entities." << std::endl;
+    }
+  }
+}



More information about the moab-dev mailing list