NiHu  2.0
corner_angle.hpp
1 #ifndef NIHU_CORNER_ANGLE_HPP_INCLUDED
2 #define NIHU_CORNER_ANGLE_HPP_INCLUDED
3 
4 #include "element.hpp"
5 #include "shapeset.hpp"
6 
7 #include "boost/math/constants/constants.hpp"
8 
9 namespace NiHu
10 {
11 
12 
13 template <class Elem, class NSet, unsigned dimension = Elem::domain_t::dimension>
15 
16 template <class Elem, class Nset>
17 class corner_angle_computer<Elem, Nset, 1>
18 {
19  typedef Elem elem_t;
20  typedef Nset nset_t;
21 public:
22  static double eval(elem_t const&, unsigned nset_corner_idx)
23  {
24  // Position DOF can be 0 (corner) or 1 (inside)
25  return 0.5 * (1 + nset_t::position_dof(nset_corner_idx));
26  }
27 };
28 
29 template <class Elem, class Nset>
30 class corner_angle_computer<Elem, Nset, 2>
31 {
32  typedef Elem elem_t;
33  typedef Nset nset_t;
34 
35  typedef typename elem_t::domain_t domain_t;
36 
37  static unsigned const num_domain_corners = domain_t::num_corners;
38 
39 public:
40  static double eval(Elem const& elem, unsigned nset_corner_idx)
41  {
42  auto position_dof = nset_t::position_dof(nset_corner_idx);
43 
44  if (position_dof == 0) // Nset corner is in domain corner
45  {
46  int domain_corner_idx = nset_t::node_to_domain_corner(nset_corner_idx);
47 
48  auto cp = domain_t::get_corner((domain_corner_idx + num_domain_corners-1) % num_domain_corners);
49  auto c0 = domain_t::get_corner(domain_corner_idx);
50  auto cn = domain_t::get_corner((domain_corner_idx + 1)%num_domain_corners);
51 
52  auto dcp = (cp - c0);
53  auto dcn = (cn - c0);
54 
55  auto dx = elem.get_dx(nset_t::corner_at(nset_corner_idx));
56 
57  auto dx_p = (dx * dcp).normalized();
58  auto dx_n = (dx * dcn).normalized();
59 
60 
61  double angle = std::acos(dx_p.dot(dx_n));
62 
63  return angle / (2.0 * boost::math::double_constants::pi);
64 
65  }
66  else
67  {
68  // Nset corner is on edge (return 0.5), or in domain (return 1.0)
69  return 0.5 * position_dof;
70  }
71  }
72 };
73 
74 } // namespace NiHu
75 
76 #endif /* NIHU_CORNER_ANGLE_HPP_INCLUDED */
NiHu::corner_angle_computer
Definition: corner_angle.hpp:14
NiHu::position_dof
position degree of freedom of a point in the intrinsic domain
Definition: shapeset.hpp:65
element.hpp
Declaration of element classes.
NiHu::volume_element::domain_t
typename base_t::domain_t domain_t
the domain type
Definition: element.hpp:637
shapeset.hpp
Definition of shape function sets.