MeshKit  1.0
example_ebmesh.cpp
Go to the documentation of this file.
00001 
00014 #include "meshkit/MKCore.hpp"
00015 #include "meshkit/MeshOp.hpp"
00016 #include "meshkit/EBMesher.hpp"
00017 #include "meshkit/SCDMesh.hpp"
00018 #include "meshkit/ModelEnt.hpp"
00019 
00020 //#include "CGMApp.hpp"
00021 using namespace MeshKit;
00022 
00023 
00024 
00025 #ifdef HAVE_ACIS
00026 #define DEFAULT_TEST_FILE "sphere.sat"
00027 #elif defined(HAVE_OCC)
00028 #define DEFAULT_TEST_FILE "sphere.stp"
00029 #endif
00030 
00031 const bool debug_EBMesher = false;
00032 
00033 int load_and_mesh(const char *input_filename,
00034                   const char *output_filename,
00035                   int whole_geom, int* n_intervals, int mesh_based_geom,
00036                   double box_increase, int vol_frac_res);
00037 
00038 int main(int argc, char **argv) 
00039 {
00040   // check command line arg
00041   std::string input_filename;
00042   const char *output_filename = NULL;
00043   int whole_geom = 1;
00044   int n_interval[3] = {10, 10, 10};
00045   int mesh_based_geom = 0;
00046   double box_increase = .03;
00047   int vol_frac_res = 0;
00048 
00049   if (argc > 2 && argc < 11) {
00050     input_filename += argv[1];
00051     if (argc > 2) whole_geom = atoi(argv[2]);
00052     if (argc > 3) n_interval[0] = atoi(argv[3]);
00053     if (argc > 4) n_interval[1] = atoi(argv[4]);
00054     if (argc > 5) n_interval[2] = atoi(argv[5]);
00055     if (argc > 6) mesh_based_geom = atoi(argv[6]);
00056     if (argc > 7) output_filename = argv[7];
00057     if (argc > 8) box_increase = atof(argv[8]);
00058     if (argc > 9) vol_frac_res = atoi(argv[9]);
00059   }
00060   else {
00061     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;
00062     std::cout << "<input_geom_filename> : input geometry file name" << std::endl;
00063     std::cout << "<whole_geom> : make mesh for whole geom or individually(1/0), default whole geom(1)" << std::endl;
00064     std::cout << "{x/y/z: # ofintervals} : optional argument. # of intervals. if it is not set, set to 10." << std::endl;
00065     std::cout << "<mesh_based_geom> : use mesh based geometry(1/0), default not-use(0)" << std::endl;
00066     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;
00067     std::cout << "{box size increase} : optional argument. Cartesian mesh box increase form geometry. default 0.03" << std::endl;
00068     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;
00069     std::cout << std::endl;
00070     if (argc != 1) return 1;
00071     std::cout << "No file specified.  Defaulting to: " << DEFAULT_TEST_FILE << std::endl;
00072     std::string file_name = std::string(MESH_DIR) + "/" + DEFAULT_TEST_FILE;
00073     input_filename += std::string(MESH_DIR);
00074     input_filename += "/";
00075     input_filename += DEFAULT_TEST_FILE;
00076   }
00077   
00078   if (load_and_mesh(input_filename.c_str(), output_filename,
00079                     whole_geom, n_interval, mesh_based_geom, box_increase, vol_frac_res)) return 1;
00080   
00081   return 0;
00082 }
00083 
00084 int load_and_mesh(const char *input_filename,
00085                   const char *output_filename,
00086                   int whole_geom, int* n_interval, int mesh_based_geom,
00087                   double box_increase, int vol_frac_res)
00088 {
00089   bool result;
00090   time_t start_time, load_time, mesh_time, vol_frac_time,
00091     export_time, query_time_techX, query_time;
00092 
00093   // start up MK and load the geometry
00094   MKCore mk;
00095   time(&start_time);
00096   mk.load_mesh(input_filename, NULL, 0, 0, 0, true);
00097   time(&load_time);
00098 
00099   if (debug_EBMesher) {
00100     mk.save_mesh("input.vtk");
00101   }
00102 
00103   // get the volumes
00104   MEntVector vols;
00105   mk.get_entities_by_dimension(3, vols);
00106 
00107   // make EBMesher
00108   EBMesher *ebm = (EBMesher*) mk.construct_meshop("EBMesher", vols);
00109   ebm->use_whole_geom(whole_geom);
00110   ebm->use_mesh_geometry(mesh_based_geom);
00111   ebm->set_num_interval(n_interval);
00112   ebm->increase_box(box_increase);
00113   if (mesh_based_geom) ebm->set_obb_tree_box_dimension();
00114 
00115   // mesh embedded boundary mesh, by calling execute
00116   mk.setup_and_execute();
00117   time(&mesh_time);
00118 
00119   // caculate volume fraction, only for geometry input
00120   if (vol_frac_res > 0) {
00121     result = ebm->get_volume_fraction(vol_frac_res);
00122     if (!result) {
00123       std::cerr << "Couldn't get volume fraction." << std::endl;
00124       return 1;
00125     }
00126   }
00127   time(&vol_frac_time);
00128 
00129   // export mesh
00130   if (output_filename != NULL) {
00131     ebm->export_mesh(output_filename);
00132   }
00133   time(&export_time);
00134 
00135   if (whole_geom && debug_EBMesher) {
00136     // techX query function test
00137     double boxMin[3], boxMax[3];
00138     int nDiv[3];
00139     std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan > mdCutCellSurfEdge;
00140     std::vector<int> vnInsideCellTechX;
00141     
00142     ebm->get_grid_and_edges_techX(boxMin, boxMax, nDiv,
00143                                   mdCutCellSurfEdge, vnInsideCellTechX);
00144     time(&query_time_techX);
00145     
00146     // multiple intersection EBMesh_cpp_fraction query test
00147     std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan > mdCutCellEdge;
00148     std::vector<int> vnInsideCell;
00149     result = ebm->get_grid_and_edges(boxMin, boxMax, nDiv,
00150                                      mdCutCellEdge, vnInsideCell);
00151     if (!result) {
00152       std::cerr << "Couldn't get mesh information." << std::endl;
00153       return 1;
00154     }
00155     time(&query_time);
00156     std::cout << "# of TechX cut-cell surfaces: " << mdCutCellSurfEdge.size() 
00157               << ", # of nInsideCell: " << vnInsideCell.size()/3 << std::endl;
00158   }
00159 
00160   std::cout << "EBMesh is succesfully finished." << std::endl;
00161   std::cout << "Time including loading: "
00162             << difftime(mesh_time, start_time)
00163             << " secs, Time excluding loading: "
00164             << difftime(mesh_time, load_time)
00165             << " secs, Time volume fraction: "
00166             << difftime(vol_frac_time, mesh_time) << " secs";
00167 
00168   if (output_filename != NULL) {
00169     std::cout << ", Time export mesh: "
00170               << difftime(export_time, vol_frac_time) << " secs";
00171   }
00172 
00173   if (whole_geom && debug_EBMesher) {
00174     std::cout << ", TechX query time: "
00175               << difftime(query_time_techX, export_time)
00176               << " secs, multiple intersection EBMesh_cpp_fraction query (elems, edge-cut fractions): "
00177               << difftime(query_time, query_time_techX) << " secs.";
00178   }
00179 
00180   std::cout << std::endl;
00181   mk.clear_graph();
00182 
00183   return 0;
00184 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines