NiHu  2.0
lib_domain.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-2019 Peter Fiala <fiala@hit.bme.hu>
4 // Copyright (C) 2012-2019 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 
21 
22 #ifndef LIB_DOMAIN_HPP_INCLUDED
23 #define LIB_DOMAIN_HPP_INCLUDED
24 
25 #include "../core/domain.hpp"
26 
27 namespace NiHu
28 {
29 
31 class line_domain;
32 
33 namespace domain_traits
34 {
36 template <>
38 
40 template <>
41 struct volume<line_domain> { static constexpr double value = 2.0; };
42 
44 template <>
45 struct num_corners<line_domain> { enum { value = 2 }; };
46 
48 template <>
49 struct num_edges<line_domain> { enum { value = 1 }; };
50 }
51 
53 class line_domain :
54  public domain_base<line_domain>
55 {
56 public:
58  static edges_t const &get_edges_impl() { return m_edges; }
60  static corners_t const &get_corners_impl() { return m_corners; }
62  static xi_t const &get_center_impl() { return m_center; }
63 
64  static xi_t constrain_inside_impl(xi_t const &xi)
65  {
66  xi_t res = xi;
67  res(0) = std::min(res(0), 1.);
68  res(0) = std::max(res(0), -1.);
69  return res;
70  }
71 
72 private:
73  static corners_t const m_corners;
74  static edges_t const m_edges;
75  static xi_t const m_center;
76 };
77 
79 class tria_domain;
80 
81 namespace domain_traits
82 {
84 template <>
86 
88 template <>
89 struct volume<tria_domain> { static constexpr double value = 0.5; };
90 
91 template <>
92 
93 struct num_corners<tria_domain> { enum { value = 3 }; };
94 
96 template <>
97 struct num_edges<tria_domain> { enum { value = 3 }; };
98 }
99 
101 class tria_domain :
102  public domain_base<tria_domain>
103 {
104 public:
106  static corners_t const &get_corners_impl() { return m_corners; }
108  static edges_t const &get_edges_impl() { return m_edges; }
110  static xi_t const &get_center_impl() { return m_center; }
111 
112  static xi_t constrain_inside_impl(xi_t const &xi)
113  {
114  xi_t res = xi;
115  scalar_t sum = res(0) + res(1);
116  scalar_t D = (sum - 1.) / 2.;
117  D = std::max(0., D); // D = 0 if xi + eta < 1
118 
119  for (size_t d = 0; d < dimension; d++)
120  {
121  res(d) -= D;
122  res(d) = std::min(res(d), 1.);
123  res(d) = std::max(res(d), 0.);
124  }
125  return res;
126  }
127 
128 private:
129  static corners_t const m_corners;
130  static edges_t const m_edges;
131  static xi_t const m_center;
132 };
133 
135 class quad_domain;
136 
137 namespace domain_traits
138 {
140 template <>
142 
144 template <>
145 struct volume<quad_domain> { static constexpr double value = 4.0; };
146 
148 template <>
149 struct num_corners<quad_domain> { enum { value = 4 }; };
150 
152 template <>
153 struct num_edges<quad_domain> { enum { value = 4 }; };
154 }
155 
157 class quad_domain :
158  public domain_base<quad_domain>
159 {
160 public:
162  static corners_t const &get_corners_impl() { return m_corners; }
164  static edges_t const &get_edges_impl() { return m_edges; }
166  static xi_t const &get_center_impl() { return m_center; }
167 
168  static xi_t constrain_inside_impl(xi_t const &xi)
169  {
170  xi_t res = xi;
171  for (size_t d = 0; d < dimension; d++)
172  {
173  res(d) = std::min(res(d), 1.);
174  res(d) = std::max(res(d), -1.);
175  }
176  return res;
177  }
178 
179 private:
180  static corners_t const m_corners;
181  static edges_t const m_edges;
182  static xi_t const m_center;
183 };
184 
186 class brick_domain;
187 
188 namespace domain_traits
189 {
191 template <>
193 
195 template <>
196 struct volume<brick_domain> { static constexpr double value = 8.0; };
197 
199 template <>
200 struct num_corners<brick_domain> { enum { value = 8 }; };
201 
203 template <>
204 struct num_edges<brick_domain> { enum { value = 12 }; };
205 }
206 
209  public domain_base<brick_domain>
210 {
211 public:
213  static corners_t const &get_corners_impl() { return m_corners; }
215  static edges_t const &get_edges_impl() { return m_edges; }
217  static xi_t const &get_center_impl() { return m_center; }
218 
219  static xi_t constrain_inside_impl(xi_t const &xi)
220  {
221  xi_t res = xi;
222  for (size_t d = 0; d < dimension; d++)
223  {
224  res(d) = std::min(res(d), 1.);
225  res(d) = std::max(res(d), -1.);
226  }
227  return res;
228  }
229 
230 private:
231  static corners_t const m_corners;
232  static edges_t const m_edges;
233  static xi_t const m_center;
234 };
235 
236 } // end of namespace NiHu
237 
238 #endif // LIB_DOMAIN_HPP_INCLUDED
239 
NiHu::domain_base< tria_domain >::dimension
@ dimension
space dimensions
Definition: domain.hpp:86
NiHu::tria_domain
a 2D triangle domain
Definition: lib_domain.hpp:101
NiHu::domain_traits::num_edges
defines the number of edges
Definition: domain.hpp:46
NiHu::brick_domain::get_corners_impl
static const corners_t & get_corners_impl()
return domain corners
Definition: lib_domain.hpp:213
NiHu::domain_base< tria_domain >::scalar_t
space_t::scalar_t scalar_t
coordinate scalar type
Definition: domain.hpp:89
NiHu::domain_base
Polygonal subset of the space. All elements are defined on a domain.
Definition: domain.hpp:71
NiHu::space
class representing a coordinate space with a scalar and a dimension
Definition: space.hpp:36
NiHu::quad_domain::get_corners_impl
static const corners_t & get_corners_impl()
return domain corners
Definition: lib_domain.hpp:162
NiHu::domain_traits::num_corners
defines the number of domain corners
Definition: domain.hpp:42
NiHu::line_domain
a 1D line domain
Definition: lib_domain.hpp:53
NiHu::line_domain::get_edges_impl
static const edges_t & get_edges_impl()
return domain edges
Definition: lib_domain.hpp:58
NiHu::line_domain::get_center_impl
static const xi_t & get_center_impl()
return domain center
Definition: lib_domain.hpp:62
NiHu::domain_traits::volume
Defines the domain's size (volume)
Definition: domain.hpp:50
NiHu::domain_traits::space_type
assigns a coordinate space to the domain
Definition: domain.hpp:38
NiHu::brick_domain::get_edges_impl
static const edges_t & get_edges_impl()
return domain edges
Definition: lib_domain.hpp:215
NiHu::tria_domain::get_edges_impl
static const edges_t & get_edges_impl()
return domain edges
Definition: lib_domain.hpp:108
NiHu::tria_domain::get_corners_impl
static const corners_t & get_corners_impl()
return domain corners
Definition: lib_domain.hpp:106
NiHu::quad_domain::get_center_impl
static const xi_t & get_center_impl()
return domain center
Definition: lib_domain.hpp:166
NiHu::quad_domain::get_edges_impl
static const edges_t & get_edges_impl()
return domain edges
Definition: lib_domain.hpp:164
NiHu::domain_base< line_domain >::xi_t
space_t::location_t xi_t
coordinate vector type
Definition: domain.hpp:91
NiHu::domain_base< line_domain >::edges_t
domain_edge_t edges_t[num_edges]
type of edges array
Definition: domain.hpp:97
NiHu::line_domain::get_corners_impl
static const corners_t & get_corners_impl()
return domain corners
Definition: lib_domain.hpp:60
NiHu::domain_base< line_domain >::corners_t
std::array< xi_t, num_corners > corners_t
type of corners array
Definition: domain.hpp:93
NiHu::brick_domain
a 3D brick domain
Definition: lib_domain.hpp:208
NiHu::quad_domain
a 2D quad domain
Definition: lib_domain.hpp:157
NiHu::tria_domain::get_center_impl
static const xi_t & get_center_impl()
return domain center
Definition: lib_domain.hpp:110
NiHu::brick_domain::get_center_impl
static const xi_t & get_center_impl()
return domain center
Definition: lib_domain.hpp:217