void testZCoords2D(MeshLib::Mesh const& input, MeshLib::Mesh const& output, double height) { std::size_t const nNodes (input.getNumberOfNodes()); for (std::size_t i=0; i<nNodes; ++i) { ASSERT_EQ((*input.getNode(i))[2], (*output.getNode(i))[2]); ASSERT_EQ((*input.getNode(i))[2] + height, (*output.getNode(nNodes+i))[2]); } }
// Project to parallels of YZ plane TEST_F(ProjectionTest, ProjectToYZ) { MathLib::Vector3 normal (1,0,0); std::size_t const n_nodes (_mesh->getNumberOfNodes()); for (std::size_t p=0; p<10; p++) { MathLib::Point3d origin (std::array<double,3>{{static_cast<double>(p),0,0}}); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t i=0; i<n_nodes; i++) ASSERT_NEAR(static_cast<double>(p), (*result->getNode(i))[0], std::numeric_limits<double>::epsilon()); delete result; } }
std::vector<double> generateNodeValueDistribution( const NumLib::ISpatialFunction &func, const MeshLib::Mesh &msh, const std::vector<std::size_t> &vec_node_ids) { // evaluate a given function with nodal coordinates std::vector<double> vec_values(vec_node_ids.size()); std::transform(vec_node_ids.begin(), vec_node_ids.end(), vec_values.begin(), [&func, &msh](std::size_t node_id) { return func(*msh.getNode(node_id)); }); return vec_values; }
// Length of normal does not matter (it's normalised within the method) TEST_F(ProjectionTest, NormalLength) { MathLib::Point3d origin (std::array<double,3>{{0,0,0}}); MathLib::Vector3 normal (0,0,1); std::size_t const n_nodes (_mesh->getNumberOfNodes()); MeshLib::Mesh* result = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t p=2; p<10; p++) { normal[2] = static_cast<double>(p); MeshLib::Mesh* result_p = MeshLib::projectMeshOntoPlane(*_mesh, origin, normal); for (std::size_t i=0; i<n_nodes; i++) ASSERT_EQ((*result->getNode(i))[2], (*result_p->getNode(i))[2]); delete result_p; } delete result; }
MeshLib::Mesh createMeshFromSelectedNodes( MeshLib::Mesh const& mesh, std::vector<std::size_t> const& selected_nodes) { // Deep copy of selected nodes from the mesh. std::vector<MeshLib::Node*> some_nodes; std::transform(begin(selected_nodes), end(selected_nodes), back_inserter(some_nodes), [&mesh](std::size_t const node_id) { return new MeshLib::Node(*mesh.getNode(node_id)); }); // The resulting mesh without elements containing the selected nodes. MeshLib::Mesh result("boundary_mesh", some_nodes, {}); addPropertyToMesh(result, "bulk_node_ids", MeshLib::MeshItemType::Node, 1, selected_nodes); return result; }
TEST(MeshLib, Duplicate) { MeshLib::Mesh* mesh (MeshLib::MeshGenerator::generateRegularQuadMesh(10, 5, 1)); std::vector<MeshLib::Node*> new_nodes (MeshLib::copyNodeVector(mesh->getNodes())); std::vector<MeshLib::Element*> new_elements (MeshLib::copyElementVector(mesh->getElements(), new_nodes)); MeshLib::Mesh new_mesh ("new", new_nodes, new_elements); ASSERT_EQ (mesh->getNElements(), new_mesh.getNElements()); ASSERT_EQ (mesh->getNNodes(), new_mesh.getNNodes()); std::vector<std::size_t> del_idx(1,1); MeshLib::removeMeshNodes(*mesh, del_idx); ASSERT_EQ (mesh->getNElements(), new_mesh.getNElements()-2); ASSERT_EQ (mesh->getNNodes(), new_mesh.getNNodes()-2); ASSERT_DOUBLE_EQ (4.0, MathLib::sqrDist(*mesh->getNode(0), *new_mesh.getNode(0))); ASSERT_DOUBLE_EQ (0.0, MathLib::sqrDist(*mesh->getNode(0), *new_mesh.getNode(2))); ASSERT_DOUBLE_EQ (4.0, MathLib::sqrDist(*mesh->getElement(0)->getNode(0), *new_mesh.getElement(0)->getNode(0))); ASSERT_DOUBLE_EQ (0.0, MathLib::sqrDist(*mesh->getElement(0)->getNode(0), *new_mesh.getElement(2)->getNode(0))); }