NiHu  2.0
lib_mesh.hpp
Go to the documentation of this file.
1 
4 #ifndef NIHU_LIB_MESH_HPP_INCLUDED
5 #define NIHU_LIB_MESH_HPP_INCLUDED
6 
7 #include "../core/mesh.hpp"
8 #include "lib_element.hpp"
9 
10 namespace NiHu
11 {
12 
19 };
20 
21 
30 template <class ElemTag = NiHu::line_1_tag>
33  double r,
34  size_t nElem,
35  orientation ori = outward,
36  ElemTag tag = ElemTag())
37 {
38  using namespace boost::math::double_constants;
39 
40  typedef ElemTag tag_t;
41  typedef typename NiHu::tag2type<tag_t>::type elem_t;
42  // the number of nodes per element
43  static size_t const M = elem_t::num_nodes;
44 
45  // the total number of nodes
46  size_t nNodes = (M-1) * nElem;
47  // create nodal locations
48  Eigen::Matrix<double, Eigen::Dynamic, 2> nodes(nNodes, 2);
49  for (size_t i = 0; i < nNodes; ++i) {
50  double phi = i*two_pi/nNodes;
51  nodes.row(i) << r * cos(phi), r * sin(phi);
52  }
53 
54  // create matrix of elements
55  Eigen::Matrix<unsigned, Eigen::Dynamic, M+1> elements(nElem, M + 1);
56  for (size_t i = 0; i < nElem; ++i) {
57  elements(i,0) = elem_t::id;
58  for (size_t j = 0; j < M; ++j)
59  if (ori == outward)
60  elements(i,j+1) = (i * (M-1) + j) % nNodes;
61  else
62  elements(i,M - j) = (i * (M-1) + j) % nNodes;
63  }
64 
65  // create the mesh
66  return NiHu::create_mesh(nodes, elements, tag);
67 } // function create_circle_mesh
68 
69 
80 template <class ElemTag = NiHu::line_1_tag>
83  double Lx, double Ly,
84  size_t nx, size_t ny,
85  orientation ori = outward,
86  ElemTag tag = ElemTag())
87 {
88  typedef ElemTag tag_t;
89  typedef typename NiHu::tag2type<tag_t>::type elem_t;
90  // number of nodes per element
91  static size_t const M = elem_t::num_nodes;
92  // total number of elements
93  size_t nElem = 2 * (nx + ny);
94  // total number of nodes
95  size_t nNodes = (M - 1) * nElem;
96  Eigen::Matrix<double, Eigen::Dynamic, 2> nodes(nNodes, 2);
97 
98  // create nodal locations
99  size_t k = 0;
100  for (size_t i = 0; i < nx * (M - 1); ++i)
101  nodes.row(k++) << Lx / (nx * (M - 1)) * i, 0.0;
102  for (size_t i = 0; i < ny * (M - 1); ++i)
103  nodes.row(k++) << Lx, Ly / (ny * (M - 1)) * i;
104  for (size_t i = 0; i < nx * (M - 1); ++i)
105  nodes.row(k++) << Lx - Lx / (nx * (M - 1)) * i, Ly;
106  for (size_t i = 0; i < ny * (M - 1); ++i)
107  nodes.row(k++) << 0.0, Ly - Ly / (ny * (M - 1)) * i;
108 
109  // create elements matrix
110  Eigen::Matrix<unsigned, Eigen::Dynamic, M + 1> elements(nElem, M + 1);
111  for (size_t i = 0; i < nElem; ++i) {
112  elements(i, 0) = elem_t::id;
113  for (size_t j = 0; j < M; ++j)
114  if (ori == outward)
115  elements(i, j + 1) = (i * (M-1) + j) % nNodes;
116  else
117  elements(i, M - j) = (i * (M-1) + j) % nNodes;
118  }
119 
120  return NiHu::create_mesh(nodes, elements, tag);
121 } // end of function create_rectangle_mesh
122 
123 
124 } // end of namespace NiHu
125 
126 #endif // NIHU_LIB_MESH_HPP_INCLUDED
NiHu::volume_element
class describing a volume element that has no normal vector
Definition: element.hpp:455
NiHu::orientation
orientation
Orientation of surface meshes.
Definition: lib_mesh.hpp:14
NiHu::tag2type
Metafunction recovering the type from a tag.
Definition: type2tag.hpp:28
NiHu::inward
@ inward
The mesh is directed inward.
Definition: lib_mesh.hpp:16
NiHu::create_mesh
mesh< tmp::vector< typename tag2type< Args >::type... > > create_mesh(nodes_t const &nodes, elements_t const &elements, Args...)
factory function to create a mesh from nodes and elements matrices
Definition: mesh.hpp:298
NiHu::create_rectangle_mesh
NiHu::mesh< tmp::vector< typename NiHu::tag2type< ElemTag >::type > > create_rectangle_mesh(double Lx, double Ly, size_t nx, size_t ny, orientation ori=outward, ElemTag tag=ElemTag())
Create a homogeneous rectangular boundary mesh.
Definition: lib_mesh.hpp:82
lib_element.hpp
NiHu::mesh
container class for a mesh
Definition: mesh.hpp:110
NiHu::create_circle_mesh
NiHu::mesh< tmp::vector< typename NiHu::tag2type< ElemTag >::type > > create_circle_mesh(double r, size_t nElem, orientation ori=outward, ElemTag tag=ElemTag())
Create a homogeneous circular boundary mesh.
Definition: lib_mesh.hpp:32
NiHu::outward
@ outward
The mesh is directed outward.
Definition: lib_mesh.hpp:18