TEST_F(NumLibDistributionQuad, Linear) { // f(x,y,z) = 1 + 2x + 3y + 4z std::array<double,4> f_coeff = {{1, 2, 3, 4}}; MathLib::LinearFunction<double,3> linear_f(f_coeff); std::vector<double> expected = {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21}}; NumLib::SpatialFunctionLinear f(linear_f); const std::vector<std::size_t>& vec_node_ids = _mshNodesSearcher.getMeshNodesAlongPolyline(*_ply0).getNodeIDs(); std::vector<double> interpolated_values = NumLib::generateNodeValueDistribution(f, *_msh, vec_node_ids); ASSERT_ARRAY_NEAR(expected, interpolated_values, expected.size(), std::numeric_limits<double>::epsilon()); }
TEST_F(NumLibSpatialFunctionQuad, Linear) { // f(x,y,z) = 1 + 2x + 3y + 4z std::array<double,4> f_coeff = {{1, 2, 3, 4}}; MathLib::LinearFunction<double,3> linear_f(f_coeff); std::vector<double> expected = {{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21}}; NumLib::SpatialFunctionLinear f(linear_f); const std::vector<std::size_t>& vec_node_ids = _mshNodesSearcher.getMeshNodesAlongPolyline(*_ply0).getNodeIDs(); std::vector<double> interpolated_values(vec_node_ids.size()); NodeIDtoNodeObject<NumLib::SpatialFunctionLinear> task(*_msh, f); std::transform(vec_node_ids.begin(), vec_node_ids.end(), interpolated_values.begin(), task); ASSERT_ARRAY_NEAR(expected, interpolated_values, expected.size(), std::numeric_limits<double>::epsilon()); }
TEST_F(NumLibDistributionHex, Linear) { // f(x,y,z) = 1 + 2x + 3y + 4z std::array<double,4> f_coeff = {{1, 2, 3, 4}}; MathLib::LinearFunction<double,3> linear_f(f_coeff); std::vector<double> expected(static_cast<std::size_t>(std::pow(_number_of_subdivisions_per_direction+1, 2))); const double dL = _geometric_size / _number_of_subdivisions_per_direction; for (std::size_t i=0; i<expected.size(); i++) { double x = 0; double y = (i%(_number_of_subdivisions_per_direction+1)) * dL; double z = (i/(_number_of_subdivisions_per_direction+1)) * dL; expected[i] = f_coeff[0] + f_coeff[1]*x + f_coeff[2]*y + f_coeff[3]*z; } NumLib::SpatialFunctionLinear f(linear_f); const std::vector<std::size_t>& vec_node_ids = _mshNodesSearcher.getMeshNodesAlongSurface(*_sfc1).getNodeIDs(); std::vector<double> interpolated_values = NumLib::generateNodeValueDistribution(f, *_msh, vec_node_ids); ASSERT_ARRAY_NEAR(expected, interpolated_values, expected.size(), std::numeric_limits<double>::epsilon()); }
TEST(NumLib, SpatialFunctionLinear) { // f(x,y,z) = 1 + 2x + 3y + 4z std::array<double,4> f_coeff = {{1, 2, 3, 4}}; MathLib::LinearFunction<double,3> linear_f(f_coeff); NumLib::SpatialFunctionLinear f(linear_f); ASSERT_DOUBLE_EQ(1., f(GeoLib::Point(0,0,0))); ASSERT_DOUBLE_EQ(10., f(GeoLib::Point(1,1,1))); ASSERT_DOUBLE_EQ(-8, f(GeoLib::Point(-1,-1,-1))); for (std::size_t k(0); k < 5; ++k) { GeoLib::Point pt(0, 0, 0); for (unsigned i = 0; i < 3; ++i) pt[i] = (double) rand() - (RAND_MAX / 2.0); double expected = 1+2*pt[0]+3*pt[1]+4*pt[2]; ASSERT_DOUBLE_EQ(expected, f(pt)); } }