MeshKit  1.0
test_copymesh.cpp
Go to the documentation of this file.
00001 
00007 #include "meshkit/MKCore.hpp"
00008 #include "meshkit/MeshOp.hpp"
00009 #include "meshkit/CopyMesh.hpp"
00010 #include "meshkit/ModelEnt.hpp"
00011 #include "meshkit/MergeMesh.hpp"
00012 
00013 using namespace MeshKit;
00014 
00015 #include "TestUtil.hpp"
00016 #define DEFAULT_TEST_FILE1 "c.h5m"
00017 #define DEFAULT_TEST_FILE2 "d.h5m"
00018 
00019 MKCore *mk;
00020 
00021 void test_copy_quad();
00022 void test_load_and_copymove();
00023 void test_set_imesh();
00024 
00025 int main(int argc, char **argv)
00026 {
00027     mk = new MKCore();
00028     int num_fail = 0;
00029     num_fail += RUN_TEST(test_set_imesh);
00030     num_fail += RUN_TEST(test_load_and_copymove);
00031     num_fail += RUN_TEST(test_copy_quad);
00032 
00033     delete mk;
00034     return num_fail;
00035 }
00036 
00037 void test_set_imesh()
00038 {
00039     std::vector <CopyMesh*> cm;
00040     iMesh *imesh = mk->imesh_instance();
00041     int err =0;
00042     std::vector<std::string> files;
00043     std::string name1 = TestDir + "/" + DEFAULT_TEST_FILE1;
00044     std::string name2 = TestDir + "/" + DEFAULT_TEST_FILE2;
00045 
00046     files.push_back(name1);
00047     files.push_back(name2);
00048     cm.resize(files.size());
00049     iBase_EntitySetHandle orig_set;
00050 
00051     for (unsigned int i = 0; i < files.size(); i++) {
00052         iMesh_createEntSet(imesh->instance(), 0, &orig_set, &err);
00053         //ERRORR("Couldn't create file set.", err);
00054         std::cout << "Loading File: " << files[i].c_str() << std::endl;
00055         iMesh_load(imesh->instance(), orig_set, files[i].c_str(), NULL, &err, strlen(files[i].c_str()), 0);
00056 
00057         ModelEnt *me;
00058         me = NULL;
00059         me = new ModelEnt(mk, iBase_EntitySetHandle(0), /*igeom instance*/0, (moab::EntityHandle)orig_set, 0);
00060         MEntVector assm_set;
00061         //assm_set.clear();
00062         assm_set.push_back(me);
00063         cm[i] = (CopyMesh*) mk->construct_meshop("CopyMesh", assm_set);
00064         cm[i]->set_name("copy_move_mesh");
00065         cm[i]->copy_sets().add_set(orig_set);
00066         // some entity tag types are always copy or expand
00067         cm[i]->expand_sets().add_tag("MATERIAL_SET");
00068         cm[i]->expand_sets().add_tag("DIRICHLET_SET");
00069         cm[i]->expand_sets().add_tag("NEUMANN_SET");
00070         cm[i]->copy_sets().add_tag("GEOM_DIMENSION");
00071 
00072         Vector<3> dx; dx[0] = 10; dx[1] = 0; dx[2] = 0;
00073         cm[i]->set_transform(Copy::Translate(dx));
00074     }
00075     // copy and merge
00076     mk->setup_and_execute();
00077      for (unsigned int i = 0; i < files.size(); i++)
00078          delete cm[i];
00079 }
00080 
00081 
00082 void test_load_and_copymove()
00083 {
00084     //clear_mesh(mk);
00085     mk->delete_all();
00086     std::string filename = TestDir + "/" + DEFAULT_TEST_FILE1;
00087     mk->load_mesh(filename.c_str());
00088 
00089     // get the hexes
00090     MEntVector vols, v1;
00091     //mk->get_entities_by_dimension(3, vols);
00092     moab::EntityHandle root_set = mk->moab_instance()->get_root_set();
00093     ModelEnt me(mk, iBase_EntitySetHandle(0), /*igeom instance*/0, root_set);
00094     vols.push_back(&me);
00095 
00096     CopyMesh *cm = (CopyMesh*) mk->construct_meshop("CopyMesh", vols);
00097     cm->set_name("copy_move_mesh");
00098     // some entity tag types are always copy or expand
00099     cm->expand_sets().add_tag("MATERIAL_SET");
00100     cm->expand_sets().add_tag("DIRICHLET_SET");
00101     cm->expand_sets().add_tag("NEUMANN_SET");
00102 
00103     Vector<3> dx; dx[0] = 10; dx[1] = 0; dx[2] = 0;
00104     cm->set_transform(Copy::Translate(dx));
00105 
00106     //accesses entities for merging directly from moab instance, vols are used for finding the dimension
00107     MergeMesh *mm = (MergeMesh*) mk->construct_meshop("MergeMesh", v1);
00108     mm->set_name("merge_mesh");
00109 
00110     double merge_tol = 1e-3; int updatesets = 0, domerge = 1; iBase_TagHandle merge_tag = NULL;
00111     mm->set_merge_params(merge_tol, updatesets, domerge, merge_tag);
00112 
00113     // put them in the graph
00114     mk->get_graph().addArc(mk->root_node()->get_node(), cm->get_node());
00115     mk->get_graph().addArc(cm->get_node(), mm->get_node());
00116     mk->get_graph().addArc(mm->get_node(), mk->leaf_node()->get_node());
00117 
00118     // copy and merge
00119     mk->setup_and_execute();
00120     delete cm;
00121 }
00122 
00123 
00124 void test_copy_quad()
00125 {
00126     mk->delete_all();
00127     iMesh *mesh = mk->imesh_instance();
00128 
00129     double coords[] = {
00130         0, 0, 0,
00131         1, 0, 0,
00132         1, 1, 0,
00133         0, 1, 0,
00134     };
00135 
00136     iMesh::EntityHandle verts[4];
00137     iMesh::EntityHandle quad;
00138     iMesh::EntitySetHandle set;
00139 
00140     mesh->createVtxArr(4, iBase_INTERLEAVED, coords, verts);
00141     mesh->createEnt(iMesh_QUADRILATERAL, verts, 4, quad);
00142     mesh->createEntSet(true, set);
00143     mesh->addEntToSet(quad, set);
00144 
00145     ModelEnt me(mk, iBase_EntitySetHandle(0), /*igeom instance*/0, (moab::EntityHandle)set);
00146     MEntVector selection;
00147     selection.push_back(&me);
00148 
00149     CopyMesh *cm = (CopyMesh*) mk->construct_meshop("CopyMesh", selection);
00150     cm->set_name("copy_move_mesh");
00151 
00152     Vector<3> dx; dx[0] = 0; dx[1] = 0; dx[2] = 10;
00153     cm->set_transform(Copy::Translate(dx));
00154 
00155     // put them in the graph
00156     mk->get_graph().addArc(mk->root_node()->get_node(), cm->get_node());
00157     mk->get_graph().addArc(cm->get_node(), mk->leaf_node()->get_node());
00158 
00159     cm->copy_sets().add_set(set);
00160     cm->flag_process_ce_set = true;
00161     // mesh embedded boundary mesh, by calling execute
00162     mk->setup_and_execute();
00163 
00164     std::vector<iMesh::EntityHandle> new_verts;
00165     double new_coords[4*3];
00166     std::vector<iMesh::EntityHandle> new_quad;
00167     iMesh::EntitySetHandle new_set;
00168 
00169     mesh->getEntSetEHData(set, cm->copy_tag(), (iMesh::EntityHandle&)new_set);
00170 
00171     mesh->getEntities(new_set, iBase_ALL_TYPES, iMesh_ALL_TOPOLOGIES, new_quad);
00172     CHECK_EQUAL(new_quad.size(), size_t(1));
00173 
00174     mesh->getEntAdj(new_quad[0], iBase_ALL_TYPES, new_verts);
00175     CHECK_EQUAL(new_verts.size(), size_t(4));
00176 
00177     mesh->getVtxArrCoords(&new_verts[0], new_verts.size(), iBase_INTERLEAVED,
00178             new_coords);
00179 
00180     for(int i=0; i<4; i++) {
00181         CHECK_REAL_EQUAL(coords[i*3+0],    new_coords[i*3+0], 0.00001);
00182         CHECK_REAL_EQUAL(coords[i*3+1],    new_coords[i*3+1], 0.00001);
00183         CHECK_REAL_EQUAL(coords[i*3+2]+10, new_coords[i*3+2], 0.00001);
00184     }
00185     delete cm;
00186 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines