9#define _USE_MATH_DEFINES
11#include "torus_mesh_builder.h"
13#include <lf/geometry/geometry.h>
14#include <spdlog/spdlog.h>
19#include "lf/mesh/mesh_interface.h"
30 using coord_t = Eigen::Vector3d;
36 const unsigned no_of_cells = nx * ny;
37 const unsigned no_of_edges = 2 * nx * ny;
38 const unsigned no_of_vertices = nx * ny;
40 if (no_of_cells == 0) {
47 if ((x_size <= 0.0) || (y_size <= 0.0)) {
52 const double hx = x_size / nx;
53 const double hy = y_size / ny;
56 const double r = x_size / (2. * M_PI);
57 const double R = y_size / (2. * M_PI);
58 auto theta = [r, hx](
double i) ->
double {
return (i * hx) / r; };
59 auto phi = [R, hy](
double j) ->
double {
return (j * hy) / R; };
63 "TorusMesh: {} cells, {} edges, {} vertices, mesh widths hx/hy = {}/{}",
64 no_of_cells, no_of_edges, no_of_vertices, hx, hy);
67 std::vector<size_type> v_idx(no_of_vertices);
71 for (
size_type i = 0; i < nx; ++i, ++node_cnt) {
74 node_coord << (R + r * std::cos(theta(i))) * std::cos(phi(j)),
75 (R + r * std::cos(theta(i))) * std::sin(phi(j)),
76 r * std::sin(theta(i));
78 SPDLOG_LOGGER_TRACE(
Logger(),
"Adding vertex {}: {}", node_cnt,
79 node_coord.transpose());
86 std::vector<size_type> t_idx(no_of_cells);
90 for (
size_type j = 0; j < ny; ++j, quad_cnt++) {
92 std::vector<size_type> vertex_index_list{
97 Eigen::Matrix<double, 3, 4> quad_geo;
98 quad_geo << (R + r * std::cos(theta(i))) * std::cos(phi(j)),
99 (R + r * std::cos(theta(i + 1))) * std::cos(phi(j)),
100 (R + r * std::cos(theta(i + 1))) * std::cos(phi(j + 1)),
101 (R + r * std::cos(theta(i))) * std::cos(phi(j + 1)),
102 (R + r * std::cos(theta(i))) * std::sin(phi(j)),
103 (R + r * std::cos(theta(i + 1))) * std::sin(phi(j)),
104 (R + r * std::cos(theta(i + 1))) * std::sin(phi(j + 1)),
105 (R + r * std::cos(theta(i))) * std::sin(phi(j + 1)),
106 r * std::sin(theta(i)), r * std::sin(theta(i + 1)),
107 r * std::sin(theta(i + 1)), r * std::sin(theta(i));
109 SPDLOG_LOGGER_TRACE(
Logger(),
"Adding quad {}:\n{}", quad_cnt, quad_geo);
115 std::make_unique<geometry::QuadO1>(quad_geo));
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
mesh::Mesh::size_type size_type
Eigen::Vector2d bottom_left_corner_
Eigen::Vector2d top_right_corner_
size_type num_of_x_cells_
size_type num_of_y_cells_
std::unique_ptr< mesh::MeshFactory > mesh_factory_
size_type VertexIndex(size_type i, size_type j) const
vertex index from grid position
std::shared_ptr< mesh::Mesh > Build() override
actual construction of the mesh
static std::shared_ptr< spdlog::logger > & Logger()
logger that is used by Build() to provide additional debug info.
std::shared_ptr< spdlog::logger > InitLogger(const std::string &name)
Create a spdlog logger, register it in the spdlog registry and initialize it with LehrFEM++ specific ...
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.