MeshKit  1.0
test_camalmbgeomvar.cpp
Go to the documentation of this file.
00001 
00007 #include "meshkit/MKCore.hpp"
00008 #include "meshkit/FBiGeom.hpp"
00009 #include "meshkit/SizingFunctionVar.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 double fixedPoint[3] = {0., 0., 0.};
00021 double a=0.1, b=0.1, c=0.1; // so size will vary from 0.3 to about 0.6, for the default model
00022 
00023 #include "TestUtil.hpp"
00024 
00025 void meshFBvar();
00026 
00027 int main(int argc, char **argv)
00028 {
00029   // start up a new iGeom engine, based on moab
00030   /*moab::Interface * mb = new moab::Core();
00031    iGeom * fbiGeom = new FBiGeom(mb); // true means smooth
00032    MKCore mk(fbiGeom, mb); // iMesh, iRel, will be constructed*/
00033 
00034   file_name = TestDir + "/" + "shell.h5m";// default test file
00035   output_file = "output.h5m";
00036   if (argc < 5) {
00037     {
00038       std::cout << "Usage : filename outfile < q, t >  <mesh_size>  x0  y0  z0  a  b  c \n";
00039       std::cout <<  " mesh size is variable with formula: \n size(x, y, z) = mesh_size+a(x-x0)+b(y-y0)+c(z-z0)\n";
00040       std::cout << "use default options: " << file_name << " " << output_file << " "<<
00041           (quadMesh ? "q " : "t " ) << mesh_size ;
00042       std::cout << " 0. 0. 0. 0.1 0.1 0.1 \n";
00043     }
00044   }
00045   else
00046   {
00047     file_name = argv[1];
00048     output_file = argv[2];
00049     if (!strcmp(argv[3], "t"))
00050       quadMesh = false;
00051     mesh_size = atof(argv[4]);
00052     save_mesh = true;
00053     // give some linear coefficients to the var size case
00054     if (argc==11)
00055     {
00056       fixedPoint[0] = atof(argv[5]);
00057       fixedPoint[1] = atof(argv[6]);
00058       fixedPoint[2] = atof(argv[7]);
00059       a = atof(argv[8]);
00060       b = atof(argv[9]);
00061       c = atof(argv[10]);
00062     }
00063     else
00064     {
00065       std::cout<<" wrong number of arguments: argc=" << argc << "\n";
00066       return 1; // fail;
00067     }
00068 
00069   }
00070 
00071   int num_fail = 0;
00072   num_fail += RUN_TEST(meshFBvar);
00073 
00074   return num_fail;
00075 }
00076 
00077 void meshFBvar()
00078 {
00079   mk = new MKCore;
00080   FBiGeom * fbiGeom = new FBiGeom(); // true for smooth, false for linear
00081   unsigned int ix = mk->add_igeom_instance(fbiGeom);
00082 
00083   // this will do the reading of the moab db in memory
00084 
00085   //this also will do heavy stuff, like smoothing
00086   // we do not want to do it in the constructor
00087   // this should also populate ModelEnts in MKCore
00088   std::string opts( "SMOOTH;");
00089   mk->load_geometry(file_name.c_str(), opts.c_str(), ix, 0, -1, false, true);
00090   /*fbiGeom->load(file_name.c_str(), opts.c_str());
00091   mk->populate_model_ents(ix, 0, -1, true);*/
00092 
00093   moab::Range tris;
00094   moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension(
00095       (moab::EntityHandle)fbiGeom->getRootSet() , 2,
00096       tris, /*recursive*/ true);
00097 
00098   int nbInitial = tris.size();
00099   tris.clear();
00100   // initial number of triangles
00101   std::cout << nbInitial << " initial elements in the model" << std::endl;
00102   //fbiGeom->Init();
00103 
00104   // get the surface model ents
00105   MEntVector surfs;
00106   mk->get_entities_by_dimension(2, surfs);
00107 
00108   // create surface mesher for them, either quad or tri mesher
00109   if (quadMesh)
00110     mk->construct_meshop("CAMALPaver", surfs);
00111   else
00112     mk->construct_meshop("CAMALTriAdvance", surfs);
00113 
00114 
00115 
00116   // size the mesh
00117   SizingFunctionVar *sf = new SizingFunctionVar(mk, -1, mesh_size);
00118   for (unsigned int i = 0; i < surfs.size(); i++)
00119     surfs[i]->sizing_function_index(sf->core_index());
00120 
00121   double coeff[4] = {a, b, c, mesh_size};
00122   sf->set_linear_coeff(fixedPoint, coeff);
00123 
00124   // now mesh them
00125   mk->setup_and_execute();
00126 
00127   // report the number of triangles generated
00128   // put it in a new set in moab
00129 
00130   rval = mk->moab_instance()->get_entities_by_dimension(0, 2, tris);
00131   CHECK_EQUAL(moab::MB_SUCCESS, rval);
00132   std::string elem =(quadMesh? " quads ": " triangles");
00133   std::cout << tris.size() - nbInitial << elem << " generated." << std::endl;
00134 
00135   delete fbiGeom;// this will trigger also deletion of FBEngine tags, etc
00136 
00137   if (save_mesh) {
00138     // output mesh for surfaces (implicitly for edges too, as edges are children of surface sets)
00139     mk->save_mesh_from_model_ents(output_file.c_str(), surfs);
00140   }
00141   // delete the model ents too, unload geometry
00142 
00143   delete mk;
00144 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines