MeshKit
1.0
|
00001 00007 #include "meshkit/MKCore.hpp" 00008 #include "meshkit/MeshOp.hpp" 00009 #include "meshkit/ExtrudeMesh.hpp" 00010 #include "meshkit/ModelEnt.hpp" 00011 00012 using namespace MeshKit; 00013 00014 #include "TestUtil.hpp" 00015 #define DEFAULT_TEST_FILE "rect_quads.cub" 00016 00017 MKCore *mk; 00018 00019 void test_load_and_extrude(); 00020 void test_extrude_quad(); 00021 void test_extrude_tri(); 00022 00023 void help_test_extrude_face(iMesh_EntityTopology topo, double *coords, 00024 size_t nverts); 00025 00026 int main(int argc, char **argv) 00027 { 00028 mk = new MKCore(); 00029 int num_fail = 0; 00030 00031 num_fail += RUN_TEST(test_load_and_extrude); 00032 num_fail += RUN_TEST(test_extrude_quad); 00033 num_fail += RUN_TEST(test_extrude_tri); 00034 00035 delete mk; 00036 return num_fail; 00037 } 00038 00039 void clear_mesh(MKCore *mk) 00040 { 00041 iMesh *mesh = mk->imesh_instance(); 00042 std::vector<iMesh::EntityHandle> ents; 00043 mesh->getEntities(mesh->getRootSet(), iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, 00044 ents); 00045 mesh->deleteEntArr(&ents[0], ents.size()); 00046 } 00047 00048 void test_load_and_extrude() 00049 { 00050 clear_mesh(mk); 00051 std::string filename = TestDir + "/" + DEFAULT_TEST_FILE; 00052 mk->load_mesh(filename.c_str()); 00053 00054 // populate mesh with no attached geometry or relations 00055 mk->populate_model_ents(-1, 0, -1); 00056 00057 // get the hexes 00058 MEntVector vols; 00059 mk->get_entities_by_dimension(2, vols); 00060 00061 ExtrudeMesh *em = (ExtrudeMesh*) mk->construct_meshop("ExtrudeMesh", vols); 00062 em->set_name("extrude_mesh"); 00063 00064 // some entity tag types are always copy or expand 00065 em->expand_sets().add_tag("MATERIAL_SET"); 00066 em->expand_sets().add_tag("DIRICHLET_SET"); 00067 em->copy_sets().add_tag("NEUMANN_SET"); 00068 em->copy_faces(true); 00069 00070 Vector<3> dx; dx[0] = 0; dx[1] = 0; dx[2] = 3; 00071 em->set_transform(Extrude::Translate(dx, 1)); 00072 00073 // put them in the graph 00074 mk->get_graph().addArc(mk->root_node()->get_node(), em->get_node()); 00075 mk->get_graph().addArc(em->get_node(), mk->leaf_node()->get_node()); 00076 00077 moab::Tag mattag; 00078 mk->moab_instance()->tag_get_handle( "MATERIAL_SET", 1, moab::MB_TYPE_INTEGER, mattag ); 00079 moab::Range matsets; 00080 std::vector <moab::EntityHandle> set_ents; 00081 mk->moab_instance()->get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &mattag, 0, 1, matsets ); 00082 00083 moab::Range::iterator set_it; 00084 for (set_it = matsets.begin(); set_it != matsets.end(); set_it++) { 00085 moab::EntityHandle this_set = *set_it; 00086 em->extrude_sets().add_set((iMesh::EntitySetHandle)this_set); 00087 } 00088 00089 // some entity tag types are always copy or expand 00090 em->extrude_sets().add_tag("MATERIAL_SET"); 00091 00092 // mesh embedded boundary mesh, by calling execute 00093 mk->setup_and_execute(); 00094 00095 // now delete all the 2D material sets: 00096 matsets.clear(); 00097 // doing this again, to get new material sets created by extrude 00098 mk->moab_instance()->get_entities_by_type_and_tag( 0, moab::MBENTITYSET, &mattag, 0, 1, matsets ); 00099 for (set_it = matsets.begin(); set_it != matsets.end(); set_it++) { 00100 moab::EntityHandle this_set = *set_it; 00101 // get material sets with two dimension and delete 00102 std::vector <moab::EntityHandle> set_ents; 00103 mk->moab_instance()->get_entities_by_dimension(this_set, 2, set_ents, true); 00104 if(set_ents.size() > 0) 00105 mk->moab_instance()->delete_entities(&this_set, 1); 00106 } 00107 delete em; 00108 } 00109 00110 00111 void help_test_extrude_face(iMesh_EntityTopology topo, double *coords, 00112 size_t nverts) 00113 { 00114 clear_mesh(mk); 00115 00116 iMesh *mesh = mk->imesh_instance(); 00117 00118 std::vector<iMesh::EntityHandle> verts(nverts); 00119 iMesh::EntityHandle face; 00120 iMesh::EntitySetHandle set; 00121 00122 mesh->createVtxArr(nverts, iBase_INTERLEAVED, coords, &verts[0]); 00123 mesh->createEnt(topo, &verts[0], nverts, face); 00124 mesh->createEntSet(true, set); 00125 mesh->addEntToSet(face, set); 00126 00127 ModelEnt me(mk, iBase_EntitySetHandle(0), /*igeom instance*/0, 00128 (moab::EntityHandle)set); 00129 MEntVector selection; 00130 selection.push_back(&me); 00131 00132 ExtrudeMesh *em = (ExtrudeMesh*) mk->construct_meshop("ExtrudeMesh", 00133 selection); 00134 em->set_name("extrude_mesh"); 00135 00136 Vector<3> dx; dx[0] = 0; dx[1] = 0; dx[2] = 10; 00137 em->set_transform(Extrude::Translate(dx, 10)); 00138 em->copy_faces(true); 00139 00140 // put them in the graph 00141 mk->get_graph().addArc(mk->root_node()->get_node(), em->get_node()); 00142 mk->get_graph().addArc(em->get_node(), mk->leaf_node()->get_node()); 00143 00144 em->copy_sets().add_set(set); 00145 em->extrude_sets().add_set(set); 00146 00147 // mesh embedded boundary mesh, by calling execute 00148 mk->setup_and_execute(); 00149 00150 std::vector<iMesh::EntityHandle> new_verts; 00151 std::vector<double> new_coords(nverts*3); 00152 std::vector<iMesh::EntityHandle> new_face; 00153 iMesh::EntitySetHandle copy_set; 00154 00155 mesh->getEntSetEHData(set, em->copy_tag(), (iMesh::EntityHandle&)copy_set); 00156 00157 mesh->getEntities(copy_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, new_face); 00158 CHECK_EQUAL(new_face.size(), size_t(1)); 00159 00160 mesh->getEntAdj(new_face[0], iBase_VERTEX, new_verts); 00161 CHECK_EQUAL(new_verts.size(), nverts); 00162 00163 mesh->getVtxArrCoords(&new_verts[0], new_verts.size(), iBase_INTERLEAVED, 00164 &new_coords[0]); 00165 00166 for(size_t i=0; i<nverts; i++) { 00167 CHECK_REAL_EQUAL(coords[i*3+0], new_coords[i*3+0], 0.00001); 00168 CHECK_REAL_EQUAL(coords[i*3+1], new_coords[i*3+1], 0.00001); 00169 CHECK_REAL_EQUAL(coords[i*3+2]+10, new_coords[i*3+2], 0.00001); 00170 } 00171 00172 iMesh::EntitySetHandle extrude_set; 00173 int n; 00174 mesh->getEntSetEHData(set, em->extrude_tag(), 00175 (iMesh::EntityHandle&)extrude_set); 00176 mesh->getNumOfType(extrude_set, iBase_ALL_TYPES, n); 00177 CHECK_EQUAL(n, 10); 00178 00179 delete em; 00180 } 00181 00182 void test_extrude_quad() 00183 { 00184 double coords[] = { 00185 0, 0, 0, 00186 1, 0, 0, 00187 1, 1, 0, 00188 0, 1, 0 00189 }; 00190 00191 help_test_extrude_face(iMesh_QUADRILATERAL, coords, 4); 00192 } 00193 00194 void test_extrude_tri() 00195 { 00196 double coords[] = { 00197 0, 0, 0, 00198 1, 0, 0, 00199 1, 1, 0 00200 }; 00201 00202 help_test_extrude_face(iMesh_TRIANGLE, coords, 3); 00203 }