MeshKit
1.0
|
00001 00007 #include "meshkit/MKCore.hpp" 00008 #include "meshkit/SizingFunction.hpp" 00009 #include "meshkit/ModelEnt.hpp" 00010 00011 using namespace MeshKit; 00012 00013 MKCore * mk; 00014 bool save_mesh = false; 00015 bool quadMesh = true; 00016 double mesh_size = 0.3; 00017 std::string file_name; //="shell.h5m"; 00018 std::string output_file; //="output.h5m"; 00019 00020 #include "TestUtil.hpp" 00021 00022 void meshFB2(); 00023 00024 int main(int argc, char **argv) 00025 { 00026 // start up a new iGeom engine, based on moab 00027 /*moab::Interface * mb = new moab::Core(); 00028 iGeom * fbiGeom = new FBiGeom(mb); // true means smooth 00029 MKCore mk(fbiGeom, mb); // iMesh, iRel, will be constructed*/ 00030 00031 file_name = TestDir + "/" + "shell.h5m";// default test file 00032 output_file = "output.h5m"; 00033 00034 if (argc < 5) { 00035 { 00036 std::cout << "Usage : filename output < q, t > <mesh_size> \n"; 00037 std::cout << "use default options: " << file_name << " " << output_file << 00038 (quadMesh ? " q " : " t " ) << mesh_size << "\n"; 00039 } 00040 } 00041 else 00042 { 00043 file_name = argv[1]; 00044 output_file = argv[2]; 00045 if (!strcmp(argv[3], "t")) 00046 quadMesh = false; 00047 mesh_size = atof(argv[4]); 00048 save_mesh = true; 00049 } 00050 00051 int num_fail = 0; 00052 num_fail += RUN_TEST(meshFB2); 00053 00054 return num_fail; 00055 } 00056 void meshFB2() 00057 { 00058 mk = new MKCore; 00059 00060 mk->load_mesh(file_name.c_str(), NULL, 0, 0, 0, false, false); 00061 int indx= mk->initialize_mesh_based_geometry(0); 00062 00063 moab::Range tris; 00064 moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension( 00065 (moab::EntityHandle)0 , 2, 00066 tris); 00067 00068 int nbInitial = tris.size(); 00069 tris.clear(); 00070 // initial number of triangles 00071 std::cout << nbInitial << " initial elements in the model" << std::endl; 00072 //fbiGeom->Init(); 00073 00074 // get the surface model ents 00075 MEntVector surfs; 00076 mk->get_entities_by_dimension(2, surfs); 00077 00078 // create surface mesher for them, either quad or tri mesher 00079 if (quadMesh) 00080 mk->construct_meshop("CAMALPaver", surfs); 00081 else 00082 mk->construct_meshop("CAMALTriAdvance", surfs); 00083 00084 00085 // size the mesh 00086 SizingFunction *sf = new SizingFunction(mk, -1, mesh_size); 00087 for (unsigned int i = 0; i < surfs.size(); i++) 00088 surfs[i]->sizing_function_index(sf->core_index()); 00089 00090 // now mesh them 00091 mk->setup_and_execute(); 00092 00093 std::cout<<" after execute:\n"; 00094 // just for debugging 00095 mk->print_graph(); 00096 00097 // report the number of triangles generated 00098 // put it in a new set in moab 00099 00100 rval = mk->moab_instance()->get_entities_by_dimension(0, 2, tris); 00101 CHECK_EQUAL(moab::MB_SUCCESS, rval); 00102 std::string elem =(quadMesh? " quads ": " triangles"); 00103 std::cout << tris.size() - nbInitial << elem << " generated." << std::endl; 00104 00105 mk->remove_mesh_based_geometry(indx); 00106 if (save_mesh) { 00107 // output mesh for surfaces (implicitly for edges too, as edges are children of surface sets) 00108 mk->save_mesh_from_model_ents(output_file.c_str(), surfs); 00109 } 00110 // delete the model ents too, unload geometry 00111 00112 delete mk; 00113 }