BOOST_AUTO_TEST_CASE_TEMPLATE(from_euler, T, float_types) { vmath::core::Quaternion<T> H_param3(vmath::radians(static_cast<T>(90.0)), static_cast<T>(0.0), static_cast<T>(0.0)); BOOST_CHECK_CLOSE(H_param3.x, static_cast<T>(0.707106769), 1e-4f); BOOST_CHECK_SMALL(H_param3.y, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(H_param3.z, static_cast<T>(1e-7)); BOOST_CHECK_CLOSE(H_param3.w, static_cast<T>(0.707106769), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(create, T, float_types) { // default constructor vmath::core::Matrix<T, 2> M_default; BOOST_CHECK_SMALL(M_default[0][0], static_cast<T>(1e-7)); BOOST_CHECK_SMALL(M_default[0][1], static_cast<T>(1e-7)); BOOST_CHECK_SMALL(M_default[1][0], static_cast<T>(1e-7)); BOOST_CHECK_SMALL(M_default[1][1], static_cast<T>(1e-7)); // paremeterized constructor std::array<vmath::core::Vector<T, 2>, 2> data = {{ vmath::core::Vector<T, 2>(static_cast<T>(1.0), static_cast<T>(2.0)), vmath::core::Vector<T, 2>(static_cast<T>(3.0), static_cast<T>(4.0)) }}; vmath::core::Matrix<T, 2> M_param(data); BOOST_CHECK_CLOSE(M_param[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_param[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_param[1][0], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_param[1][1], static_cast<T>(4.0), 1e-4f); // parameterized constructor vmath::core::Vector<T, 2> col1(static_cast<T>(1.0), static_cast<T>(2.0)); vmath::core::Vector<T, 2> col2(static_cast<T>(3.0), static_cast<T>(4.0)); vmath::core::Matrix<T, 2> M_param2(col1, col2); BOOST_CHECK_CLOSE(M_param2[0][0], static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(M_param2[0][1], static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(M_param2[1][0], static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(M_param2[1][1], static_cast<T>(4.0), 1e-4f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(create, T, float_types) { // default constructor vmath::core::Vector<T, 4> V_default; BOOST_CHECK_SMALL(V_default.x, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(V_default.y, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(V_default.z, static_cast<T>(1e-7)); // parameterized constructor vmath::core::Vector<T, 4> V_param(static_cast<T>(1.0), static_cast<T>(2.0), static_cast<T>(3.0), static_cast<T>(4.0)); BOOST_CHECK_CLOSE(V_param.x, static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(V_param.y, static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(V_param.z, static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(V_param.w, static_cast<T>(4.0), 1e-4f); // copy vector2 vmath::core::Vector<T, 2> V2; V2.x = static_cast<T>(4.0); V2.y = static_cast<T>(3.0); vmath::core::Vector<T, 4> V_param2(V2, static_cast<T>(2.0), static_cast<T>(1.0)); BOOST_CHECK_CLOSE(V_param2.x, static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(V_param2.y, static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(V_param2.z, static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(V_param2.w, static_cast<T>(1.0), 1e-4f); // copy vector3 vmath::core::Vector<T, 3> V3; V3.x = static_cast<T>(4.0); V3.y = static_cast<T>(3.0); V3.z = static_cast<T>(2.0); vmath::core::Vector<T, 4> V_param3(V3, static_cast<T>(1.0)); BOOST_CHECK_CLOSE(V_param3.x, static_cast<T>(4.0), 1e-4f); BOOST_CHECK_CLOSE(V_param3.y, static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(V_param3.z, static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(V_param3.w, static_cast<T>(1.0), 1e-4f); }
void test_smooth_r4<float_type>::test() { // place particles along the x-axis within one half of the box, // put every second particle at the origin unsigned int npart = particle->nparticle(); vector_type dx(0); dx[0] = box->edges()(0, 0) / npart / 2; std::vector<vector_type> r_list(particle->nparticle()); std::vector<unsigned int> species(particle->nparticle()); for (unsigned int k = 0; k < r_list.size(); ++k) { r_list[k] = (k % 2) ? k * dx : vector_type(0); species[k] = (k < npart_list[0]) ? 0U : 1U; // set particle type for a binary mixture } BOOST_CHECK( set_position(*particle, r_list.begin()) == r_list.end() ); BOOST_CHECK( set_species(*particle, species.begin()) == species.end() ); // read forces and other stuff from device std::vector<float> en_pot(particle->nparticle()); BOOST_CHECK( get_potential_energy(*particle, en_pot.begin()) == en_pot.end() ); std::vector<vector_type> f_list(particle->nparticle()); BOOST_CHECK( get_force(*particle, f_list.begin()) == f_list.end() ); float const eps = std::numeric_limits<float>::epsilon(); for (unsigned int i = 0; i < npart; ++i) { unsigned int type1 = species[i]; unsigned int type2 = species[(i + 1) % npart]; vector_type r = r_list[i] - r_list[(i + 1) % npart]; vector_type f = f_list[i]; // reference values from host module host_float_type fval, en_pot_; host_float_type rr = inner_prod(r, r); std::tie(fval, en_pot_) = (*host_potential)(rr, type1, type2); if (rr < host_potential->rr_cut(type1, type2)) { double rcut = host_potential->r_cut(type1, type2); // the GPU force module stores only a fraction of these values en_pot_ /= 2; // the first term is from the smoothing, the second from the potential // (see lennard_jones.cpp from unit tests) float const tolerance = 8 * eps * (1 + rcut/(rcut - std::sqrt(rr))) + 10 * eps; BOOST_CHECK_SMALL(norm_inf(fval * r - f), std::max(norm_inf(fval * r), 1.f) * tolerance * 2); BOOST_CHECK_CLOSE_FRACTION(en_pot_, en_pot[i], 2 * tolerance); } else { // when the distance is greater than the cutoff // set the force and the pair potential to zero fval = en_pot_ = 0; BOOST_CHECK_SMALL(norm_inf(f), eps); BOOST_CHECK_SMALL(en_pot[i], eps); } } }
BOOST_AUTO_TEST_CASE_TEMPLATE(from_axis_angle, T, float_types) { vmath::core::Quaternion<T> H_param2( vmath::core::Vector<T, 3>(static_cast<T>(1.0), static_cast<T>(0.0), static_cast<T>(0.0)), vmath::radians(static_cast<T>(90.0))); BOOST_CHECK_CLOSE(H_param2.x, static_cast<T>(0.707106769), 1e-4f); BOOST_CHECK_SMALL(H_param2.y, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(H_param2.z, static_cast<T>(1e-7)); BOOST_CHECK_CLOSE(H_param2.w, static_cast<T>(0.707106769), 1e-4f); }
void testEndEffectors(const rbd::MultiBodyConfig& mbc1, const rbd::MultiBodyConfig& mbc2, int endEffectorIndex, const Eigen::Matrix3d& target, double tol=1e-6) { BOOST_CHECK_SMALL((mbc1.bodyPosW[endEffectorIndex].translation() - mbc2.bodyPosW[endEffectorIndex].translation()).norm(), tol); BOOST_CHECK_SMALL(sva::rotationError(mbc1.bodyPosW[endEffectorIndex].rotation(), mbc2.bodyPosW[endEffectorIndex].rotation(), 1e-7).norm(), tol); BOOST_CHECK_SMALL(sva::rotationError(mbc1.bodyPosW[endEffectorIndex].rotation(), target, 1e-7).norm(), tol); BOOST_CHECK_SMALL(sva::rotationError(mbc2.bodyPosW[endEffectorIndex].rotation(), target, 1e-7).norm(), tol); }
BOOST_AUTO_TEST_CASE_TEMPLATE(create, T, float_types) { // default constructor vmath::core::Quaternion<T> H_default; BOOST_CHECK_SMALL(H_default.x, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(H_default.y, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(H_default.z, static_cast<T>(1e-7)); // parameterized constructor vmath::core::Quaternion<T> H_param(static_cast<T>(1.0), static_cast<T>(2.0), static_cast<T>(3.0), static_cast<T>(4.0)); BOOST_CHECK_CLOSE(H_param.x, static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(H_param.y, static_cast<T>(2.0), 1e-4f); BOOST_CHECK_CLOSE(H_param.z, static_cast<T>(3.0), 1e-4f); BOOST_CHECK_CLOSE(H_param.w, static_cast<T>(4.0), 1e-4f); }
void TestInterpolationHCurl::testInterpolation( std::string one_element_mesh ) { // expr to interpolate auto myexpr = unitX() + unitY(); //(1,1) // one element mesh auto mesh_name = one_element_mesh + ".msh"; //create the mesh and load it fs::path mesh_path( mesh_name ); mesh_ptrtype oneelement_mesh = loadMesh( _mesh=new mesh_type, _filename=mesh_name); // refined mesh (export) auto refine_level = std::floor(1 - math::log( 0.1 )); //Deduce refine level from meshSize (option) mesh_ptrtype mesh = loadMesh( _mesh=new mesh_type, _filename=mesh_name, _refine=( int )refine_level); space_ptrtype Xh = space_type::New( oneelement_mesh ); std::vector<std::string> faces, edges; //list of edges edges = {"hypo","vert","hor"}; element_type U_h_int = Xh->element(); element_type U_h_on = Xh->element(); element_type U_h_on_boundary = Xh->element(); // handly computed interpolant coeff (in hcurl basis) for ( int i = 0; i < Xh->nLocalDof(); ++i ) { CHECK( oneelement_mesh->hasMarkers( {edges[i]} ) ); U_h_int(i) = integrate( markedfaces( oneelement_mesh, edges[i] ), trans( T() )*myexpr ).evaluate()(0,0); } // nedelec interpolant using on U_h_on.zero(); U_h_on.on(_range=elements(oneelement_mesh), _expr=myexpr); U_h_on_boundary.on(_range=boundaryfaces(oneelement_mesh), _expr=myexpr); auto exporter_proj = exporter( _mesh=mesh, _name=( boost::format( "%1%" ) % this->about().appName() ).str() ); exporter_proj->step( 0 )->add( "U_interpolation_handly_"+mesh_path.stem().string(), U_h_int ); exporter_proj->step( 0 )->add( "U_interpolation_on_"+mesh_path.stem().string(), U_h_on ); exporter_proj->save(); // print coefficient only for reference element U_h_int.printMatlab( "U_h_int_" + mesh_path.stem().string() + ".m" ); U_h_on.printMatlab( "U_h_on_" + mesh_path.stem().string() + ".m" ); U_h_on_boundary.printMatlab( "U_h_on_boundary_" + mesh_path.stem().string() + ".m" ); //L2 norm of error auto error = vf::project(_space=Xh, _range=elements(oneelement_mesh), _expr=idv(U_h_int) - idv(U_h_on) ); double L2error = error.l2Norm(); std::cout << "L2 error (elements) = " << L2error << std::endl; auto error_boundary = vf::project(_space=Xh, _range=boundaryfaces(oneelement_mesh), _expr=idv(U_h_int) - idv(U_h_on_boundary) ); double L2error_boundary = error_boundary.l2Norm(); std::cout << "L2 error (boundary) = " << L2error_boundary << std::endl; BOOST_CHECK_SMALL( L2error_boundary - L2error, 1e-13 ); }
BOOST_AUTO_TEST_CASE_TEMPLATE(reflect, T, float_types) { vmath::core::Vector<T, 4> I; I.x = static_cast<T>(-1.0); I.y = static_cast<T>(-1.0); I.z = static_cast<T>(0.0); I.w = static_cast<T>(0.0); vmath::core::Vector<T, 4> N; N.x = static_cast<T>(1.0); N.y = static_cast<T>(0.0); N.z = static_cast<T>(0.0); N.w = static_cast<T>(0.0); vmath::core::Vector<T, 4> R = vmath::core::Vector<T, 4>::reflect(I, N); BOOST_CHECK_CLOSE(R.x, static_cast<T>(1.0), 1e-4f); BOOST_CHECK_CLOSE(R.y, static_cast<T>(-1.0), 1e-4f); BOOST_CHECK_SMALL(R.z, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(R.w, static_cast<T>(1e-7)); }
void run() { BOOST_TEST_MESSAGE( "test_eval_at_point D=" << DimGeo << " P=" << OrderPoly << "..." ); Environment::changeRepository( boost::format( "%1%/D%2%/P%3%" ) % Environment::about().appName() % DimGeo % OrderPoly ); auto mesh = loadMesh(_mesh = new Mesh<Simplex<DimGeo>>); auto Vh = Pchv<OrderPoly>( mesh ); auto u = Vh->element(); std::string e_str; if ( DimGeo == 2 ) e_str = "{x*x*y,x*y*y}:x:y"; else if ( DimGeo == 3 ) e_str = "{x*x*y*z,x*y*y*z,x*y*z*z}:x:y:z"; auto e = expr<DimGeo,1>( e_str ); u = vf::project(Vh,elements(mesh), e ); node_type pt(DimGeo); pt[0] = 0.5; if ( DimGeo >= 2 ) pt[1] = 0.5; if ( DimGeo >= 3 ) pt[2] = 0.5; auto eval = u(pt)[0]; auto e_eval = e.evaluate(); if ( DimGeo >= 2 ) { e.setParameterValues( { { "x", 0.5 },{ "y", 0.5 } } ); if ( DimGeo >= 3 ) e.setParameterValues( { { "x", 0.5 },{ "y", 0.5 }, { "z", 0.5 } } ); auto sol = e.evaluate(); double min = doption(_name="gmsh.hsize"); #if USE_BOOST_TEST if ( OrderPoly < 4 ) BOOST_CHECK_SMALL( (eval-sol).cwiseQuotient(sol).norm(), min ); else BOOST_CHECK_SMALL( (eval-sol).cwiseQuotient(sol).norm(), 1e-13 ); #else CHECK( (eval-sol).norm() < min ) << "Error in evaluation at point " << pt << " value = [ " << eval << " ] expected = [ " << sol << " ] "; #endif BOOST_TEST_MESSAGE( "test_eval_at_point D=" << DimGeo << " P=" << OrderPoly << "done" ); } }
void DiskFixture::testPosition(std::array<float,3> p) { // check that point lies in plane BOOST_CHECK_SMALL(dot(m_normal,p-m_centre),1e-5f); // check that point is sufficiently close to centre BOOST_CHECK_LE(norm2(p-m_centre), m_radiusSquared); }
BOOST_AUTO_TEST_CASE_TEMPLATE(to_axis_angle, T, float_types) { vmath::core::Quaternion<T> H( vmath::core::Vector<T, 3>(static_cast<T>(1.0), static_cast<T>(1.0), static_cast<T>(0.0)), vmath::radians(static_cast<T>(22.0))); BOOST_CHECK_CLOSE(H.axis().x, static_cast<T>(0.707106829), 1e-4f); BOOST_CHECK_CLOSE(H.axis().y, static_cast<T>(0.707106829), 1e-4f); BOOST_CHECK_SMALL(H.axis().z, static_cast<T>(1e-7)); BOOST_CHECK_CLOSE(H.angle(), vmath::radians(static_cast<T>(22.0)), 1e-4f); }
void Integrate1DLine(int maxOrder, int numNodes1D, NuTo::eIntegrationMethod method) { NuTo::IntegrationTypeTensorProduct<1> intType(numNodes1D, method); for (int i = 0; i <= maxOrder; i++) { auto f = [i](Eigen::VectorXd x) { return (std::pow(x[0], i)); }; double computedResult = integrate(f, intType); double expectedResult = 1. / (i + 1) * (1. - std::pow(-1, i + 1)); BOOST_CHECK_SMALL(computedResult - expectedResult, 1.e-13); } }
BOOST_AUTO_TEST_CASE_TEMPLATE(normal, T, float_types) { vmath::core::Quaternion<T> H; H.x = static_cast<T>(20.12); H.y = static_cast<T>(100.89); H.z = static_cast<T>(-18.2); H.w = static_cast<T>(35.62); vmath::core::Quaternion<T> H_norm(H.normal()); BOOST_CHECK_CLOSE(H_norm.x, static_cast<T>(0.18228024747696905), 1e-4f); BOOST_CHECK_CLOSE(H_norm.y, static_cast<T>(0.914028537145233), 1e-4f); BOOST_CHECK_CLOSE(H_norm.z, static_cast<T>(-0.16488571093841137), 1e-4f); BOOST_CHECK_CLOSE(H_norm.w, static_cast<T>(0.32270489140803366), 2e-5f); H.x = static_cast<T>(1.0); H.y = static_cast<T>(0.0); H.z = static_cast<T>(0.0); H.w = static_cast<T>(0.0); H_norm = H.normal(); BOOST_CHECK_CLOSE(H_norm.x, static_cast<T>(1.0), 1e-4f); BOOST_CHECK_SMALL(H_norm.y, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(H_norm.z, static_cast<T>(1e-7)); }
BOOST_AUTO_TEST_CASE_TEMPLATE(normalize, T, float_types) { vmath::core::Vector<T, 4> V; V.x = static_cast<T>(20.12); V.y = static_cast<T>(100.89); V.z = static_cast<T>(-18.2); V.w = static_cast<T>(35.62); V.normalize(); BOOST_CHECK_CLOSE(V.x, static_cast<T>(0.18228024747696905), 1e-4f); BOOST_CHECK_CLOSE(V.y, static_cast<T>(0.914028537145233), 1e-4f); BOOST_CHECK_CLOSE(V.z, static_cast<T>(-0.16488571093841137), 1e-4f); BOOST_CHECK_CLOSE(V.w, static_cast<T>(0.32270489140803366), 2e-5f); V.x = static_cast<T>(1.0); V.y = static_cast<T>(0.0); V.z = static_cast<T>(0.0); V.w = static_cast<T>(0.0); vmath::core::Vector<T, 4> V_norm; V_norm = V.normalize(); BOOST_CHECK_CLOSE(V_norm.x, static_cast<T>(1.0), 1e-4f); BOOST_CHECK_SMALL(V.y, static_cast<T>(1e-7)); BOOST_CHECK_SMALL(V.z, static_cast<T>(1e-7)); }
BOOST_AUTO_TEST_CASE_TEMPLATE(to_matrix4, T, float_types) { vmath::core::Quaternion<T> H; H.x = static_cast<T>(0.126973); H.y = static_cast<T>(0.145493); H.z = static_cast<T>(0.361453); H.w = static_cast<T>(0.912173); vmath::core::Matrix<T, 4> M; M = H.to_matrix(); BOOST_CHECK_CLOSE(M[0][0], static_cast<T>(0.696367031483999), 1e-3f); BOOST_CHECK_CLOSE(M[0][1], static_cast<T>(0.6963627001160001), 1e-3f); BOOST_CHECK_CLOSE(M[0][2], static_cast<T>(-0.17364002904), 1e-3f); BOOST_CHECK_SMALL(M[0][3], static_cast<T>(1e-7f)); BOOST_CHECK_CLOSE(M[1][0], static_cast<T>(-0.62246796936), 1e-3f); BOOST_CHECK_CLOSE(M[1][1], static_cast<T>(0.706459172124), 1e-3f); BOOST_CHECK_CLOSE(M[1][2], static_cast<T>(0.336820447316), 1e-3f); BOOST_CHECK_SMALL(M[1][3], static_cast<T>(1e-7f)); BOOST_CHECK_CLOSE(M[2][0], static_cast<T>(0.357219116116), 1e-3f); BOOST_CHECK_CLOSE(M[2][1], static_cast<T>(-0.12646492199), 1e-3f); BOOST_CHECK_CLOSE(M[2][2], static_cast<T>(0.925419288444), 1e-3f); BOOST_CHECK_SMALL(M[2][3], static_cast<T>(1e-7f)); BOOST_CHECK_SMALL(M[3][0], static_cast<T>(1e-7f)); BOOST_CHECK_SMALL(M[3][1], static_cast<T>(1e-7f)); BOOST_CHECK_SMALL(M[3][2], static_cast<T>(1e-7f)); BOOST_CHECK_CLOSE(M[3][3], static_cast<T>(1.0), 1e-3f); }
BOOST_AUTO_TEST_CASE_TEMPLATE(det, T, float_types) { vmath::core::Matrix<T, 2> M; M[0][0] = static_cast<T>(1.0); M[0][1] = static_cast<T>(2.0); M[1][0] = static_cast<T>(3.0); M[1][1] = static_cast<T>(4.0); BOOST_CHECK_CLOSE(M.det(), static_cast<T>(-2.0), 1e-4f); M[0][0] = static_cast<T>(0.0); M[0][1] = static_cast<T>(0.0); M[1][0] = static_cast<T>(3.0); M[1][1] = static_cast<T>(4.0); BOOST_CHECK_SMALL(M.det(), static_cast<T>(1e-7)); }
void Integrate2DQuad(int maxOrder, int numNodes1D, NuTo::eIntegrationMethod method) { NuTo::IntegrationTypeTensorProduct<2> intType(numNodes1D, method); for (int n = 0; n <= maxOrder; n++) { for (int i = 0; i < n + 1; i++) { auto f = [n, i](Eigen::VectorXd x) { return (std::pow(x[0], i) * std::pow(x[1], n - i)); }; double computedResult = integrate(f, intType); double expectedResult = 1. / (i + 1) / (n - i + 1) * ((1. - std::pow(-1, i + 1)) * (1. - std::pow(-1, n - i + 1))); BOOST_CHECK_SMALL(computedResult - expectedResult, 1.e-13); } } }
BOOST_AUTO_TEST_CASE_TEMPLATE(mag2, T, float_types) { vmath::core::Vector<T, 4> V; V.x = static_cast<T>(20.12); V.y = static_cast<T>(100.89); V.z = static_cast<T>(-18.2); V.w = static_cast<T>(35.62); T mag2 = V.mag2(); BOOST_CHECK_CLOSE(mag2, static_cast<T>(12183.6309), 1e-4f); V.x = static_cast<T>(1.0); V.y = static_cast<T>(0.0); V.z = static_cast<T>(0.0); V.w = static_cast<T>(0.0); mag2 = V.mag2(); BOOST_CHECK_CLOSE(mag2, static_cast<T>(1.0), 1e-4f); V.x = static_cast<T>(0.0); V.y = static_cast<T>(0.0); V.z = static_cast<T>(0.0); V.w = static_cast<T>(0.0); mag2 = V.mag2(); BOOST_CHECK_SMALL(mag2, static_cast<T>(1e-7)); }
BOOST_AUTO_TEST_CASE_TEMPLATE(mag2, T, float_types) { vmath::core::Quaternion<T> H; H.x = static_cast<T>(20.12); H.y = static_cast<T>(100.89); H.z = static_cast<T>(-18.2); H.w = static_cast<T>(35.62); T mag2 = H.mag2(); BOOST_CHECK_CLOSE(mag2, static_cast<T>(12183.6309), 1e-4f); H.x = static_cast<T>(1.0); H.y = static_cast<T>(0.0); H.z = static_cast<T>(0.0); H.w = static_cast<T>(0.0); mag2 = H.mag2(); BOOST_CHECK_CLOSE(mag2, static_cast<T>(1.0), 1e-4f); H.x = static_cast<T>(0.0); H.y = static_cast<T>(0.0); H.z = static_cast<T>(0.0); H.w = static_cast<T>(0.0); mag2 = H.mag2(); BOOST_CHECK_SMALL(mag2, static_cast<T>(1e-7)); }
BOOST_AUTO_TEST_CASE_TEMPLATE(mag, T, float_types) { vmath::core::Quaternion<T> H; H.x = static_cast<T>(20.12); H.y = static_cast<T>(100.89); H.z = static_cast<T>(-18.2); H.w = static_cast<T>(35.62); T mag = H.mag(); BOOST_CHECK_CLOSE(mag, static_cast<T>(110.37948586580751), 1e-4f); H.x = static_cast<T>(1.0); H.y = static_cast<T>(0.0); H.z = static_cast<T>(0.0); H.w = static_cast<T>(0.0); mag = H.mag(); BOOST_CHECK_CLOSE(mag, static_cast<T>(1.0), 1e-4f); H.x = static_cast<T>(0.0); H.y = static_cast<T>(0.0); H.z = static_cast<T>(0.0); H.w = static_cast<T>(0.0); mag = H.mag(); BOOST_CHECK_SMALL(mag, static_cast<T>(1e-7)); }
BOOST_AUTO_TEST_CASE_TEMPLATE(mag, T, float_types) { vmath::core::Vector<T, 4> V; V.x = static_cast<T>(20.12); V.y = static_cast<T>(100.89); V.z = static_cast<T>(-18.2); V.w = static_cast<T>(35.62); T mag = V.mag(); BOOST_CHECK_CLOSE(mag, static_cast<T>(110.37948586580751), 1e-4f); V.x = static_cast<T>(1.0); V.y = static_cast<T>(0.0); V.z = static_cast<T>(0.0); V.w = static_cast<T>(0.0); mag = V.mag(); BOOST_CHECK_CLOSE(mag, static_cast<T>(1.0), 1e-4f); V.x = static_cast<T>(0.0); V.y = static_cast<T>(0.0); V.z = static_cast<T>(0.0); V.w = static_cast<T>(0.0); mag = V.mag(); BOOST_CHECK_SMALL(mag, static_cast<T>(1e-7)); }
//! Use performIntegrationStep() to integrate to specified time in multiple steps. void performIntegrationStepToSpecifiedTime( const Eigen::MatrixXd benchmarkData, const double singleStepTestTolerance, const double fullIntegrationTestTolerance, const numerical_integrators::NumericalIntegratorXdPointer integrator ) { // Use performIntegrationstep() to integrate to specified time in multiple steps and check // results against benchmark data. // Declare last time and state. double lastTime = TUDAT_NAN; Eigen::VectorXd lastState = Eigen::VectorXd::Zero( 1 ); // Loop through all the integration steps in the benchmark data. for ( int i = 1; i < benchmarkData.rows( ); i++ ) { // Set the step size based on the benchmark data. double stepSize = benchmarkData( i, TIME_COLUMN_INDEX ) - benchmarkData( i - 1, TIME_COLUMN_INDEX ); // Store last time and state. lastTime = integrator->getCurrentIndependentVariable( ); lastState = integrator->getCurrentState( ); // Perform the integration step. integrator->performIntegrationStep( stepSize ); // Check if the expected time at the end of the integration step matches the required // time. This test should be accurate to effectively machine precision. if ( std::fabs( integrator->getCurrentIndependentVariable( ) ) < std::numeric_limits< double >::epsilon( ) ) { BOOST_CHECK_SMALL( benchmarkData( i, TIME_COLUMN_INDEX ), singleStepTestTolerance ); } else { BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ), singleStepTestTolerance ); } // Check if expected state at end of integration step matches required state. // The reason this test has a different, higher tolerance than for a single integration // step is because the acummulated error builds up, since this test is based off of // a time-series. The individual steps are accurate to singleStepTestTolerance. BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ), fullIntegrationTestTolerance ); } // Roll back to the previous step. This should be possible since the // performIntegrationStep() function was called above. BOOST_CHECK( integrator->rollbackToPreviousState( ) ); // Check that the rolled back time is as required. This test should be exact. BOOST_CHECK_EQUAL( lastTime, integrator->getCurrentIndependentVariable( ) ); // Check that the rolled back state is as required. This test should be exact. BOOST_CHECK_EQUAL( lastState( 0 ), integrator->getCurrentState( )( 0 ) ); // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); }
void TestInterpolationHCurl3D::testInterpolation( std::string one_element_mesh ) { //auto myexpr = unitX() + unitY() + unitZ() ; //(1,1,1) auto myexpr = vec( cst(1.), cst(1.), cst(1.)); // one element mesh auto mesh_name = one_element_mesh + ".msh"; //create the mesh and load it fs::path mesh_path( mesh_name ); mesh_ptrtype oneelement_mesh = loadMesh( _mesh=new mesh_type, _filename=mesh_name); // refined mesh (export) auto refine_level = std::floor(1 - math::log( 0.1 )); //Deduce refine level from meshSize (option) mesh_ptrtype mesh = loadMesh( _mesh=new mesh_type, _filename=mesh_name, _refine=( int )refine_level); space_ptrtype Xh = space_type::New( oneelement_mesh ); std::vector<std::string> faces = {"yzFace","xyzFace","xyFace"}; std::vector<std::string> edges = {"zAxis","yAxis","yzAxis","xyAxis","xzAxis","xAxis"}; element_type U_h_int = Xh->element(); element_type U_h_on = Xh->element(); element_type U_h_on_boundary = Xh->element(); submesh1d_ptrtype edgeMesh( new submesh1d_type ); edgeMesh = createSubmesh(oneelement_mesh, boundaryedges(oneelement_mesh) ); //submesh of edges // Tangents on ref element auto t0 = vec(cst(0.),cst(0.),cst(-2.)); auto t1 = vec(cst(0.),cst(2.),cst(0.)); auto t2 = vec(cst(0.),cst(-2.),cst(2.)); auto t3 = vec(cst(2.),cst(-2.),cst(0.)); auto t4 = vec(cst(2.),cst(0.),cst(-2.)); auto t5 = vec(cst(2.),cst(0.),cst(0.)); // Jacobian of geometrical transforms std::string jac; if(mesh_path.stem().string() == "one-elt-ref-3d" || mesh_path.stem().string() == "one-elt-real-h**o-3d" ) jac = "{1,0,0,0,1,0,0,0,1}:x:y:z"; else if(mesh_path.stem().string() == "one-elt-real-rotx" ) jac = "{1,0,0,0,0,-1,0,1,0}:x:y:z"; else if(mesh_path.stem().string() == "one-elt-real-roty" ) jac = "{0,0,1,0,1,0,-1,0,0}:x:y:z"; else if(mesh_path.stem().string() == "one-elt-real-rotz" ) jac = "{0,-1,0,1,0,0,0,0,1}:x:y:z"; U_h_int(0) = integrate( markedelements(edgeMesh, edges[0]), trans(expr<3,3>(jac)*t0)*myexpr ).evaluate()(0,0); U_h_int(1) = integrate( markedelements(edgeMesh, edges[1]), trans(expr<3,3>(jac)*t1)*myexpr ).evaluate()(0,0); U_h_int(2) = integrate( markedelements(edgeMesh, edges[2]), trans(expr<3,3>(jac)*t2)*myexpr ).evaluate()(0,0); U_h_int(3) = integrate( markedelements(edgeMesh, edges[3]), trans(expr<3,3>(jac)*t3)*myexpr ).evaluate()(0,0); U_h_int(4) = integrate( markedelements(edgeMesh, edges[4]), trans(expr<3,3>(jac)*t4)*myexpr ).evaluate()(0,0); U_h_int(5) = integrate( markedelements(edgeMesh, edges[5]), trans(expr<3,3>(jac)*t5)*myexpr ).evaluate()(0,0); for(int i=0; i<edges.size(); i++) { double edgeLength = integrate( markedelements(edgeMesh, edges[i]), cst(1.) ).evaluate()(0,0); U_h_int(i) /= edgeLength; } #if 0 //Doesn't work for now for(int i=0; i<Xh->nLocalDof(); i++) { CHECK( edgeMesh->hasMarkers( {edges[i]} ) ); U_h_int(i) = integrate( markedelements(edgeMesh, edges[i]), trans( print(T(),"T=") )*myexpr ).evaluate()(0,0); std::cout << "U_h_int(" << i << ")= " << U_h_int(i) << std::endl; } #endif // nedelec interpolant using on keyword // interpolate on element U_h_on.zero(); U_h_on.on(_range=elements(oneelement_mesh), _expr=myexpr); U_h_on_boundary.on(_range=boundaryfaces(oneelement_mesh), _expr=myexpr); auto exporter_proj = exporter( _mesh=mesh, _name=( boost::format( "%1%" ) % this->about().appName() ).str() ); exporter_proj->step( 0 )->add( "U_interpolation_handly_"+mesh_path.stem().string(), U_h_int ); exporter_proj->step( 0 )->add( "U_interpolation_on_"+mesh_path.stem().string(), U_h_on ); exporter_proj->save(); // print coefficient only for reference element U_h_int.printMatlab( "U_h_int_" + mesh_path.stem().string() + ".m" ); U_h_on.printMatlab( "U_h_on_" + mesh_path.stem().string() + ".m" ); U_h_on_boundary.printMatlab( "U_h_on_boundary_" + mesh_path.stem().string() + ".m" ); //L2 norm of error auto error = vf::project(_space=Xh, _range=elements(oneelement_mesh), _expr=idv(U_h_int) - idv(U_h_on) ); double L2error = error.l2Norm(); std::cout << "L2 error (elements) = " << L2error << std::endl; auto error_boundary = vf::project(_space=Xh, _range=elements(oneelement_mesh), _expr=idv(U_h_int) - idv(U_h_on_boundary) ); double L2error_boundary = error_boundary.l2Norm(); std::cout << "L2 error (boundary) = " << L2error_boundary << std::endl; BOOST_CHECK_SMALL( L2error_boundary - L2error, 1e-13 ); }
void checkModel(rbdyn_urdf::Urdf urdf1, rbdyn_urdf::Urdf urdf2) { rbd::MultiBody mb1(urdf1.mbg.makeMultiBody(0, true)); rbd::MultiBody mb2(urdf2.mbg.makeMultiBody(0, true)); // basic check BOOST_CHECK_EQUAL(mb1.nrBodies(), mb2.nrBodies()); BOOST_CHECK_EQUAL(mb1.nrJoints(), mb2.nrJoints()); BOOST_CHECK_EQUAL(mb1.nrParams(), mb2.nrParams()); BOOST_CHECK_EQUAL(mb1.nrDof(), mb2.nrDof()); // mb structure check BOOST_CHECK(std::equal(mb1.predecessors().begin(), mb1.predecessors().end(), mb2.predecessors().begin())); BOOST_CHECK(std::equal(mb1.successors().begin(), mb1.successors().end(), mb2.successors().begin())); BOOST_CHECK(std::equal(mb1.parents().begin(), mb1.parents().end(), mb2.parents().begin())); BOOST_CHECK(std::equal(mb1.transforms().begin(), mb1.transforms().end(), mb2.transforms().begin())); // check limits // position BOOST_CHECK(std::equal(urdf1.limits.ql.begin(), urdf1.limits.ql.end(), urdf2.limits.ql.begin())); BOOST_CHECK(std::equal(urdf1.limits.qu.begin(), urdf1.limits.qu.end(), urdf2.limits.qu.begin())); // velocity BOOST_CHECK(std::equal(urdf1.limits.vl.begin(), urdf1.limits.vl.end(), urdf2.limits.vl.begin())); BOOST_CHECK(std::equal(urdf1.limits.vu.begin(), urdf1.limits.vu.end(), urdf2.limits.vu.begin())); // torque BOOST_CHECK(std::equal(urdf1.limits.tl.begin(), urdf1.limits.tl.end(), urdf2.limits.tl.begin())); BOOST_CHECK(std::equal(urdf1.limits.tu.begin(), urdf1.limits.tu.end(), urdf2.limits.tu.begin())); // check bodies for(int i = 0; i < mb1.nrBodies(); ++i) { const rbd::Body& b1 = mb1.body(i); const rbd::Body& b2 = mb2.body(i); BOOST_CHECK_EQUAL(b1.id(), b2.id()); BOOST_CHECK_EQUAL(b1.name(), b2.name()); BOOST_CHECK_EQUAL(b1.inertia().mass(), b2.inertia().mass()); BOOST_CHECK_EQUAL(b1.inertia().momentum(), b2.inertia().momentum()); BOOST_CHECK_SMALL((b1.inertia().inertia() - b2.inertia().inertia()).norm(), TOL); } // check joints for(int i = 0; i < mb1.nrJoints(); ++i) { const rbd::Joint& j1 = mb1.joint(i); const rbd::Joint& j2 = mb2.joint(i); BOOST_CHECK_EQUAL(j1.id(), j2.id()); BOOST_CHECK_EQUAL(j1.name(), j2.name()); BOOST_CHECK_EQUAL(j1.type(), j2.type()); BOOST_CHECK_EQUAL(j1.direction(), j2.direction()); BOOST_CHECK_EQUAL(j1.motionSubspace(), j2.motionSubspace()); } }
//! Use performIntegrationStep() to integrate to specified time in multiple steps, including //! discrete events. void performIntegrationStepToSpecifiedTimeWithEvents( const Eigen::MatrixXd benchmarkData, const double singleStepTestTolerance, const double fullIntegrationTestTolerance, const numerical_integrators::ReinitializableNumericalIntegratorXdPointer integrator ) { // Use performIntegrationstep() to integrate to specified time in multiple steps, including // discrete events and check results against benchmark data. The discrete events are enabled // by modifying the state instantaneously. These discrete events cannot be rolled back. // Declare last time and state. double lastTime = TUDAT_NAN; Eigen::VectorXd lastState = Eigen::VectorXd::Zero( 1 ); // Loop through all the integration steps in the benchmark data. for ( int i = 1; i < benchmarkData.rows( ); i++ ) { // Set the step size based on the benchmark data generated. const double stepSize = benchmarkData( i, TIME_COLUMN_INDEX ) - benchmarkData( i - 1, TIME_COLUMN_INDEX ); // Store last time and state. lastTime = integrator->getCurrentIndependentVariable( ); lastState = integrator->getCurrentState( ); // Perform the integration step. integrator->performIntegrationStep( stepSize ); // Check if the expected time at the end of the integration step matches the required // time. This test should be accurate to effectively machine precision. if ( std::fabs( benchmarkData( i, TIME_COLUMN_INDEX ) ) < std::numeric_limits< double >::min( ) ) { BOOST_CHECK_SMALL( integrator->getCurrentIndependentVariable( ), std::numeric_limits< double >::epsilon( ) ); } else { BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, TIME_COLUMN_INDEX ), integrator->getCurrentIndependentVariable( ), singleStepTestTolerance ); } // Check if expected state at end of integration step matches required state. // The reason this test has a different, higher tolerance than for a single integration // step is because the acummulated error builds up, since this test is based off of // a time-series. The individual steps are accurate to the tolerance used in // Case 1. BOOST_CHECK_CLOSE_FRACTION( benchmarkData( i, STATE_COLUMN_INDEX ), integrator->getCurrentState( )( 0 ), fullIntegrationTestTolerance ); // Check if a discrete event is schedule to take place, and execute discrete event // if so. if ( i < benchmarkData.rows( ) - 1 && std::fabs( benchmarkData( i + 1, TIME_COLUMN_INDEX ) - benchmarkData( i, TIME_COLUMN_INDEX ) ) < std::numeric_limits< double >::epsilon( ) ) { // Increment loop to next row in matrix, which contains the discrete event that // affects the state. i++; // Modify the current state based on the discrete event integrator->modifyCurrentState( Eigen::VectorXd::Constant( 1, benchmarkData( i, STATE_COLUMN_INDEX ) ) ); // Check that it is now not possible to roll back. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); } } // Check that it is possible to roll back to the previous step. This is allowable, because // the last action performed by the integrator is the performIntegrationStep() function. BOOST_CHECK( integrator->rollbackToPreviousState( ) ); // Check that the rolled back time is as required. This test should be exact. BOOST_CHECK_EQUAL( lastTime, integrator->getCurrentIndependentVariable( ) ); // Check that the rolled back state is as required. This test should be exact. BOOST_CHECK_EQUAL( lastState( 0 ), integrator->getCurrentState( )( 0 ) ); // Check that it is now not possible to roll back to the previous step. BOOST_CHECK( !integrator->rollbackToPreviousState( ) ); }
BOOST_AUTO_TEST_CASE_TEMPLATE(radians_to_degrees, T, float_types) { BOOST_CHECK_SMALL(vmath::degrees(static_cast<T>(0.0)), static_cast<T>(1e-7)); BOOST_CHECK_CLOSE(vmath::degrees(static_cast<T>(vmath::PI)), static_cast<T>(180.0), 1e-4f); BOOST_CHECK_CLOSE(vmath::degrees(static_cast<T>(0.345)), static_cast<T>(19.76704393), 1e-4f); }
void run() { Environment::changeRepository( boost::format( "/testsuite/feeldiscr/%1%/P%2%/" ) % Environment::about().appName() % OrderPoly ); /* change parameters below */ const int nDim = 2; const int nOrderPoly = OrderPoly; const int nOrderGeo = 1; //------------------------------------------------------------------------------// typedef Mesh< Simplex<nDim, 1,nDim> > mesh_type; typedef Mesh< Simplex<nDim, 1,nDim> > mesh_bis_type; double meshSize = option("hsize").as<double>(); double meshSizeBis = option("hsize-bis").as<double>(); // mesh GeoTool::Node x1( 0,0 ); GeoTool::Node x2( 4,1 ); GeoTool::Rectangle Omega( meshSize,"Omega",x1,x2 ); Omega.setMarker( _type="line",_name="Entree",_marker4=true ); Omega.setMarker( _type="line",_name="Sortie",_marker2=true ); Omega.setMarker( _type="line",_name="Paroi",_marker1=true,_marker3=true ); Omega.setMarker( _type="surface",_name="Fluid",_markerAll=true ); auto mesh = Omega.createMesh(_mesh=new mesh_type,_name="omega_"+ mesh_type::shape_type::name() ); LOG(INFO) << "created mesh\n"; GeoTool::Rectangle OmegaBis( meshSizeBis,"Omega",x1,x2 ); OmegaBis.setMarker( _type="line",_name="Entree",_marker4=true ); OmegaBis.setMarker( _type="line",_name="Sortie",_marker2=true ); OmegaBis.setMarker( _type="line",_name="Paroi",_marker1=true,_marker3=true ); OmegaBis.setMarker( _type="surface",_name="Fluid",_markerAll=true ); auto meshBis = OmegaBis.createMesh(_mesh=new mesh_bis_type,_name="omegaBis_"+ mesh_type::shape_type::name() ); //auto meshBis= mesh->createP1mesh(); LOG(INFO) << "created meshBis\n"; typedef Lagrange<nOrderPoly,Scalar,Continuous,PointSetFekete> basis_type; typedef FunctionSpace<mesh_type, bases<basis_type> > space_type; auto Xh = space_type::New( mesh ); auto u = Xh->element(); auto v = Xh->element(); auto u2 = Xh->element(); LOG(INFO) << "created space and elements\n"; auto mybackend = backend(); //--------------------------------------------------------------// auto A = mybackend->newMatrix( Xh, Xh ); auto F = mybackend->newVector( Xh ); auto pi = cst( M_PI ); auto u_exact = cos( pi*Px() )*sin( pi*Py() ); auto dudx = -pi*sin( pi*Px() )*sin( pi*Py() ); auto dudy = pi*cos( pi*Px() )*cos( pi*Py() ); auto grad_u_uexact = vec( dudx,dudy ); auto lap = -2*pi*pi*cos( pi*Px() )*sin( pi*Py() ); //auto lap = -pi*pi*cos(pi*Px())*sin(pi*Py()) // -pi*pi*cos(pi*Px())*sin(pi*Py()); LOG(INFO) << "created exact data and matrix/vector\n"; auto f = -lap;//cst(1.); double gammabc=10; // assemblage form2( Xh, Xh, A, _init=true ) = integrate( elements( mesh ), //_Q<15>(), + gradt( u )*trans( grad( v ) ) ); form2( Xh, Xh, A ) += integrate( boundaryfaces( mesh ), - gradt( u )*N()*id( v ) + gammabc*idt( u )*id( v )/hFace() ); form1( Xh, F, _init=true ) = integrate( elements( mesh ), // _Q<10>(), trans( f )*id( v ) ); form1( Xh, F ) += integrate( boundaryfaces( mesh ), + gammabc*u_exact*id( v )/hFace() ); LOG(INFO) << "A,F assembled\n"; //form2( Xh, Xh, A ) += // on( boundaryfaces(mesh) , u, F, u_exact ); // solve system mybackend->solve( A,u,F ); LOG(INFO) << "A u = F solved\n"; //--------------------------------------------------------------// auto a2 = form2( _test=Xh, _trial=Xh ); auto f2 = form1( _test=Xh ); LOG(INFO) << "created form2 a2 and form1 F2\n"; // assemblage a2 = integrate( elements( meshBis ), + gradt( u2 )*trans( grad( v ) ), _Q<10>() ); LOG(INFO) << "a2 grad.grad term\n"; a2 += integrate( boundaryfaces( meshBis ), - gradt( u2 )*N()*id( v ) + gammabc*idt( u2 )*id( v )/hFace(), _Q<10>() ); LOG(INFO) << "a2 weak dirichlet terms\n"; f2 = integrate( elements( meshBis ), trans( f )*id( v ), _Q<10>() ); LOG(INFO) << "f2 source term\n"; f2 += integrate( boundaryfaces( meshBis ), + gammabc*u_exact*id( v )/hFace(), _Q<10>() ); LOG(INFO) << "f2 dirichlet terms\n"; LOG(INFO) << "a2,f2 assembled\n"; //form2( Xh, Xh, A2 ) += // on( boundaryfaces(mesh) , u2, F2, u_exact ); #if 0 for ( size_type i = 0 ; i< F->size() ; ++i ) { auto errOnF = std::abs( ( *F )( i )-( *F2 )( i ) ); if ( errOnF > 1e-8 ) std::cout << "\nerrOnF : " << errOnF; } std::cout << "\nFin errOnF !!!!\n"; #endif // solve system a2.solve( _rhs=f2, _solution=u2 ); auto diff = std::sqrt( integrate( elements( mesh ), ( idv( u )-idv( u2 ) )*( idv( u )-idv( u2 ) ) ).evaluate()( 0,0 ) ); #if 0 auto int1 = integrate( elements( mesh ), abs( idv( u ) ) ).evaluate()( 0,0 ); auto int2 = integrate( elements( mesh ), abs( idv( u2 ) ) ).evaluate()( 0,0 ); std::cout << "\nThe diff : " << diff << " int1 :" << int1 << " int2 :" << int2 << "\n"; #endif #if USE_BOOST_TEST BOOST_CHECK_SMALL( diff,1e-2 ); #endif //--------------------------------------------------------------// if ( option("exporter.export").as<bool>() ) { // export auto ex = exporter( _mesh=mesh ); ex->add( "u", u ); ex->add( "ubis", u2 ); ex->save(); } }
BOOST_AUTO_TEST_CASE_TEMPLATE(degrees_to_radians, T, float_types) { BOOST_CHECK_SMALL(vmath::radians(static_cast<T>(0.0)), static_cast<T>(1e-7)); BOOST_CHECK_CLOSE(vmath::radians(static_cast<T>(180.0)), static_cast<T>(vmath::PI), 1e-4f); BOOST_CHECK_CLOSE(vmath::radians(static_cast<T>(23.5)), static_cast<T>(0.410152374), 1e-4f); BOOST_CHECK_CLOSE(vmath::radians(static_cast<T>(985.0)), static_cast<T>(17.1914921), 1e-4f); }