Alamo
Base.H
Go to the documentation of this file.
1#ifndef SET_BASE_H
2#define SET_BASE_H
3
4#include "AMReX.H"
5#include "AMReX_REAL.H"
6#include "AMReX_SPACE.H"
7#include "AMReX_Vector.H"
8#include "AMReX_BLassert.H"
9#include "AMReX_Geometry.H"
10#include "AMReX_IndexType.H"
11#include <eigen3/Eigen/Core>
12#include <eigen3/Eigen/Geometry>
13#include <eigen3/Eigen/SVD>
14#include <AMReX_REAL.H>
15
16namespace Set
17{
18using Scalar = amrex::Real;
19using Vector = Eigen::Matrix<amrex::Real,AMREX_SPACEDIM,1>;
20using Vector3d = Eigen::Vector3d;
21using Covector = Eigen::Matrix<amrex::Real,1,AMREX_SPACEDIM>;
22using Matrix = Eigen::Matrix<amrex::Real,AMREX_SPACEDIM,AMREX_SPACEDIM>;
23using Matrix3d = Eigen::Matrix3d;
24using iMatrix = Eigen::Matrix<int,AMREX_SPACEDIM,AMREX_SPACEDIM>;
25
28{
29 return in.block<AMREX_SPACEDIM,AMREX_SPACEDIM>(0,0);
30}
31
34{
35 Set::Matrix3d ret = Set::Matrix3d::Zero();
36 ret.block<AMREX_SPACEDIM,AMREX_SPACEDIM>(0,0) = in;
37 return ret;
38}
39
40//using Quaternion = Eigen::Quaterniond;
41
42class Quaternion : public Eigen::Quaterniond
43{
44public:
46 : Eigen::Quaterniond() {}
48 : Eigen::Quaterniond(w,x,y,z) {}
49 Quaternion(const Eigen::Matrix3d &R)
50 : Eigen::Quaterniond(R) {}
51 Quaternion(Eigen::Quaterniond &q)
52 : Eigen::Quaterniond(q.w(),q.x(),q.y(),q.z()) {}
53
55 void operator = (const Eigen::Quaterniond &rhs)
56 {
57 w() = rhs.w(); x() = rhs.x(); y() = rhs.y(); z() = rhs.z();
58 }
59
61 void operator += (const Quaternion &rhs)
62 {
63 w() += rhs.w(); x() += rhs.x(); y() += rhs.y(); z() += rhs.z();
64 }
65 // AMREX_FORCE_INLINE
66 // void operator * (const Set::Scalar alpha)
67 // {
68 // w += alpha; x *= alpha; y *= alpha; z *= alpha;
69 // }
70 friend Quaternion operator * (const Set::Scalar alpha, const Quaternion b);
71 friend Quaternion operator * (const Quaternion b,const Set::Scalar alpha);
72 friend Quaternion operator + (const Quaternion a, const Quaternion b);
73 friend Quaternion operator - (const Quaternion a, const Quaternion b);
74 friend bool operator == (const Quaternion a, const Quaternion b);
75};
78{
80 ret.w() = b.w()*alpha; ret.x() = b.x()*alpha; ret.y() = b.y()*alpha; ret.z() = b.z()*alpha;
81 return ret;
82}
85{
87 ret.w() = b.w()*alpha; ret.x() = b.x()*alpha; ret.y() = b.y()*alpha; ret.z() = b.z()*alpha;
88 return ret;
89}
92{
94 ret.w() = a.w()+b.w(); ret.x() = a.x()+b.x(); ret.y() = a.y()+b.y(); ret.z() = a.z()+b.z();
95 return ret;
96}
97
100{
102 ret.w() = a.w()-b.w(); ret.x() = a.x()-b.x(); ret.y() = a.y()-b.y(); ret.z() = a.z()-b.z();
103 return ret;
104}
105
108{
109 if (fabs((a.w() - b.w())/(a.w()+a.w())) > 1E-8) return false;
110 if (fabs((a.x() - b.x())/(a.x()+a.x())) > 1E-8) return false;
111 if (fabs((a.y() - b.y())/(a.y()+a.y())) > 1E-8) return false;
112 if (fabs((a.z() - b.z())/(a.z()+a.z())) > 1E-8) return false;
113 return true;
114}
115
116
118
120Vector Position(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
121{
122 (void)k;
123 if (ixType == amrex::IndexType::TheNodeType())
124 {
125 return Vector(AMREX_D_DECL(
126 geom.ProbLo()[0] + ((amrex::Real)(i)) * geom.CellSize()[0],
127 geom.ProbLo()[1] + ((amrex::Real)(j)) * geom.CellSize()[1],
128 geom.ProbLo()[2] + ((amrex::Real)(k)) * geom.CellSize()[2]));
129 }
130 else if (ixType == amrex::IndexType::TheCellType())
131 {
132 return Vector(AMREX_D_DECL(
133 geom.ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom.CellSize()[0],
134 geom.ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom.CellSize()[1],
135 geom.ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom.CellSize()[2]));
136 }
137 return Set::Vector::Zero();
138}
139
141Vector Normal( AMREX_D_DECL(bool xmin,bool ymin, bool zmin),
142 AMREX_D_DECL(bool xmax,bool ymax, bool zmax))
143{
144 Set::Vector N = Set::Vector::Zero();
145 if (xmin) N(0) = -1.0;
146 else if (xmax) N(0) = 1.0;
147#if AMREX_SPACEDIM>1
148 if (ymin) N(1) = -1.0;
149 else if (ymax) N(1) = 1.0;
150#endif
151#if AMREX_SPACEDIM>2
152 if (zmin) N(2) = -1.0;
153 else if (zmax) N(2) = 1.0;
154#endif
155 return N;
156}
157
159Vector Size(const amrex::Geometry &geom)
160{
162 size(0) = geom.ProbHi()[0] - geom.ProbLo()[0];
163#if AMREX_SPACEDIM>1
164 size(1) = geom.ProbHi()[1] - geom.ProbLo()[1];
165#endif
166#if AMREX_SPACEDIM>2
167 size(2) = geom.ProbHi()[2] - geom.ProbLo()[2];
168#endif
169 return size;
170}
171
172
174Vector Volume(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
175{
176 (void)k;
177 if (ixType == amrex::IndexType::TheNodeType())
178 {
179 return Vector(AMREX_D_DECL(
180 geom.ProbLo()[0] + ((amrex::Real)(i)) * geom.CellSize()[0],
181 geom.ProbLo()[1] + ((amrex::Real)(j)) * geom.CellSize()[1],
182 geom.ProbLo()[2] + ((amrex::Real)(k)) * geom.CellSize()[2]));
183 }
184 else if (ixType == amrex::IndexType::TheCellType())
185 {
186 return Vector(AMREX_D_DECL(
187 geom.ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom.CellSize()[0],
188 geom.ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom.CellSize()[1],
189 geom.ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom.CellSize()[2]));
190 }
191 return Set::Vector::Zero();
192}
193
195template<int dim,int sym> class Matrix4{};
196template<int dim, int sym>
197std::ostream&
198operator<< (std::ostream& os, const Matrix4<dim,sym>& b)
199{
201 bcopy.Print(os);
202 return os;
203}
204}
205#endif
AMREX_FORCE_INLINE void operator+=(const Quaternion &rhs)
Definition Base.H:61
friend Quaternion operator-(const Quaternion a, const Quaternion b)
Definition Base.H:99
friend Quaternion operator*(const Set::Scalar alpha, const Quaternion b)
Definition Base.H:77
Quaternion(const Eigen::Matrix3d &R)
Definition Base.H:49
friend Quaternion operator+(const Quaternion a, const Quaternion b)
Definition Base.H:91
AMREX_FORCE_INLINE void operator=(const Eigen::Quaterniond &rhs)
Definition Base.H:55
friend bool operator==(const Quaternion a, const Quaternion b)
Definition Base.H:107
Quaternion(Set::Scalar w, Set::Scalar x, Set::Scalar y, Set::Scalar z)
Definition Base.H:47
Quaternion(Eigen::Quaterniond &q)
Definition Base.H:51
A collection of data types and symmetry-reduced data structures.
Definition Base.H:17
Eigen::Matrix< int, AMREX_SPACEDIM, AMREX_SPACEDIM > iMatrix
Definition Base.H:24
AMREX_FORCE_INLINE Quaternion operator-(const Quaternion a, const Quaternion b)
Definition Base.H:99
static Scalar Garbage
Definition Base.H:117
Sym
Definition Base.H:194
@ None
Definition Base.H:194
@ MajorMinor
Definition Base.H:194
@ Full
Definition Base.H:194
@ Diagonal
Definition Base.H:194
@ Isotropic
Definition Base.H:194
@ Major
Definition Base.H:194
@ Minor
Definition Base.H:194
amrex::Real Scalar
Definition Base.H:18
Eigen::Matrix3d Matrix3d
Definition Base.H:23
AMREX_FORCE_INLINE Vector Volume(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
Definition Base.H:174
Eigen::Matrix< amrex::Real, 1, AMREX_SPACEDIM > Covector
Definition Base.H:21
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:19
AMREX_FORCE_INLINE Vector Position(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
Definition Base.H:120
Eigen::Vector3d Vector3d
Definition Base.H:20
AMREX_FORCE_INLINE bool operator==(const Quaternion a, const Quaternion b)
Definition Base.H:107
AMREX_FORCE_INLINE Quaternion operator+(const Quaternion a, const Quaternion b)
Definition Base.H:91
AMREX_FORCE_INLINE Set::Matrix3d expand(const Set::Matrix &in)
Definition Base.H:33
AMREX_FORCE_INLINE Vector Size(const amrex::Geometry &geom)
Definition Base.H:159
AMREX_FORCE_INLINE Vector Normal(AMREX_D_DECL(bool xmin, bool ymin, bool zmin), AMREX_D_DECL(bool xmax, bool ymax, bool zmax))
Definition Base.H:141
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
Definition Base.H:22
AMREX_FORCE_INLINE Set::Matrix reduce(const Set::Matrix3d &in)
Definition Base.H:27
AMREX_FORCE_INLINE Quaternion operator*(const Set::Scalar alpha, const Quaternion b)
Definition Base.H:77
std::ostream & operator<<(std::ostream &os, const Matrix4< dim, sym > &b)
Definition Base.H:198