DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
Geometric.hpp
Go to the documentation of this file.
1#pragma once
2#include "DNDS/Defines.hpp"
3
4namespace DNDS::Geom
5{
6 using t_index = int32_t;
7 const t_index invalid_index = INT32_MAX;
8 using t_real = double;
9 using tPoint = Eigen::Vector3d;
10 using tJacobi = Eigen::Matrix3d;
11 using tGPoint = Eigen::Matrix3d;
12 using tPointMap = Eigen::Map<tPoint, Eigen::Unaligned>;
13 using tPointConstMap = Eigen::Map<const tPoint, Eigen::Unaligned>;
14 using tGPointMap = Eigen::Map<tGPoint, Eigen::Unaligned>;
15 using tGPointConstMap = Eigen::Map<const tGPoint, Eigen::Unaligned>;
16
18 {
19 std::array<real, 3> d;
22 {
23 return tPointMap{d.data()};
24 }
25
26 DNDS_DEVICE_CALLABLE [[nodiscard]] auto map() const
27 {
28 return tPointConstMap{d.data()};
29 }
30 };
31
33 {
34 std::array<real, 9> d;
37 {
38 return tGPointMap{d.data()};
39 }
40
41 DNDS_DEVICE_CALLABLE [[nodiscard]] auto map() const
42 {
43 return tGPointConstMap{d.data()};
44 }
45 };
46
47 static_assert(std::is_trivially_copyable_v<tPointPortable>);
48 static_assert(std::is_trivially_copyable_v<tGPointPortable>);
49
50 using tSmallCoords = Eigen::Matrix<real, 3, Eigen::Dynamic>;
52 {
53 auto operator[](Eigen::Index i)
54 {
55 return tSmallCoords::operator()(EigenAll, i);
56 }
57
58 auto operator[](Eigen::Index i) const
59 {
60 return tSmallCoords::operator()(EigenAll, i);
61 }
62 };
63
64 static_assert(std::is_signed_v<t_index>);
65
66 using tLocalMatStruct = std::vector<std::vector<index>>;
67}
68
69namespace DNDS::Geom
70{
71
72 inline std::vector<real> JacobiToSTDVector(const tJacobi &j)
73 {
74 std::vector<real> ret(9);
75 for (int i = 0; i < 9; i++)
76 ret[i] = j(i);
77 return ret; // TODO this is bullshit code
78 }
79
80 inline tJacobi STDVectorToJacobi(const std::vector<real> &v)
81 {
82 tJacobi ret;
83 DNDS_assert(v.size() == 9);
84 for (int i = 0; i < 9; i++)
85 ret(i) = v[i];
86 return ret; // TODO this is bullshit code
87 }
88
89 inline std::vector<real> VectorToSTDVector(const Eigen::VectorXd &v)
90 {
91 return {v.begin(), v.end()}; // TODO this is bullshit code
92 }
93
94 inline Eigen::VectorXd STDVectorToVector(const std::vector<real> &v)
95 {
96 auto ret = Eigen::VectorXd(v.size());
97 for (size_t i = 0; i < v.size(); i++)
98 ret[i] = v[i]; // TODO this is bullshit code
99 return ret;
100 }
101}
102
103namespace DNDS::Geom
104{
105 /**
106 * @brief get normal vector from facial jacobian
107 * note that
108 * $$
109 * J_{ij} = \partial_{\xi_j} x_i
110 * $$
111 */
112 template <int d>
114 {
115 static_assert(d == 2 || d == 3);
116 if constexpr (d == 2)
117 {
118 DNDS_assert_info(J(2, 0) == 0, "Must be a line in x-y plane");
119 DNDS_assert_info(J(EigenAll, 1).norm() == 0, "Must be a line in x-y plane");
120 DNDS_assert_info(J(EigenAll, 2).norm() == 0, "Must be a line in x-y plane");
121 return tPoint{J(1, 0), -J(0, 0), 0};
122 }
123 if constexpr (d == 3)
124 {
125 DNDS_assert_info(J(EigenAll, 2).norm() == 0, "Must be a face");
126 return J(EigenAll, 0).cross(J(EigenAll, 1));
127 }
128 }
129
130 /**
131 * @brief input uNorm should already be normalized
132 *
133 */
134 template <int dim>
135 inline Eigen::Matrix<real, dim, dim> NormBuildLocalBaseV(const Eigen::Ref<const Eigen::Vector<real, dim>> &uNorm)
136 {
137 Eigen::Matrix<real, dim, dim> base;
138 static_assert(dim == 2 || dim == 3, "dim is bad");
139 if constexpr (dim == 3)
140 {
141 base({0, 1, 2}, 0) = uNorm;
142 if (std::abs(uNorm(2)) < 0.9)
143 base({0, 1, 2}, 1) = -uNorm.cross(tPoint{0, 0, 1}).normalized();
144 else
145 base({0, 1, 2}, 1) = -uNorm.cross(tPoint{0, 1, 0}).normalized();
146
147 base({0, 1, 2}, 2) = base({0, 1, 2}, 0).cross(base({0, 1, 2}, 1)).normalized();
148 }
149 else
150 {
151 base({0, 1}, 0) = uNorm;
152 base(0, 1) = -uNorm(1); // x2=-y1
153 base(1, 1) = uNorm(0); // y2=x1
154 }
155 return base;
156 }
157
158 inline tGPoint RotZ(real theta)
159 {
160 theta *= pi / 180.0;
161 return tGPoint{{cos(theta), -sin(theta), 0},
162 {sin(theta), cos(theta), 0},
163 {0, 0, 1}};
164 }
165
166 inline tGPoint RotX(real theta)
167 {
168 theta *= pi / 180.0;
169 return tGPoint{{1, 0, 0},
170 {0, cos(theta), -sin(theta)},
171 {0, sin(theta), cos(theta)}};
172 }
173
174 inline tGPoint RotY(real theta)
175 {
176 theta *= pi / 180.0;
177 return tGPoint{
178 {cos(theta), 0, sin(theta)},
179 {0, 1, 0},
180 {-sin(theta), 0, cos(theta)}};
181 }
182
183 inline tGPoint RotateAxis(const tPoint &axis)
184 {
185 real theta = axis.norm();
186 if (theta < smallReal)
187 return tGPoint::Identity();
188 tPoint axn = axis / theta;
189 tGPoint Omega{{0, -axn(2), axn(1)},
190 {axn(2), 0, -axn(0)},
191 {-axn(1), axn(0), 0}};
192 return axn * axn.transpose() + std::sin(theta) * Omega - std::cos(theta) * (Omega * Omega);
193 }
194
195 inline tGPoint CrossVecToMat(const tPoint &axn)
196 {
197 return tGPoint{{0, -axn(2), axn(1)},
198 {axn(2), 0, -axn(0)},
199 {-axn(1), axn(0), 0}};
200 }
201
202 inline tPoint CrossMatToVec(const tGPoint &axnM)
203 {
204 return tPoint{axnM(2, 1), axnM(0, 2), axnM(1, 0)};
205 }
206
207 template <int dim>
208 tPoint ToThreeDim(const Eigen::Vector<real, dim> &v)
209 {
210 tPoint r;
211 r.setZero();
212 r(Eigen::seq(Eigen::fix<0>, Eigen::fix<dim - 1>)) = v;
213 return r;
214 }
215}
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
Definition Defines.hpp:83
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
Definition Errors.hpp:113
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
Eigen::Matrix< real, dim, dim > NormBuildLocalBaseV(const Eigen::Ref< const Eigen::Vector< real, dim > > &uNorm)
input uNorm should already be normalized
Eigen::VectorXd STDVectorToVector(const std::vector< real > &v)
Definition Geometric.hpp:94
tJacobi STDVectorToJacobi(const std::vector< real > &v)
Definition Geometric.hpp:80
int32_t t_index
Definition Geometric.hpp:6
Eigen::Matrix3d tJacobi
Definition Geometric.hpp:10
tGPoint RotateAxis(const tPoint &axis)
Eigen::Vector3d tPoint
Definition Geometric.hpp:9
Eigen::Map< tPoint, Eigen::Unaligned > tPointMap
Definition Geometric.hpp:12
Eigen::Map< const tGPoint, Eigen::Unaligned > tGPointConstMap
Definition Geometric.hpp:15
Eigen::Map< tGPoint, Eigen::Unaligned > tGPointMap
Definition Geometric.hpp:14
tPoint ToThreeDim(const Eigen::Vector< real, dim > &v)
tPoint FacialJacobianToNormVec(const tJacobi &J)
get normal vector from facial jacobian note that $$ J_{ij} = \partial_{\xi_j} x_i $$
Eigen::Matrix< real, 3, Eigen::Dynamic > tSmallCoords
Definition Geometric.hpp:50
Eigen::Map< const tPoint, Eigen::Unaligned > tPointConstMap
Definition Geometric.hpp:13
tGPoint CrossVecToMat(const tPoint &axn)
tGPoint RotX(real theta)
tGPoint RotZ(real theta)
tPoint CrossMatToVec(const tGPoint &axnM)
std::vector< real > JacobiToSTDVector(const tJacobi &j)
Definition Geometric.hpp:72
const t_index invalid_index
Definition Geometric.hpp:7
std::vector< real > VectorToSTDVector(const Eigen::VectorXd &v)
Definition Geometric.hpp:89
double t_real
Definition Geometric.hpp:8
std::vector< std::vector< index > > tLocalMatStruct
Definition Geometric.hpp:66
Eigen::Matrix3d tGPoint
Definition Geometric.hpp:11
tGPoint RotY(real theta)
DNDS_CONSTANT const real pi
π in double precision (matches DNDS_E_PI macro).
Definition Defines.hpp:199
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:105
DNDS_CONSTANT const real smallReal
Loose lower bound (for iterative-solver tolerances etc.).
Definition Defines.hpp:196
auto operator[](Eigen::Index i) const
Definition Geometric.hpp:58
auto operator[](Eigen::Index i)
Definition Geometric.hpp:53
DNDS_DEVICE_CALLABLE auto map()
Definition Geometric.hpp:36
DNDS_DEVICE_CALLABLE auto map() const
Definition Geometric.hpp:41
std::array< real, 9 > d
Definition Geometric.hpp:34
DNDS_DEVICE_CALLABLE auto map() const
Definition Geometric.hpp:26
DNDS_DEVICE_CALLABLE auto map()
Definition Geometric.hpp:21
std::array< real, 3 > d
Definition Geometric.hpp:19
Eigen::Matrix< real, 5, 1 > v
tVec r(NCells)
if(g_mpi.rank==0) std auto[rhsDensity, rhsEnergy, incL2]