MeshKit
1.0
|
00001 00007 #include "meshkit/MKCore.hpp" 00008 #include "meshkit/EdgeMesher.hpp" 00009 #include "meshkit/SizingFunction.hpp" 00010 #include "meshkit/SizingFunctionVar.hpp" 00011 #include "meshkit/ModelEnt.hpp" 00012 #include "meshkit/Matrix.hpp" 00013 #include "meshkit/VertexMesher.hpp" 00014 00015 using namespace MeshKit; 00016 00017 #include "TestUtil.hpp" 00018 00019 MKCore *mk = NULL; 00020 00021 void edgemesh_hole(); 00022 void edgemesh_square(); 00023 void edgemesh_brick(); 00024 void edgemesh_var(); 00025 void edgemesh_dual(); 00026 00027 #ifdef HAVE_ACIS 00028 std::string extension = ".sat"; 00029 #elif HAVE_OCC 00030 std::string extension = ".stp"; 00031 #else 00032 std::string extension = ".facet"; 00033 #define HAVE_FACET 00034 #endif 00035 00036 int main(int argc, char **argv) 00037 { 00038 00039 // start up MK and load the geometry 00040 mk = new MKCore(); 00041 00042 int num_fail = 0; 00043 num_fail += RUN_TEST(edgemesh_brick); 00044 num_fail += RUN_TEST(edgemesh_square); 00045 num_fail += RUN_TEST(edgemesh_var); 00046 #ifndef HAVE_FACET 00047 num_fail += RUN_TEST(edgemesh_hole); 00048 num_fail += RUN_TEST(edgemesh_dual); 00049 #endif 00050 #if HAVE_OCC 00051 return 0; 00052 #else 00053 return num_fail; 00054 #endif 00055 } 00056 00057 void edgemesh_hole() 00058 { 00059 std::string file_name = TestDir + "/holysurf" + extension; 00060 mk->load_geometry(file_name.c_str()); 00061 00062 // get the surface 00063 MEntVector surfs, curves, loops; 00064 mk->get_entities_by_dimension(2, surfs); 00065 CHECK_EQUAL(1, (int)surfs.size()); 00066 00067 // test getting loops 00068 std::vector<int> senses, loop_sizes; 00069 surfs[0]->boundary(0, loops, &senses, &loop_sizes); 00070 CHECK_EQUAL(4, (int)loop_sizes.size()); 00071 00072 // add up the loop sizes, should add to 8 00073 unsigned int l = 0; 00074 for (unsigned int i = 0; i < loop_sizes.size(); i++) l += loop_sizes[i]; 00075 CHECK_EQUAL(8, (int)l); 00076 00077 // make an edge mesher 00078 mk->get_entities_by_dimension(1, curves); 00079 EdgeMesher *em = (EdgeMesher*) mk->construct_meshop("EdgeMesher", curves); 00080 00081 // make a sizing function and set it on the surface 00082 SizingFunction esize(mk, -1, 0.25); 00083 surfs[0]->sizing_function_index(esize.core_index()); 00084 00085 // mesh the edges, by calling execute 00086 mk->setup_and_execute(); 00087 00088 // make sure we got the right number of edges 00089 moab::Range edges; 00090 moab::ErrorCode rval = mk->moab_instance()->get_entities_by_dimension(0, 1, edges); 00091 CHECK_EQUAL(moab::MB_SUCCESS, rval); 00092 CHECK_EQUAL(79, (int)edges.size()); 00093 00094 // clean up 00095 delete em; 00096 delete mk->vertex_mesher(); 00097 } 00098 00099 void edgemesh_square() 00100 { 00101 std::string file_name = TestDir + "/squaresurf" + extension; 00102 mk->load_geometry(file_name.c_str()); 00103 00104 // get the surface 00105 MEntVector surfs, curves, loops; 00106 mk->get_entities_by_dimension(2, surfs); 00107 ModelEnt *this_surf = (*surfs.rbegin()); 00108 00109 // test getting loops 00110 std::vector<int> senses, loop_sizes; 00111 this_surf->boundary(0, loops, &senses, &loop_sizes); 00112 CHECK_EQUAL(1, (int)loop_sizes.size()); 00113 00114 // make an edge mesher 00115 this_surf->get_adjacencies(1, curves); 00116 mk->construct_meshop("EdgeMesher", curves); 00117 00118 // make a sizing function and set it on the surface 00119 SizingFunction esize(mk, 1, 1.0); 00120 this_surf->sizing_function_index(esize.core_index()); 00121 00122 // mesh the edges, by calling execute 00123 mk->setup_and_execute(); 00124 00125 senses.clear(); 00126 loop_sizes.clear(); 00127 std::vector<moab::EntityHandle> mloops; 00128 this_surf->boundary(0, mloops, &senses, &loop_sizes); 00129 CHECK_EQUAL(4, (int)mloops.size()); 00130 00131 // print the vertex positions 00132 std::vector<double> coords(12); 00133 moab::ErrorCode rval = mk->moab_instance()->get_coords(&mloops[0], mloops.size(), &coords[0]); 00134 MBERRCHK(rval, mk->moab_instance()); 00135 // std::cout << "Vertex positions:" << std::endl; 00136 // for (unsigned int i = 0; i < 4; i++) 00137 // std::cout << coords[3*i] << ", " << coords[3*i+1] << ", " << coords[3*i+2] << std::endl; 00138 00139 // compute the cross product vector and print that 00140 double tmp[] = {0.0, 0.0, 1.0}; 00141 Vector<3> p0(&coords[0]), p1(&coords[3]), p2(&coords[6]), unitz(tmp); 00142 p0 -= p1; 00143 p2 -= p1; 00144 p1 = vector_product(p2, p0); 00145 double dot = inner_product(unitz, p1); 00146 CHECK_REAL_EQUAL(1.0, dot, 1.0e-6); 00147 00148 mk->clear_graph(); 00149 } 00150 00151 void edgemesh_brick() 00152 { 00153 std::string file_name = TestDir + "/brick" + extension; 00154 mk->load_geometry(file_name.c_str()); 00155 00156 // get the vol, surfs, curves 00157 MEntVector vols, surfs, curves, loops; 00158 mk->get_entities_by_dimension(3, vols); 00159 ModelEnt *this_vol = (*vols.rbegin()); 00160 this_vol->get_adjacencies(2, surfs); 00161 this_vol->get_adjacencies(1, curves); 00162 00163 // mesh all the edges 00164 mk->construct_meshop("EdgeMesher", curves); 00165 SizingFunction esize(mk, 1, 1.0); 00166 this_vol->sizing_function_index(esize.core_index()); 00167 mk->setup_and_execute(); 00168 00169 // test loop directionality for each surface 00170 for (MEntVector::iterator vit = surfs.begin(); vit != surfs.end(); vit++) { 00171 00172 std::vector<int> senses, loop_sizes; 00173 std::vector<moab::EntityHandle> mloops; 00174 (*vit)->boundary(0, mloops, &senses, &loop_sizes); 00175 CHECK_EQUAL(4, (int)mloops.size()); 00176 00177 // get the vertex positions 00178 std::vector<double> coords(12); 00179 moab::ErrorCode rval = mk->moab_instance()->get_coords(&mloops[0], mloops.size(), &coords[0]); 00180 MBERRCHK(rval, mk->moab_instance()); 00181 00182 00183 // compute the cross product vector and compare it to the surface normal 00184 Vector<3> p0(&coords[0]), p1(&coords[3]), p2(&coords[6]), p3; 00185 p0 -= p1; 00186 p2 -= p1; 00187 p1 = vector_product(p2, p0); 00188 (*vit)->evaluate(coords[0], coords[1], coords[2], NULL, p3.data()); 00189 double dot = inner_product(p3, p1); 00190 CHECK_REAL_EQUAL(1.0, dot, 1.0e-6); 00191 00192 } 00193 00194 mk->clear_graph(); 00195 #ifdef HAVE_FACET 00196 mk->save_mesh("brickedges.h5m"); 00197 #endif 00198 } 00199 void edgemesh_var() 00200 { 00201 // delete existing mesh 00202 mk->moab_instance()->delete_mesh(); 00203 00204 std::string file_name = TestDir + "/squaresurf" + extension; 00205 mk->load_geometry(file_name.c_str()); 00206 00207 // get the surface 00208 MEntVector surfs, curves, loops; 00209 mk->get_entities_by_dimension(2, surfs); 00210 ModelEnt *this_surf = (*surfs.rbegin()); 00211 00212 // test getting loops 00213 std::vector<int> senses, loop_sizes; 00214 this_surf->boundary(0, loops, &senses, &loop_sizes); 00215 CHECK_EQUAL(1, (int)loop_sizes.size()); 00216 00217 // make an edge mesher 00218 this_surf->get_adjacencies(1, curves); 00219 EdgeMesher * emesher = (EdgeMesher *)mk->construct_meshop("EdgeMesher", curves); 00220 00221 emesher->set_edge_scheme(EdgeMesher::VARIABLE); 00222 00223 // make a sizing function and set it on the surface 00224 SizingFunctionVar * svar = new SizingFunctionVar(mk, -1, 0.1); 00225 00226 // these could be read from a file, or something 00227 double point0[3] = {0, 0, 0}; 00228 double coeffs[4] = {0.05, 0.05, 0.05, 0.1}; 00229 svar->set_linear_coeff(point0, coeffs); 00230 00231 this_surf->sizing_function_index(svar->core_index()); 00232 00233 mk->setup_and_execute(); 00234 00235 //mk->moab_instance()->write_file("var1.vtk"); 00236 mk->clear_graph(); 00237 00238 } 00239 void edgemesh_dual() 00240 { 00241 // delete existing mesh 00242 mk->moab_instance()->delete_mesh(); 00243 00244 std::string file_name = TestDir + "/squaresurf" + extension; 00245 mk->load_geometry(file_name.c_str()); 00246 00247 // get the surface 00248 MEntVector surfs, curves, loops; 00249 mk->get_entities_by_dimension(2, surfs); 00250 ModelEnt *this_surf = (*surfs.rbegin()); 00251 00252 // test getting loops 00253 std::vector<int> senses, loop_sizes; 00254 this_surf->boundary(0, loops, &senses, &loop_sizes); 00255 CHECK_EQUAL(1, (int)loop_sizes.size()); 00256 00257 // make an edge mesher 00258 this_surf->get_adjacencies(1, curves); 00259 EdgeMesher * emesher = (EdgeMesher *)mk->construct_meshop("EdgeMesher", curves); 00260 00261 emesher->set_edge_scheme(EdgeMesher::DUAL); 00262 00263 // make a sizing function and set it on the surface 00264 SizingFunction * svar = new SizingFunction(mk, 10, -1); 00265 00266 emesher->set_ratio(1.3); 00267 00268 this_surf->sizing_function_index(svar->core_index()); 00269 00270 mk->setup_and_execute(); 00271 00272 //mk->moab_instance()->write_file("dual1.1.vtk"); 00273 mk->clear_graph(); 00274 00275 }