MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 /* ***************************************************************** 00002 MESQUITE -- The Mesh Quality Improvement Toolkit 00003 00004 Copyright 2010 Sandia National Laboratories. Developed at the 00005 University of Wisconsin--Madison under SNL contract number 00006 624796. The U.S. Government and the University of Wisconsin 00007 retain certain rights to this software. 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 (lgpl.txt) along with this library; if not, write to the Free Software 00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 00023 (2010) [email protected] 00024 00025 ***************************************************************** */ 00026 00027 /** \file ConicDomainTest.cpp 00028 * \brief Unit tests for ConicDomain class 00029 * \author Jason Kraftcheck 00030 */ 00031 00032 #include "Mesquite.hpp" 00033 #include "UnitUtil.hpp" 00034 #include "ConicDomain.hpp" 00035 00036 using namespace MBMesquite; 00037 00038 class ConicDomainTest : public CppUnit::TestFixture 00039 { 00040 CPPUNIT_TEST_SUITE( ConicDomainTest ); 00041 CPPUNIT_TEST( test_construct ); 00042 CPPUNIT_TEST( test_snap_to ); 00043 CPPUNIT_TEST( test_normal_at ); 00044 CPPUNIT_TEST( test_closest_point ); 00045 CPPUNIT_TEST( test_domain_DoF ); 00046 CPPUNIT_TEST_SUITE_END(); 00047 00048 public: 00049 void test_construct(); 00050 void test_snap_to(); 00051 void test_normal_at(); 00052 void test_closest_point(); 00053 void test_domain_DoF(); 00054 }; 00055 00056 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ConicDomainTest, "ConicDomainTest" ); 00057 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ConicDomainTest, "Unit" ); 00058 00059 void ConicDomainTest::test_construct() 00060 { 00061 double rad = 1.5; 00062 double hei = 20.1; 00063 Vector3D axis( 1, 2, 3 ); 00064 Vector3D point( -1, -1, 1 ); 00065 ConicDomain dom( rad, hei, axis, point ); 00066 00067 axis /= axis.length(); 00068 CPPUNIT_ASSERT_VECTORS_EQUAL( axis, dom.axis(), 1e-6 ); 00069 CPPUNIT_ASSERT_VECTORS_EQUAL( point, dom.point(), 1e-18 ); 00070 CPPUNIT_ASSERT_DOUBLES_EQUAL( rad, dom.point_radius(), 1e-18 ); 00071 CPPUNIT_ASSERT_DOUBLES_EQUAL( hei, dom.height_from_point(), 1e-18 ); 00072 } 00073 00074 void ConicDomainTest::test_snap_to() 00075 { 00076 const double a = 3.0, b = 4.0; 00077 const double f = a * b / ( a * a + b * b ); 00078 ConicDomain cone( a, b ); 00079 00080 // test some points 00081 Vector3D pt( b, 0, a ); 00082 Vector3D close( pt ); 00083 cone.snap_to( 0, close ); 00084 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00085 00086 pt = Vector3D( 0, b, a ); 00087 close = pt; 00088 cone.snap_to( 0, close ); 00089 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00090 00091 pt = Vector3D( 0, -b, a ); 00092 close = pt; 00093 cone.snap_to( 0, close ); 00094 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00095 00096 pt = Vector3D( -b, 0, a ); 00097 close = pt; 00098 cone.snap_to( 0, close ); 00099 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00100 00101 // test point at apex 00102 pt = cone.point() + cone.height_from_point() * cone.axis(); 00103 close = pt; 00104 cone.snap_to( 0, close ); 00105 CPPUNIT_ASSERT_VECTORS_EQUAL( pt, close, 1e-6 ); 00106 } 00107 00108 void ConicDomainTest::test_normal_at() 00109 { 00110 const double a = 3.0, b = 4.0; 00111 ConicDomain cone( a, b ); 00112 00113 Vector3D pt( b, 0, a ); 00114 Vector3D norm( pt ); 00115 cone.vertex_normal_at( 0, norm ); 00116 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00117 norm = pt; 00118 cone.element_normal_at( 0, norm ); 00119 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00120 00121 pt = Vector3D( 0, b, a ); 00122 norm = pt; 00123 cone.vertex_normal_at( 0, norm ); 00124 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00125 norm = pt; 00126 cone.element_normal_at( 0, norm ); 00127 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00128 00129 pt = Vector3D( 0, -b, a ); 00130 norm = pt; 00131 cone.vertex_normal_at( 0, norm ); 00132 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00133 norm = pt; 00134 cone.element_normal_at( 0, norm ); 00135 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00136 00137 pt = Vector3D( -b, 0, a ); 00138 norm = pt; 00139 cone.vertex_normal_at( 0, norm ); 00140 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00141 norm = pt; 00142 cone.element_normal_at( 0, norm ); 00143 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00144 } 00145 00146 void ConicDomainTest::test_closest_point() 00147 { 00148 const double a = 3.0, b = 4.0; 00149 const double f = a * b / ( a * a + b * b ); 00150 ConicDomain cone( a, b ); 00151 MsqError err; 00152 00153 Vector3D pt( b, 0, a ), close, norm; 00154 cone.closest_point( 0, pt, close, norm, err ); 00155 ASSERT_NO_ERROR( err ); 00156 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00157 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00158 00159 pt = Vector3D( 0, b, a ); 00160 cone.closest_point( 0, pt, close, norm, err ); 00161 ASSERT_NO_ERROR( err ); 00162 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00163 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00164 00165 pt = Vector3D( 0, -b, a ); 00166 cone.closest_point( 0, pt, close, norm, err ); 00167 ASSERT_NO_ERROR( err ); 00168 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00169 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00170 00171 pt = Vector3D( -b, 0, a ); 00172 cone.closest_point( 0, pt, close, norm, err ); 00173 ASSERT_NO_ERROR( err ); 00174 CPPUNIT_ASSERT_VECTORS_EQUAL( pt * f, close, 1e-6 ); 00175 CPPUNIT_ASSERT_VECTORS_EQUAL( pt / pt.length(), norm, 1e-6 ); 00176 } 00177 00178 void ConicDomainTest::test_domain_DoF() 00179 { 00180 std::vector< Mesh::VertexHandle > junk( 10 ); 00181 std::vector< unsigned short > dof( junk.size() ); 00182 std::vector< unsigned short > expected( dof.size(), 2 ); 00183 ConicDomain dom; 00184 MsqPrintError err( std::cout ); 00185 dom.domain_DoF( arrptr( junk ), arrptr( dof ), junk.size(), err ); 00186 ASSERT_NO_ERROR( err ); 00187 CPPUNIT_ASSERT( expected == dof ); 00188 }