NiHu  2.0
plane_element_helper.hpp
Go to the documentation of this file.
1 // This file is a part of NiHu, a C++ BEM template library.
2 //
3 // Copyright (C) 2012-2014 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2014 Peter Rucz <rucz@hit.bme.hu>
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
25 #ifndef NIHU_PLANE_ELEMENT_HELPER_HPP_INCLUDED
26 #define NIHU_PLANE_ELEMENT_HELPER_HPP_INCLUDED
27 
28 namespace NiHu
29 {
30 
39 template <class elem_t>
41  elem_t const &elem,
42  typename elem_t::x_t const &x0,
43  typename elem_t::scalar_t r[],
44  typename elem_t::scalar_t theta[],
45  typename elem_t::scalar_t alpha[])
46 {
48  enum{ N = elem_t::domain_t::num_corners };
49 
50  auto const &C_old = elem.get_coords();
51 
52  typename elem_t::coords_t R, C;
53  for (unsigned i = 0; i < N; ++i)
54  {
55  R.col(i) = C_old.col(i) - x0;
56  r[i] = R.col(i).norm();
57  R.col(i) /= r[i];
58  C.col(i) = C_old.col(i) - C_old.col((i+1) % N);
59  C.col(i) /= C.col(i).norm();
60  }
61 
62  for (unsigned i = 0; i < N; ++i)
63  {
64  double cs = R.col(i).dot(R.col((i+1) % N));
65  if (cs >= 1.)
66  theta[i] = 0.;
67  else
68  theta[i] = std::acos(cs);
69  alpha[i] = std::acos(R.col(i).dot(C.col(i)));
70  }
71 }
72 
73 template <class matrixDerived, class vectorDerived>
74 void plane_elem_helper_mid(
75  Eigen::DenseBase<matrixDerived> const &coords,
76  Eigen::DenseBase<vectorDerived> const &x0,
77  double ref_distance[],
78  double theta_lim[],
79  double theta0[]
80 )
81 {
82  // geometrical parameters (planar helpers)
83  unsigned const N = coords.cols();
84  for (unsigned n = 0; n < N; ++n)
85  {
86  Eigen::Matrix<double, 2, 1> c1 = coords.topRows(2).col(n); // corner
87  Eigen::Matrix<double, 2, 1> c2 = coords.topRows(2).col((n + 1) % N); // next corner
88 
89  Eigen::Matrix<double, 2, 1> l = (c2 - c1).normalized(); // side unit vector
90 
91  Eigen::Matrix<double, 2, 1> d1 = c1 - x0.topRows(2); // vector to corners
92  Eigen::Matrix<double, 2, 1> d0 = d1 - l * d1.dot(l); // perpendicular to side
93 
94  theta_lim[n] = std::atan2(d1(1), d1(0)); // corner angle
95  theta0[n] = std::atan2(d0(1), d0(0)); // mid angle
96  ref_distance[n] = d0.norm(); // distance to side
97  }
98 }
99 
110 template <class V>
111 Eigen::Matrix<double, 3, 3> plane_elem_transform(
112  Eigen::DenseBase<V> const &v1_in,
113  Eigen::DenseBase<V> const &v2_in)
114 {
116  Eigen::Matrix<double, 3, 1> v1 = v1_in;
117  Eigen::Matrix<double, 3, 1> v2 = v2_in;
118 
119  Eigen::Matrix<double, 3, 3> T;
120  T.col(0) = v1.normalized();
121  T.col(2) = v1.cross(v2).normalized();
122  T.col(1) = T.col(2).cross(T.col(0)).normalized();
123 
124  return T;
125 }
126 
127 } // end of namespace NiHu
128 
129 #endif /* NIHU_PLANE_ELEMENT_HELPER_HPP_INCLUDED */
NiHu::plane_element_helper
void plane_element_helper(elem_t const &elem, typename elem_t::x_t const &x0, typename elem_t::scalar_t r[], typename elem_t::scalar_t theta[], typename elem_t::scalar_t alpha[])
compute angles and radii in a plane element
Definition: plane_element_helper.hpp:40
NiHu::volume_element
class describing a volume element that has no normal vector
Definition: element.hpp:455
NiHu::plane_elem_transform
Eigen::Matrix< double, 3, 3 > plane_elem_transform(Eigen::DenseBase< V > const &v1_in, Eigen::DenseBase< V > const &v2_in)
Transformation matrix to get planar element parallel to the x-y plane.
Definition: plane_element_helper.hpp:111
C
Definition: bbfmm_covariance.cpp:47
NiHu::volume_element::coords_t
element_traits::coords_type< Derived >::type coords_t
matrix type that stores the element's corner nodes
Definition: element.hpp:235
NiHu::volume_element::x_t
element_traits::location_value_type< Derived, 0 >::type x_t
type of the element's physical location variable
Definition: element.hpp:220