MeshKit  1.0
test_ebmesh.cpp
Go to the documentation of this file.
00001 
00007 #include "meshkit/MKCore.hpp"
00008 #include "meshkit/MeshOp.hpp"
00009 #include "meshkit/EBMesher.hpp"
00010 #include "meshkit/SCDMesh.hpp"
00011 #include "meshkit/ModelEnt.hpp"
00012 
00013 #include "moab/Interface.hpp"
00014 #include "moab/EntityHandle.hpp"
00015 
00016 //#include "CGMApp.hpp"
00017 using namespace MeshKit;
00018 
00019 #include "TestUtil.hpp"
00020 
00021 #ifdef HAVE_ACIS
00022 #define DEFAULT_TEST_FILE "sphere.sat"
00023 #elif defined(HAVE_OCC)
00024 #define DEFAULT_TEST_FILE "sphere.stp"
00025 #endif
00026 
00027 const bool debug_ebmesher = true;
00028 
00029 int load_and_mesh(const char *input_filename,
00030                   const char *output_filename,
00031                   int whole_geom, int* n_intervals, int mesh_based_geom,
00032                   double box_increase, int vol_frac_res);
00033 
00034 int main(int argc, char **argv) 
00035 {
00036   // check command line arg
00037   std::string input_filename;
00038   const char *output_filename = "ebmesh_out.vtk";
00039   int whole_geom = 1;
00040   int n_interval[3] = {10, 10, 10};
00041   int mesh_based_geom = 0;
00042   double box_increase = .03;
00043   int vol_frac_res = 0;
00044 
00045   if (argc > 2 && argc < 11) {
00046     input_filename += argv[1];
00047     if (argc > 2) whole_geom = atoi(argv[2]);
00048     if (argc > 3) n_interval[0] = atoi(argv[3]);
00049     if (argc > 4) n_interval[1] = atoi(argv[4]);
00050     if (argc > 5) n_interval[2] = atoi(argv[5]);
00051     if (argc > 6) mesh_based_geom = atoi(argv[6]);
00052     if (argc > 7) output_filename = argv[7];
00053     if (argc > 8) box_increase = atof(argv[8]);
00054     if (argc > 9) vol_frac_res = atoi(argv[9]);
00055   }
00056   else {
00057     std::cout << "Usage: " << argv[0] << "<input_geom_filename> <whole_geom> {x: # of intervals} {y: # of intervals} {z: # of intervals} {mesh_based_geom} {output_mesh_filename} {box_size_increase} {vol_frac_res}" << std::endl;
00058     std::cout << "<input_geom_filename> : input geometry file name" << std::endl;
00059     std::cout << "<whole_geom> : make mesh for whole geom or individually(1/0), default whole geom(1)" << std::endl;
00060     std::cout << "{x/y/z: # ofintervals} : optional argument. # of intervals. if it is not set, set to 10." << std::endl;
00061     std::cout << "<mesh_based_geom> : use mesh based geometry(1/0), default not-use(0)" << std::endl;
00062     std::cout << "{output_mesh_filename} : optional argument. if it is not set, dosn't export. can output mesh file (e.g. output.vtk.)" << std::endl;
00063     std::cout << "{box size increase} : optional argument. Cartesian mesh box increase form geometry. default 0.03" << std::endl;
00064     std::cout << "{vol_frac_res} : optional argument, volume fraction resolution of boundary cells for each material, you can specify it as # of divisions (e.g. 4)." << std::endl;
00065     std::cout << std::endl;
00066     if (argc != 1) return 1;
00067     std::cout << "No file specified.  Defaulting to: " << DEFAULT_TEST_FILE << std::endl;
00068     std::string file_name = TestDir + "/" + DEFAULT_TEST_FILE;
00069     input_filename += TestDir;
00070     input_filename += "/";
00071     input_filename += DEFAULT_TEST_FILE;
00072   }
00073   
00074   if (load_and_mesh(input_filename.c_str(), output_filename,
00075                     whole_geom, n_interval, mesh_based_geom, box_increase, vol_frac_res)) return 1;
00076   
00077   return 0;
00078 }
00079 
00080 int load_and_mesh(const char *input_filename,
00081                   const char *output_filename,
00082                   int whole_geom, int* n_interval, int mesh_based_geom,
00083                   double box_increase, int vol_frac_res)
00084 {
00085   bool result;
00086   time_t start_time, load_time, mesh_time, vol_frac_time,
00087     export_time, query_time_techX, query_time;
00088 
00089   // start up MK and load the geometry
00090   MKCore mk;
00091   time(&start_time);
00092 //  CGMApp::instance()->attrib_manager()->auto_flag( CUBIT_TRUE );
00093   mk.load_mesh(input_filename, NULL, 0, 0, 0, true);
00094   time(&load_time);
00095 
00096   if (debug_ebmesher) {
00097     mk.save_mesh("input.vtk");
00098   }
00099 
00100   // get the volumes
00101   MEntVector vols;
00102   mk.get_entities_by_dimension(3, vols);
00103   if (vols.empty())
00104   {
00105     // check the surfaces
00106     MEntVector surfs;
00107     mk.get_entities_by_dimension(2, surfs);
00108     if (surfs.empty())
00109     {
00110       std::cout<<" no geometry, bail out \n";
00111       return 1;
00112     }
00113     if (surfs.size()==1)
00114     {
00115       // create a new ModelEnt, volume, with one surface
00116       // also create a volume ; add to it a surface entity
00117       moab::EntityHandle surfSet = surfs[0]->mesh_handle();
00118       moab::EntityHandle volSet;
00119       moab::ErrorCode rval = mk.moab_instance()->create_meshset(moab::MESHSET_SET, volSet);
00120       MBERRCHK(rval, mk.moab_instance());
00121       rval = mk.moab_instance()->add_parent_child(volSet, surfSet);
00122       MBERRCHK(rval, mk.moab_instance());
00123       // also, set the geom dimension
00124       int dimension = 3;
00125       rval =mk.moab_instance()->tag_set_data(mk.moab_geom_dim_tag(), &volSet, 1, &dimension);
00126       MBERRCHK(rval, mk.moab_instance());
00127       ModelEnt * this_me = new ModelEnt(&mk, (iGeom::EntityHandle)NULL, 0, volSet, 0, 0);
00128       //mk.modelEnts[3].push_back(this_me);
00129       // get out if we created one model ent
00130       vols.push_back(this_me);
00131     }
00132   }
00133 
00134   // make EBMesher
00135   EBMesher *ebm = (EBMesher*) mk.construct_meshop("EBMesher", vols);
00136   ebm->use_whole_geom(whole_geom);
00137   ebm->use_mesh_geometry(mesh_based_geom);
00138   ebm->set_num_interval(n_interval);
00139   ebm->increase_box(box_increase);
00140   if (mesh_based_geom) ebm->set_obb_tree_box_dimension();
00141 
00142   // mesh embedded boundary mesh, by calling execute
00143   mk.setup_and_execute();
00144   time(&mesh_time);
00145 
00146   // caculate volume fraction, only for geometry input
00147   if (vol_frac_res > 0) {
00148     result = ebm->get_volume_fraction(vol_frac_res);
00149     if (!result) {
00150       std::cerr << "Couldn't get volume fraction." << std::endl;
00151       return 1;
00152     }
00153   }
00154   time(&vol_frac_time);
00155 
00156   // export mesh
00157   if (output_filename != NULL) {
00158     ebm->export_mesh(output_filename);
00159   }
00160   time(&export_time);
00161 
00162   if (whole_geom && debug_ebmesher) {
00163     // techX query function test
00164     double boxMin[3], boxMax[3];
00165     int nDiv[3];
00166     std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan > mdCutCellSurfEdge;
00167     std::vector<int> vnInsideCellTechX;
00168     
00169     ebm->get_grid_and_edges_techX(boxMin, boxMax, nDiv,
00170                                   mdCutCellSurfEdge, vnInsideCellTechX);
00171     time(&query_time_techX);
00172     
00173     // multiple intersection fraction query test
00174     std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan > mdCutCellEdge;
00175     std::vector<int> vnInsideCell;
00176     result = ebm->get_grid_and_edges(boxMin, boxMax, nDiv,
00177                                      mdCutCellEdge, vnInsideCell);
00178     if (!result) {
00179       std::cerr << "Couldn't get mesh information." << std::endl;
00180       return 1;
00181     }
00182     time(&query_time);
00183     std::cout << "# of TechX cut-cell surfaces: " << mdCutCellSurfEdge.size() 
00184               << ", # of nInsideCell: " << vnInsideCell.size()/3 << std::endl;
00185   }
00186 
00187   std::cout << "EBMesh is succesfully finished." << std::endl;
00188   std::cout << "Time including loading: "
00189             << difftime(mesh_time, start_time)
00190             << " secs, Time excluding loading: "
00191             << difftime(mesh_time, load_time)
00192             << " secs, Time volume fraction: "
00193             << difftime(vol_frac_time, mesh_time) << " secs";
00194 
00195   if (output_filename != NULL) {
00196     std::cout << ", Time export mesh: "
00197               << difftime(export_time, vol_frac_time) << " secs";
00198   }
00199 
00200   if (whole_geom && debug_ebmesher) {
00201     std::cout << ", TechX query time: "
00202               << difftime(query_time_techX, export_time)
00203               << " secs, multiple intersection fraction query (elems, edge-cut fractions): "
00204               << difftime(query_time, query_time_techX) << " secs.";
00205   }
00206 
00207   std::cout << std::endl;
00208   mk.clear_graph();
00209 
00210   return 0;
00211 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines