Mesh* MeshGenerator::generateRegularQuadMesh( const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, GeoLib::Point const& origin, std::string const& mesh_name) { std::vector<double> vec_x(div_x()); std::vector<double> vec_y(div_y()); std::vector<Node*> nodes(generateRegularNodes(vec_x, vec_y, origin)); const unsigned n_x_nodes (vec_x.size()); //elements std::vector<Element*> elements; const unsigned n_x_cells (vec_x.size()-1); const unsigned n_y_cells (vec_y.size()-1); elements.reserve(n_x_cells * n_y_cells); for (std::size_t j = 0; j < n_y_cells; j++) { const std::size_t offset_y1 = j * n_x_nodes; const std::size_t offset_y2 = (j + 1) * n_x_nodes; for (std::size_t k = 0; k < n_x_cells; k++) { std::array<Node*, 4> element_nodes; element_nodes[0] = nodes[offset_y1 + k]; element_nodes[1] = nodes[offset_y1 + k + 1]; element_nodes[2] = nodes[offset_y2 + k + 1]; element_nodes[3] = nodes[offset_y2 + k]; elements.push_back (new Quad(element_nodes)); } } return new Mesh(mesh_name, nodes, elements); }
Mesh* MeshGenerator::generateRegularHexMesh( const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, GeoLib::Point const& origin, std::string const& mesh_name) { std::vector<double> vec_x(div_x()); std::vector<double> vec_y(div_y()); std::vector<double> vec_z(div_z()); std::vector<Node*> nodes(generateRegularNodes(vec_x, vec_y, vec_z, origin)); const unsigned n_x_nodes (vec_x.size()); const unsigned n_y_nodes (vec_y.size()); const unsigned n_x_cells (vec_x.size()-1); const unsigned n_y_cells (vec_y.size()-1); const unsigned n_z_cells (vec_z.size()-1); //elements std::vector<Element*> elements; elements.reserve(n_x_cells * n_y_cells * n_z_cells); for (std::size_t i = 0; i < n_z_cells; i++) { const std::size_t offset_z1 = i * n_x_nodes * n_y_nodes; // bottom const std::size_t offset_z2 = (i + 1) * n_x_nodes * n_y_nodes; // top for (std::size_t j = 0; j < n_y_cells; j++) { const std::size_t offset_y1 = j * n_x_nodes; const std::size_t offset_y2 = (j + 1) * n_x_nodes; for (std::size_t k = 0; k < n_x_cells; k++) { std::array<Node*, 8> element_nodes; // bottom element_nodes[0] = nodes[offset_z1 + offset_y1 + k]; element_nodes[1] = nodes[offset_z1 + offset_y1 + k + 1]; element_nodes[2] = nodes[offset_z1 + offset_y2 + k + 1]; element_nodes[3] = nodes[offset_z1 + offset_y2 + k]; // top element_nodes[4] = nodes[offset_z2 + offset_y1 + k]; element_nodes[5] = nodes[offset_z2 + offset_y1 + k + 1]; element_nodes[6] = nodes[offset_z2 + offset_y2 + k + 1]; element_nodes[7] = nodes[offset_z2 + offset_y2 + k]; elements.push_back (new Hex(element_nodes)); } } } return new Mesh(mesh_name, nodes, elements); }
quatd vec4d_to_quat(vec4d v) { return quatd_make(vec_x(v), vec_y(v), vec_z(v), vec_w(v)); }
quatf vec4f_to_quat(vec4f v) { return quatf_make(vec_x(v), vec_y(v), vec_z(v), vec_w(v)); }
quatd vec3d_to_quat(vec3d v) { return quatd_make(vec_x(v), vec_y(v), vec_z(v), 0); }
quatf vec3f_to_quat(vec3f v) { return quatf_make(vec_x(v), vec_y(v), vec_z(v), 0); }