MeshKit  1.0
test_ngtetmesher.cpp
Go to the documentation of this file.
00001 
00007 #include "meshkit/MKCore.hpp"
00008 #include "meshkit/NGTetMesher.hpp"
00009 #include "meshkit/SizingFunction.hpp"
00010 #include "meshkit/ModelEnt.hpp"
00011 
00012 using namespace MeshKit;
00013 
00014 #include "TestUtil.hpp"
00015 
00016 MKCore *mk = NULL;
00017 bool save_mesh = false;
00018 
00019 void threeholecube_test();
00020 void simpletet_test();
00021 void mesh_test(std::string filebase, double size);
00022 
00023 #ifdef HAVE_ACIS
00024 std::string extension = ".sat";
00025 #elif HAVE_OCC
00026 std::string extension = ".stp";
00027 #endif
00028 
00029 int main(int argc, char **argv) 
00030 {
00031   
00032     // start up MK and load the geometry
00033   mk = new MKCore;
00034   int num_fail = 0;
00035   
00036   if (argc == 2) save_mesh = true;
00037   
00038   // Test 1                                                                                                                                                                            
00039   num_fail += RUN_TEST(simpletet_test);
00040   // clear mk, geometry and mesh                                                                                                                                                       
00041   mk->delete_all();
00042   // Test 2                                                                                                                                                                            
00043   num_fail += RUN_TEST(threeholecube_test);
00044   
00045   return num_fail;
00046 }
00047 
00048 void simpletet_test() 
00049 {
00050   mesh_test("simpletet", 0.25);
00051 }
00052 
00053 void threeholecube_test() 
00054 {
00055   mesh_test("threeholecube", 0.1);
00056 }
00057 
00058 void mesh_test(std::string filebase, double size)
00059 {
00060   std::string file_name = TestDir + "/" + filebase + extension;
00061   mk->load_geometry(file_name.c_str());
00062 
00063     // get the volume
00064   MEntVector dum, vols;
00065   mk->get_entities_by_dimension(3, dum);
00066   vols.push_back(*dum.rbegin());
00067   NGTetMesher *tm = (NGTetMesher*) mk->construct_meshop("NGTetMesher", vols);
00068 
00069     // make a sizing function and set it on the surface
00070   SizingFunction esize(mk, -1, size);
00071   vols[0]->sizing_function_index(esize.core_index());
00072   
00073     // mesh the surface, by calling execute
00074   mk->setup_and_execute();
00075 
00076     // report the number of tets
00077   moab::Range tets;
00078   moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension(0, 3, tets);
00079   CHECK_EQUAL(moab::MB_SUCCESS, rval);
00080   std::cout << tets.size() << " tets generated." << std::endl;
00081 
00082   if (save_mesh) {
00083         // output mesh
00084     std::string outfile = filebase + std::string(".vtk");
00085     moab::EntityHandle out_set = vols[0]->mesh_handle();
00086     rval = mk->moab_instance()->write_file(outfile.c_str(), NULL, NULL, &out_set, 1);
00087     MBERRCHK(rval, mk->moab_instance());
00088   }
00089 
00090   mk->clear_graph();
00091 }
00092 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines