Caribou
BaseSegment.h
1 #pragma once
2 
3 #include <Caribou/config.h>
4 #include <Caribou/constants.h>
5 #include <Caribou/Geometry/Element.h>
6 #include <Eigen/Core>
7 
8 namespace caribou::geometry {
9 
10 template<typename Derived>
11 struct BaseSegment : public Element<Derived> {
12  // Types
13  using Base = Element<Derived>;
14 
15  using LocalCoordinates = typename Base::LocalCoordinates;
16  using WorldCoordinates = typename Base::WorldCoordinates;
17 
18  using GaussNode = typename Base::GaussNode;
19 
20  template <UNSIGNED_INTEGER_TYPE Dim>
21  using Vector = typename Base::template Vector<Dim>;
22 
23  template <UNSIGNED_INTEGER_TYPE Rows, UNSIGNED_INTEGER_TYPE Cols>
24  using Matrix = typename Base::template Matrix<Rows, Cols>;
25 
26  // Constants
27  static constexpr auto CanonicalDimension = Base::CanonicalDimension;
28  static constexpr auto Dimension = Base::Dimension;
29  static constexpr auto NumberOfNodesAtCompileTime = Base::NumberOfNodesAtCompileTime;
30  static constexpr auto NumberOfGaussNodesAtCompileTime = Base::NumberOfGaussNodesAtCompileTime;
31 
33  BaseSegment() = default;
34 
36  template<typename EigenType, REQUIRES(EigenType::RowsAtCompileTime == NumberOfNodesAtCompileTime)>
37  explicit BaseSegment(Eigen::EigenBase<EigenType> & nodes) :p_nodes(nodes.derived().template cast<typename Base::Scalar>()) {}
38 
40  template<typename EigenType, REQUIRES(EigenType::RowsAtCompileTime == NumberOfNodesAtCompileTime)>
41  explicit BaseSegment(const Eigen::EigenBase<EigenType> & nodes) :p_nodes(nodes.derived().template cast<typename Base::Scalar>()) {}
42 
44  template<typename EigenType, int Options, typename StrideType>
45  explicit BaseSegment(const Eigen::Ref<EigenType, Options, StrideType> & nodes) : p_nodes(nodes.derived().template cast<typename Base::Scalar>()) {}
46 
48  template <
49  typename ...Nodes,
50  REQUIRES(NumberOfNodesAtCompileTime == sizeof...(Nodes)+1)
51  >
52  explicit BaseSegment(const WorldCoordinates & first_node, Nodes&&...remaining_nodes)
53  {
54  construct_from_nodes<0>(first_node, std::forward<Nodes>(remaining_nodes)...);
55  }
56 
57 private:
58  // Implementations
59  friend struct Element<Derived>;
60  [[nodiscard]]
61  inline auto get_number_of_nodes() const {return NumberOfNodesAtCompileTime;}
62  inline auto get_number_of_gauss_nodes() const {return NumberOfGaussNodesAtCompileTime;}
63  inline auto get_node(const UNSIGNED_INTEGER_TYPE & index) const {return WorldCoordinates(p_nodes.row(index));};
64  inline auto get_nodes() const -> const auto & {return p_nodes;};
65  inline auto get_center() const {return Base::world_coordinates(LocalCoordinates(0));};
66  inline auto get_contains_local(const LocalCoordinates & xi, const FLOATING_POINT_TYPE & eps) const -> bool {
67  const auto & u = xi[0];
68  return IN_CLOSED_INTERVAL(-1-eps, u, 1+eps);
69  }
70 
71  template <size_t index, typename ...Nodes, REQUIRES(sizeof...(Nodes) >= 1)>
72  inline
73  void construct_from_nodes(const WorldCoordinates & first_node, Nodes&&...remaining_nodes) {
74  p_nodes.row(index) = first_node;
75  construct_from_nodes<index+1>(std::forward<Nodes>(remaining_nodes)...);
76  }
77 
78  template <size_t index>
79  inline
80  void construct_from_nodes(const WorldCoordinates & last_node) {
81  p_nodes.row(index) = last_node;
82  }
83 protected:
84  Matrix<NumberOfNodesAtCompileTime, Dimension> p_nodes;
85 };
86 
87 }
caribou::geometry::BaseSegment::BaseSegment
BaseSegment(const WorldCoordinates &first_node, Nodes &&...remaining_nodes)
Constructor from a serie of nodes.
Definition: BaseSegment.h:52
caribou::geometry::Element< Derived >::world_coordinates
auto world_coordinates(const LocalCoordinates &coordinates) const -> WorldCoordinates
Get the world coordinates of a point from its local coordinates.
Definition: Element.h:157
caribou::geometry::Element
Definition: Element.h:28
caribou::geometry::BaseSegment::BaseSegment
BaseSegment(const Eigen::EigenBase< EigenType > &nodes)
Constructor from an Eigen matrix containing the positions of the segment's nodes.
Definition: BaseSegment.h:41
caribou::geometry::Element< Derived >::nodes
auto nodes() const
Get the set of nodes.
Definition: Element.h:67
caribou::geometry::BaseSegment
Definition: BaseSegment.h:11
caribou::geometry::BaseSegment::BaseSegment
BaseSegment()=default
Default empty constructor.
caribou::geometry::BaseSegment::BaseSegment
BaseSegment(const Eigen::Ref< EigenType, Options, StrideType > &nodes)
Constructor from an Eigen matrix reference containing the positions of the segment's nodes.
Definition: BaseSegment.h:45
caribou::geometry::BaseSegment::BaseSegment
BaseSegment(Eigen::EigenBase< EigenType > &nodes)
Constructor from an Eigen matrix containing the positions of the segment's nodes.
Definition: BaseSegment.h:37