NiHu  2.0
shapeset.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 
25 #ifndef SHAPESET_HPP_INCLUDED
26 #define SHAPESET_HPP_INCLUDED
27 
28 #include "../tmp/algorithm.hpp"
29 #include "../tmp/vector.hpp"
30 #include "../util/conditional_precompute.hpp"
31 #include "../util/materialize_sequence.hpp"
32 
33 #include "domain.hpp"
34 
35 #include <iostream>
36 #include <stdexcept>
37 #include <type_traits>
38 
39 namespace NiHu
40 {
41 
46 namespace shape_derivative_index
47 {
48  enum {
49  dXI = 0,
50  dETA = 1,
51  dXIXI = 0,
52  dXIETA = 1,
53  dETAXI = 1,
54  dETAETA = 2
55  };
56 }
57 
64 template <unsigned d>
65 struct position_dof : std::integral_constant<unsigned, d> {};
74 
75 template <int index>
76 struct corner_index : std::integral_constant<int, index> {};
77 
78 typedef corner_index<-1> not_corner;
79 
80 // forward declaration
81 template <class Derived, unsigned Order>
83 
89 constexpr unsigned num_derivatives(unsigned order, unsigned dim)
90 {
91  return order == 0 ? 1 : (order == 1 ? dim : dim * (dim + 1) / 2);
92 }
93 
95 namespace shape_set_traits
96 {
98  template <class Derived>
99  struct name
100  {
101  static const std::string value;
102  };
103 
105  template <class Derived>
106  struct domain;
107 
109  template <class Derived>
110  struct num_nodes;
111 
113  template <class Derived>
114  struct id
115  {
116  enum {
119  };
120  };
121 
123  template <class Derived>
125 
129  template <class Derived>
131 
133  template <class Derived, unsigned Order>
135 
137  template <class Derived, unsigned Order>
139  {
140  typedef Eigen::Matrix<
144  > type;
145  };
146 
148  template <class Derived, unsigned Order>
150  typename shape_complexity<Derived, Order>::type,
151  shape_function<Derived, Order>,
152  typename domain<Derived>::type::xi_t
153  > {};
154 
156  template <class Derived, unsigned Order>
158  {
160  };
161 
163  template <class Derived>
165 
167  template <class Derived>
169  {
170  typedef typename sequence_materializer<
172  >::eigen_vector_t type;
173  };
174 
175  template <class Derived>
177 
179  template <class Derived>
181  {
182  typedef typename sequence_materializer<
184  >::eigen_vector_t type;
185  };
186 
187 }
188 
189 
194 template <class Derived>
196 {
197 public:
200 
202  enum {
211  };
212 
214  typedef typename domain_t::scalar_t scalar_t;
216  typedef typename domain_t::xi_t xi_t;
217 
218  typedef std::array<xi_t, num_nodes> corners_t;
219  typedef typename corners_t::const_iterator corner_iterator_t;
220 
222  template <unsigned Order>
224 
225  typedef typename shape_value_type<0>::type shape_t;
226  typedef typename shape_value_type<1>::type dshape_t;
227  typedef typename shape_value_type<2>::type ddshape_t;
228 
229  template <unsigned Order>
230  static typename shape_set_traits::shape_return_type<Derived, Order>::type
231  eval_shape(xi_t const &xi)
232  {
234  }
235 
236  typedef typename shape_set_traits::position_dof_vector<Derived>::type position_dof_vector;
237  typedef typename shape_set_traits::corner_index_vector<Derived>::type corner_index_vector;
238 
240  static corner_iterator_t corner_begin()
241  {
242  return Derived::corner_begin_impl();
243  }
244 
246  static corner_iterator_t corner_end()
247  {
248  return Derived::corner_begin() + num_nodes;
249  }
250 
255  static xi_t const &corner_at(size_t idx)
256  {
257  return *(corner_begin() + idx);
258  }
259 
264  static unsigned node_to_domain_corner(unsigned idx)
265  {
266  typedef typename shape_set_traits::corner_index_vector_mat<Derived>::type runtime_corner_index_vector_t;
267  static runtime_corner_index_vector_t runtime_corner_index_vector = materialize_sequence(corner_index_vector());
268  int index = runtime_corner_index_vector[idx];
269  if (index < 0)
270  throw std::runtime_error("Node " + std::to_string(idx) + " is not a corner node in " + shape_set_traits::name<Derived>::value);
271  return index;
272  }
273 
274 
279  static unsigned position_dof(unsigned idx)
280  {
281  typedef typename shape_set_traits::position_dof_vector_mat<Derived>::type runtime_position_dof_vector_t;
282  static runtime_position_dof_vector_t runtime_position_dof_vector = materialize_sequence(position_dof_vector());
283  return runtime_position_dof_vector[idx];
284  }
285 
286 };
287 
288 // Forward declaration
289 template <class Domain>
291 
292 namespace shape_set_traits
293 {
294  template <class Domain>
295  struct domain<constant_shape_set<Domain> > : Domain {};
296 
297  template <class Domain>
298  struct num_nodes<constant_shape_set<Domain> >
299  {
300  enum { value = 1 };
301  };
302 
303  template <class Domain>
305  {
306  enum { value = 0 };
307  };
308 
309  template <class Domain>
311  {
312  enum { value = 0 };
313  };
314 
315  template <class Domain>
317 
318  template <class Domain>
320 
321  template <class Domain>
323 
324  template <class Domain>
326  {
328  };
329 
330  template <class Domain>
332  {
334  };
335 
336 }
337 
342 template <class Domain>
343 class constant_shape_set : public shape_set_base<constant_shape_set<Domain> >
344 {
345 public:
349  typedef typename base_t::domain_t domain_t;
351  typedef typename base_t::xi_t xi_t;
352  typedef typename base_t::corners_t corners_t;
353  typedef typename base_t::corner_iterator_t corner_iterator_t;
354 
358  static corner_iterator_t corner_begin_impl()
359  {
360  // Note: function-local static is used here in order to avoid
361  // ambigous order of initialization of Domain's and ShapeSet's
362  // static members.
363  static corners_t const m_corners = { Domain::get_center() };
364 
365  return m_corners.cbegin();
366  }
367 };
368 
369 
370 template <class Domain>
372 {
373  typedef typename shape_set_traits::shape_value_type<constant_shape_set<Domain>, 0>::type shape_t;
374  typedef typename shape_set_traits::domain<constant_shape_set<Domain> >::type::xi_t xi_t;
375 public:
376  static shape_t eval(xi_t const &)
377  {
378  return shape_t::Ones();
379  }
380 };
381 
382 template <class Domain>
384 {
385  typedef typename shape_set_traits::shape_value_type<constant_shape_set<Domain>, 1>::type shape_t;
386  typedef typename shape_set_traits::domain<constant_shape_set<Domain>>::type::xi_t xi_t;
387 public:
388  static shape_t eval(xi_t const &xi)
389  {
390  return shape_t::Zero();
391  }
392 };
393 
394 template <class Domain>
396 {
397  typedef typename shape_set_traits::shape_value_type<constant_shape_set<Domain>, 2>::type shape_t;
398  typedef typename shape_set_traits::domain<constant_shape_set<Domain>>::type::xi_t xi_t;
399 public:
400  static shape_t eval(xi_t const &xi)
401  {
402  return shape_t::Zero();
403  }
404 };
405 
406 
407 // Forward declaration
408 template <class Domain>
410 
412 namespace shape_set_traits
413 {
414  template <class Domain>
415  struct domain<isoparam_shape_set<Domain> > : Domain {};
416 
417  template <class Domain>
418  struct num_nodes<isoparam_shape_set<Domain> >
419  {
420  enum { value = Domain::num_corners };
421  };
422 
423  template <class Domain>
425  {
426  enum { value = 1 };
427  };
428 
429  template <class Domain>
431  dof0,
432  num_nodes<isoparam_shape_set<Domain> >::value,
433  tmp::vector<>
434  > {};
435 
436  template <class Domain>
438  std::integral_constant<int, 0>,
439  num_nodes<isoparam_shape_set<Domain> >::value,
440  tmp::vector<>,
441  1
442  > {};
443 }
444 
448 template <class Domain>
449 class isoparam_shape_set
450  : public shape_set_base<isoparam_shape_set<Domain> >
451 {
452 public:
456  typedef typename base_t::domain_t domain_t;
457 
459  typedef typename base_t::xi_t xi_t;
460 
461  typedef typename base_t::corners_t corners_t;
462  typedef typename base_t::corner_iterator_t corner_iterator_t;
463 
467  static corner_iterator_t corner_begin_impl()
468  {
469  return domain_t::get_corners().cbegin();
470  }
471 };
472 
473 } // end of namespace NiHu
474 
475 #endif // SHAPESET_HPP_INCLUDED
476 
NiHu::shape_derivative_index::dETAXI
@ dETAXI
index of eta_xi in 2nd derivative matrix
Definition: shapeset.hpp:53
tmp::constant_sequence
generate a constant sequence
Definition: algorithm.hpp:420
NiHu::conditional_precompute::eval
static return_type eval(Args const &...args)
return object computed by the function class
Definition: conditional_precompute.hpp:61
NiHu::shape_set_traits::domain
Defines the domain where the shape function set is defined.
Definition: shapeset.hpp:106
NiHu::corner_index
Definition: shapeset.hpp:76
NiHu::shape_set_base::shape_value_type
type of an vector
Definition: shapeset.hpp:223
NiHu::isoparam_shape_set::corner_begin_impl
static corner_iterator_t corner_begin_impl()
return begin iterator to the corner nodes
Definition: shapeset.hpp:467
NiHu::shape_set_base::corner_begin
static corner_iterator_t corner_begin()
return begin iterator of corner nodes
Definition: shapeset.hpp:240
NiHu::shape_derivative_index::dXIXI
@ dXIXI
index of xi_xi in 2nd derivative matrix
Definition: shapeset.hpp:51
NiHu::isoparam_shape_set::domain_t
base_t::domain_t domain_t
the domain type
Definition: shapeset.hpp:456
NiHu::isoparam_shape_set::base_t
shape_set_base< isoparam_shape_set< Domain > > base_t
the CRTP base class
Definition: shapeset.hpp:454
NiHu::shape_set_traits::position_dof_vector
defines the nodal degrees of freedoms of the shape functions
Definition: shapeset.hpp:164
tmp::vector
Compile time vector with an arbitrary number of arguments.
Definition: vector.hpp:42
NiHu::num_derivatives
constexpr unsigned num_derivatives(unsigned order, unsigned dim)
return the number of partial derivatives in dim dimensions In 1D there is one partial derivative and ...
Definition: shapeset.hpp:89
NiHu::shape_set_base::jacobian_order
@ jacobian_order
the Jacobian polynomial order
Definition: shapeset.hpp:208
NiHu::position_dof
position degree of freedom of a point in the intrinsic domain
Definition: shapeset.hpp:65
NiHu::shape_set_base::corner_end
static corner_iterator_t corner_end()
return end iterator of corner nodes
Definition: shapeset.hpp:246
NiHu::conditional_precompute::return_type
functor_ret_type return_type
the return type of the static function eval
Definition: conditional_precompute.hpp:58
NiHu::constant_shape_set::corner_begin_impl
static corner_iterator_t corner_begin_impl()
return begin iterator to the corner nodes
Definition: shapeset.hpp:358
NiHu::shape_derivative_index::dETAETA
@ dETAETA
index of eta_eta in 2nd derivative matrix
Definition: shapeset.hpp:54
NiHu::domain_traits::id
Assigns an id to the domain.
Definition: domain.hpp:54
NiHu::shape_set_base::position_dof
static unsigned position_dof(unsigned idx)
assign position dof value to node
Definition: shapeset.hpp:279
NiHu::isoparam_shape_set::xi_t
base_t::xi_t xi_t
the xi location vector type
Definition: shapeset.hpp:459
NiHu::shape_set_base
Shapeset base class for CRTP.
Definition: shapeset.hpp:195
NiHu::shape_set_traits::corner_index_vector
Definition: shapeset.hpp:176
NiHu::shape_set_traits::name::value
static const std::string value
the textual name
Definition: shapeset.hpp:101
NiHu::constant_shape_set
Constant interpolation functions.
Definition: shapeset.hpp:290
NiHu::shape_set_base::domain_t
shape_set_traits::domain< Derived >::type domain_t
Domain.
Definition: shapeset.hpp:199
NiHu::shape_set_traits::corner_index_vector_mat
the materialized corner index vector type
Definition: shapeset.hpp:180
NiHu::conditional_precompute
Conditionally precompute and store objects.
Definition: conditional_precompute.hpp:50
NiHu::shape_set_traits::jacobian_order
Defines the polynomial order of the shape set's Jacobian.
Definition: shapeset.hpp:130
NiHu::shape_set_base::node_to_domain_corner
static unsigned node_to_domain_corner(unsigned idx)
assign domain corner to node
Definition: shapeset.hpp:264
domain.hpp
declaration of CRTP base class NiHu::domain_base
NiHu::shape_set_traits::position_dof_vector_mat
the materialized position vector type
Definition: shapeset.hpp:168
NiHu::matrix_function_complexity::constant
the returned matrix is constant and can be stored
Definition: conditional_precompute.hpp:38
NiHu::shape_set_base::polynomial_order
@ polynomial_order
the shape set polynomial order
Definition: shapeset.hpp:206
NiHu::shape_set_traits::name
The shape set's textual id - used for debug information.
Definition: shapeset.hpp:99
NiHu::constant_shape_set::xi_t
base_t::xi_t xi_t
type of the domain variable
Definition: shapeset.hpp:351
NiHu::shape_set_base::scalar_t
domain_t::scalar_t scalar_t
scalar type inherited from the domain
Definition: shapeset.hpp:214
NiHu::constant_shape_set::domain_t
base_t::domain_t domain_t
the domain type
Definition: shapeset.hpp:349
NiHu::shape_derivative_index::dXI
@ dXI
index of xi in 1st derivative matrix
Definition: shapeset.hpp:49
NiHu::shape_set_base::num_nodes
@ num_nodes
Definition: shapeset.hpp:204
NiHu::matrix_function_complexity::zero
the returned matrix is a zero expression
Definition: conditional_precompute.hpp:36
NiHu::shape_set_base::xi_t
domain_t::xi_t xi_t
Definition: shapeset.hpp:216
NiHu::shape_set_traits::shape_return_type
Defines the return type of the shape function matrix.
Definition: shapeset.hpp:157
NiHu::shape_derivative_index::dXIETA
@ dXIETA
index of xi_eta in 2nd derivative matrix
Definition: shapeset.hpp:52
NiHu::shape_derivative_index::dETA
@ dETA
index of eta in 1st derivative matrix
Definition: shapeset.hpp:50
NiHu::shape_set_traits::shape_value_type
Defines the value type of the shape function matrix (and derivatives)
Definition: shapeset.hpp:138
NiHu::shape_set_traits::polynomial_order
Defines the polynomial order of the shape set.
Definition: shapeset.hpp:124
NiHu::isoparam_shape_set
Isoparametric shape sets.
Definition: shapeset.hpp:409
NiHu::shape_set_traits::factory_functor
Defines the factory functor that computes or stores the shape functions.
Definition: shapeset.hpp:149
NiHu::shape_set_traits::num_nodes
Defines the number of shape functions in the set.
Definition: shapeset.hpp:110
tmp::arithmetic_sequence
generate an arithmetic sequence
Definition: algorithm.hpp:457
NiHu::sequence_materializer
Definition: materialize_sequence.hpp:11
NiHu::constant_shape_set::base_t
shape_set_base< constant_shape_set< Domain > > base_t
the CRTP base class type
Definition: shapeset.hpp:347
NiHu::shape_function
Definition: shapeset.hpp:82
NiHu::shape_set_base::corner_at
static const xi_t & corner_at(size_t idx)
return corner at a given node number
Definition: shapeset.hpp:255
NiHu::shape_set_traits::shape_complexity
Defines the complexity to determine if the shape functions can be precomputed or not.
Definition: shapeset.hpp:134
NiHu::shape_set_traits::id
Assigns an id to the shape set.
Definition: shapeset.hpp:114