MeshKit  1.0
test_camalmbgeom.cpp
Go to the documentation of this file.
00001 
00007 #include "meshkit/MKCore.hpp"
00008 #include "meshkit/FBiGeom.hpp"
00009 #include "meshkit/SizingFunction.hpp"
00010 #include "meshkit/ModelEnt.hpp"
00011 
00012 using namespace MeshKit;
00013 
00014 MKCore * mk;
00015 bool save_mesh = false;
00016 bool quadMesh = true;
00017 double mesh_size = 0.3;
00018 std::string file_name; //="shell.h5m";
00019 std::string output_file; //="output.h5m";
00020 
00021 #include "TestUtil.hpp"
00022 
00023 void meshFB();
00024 
00025 int main(int argc, char **argv)
00026 {
00027   // start up a new iGeom engine, based on moab
00028   /*moab::Interface * mb = new moab::Core();
00029    iGeom * fbiGeom = new FBiGeom(mb); // true means smooth
00030    MKCore mk(fbiGeom, mb); // iMesh, iRel, will be constructed*/
00031 
00032   file_name = TestDir + "/" + "shell.h5m";// default test file
00033   output_file = "output.h5m";
00034   if (argc < 4) {
00035     {
00036       std::cout << "Usage : filename < 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(meshFB);
00053 
00054   return num_fail;
00055 }
00056 void meshFB()
00057 {
00058   mk = new MKCore;
00059   // just for debugging
00060   FBiGeom * fbiGeom = new FBiGeom(); // true for smooth, false for linear
00061   unsigned int ix = mk->add_igeom_instance(fbiGeom);
00062 
00063   // this will do the reading of the moab db in memory
00064 
00065   //this also will do heavy stuff, like smoothing
00066   // we do not want to do it in the constructor
00067   // this should also populate ModelEnts in MKCore
00068   std::string opts( "SMOOTH;");
00069   mk->load_geometry(file_name.c_str(), opts.c_str(), ix, 0, -1, false, true);
00070   /*fbiGeom->load(file_name.c_str(), opts.c_str());
00071 
00072   mk->populate_model_ents(ix, 0, -1, true);*/
00073 
00074   moab::Range tris;
00075   moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension(
00076       (moab::EntityHandle)fbiGeom->getRootSet() , 2,
00077       tris, /*recursive*/ true);
00078 
00079   int nbInitial = tris.size();
00080   tris.clear();
00081   // initial number of triangles
00082   std::cout << nbInitial << " initial elements in the model" << std::endl;
00083   //fbiGeom->Init();
00084 
00085   // get the surface model ents
00086   MEntVector surfs;
00087   mk->get_entities_by_dimension(2, surfs);
00088 
00089   // create surface mesher for them, either quad or tri mesher
00090   if (quadMesh)
00091     mk->construct_meshop("CAMALPaver", surfs);
00092   else
00093     mk->construct_meshop("CAMALTriAdvance", surfs);
00094 
00095 
00096   // just for debugging
00097   mk->print_graph();
00098 
00099   // size the mesh
00100   SizingFunction *sf = new SizingFunction(mk, -1, mesh_size);
00101   for (unsigned int i = 0; i < surfs.size(); i++)
00102     surfs[i]->sizing_function_index(sf->core_index());
00103 
00104   // now mesh them
00105   mk->setup_and_execute();
00106 
00107   std::cout<<" after execute:\n";
00108   // just for debugging
00109   mk->print_graph();
00110 
00111   // report the number of triangles generated
00112   // put it in a new set in moab
00113 
00114   rval = mk->moab_instance()->get_entities_by_dimension(0, 2, tris);
00115   CHECK_EQUAL(moab::MB_SUCCESS, rval);
00116   std::string elem =(quadMesh? " quads ": " triangles");
00117   std::cout << tris.size() - nbInitial << elem << " generated." << std::endl;
00118 
00119   delete fbiGeom;// this will trigger also deletion of FBEngine tags, etc
00120 
00121   if (save_mesh) {
00122     // output mesh for surfaces (implicitly for edges too, as edges are children of surface sets)
00123     mk->save_mesh_from_model_ents(output_file.c_str(), surfs);
00124   }
00125   // delete the model ents too, unload geometry
00126 
00127   delete mk;
00128 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines