Caribou
BaseRectangularQuad.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 
9 namespace caribou::geometry {
10 
11 template<typename Derived>
12 struct BaseRectangularQuad : public Element<Derived> {
13  // Types
14  using Base = Element<Derived>;
15 
16  using LocalCoordinates = typename Base::LocalCoordinates;
17  using WorldCoordinates = typename Base::WorldCoordinates;
18 
19  using GaussNode = typename Base::GaussNode;
20 
21  template <UNSIGNED_INTEGER_TYPE Dim>
22  using Vector = typename Base::template Vector<Dim>;
23 
24  template <UNSIGNED_INTEGER_TYPE Rows, UNSIGNED_INTEGER_TYPE Cols>
25  using Matrix = typename Base::template Matrix<Rows, Cols>;
26 
27  // Constants
28  static constexpr auto CanonicalDimension = Base::CanonicalDimension;
29  static constexpr auto Dimension = Base::Dimension;
30  static constexpr auto NumberOfNodesAtCompileTime = Base::NumberOfNodesAtCompileTime;
31  static constexpr auto NumberOfGaussNodesAtCompileTime = Base::NumberOfGaussNodesAtCompileTime;
32 
33  static_assert(Dimension == 2 or Dimension == 3, "Quads can only be of dimension 2 or 3.");
34 
35  using Size = Vector<CanonicalDimension>;
36  using Rotation = Matrix<Dimension,Dimension>;
37 
39  BaseRectangularQuad() : p_center(WorldCoordinates::Constant(0)), p_H(Size::Constant(2)), p_R(Rotation::Identity()) {}
40 
42  explicit BaseRectangularQuad(WorldCoordinates center) : p_center(center), p_H(Size::Constant(2)), p_R(Rotation::Identity()) {}
43 
45  BaseRectangularQuad(WorldCoordinates center, Size H) : p_center(center), p_H(H), p_R(Rotation::Identity()) {}
46 
48  BaseRectangularQuad(WorldCoordinates center, Rotation R) : p_center(center), p_H(Size::Constant(2)), p_R(R) {}
49 
51  BaseRectangularQuad(WorldCoordinates center, Size H, Rotation R) : p_center(center), p_H(H), p_R(R) {}
52 
53  // Public methods common to all rectangular quad types
54 
59  inline auto edges() const {
60  return self().boundary_elements_node_indices();
61  }
62 
64  inline auto rotation() const -> const Rotation & {
65  return p_R;
66  };
67 
69  inline auto size() const -> const Size & {
70  return p_H;
71  };
72 
74  inline auto T(const LocalCoordinates & coordinates) const -> WorldCoordinates {
75  if constexpr (Dimension == 2) {
76  return p_center + p_R * (coordinates.cwiseProduct(p_H / 2.));
77  } else {
78  WorldCoordinates p;
79  p.template block<CanonicalDimension, 1>(0,0) = coordinates.cwiseProduct(p_H / 2.);
80  p[2] = 0.;
81  return p_center + p_R * p;
82  }
83  }
84 
85 private:
86  // Implementations
87  friend struct Element<Derived>;
88  [[nodiscard]]
89  inline auto get_number_of_nodes() const {return NumberOfNodesAtCompileTime;}
90  [[nodiscard]]
91  inline auto get_number_of_gauss_nodes() const {return NumberOfGaussNodesAtCompileTime;}
92  inline auto get_center() const {return p_center;};
93  [[nodiscard]]
94  inline auto get_number_of_boundary_elements() const -> UNSIGNED_INTEGER_TYPE {return 4;};
95 
96  auto self() -> Derived& { return *static_cast<Derived*>(this); }
97  auto self() const -> const Derived& { return *static_cast<const Derived*>(this); }
98 protected:
99  WorldCoordinates p_center;
100  Size p_H;
101  Rotation p_R;
102 };
103 }
caribou::geometry::BaseRectangularQuad::edges
auto edges() const
Get the list of node indices of the edges.
Definition: BaseRectangularQuad.h:59
caribou::geometry::Element< Derived >::boundary_elements_node_indices
auto boundary_elements_node_indices() const -> const auto &
Get the list of node indices of the boundary elements.
Definition: Element.h:100
caribou::geometry::Element
Definition: Element.h:28
caribou::geometry::BaseRectangularQuad::BaseRectangularQuad
BaseRectangularQuad()
Default empty constructor.
Definition: BaseRectangularQuad.h:39
caribou::geometry::BaseRectangularQuad
Definition: BaseRectangularQuad.h:12
caribou::geometry::BaseRectangularQuad::BaseRectangularQuad
BaseRectangularQuad(WorldCoordinates center, Size H, Rotation R)
Constructor by specifying the center point, the size (hx, hy, hz) and the rotation.
Definition: BaseRectangularQuad.h:51
caribou::geometry::BaseRectangularQuad::p_R
Rotation p_R
Rotation matrix (a.k.a. the local coordinates frame) at the center of the quad.
Definition: BaseRectangularQuad.h:101
caribou::geometry::BaseRectangularQuad::BaseRectangularQuad
BaseRectangularQuad(WorldCoordinates center)
Constructor by specifying the center point.
Definition: BaseRectangularQuad.h:42
caribou::geometry::BaseRectangularQuad::T
auto T(const LocalCoordinates &coordinates) const -> WorldCoordinates
Compute the transformation of a local position {u,v} to its world position {x,y[ ,...
Definition: BaseRectangularQuad.h:74
caribou::geometry::BaseRectangularQuad::p_H
Size p_H
Size of the quad {hx, hy}.
Definition: BaseRectangularQuad.h:100
caribou::geometry::BaseRectangularQuad::BaseRectangularQuad
BaseRectangularQuad(WorldCoordinates center, Size H)
Constructor by specifying the center point and the size (hx, hy, hz)
Definition: BaseRectangularQuad.h:45
caribou::geometry::BaseRectangularQuad::rotation
auto rotation() const -> const Rotation &
Get the rotation frame of the quad.
Definition: BaseRectangularQuad.h:64
caribou::geometry::BaseRectangularQuad::p_center
WorldCoordinates p_center
Position of the center point of the quad.
Definition: BaseRectangularQuad.h:99
caribou::geometry::BaseRectangularQuad::BaseRectangularQuad
BaseRectangularQuad(WorldCoordinates center, Rotation R)
Constructor by specifying the center point and the rotation.
Definition: BaseRectangularQuad.h:48
caribou::geometry::Element< Derived >::center
auto center() const -> WorldCoordinates
Get the position at the center of the element.
Definition: Element.h:154
caribou::geometry::BaseRectangularQuad::size
auto size() const -> const Size &
Get the size (hx, hy) of the quad.
Definition: BaseRectangularQuad.h:69