Medusa  1.1
Coordinate Free Mehless Method implementation
RotatedShape.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_DOMAINS_ROTATEDSHAPE_HPP_
2 #define MEDUSA_BITS_DOMAINS_ROTATEDSHAPE_HPP_
3 
9 #include "RotatedShape_fwd.hpp"
10 #include "DomainDiscretization.hpp"
11 #include "DomainShape.hpp"
13 
14 namespace mm {
15 
16 template <typename vec_t>
18  const Eigen::Matrix<scalar_t, dim, dim>& Q) : sh(sh), Q(Q) {
19  auto* rsh = dynamic_cast<const RotatedShape<vec_t>*>(&sh);
20  if (rsh != nullptr) { // collapse double rotations
21  this->sh = rsh->sh;
22  this->Q = this->Q * rsh->Q;
23  }
24  assert_msg((Q*Q.transpose()).isApprox(Q.Identity(), 1e-12),
25  "Matrix Q is not orthogonal, QQ^T - I = %s", (Q*Q.transpose())-Q.Identity());
26 }
27 
28 template <typename vec_t>
29 std::pair<vec_t, vec_t> RotatedShape<vec_t>::bbox() const {
30  auto bb = sh->bbox();
31  vec_t m = Q*bb.first;
32  vec_t M = m, t;
33  for (unsigned i = 1; i < (1 << dim); ++i) {
34  for (unsigned j = 0; j < dim; ++j) {
35  t[j] = (i & (1u << j)) ? bb.second[j] : bb.first[j];
36  }
37  t = Q*t;
38  for (unsigned j = 0; j < dim; ++j) {
39  if (t[j] < m[j]) m[j] = t[j];
40  if (t[j] > M[j]) M[j] = t[j];
41  }
42  }
43  return {m, M};
44 }
45 
47 template <typename vec_t>
50  auto d = sh->discretizeBoundaryWithStep(step, type);
51  d.rotate(Q);
52  return d;
53 }
54 
55 template <typename vec_t>
56 DomainDiscretization<vec_t>
57 RotatedShape<vec_t>::discretizeWithStep(scalar_t step, int internal_type, int boundary_type) const {
58  auto d = sh->discretizeWithStep(step, internal_type, boundary_type);
59  d.rotate(Q);
60  return d;
61 }
62 
63 template <typename vec_t>
64 DomainDiscretization<vec_t>
65 RotatedShape<vec_t>::discretizeWithDensity(const std::function<scalar_t(vec_t)>& dr,
66  int internal_type, int boundary_type) const {
67  auto d = sh->discretizeWithDensity(dr, internal_type, boundary_type);
68  d.rotate(Q);
69  return d;
70 }
71 
72 template <typename vec_t>
73 DomainDiscretization<vec_t>
74 RotatedShape<vec_t>::discretizeBoundaryWithDensity(const std::function<scalar_t(vec_t)>& dr,
75  int type) const {
76  auto d = sh->discretizeBoundaryWithDensity(dr, type);
77  d.rotate(Q);
78  return d;
79 }
81 
82 } // namespace mm
83 
84 #endif // MEDUSA_BITS_DOMAINS_ROTATEDSHAPE_HPP_
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::DomainDiscretization
Class representing domain discretization along with an associated shape.
Definition: DomainDiscretization_fwd.hpp:46
DomainDiscretization.hpp
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::RotatedShape
Class for working with rotated (or mirrored) domain shapes.
Definition: RotatedShape_fwd.hpp:27
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::RotatedShape::sh
deep_copy_unique_ptr< DomainShape< vec_t > > sh
Shape to be transformed.
Definition: RotatedShape_fwd.hpp:33
mm::DomainShape::discretizeWithStep
virtual DomainDiscretization< vec_t > discretizeWithStep(scalar_t step, int internal_type, int boundary_type) const
Returns a discretization of this shape with approximately uniform distance step between nodes.
Definition: DomainShape_fwd.hpp:137
mm::DomainShape
Base class for geometric shapes of domains.
Definition: DomainShape_fwd.hpp:52
DomainShape.hpp
RotatedShape_fwd.hpp
mm::DomainShape::discretizeBoundaryWithDensity
virtual DomainDiscretization< vec_t > discretizeBoundaryWithDensity(const std::function< scalar_t(vec_t)> &dr, int type) const =0
Discretizes boundary with given density and fill engine.
assert.hpp
mm::DomainShape::discretizeWithDensity
virtual DomainDiscretization< vec_t > discretizeWithDensity(const std::function< scalar_t(vec_t)> &dr, int internal_type, int boundary_type) const
Returns a discretization of the domain with spatially variable step.
Definition: DomainShape.hpp:77
mm::RotatedShape::Q
Eigen::Matrix< scalar_t, dim, dim > Q
Orthogonal transformation matrix.
Definition: RotatedShape_fwd.hpp:34
mm::DomainShape::discretizeBoundaryWithStep
virtual DomainDiscretization< vec_t > discretizeBoundaryWithStep(scalar_t step, int type) const
Returns a discretization of the boundary of this shape with approximately uniform distance step betwe...
Definition: DomainShape_fwd.hpp:118
mm::RotatedShape::RotatedShape
RotatedShape(const DomainShape< vec_t > &sh, const Eigen::Matrix< scalar_t, dim, dim > &Q)
Construct a transformed shape by specifying a shape and an orthogonal transformation matrix.
Definition: RotatedShape.hpp:17
mm::RotatedShape::bbox
std::pair< vec_t, vec_t > bbox() const override
Return the bounding box of the domain.
Definition: RotatedShape.hpp:29