00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <iostream>
00014 #include <fstream>
00015 #include <sstream>
00016 #include <unistd.h>
00017 #include <tut.h>
00018 #include "myrlog.h"
00019 #include "point.h"
00020 #include "tet.h"
00021 #include "looseoctree.h"
00022 #include "tetmeshbuilder.h"
00023 #include "broadcastmeshbuilder.h"
00024 #include "netgenreader.h"
00025
00026 namespace tut {
00027 Epetra_Comm& get_comm_world();
00028 }
00029
00030 namespace
00031 {
00032 using namespace mesh;
00033
00034 struct test_data
00035 {
00036 test_data()
00037 {
00038 }
00039 static mesh::TetMesh* tmesh;
00040 };
00041
00042 mesh::TetMesh* test_data::tmesh = 0;
00043
00044 typedef tut::test_group<test_data> testgroup;
00045 typedef testgroup::object testobject;
00046 testgroup group("octree");
00047
00048 template<>
00049 template<>
00050 void testobject::test<1>()
00051 {
00052
00053 std::string mesh_file_name = "test/octree/cop40k.ng";
00054 rAssert(!access(mesh_file_name.c_str(), R_OK));
00055
00056 std::ifstream istr(mesh_file_name.c_str());
00057
00058 Epetra_Comm& comm(tut::get_comm_world());
00059 TetMeshBuilder* builder = new TetMeshBuilder();
00060 #ifdef HAVE_MPI
00061 BroadcastMeshBuilder* broadcast = new BroadcastMeshBuilder(&comm, builder);
00062 NetgenReader* reader(0);
00063 if (comm.MyPID() == 0) {
00064 reader = new NetgenReader(&istr, broadcast);
00065 reader->read();
00066 } else
00067 broadcast->receiver();
00068 delete broadcast;
00069 if (comm.MyPID() == 0)
00070 delete reader;
00071 #else
00072 NetgenReader* reader = new NetgenReader(&istr, builder);
00073 reader->read();
00074 delete reader;
00075 #endif
00076 tmesh = builder->get_mesh();
00077 delete builder;
00078 tmesh->log_mesh_info();
00079
00080
00081 tmesh->construct_octree();
00082 }
00083
00084 template<>
00085 template<>
00086 void testobject::test<10>()
00087 {
00088
00089 for (mesh::TetMesh::point_iterator it = tmesh->point_begin(); it != tmesh->point_end(); ++ it) {
00090 mesh::Vector3 p = (*it).get_coord();
00091 bool inside = tmesh->is_inside(p);
00092 if (!inside)
00093 rError("point %d outside.", (*it).get_id());
00094 ensure(inside);
00095 }
00096 }
00097
00098 template<>
00099 template<>
00100 void testobject::test<11>()
00101 {
00102 LooseOctree<Tet>* octree = tmesh->get_octree();
00103
00104
00105 vector<int> conn_tet(tmesh->get_nof_points());
00106 std::fill(conn_tet.begin(), conn_tet.end(), 0);
00107 for (TetMesh::tet_iterator it = tmesh->tet_begin(); it != tmesh->tet_end(); ++ it) {
00108 for (int i=0; i < 4; ++ i)
00109 conn_tet[(*it).get_corner_id(i)] ++;
00110 }
00111
00112 for (TetMesh::point_iterator it = tmesh->point_begin(); it != tmesh->point_end(); ++ it) {
00113 Vector3 p = (*it).get_coord();
00114
00115
00116 std::vector<Tet *> nodes;
00117 int nof_visited = 0;
00118 octree->find_nodes_by_point(p, nodes, nof_visited, &Tet::is_inside_bounding_box_gracious);
00119
00120
00121
00122 std::vector<Tet*> tets;
00123 for (std::vector<Tet *>::iterator it2 = nodes.begin(); it2 != nodes.end(); ++ it2) {
00124 Tet *tet = dynamic_cast<Tet*>(*it2);
00125 if (tet->is_inside_gracious(p))
00126 tets.push_back(tet);
00127 }
00128
00129 int nof_found = static_cast<int>(tets.size());
00130 if (nof_found != conn_tet[(*it).get_id()])
00131 rError("point %d: found %d tets, expected %d.",
00132 (*it).get_id(),
00133 nof_found,
00134 conn_tet[(*it).get_id()]);
00135 ensure(nof_found == conn_tet[(*it).get_id()]);
00136 }
00137 }
00138
00139 template<>
00140 template<>
00141 void testobject::test<20>()
00142 {
00143 for (TetMesh::tet_iterator it = tmesh->tet_begin(); it != tmesh->tet_end(); ++ it) {
00144 Tet* tet(&*it);
00145 for (int i=0; i < 4; ++ i)
00146 ensure(tet->is_inside(tet->get_corner(i)->get_coord()));
00147 }
00148 }
00149
00150 template<>
00151 template<>
00152 void testobject::test<21>()
00153 {
00154 for (TetMesh::tet_iterator it = tmesh->tet_begin(); it != tmesh->tet_end(); ++ it) {
00155 Tet* tet(&*it);
00156 for (int i=0; i < 4; ++ i)
00157 ensure(tet->is_inside_gracious(tet->get_corner(i)->get_coord()));
00158 }
00159 }
00160
00161 template<>
00162 template<>
00163 void testobject::test<22>()
00164 {
00165 for (TetMesh::tet_iterator it = tmesh->tet_begin(); it != tmesh->tet_end(); ++ it) {
00166 Tet* tet(&*it);
00167 for (int i=0; i < 4; ++ i)
00168 ensure(tet->is_inside_bounding_box(tet->get_corner(i)->get_coord()));
00169 }
00170 }
00171
00172 template<>
00173 template<>
00174 void testobject::test<23>()
00175 {
00176 for (TetMesh::tet_iterator it = tmesh->tet_begin(); it != tmesh->tet_end(); ++ it) {
00177 Tet* tet(&*it);
00178 for (int i=0; i < 4; ++ i)
00179 ensure(tet->is_inside_bounding_box_gracious(tet->get_corner(i)->get_coord()));
00180 }
00181 }
00182
00183 template<>
00184 template<>
00185 void testobject::test<50>()
00186 {
00187
00188 delete tmesh;
00189 }
00190
00191 }