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#include "Util/Util.H"
16
17namespace Set
18{
19using Scalar = amrex::Real;
20using Vector = Eigen::Matrix<amrex::Real,AMREX_SPACEDIM,1>;
21using Vector3d = Eigen::Vector3d;
22using Covector = Eigen::Matrix<amrex::Real,1,AMREX_SPACEDIM>;
23using Matrix = Eigen::Matrix<amrex::Real,AMREX_SPACEDIM,AMREX_SPACEDIM>;
24using Matrix3d = Eigen::Matrix3d;
25using iMatrix = Eigen::Matrix<int,AMREX_SPACEDIM,AMREX_SPACEDIM>;
26
29{
30 return in.block<AMREX_SPACEDIM,AMREX_SPACEDIM>(0,0);
31}
32
35{
36 Set::Matrix3d ret = Set::Matrix3d::Zero();
37 ret.block<AMREX_SPACEDIM,AMREX_SPACEDIM>(0,0) = in;
38 return ret;
39}
40
41//using Quaternion = Eigen::Quaterniond;
42
43class Quaternion : public Eigen::Quaterniond
44{
45public:
47 : Eigen::Quaterniond() {}
49 : Eigen::Quaterniond(w,x,y,z) {}
50 Quaternion(const Eigen::Matrix3d &R)
51 : Eigen::Quaterniond(R) {}
52 Quaternion(Eigen::Quaterniond &q)
53 : Eigen::Quaterniond(q.w(),q.x(),q.y(),q.z()) {}
54
56 void operator = (const Eigen::Quaterniond &rhs)
57 {
58 w() = rhs.w(); x() = rhs.x(); y() = rhs.y(); z() = rhs.z();
59 }
60
62 void operator += (const Quaternion &rhs)
63 {
64 w() += rhs.w(); x() += rhs.x(); y() += rhs.y(); z() += rhs.z();
65 }
66 // AMREX_FORCE_INLINE
67 // void operator * (const Set::Scalar alpha)
68 // {
69 // w += alpha; x *= alpha; y *= alpha; z *= alpha;
70 // }
71 friend Quaternion operator * (const Set::Scalar alpha, const Quaternion b);
72 friend Quaternion operator * (const Quaternion b,const Set::Scalar alpha);
73 friend Quaternion operator + (const Quaternion a, const Quaternion b);
74 friend Quaternion operator - (const Quaternion a, const Quaternion b);
75 friend bool operator == (const Quaternion a, const Quaternion b);
76};
79{
81 ret.w() = b.w()*alpha; ret.x() = b.x()*alpha; ret.y() = b.y()*alpha; ret.z() = b.z()*alpha;
82 return ret;
83}
86{
88 ret.w() = b.w()*alpha; ret.x() = b.x()*alpha; ret.y() = b.y()*alpha; ret.z() = b.z()*alpha;
89 return ret;
90}
93{
95 ret.w() = a.w()+b.w(); ret.x() = a.x()+b.x(); ret.y() = a.y()+b.y(); ret.z() = a.z()+b.z();
96 return ret;
97}
98
101{
103 ret.w() = a.w()-b.w(); ret.x() = a.x()-b.x(); ret.y() = a.y()-b.y(); ret.z() = a.z()-b.z();
104 return ret;
105}
106
109{
110 if (fabs((a.w() - b.w())/(a.w()+a.w())) > 1E-8) return false;
111 if (fabs((a.x() - b.x())/(a.x()+a.x())) > 1E-8) return false;
112 if (fabs((a.y() - b.y())/(a.y()+a.y())) > 1E-8) return false;
113 if (fabs((a.z() - b.z())/(a.z()+a.z())) > 1E-8) return false;
114 return true;
115}
116
117
119
121Vector Position(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
122{
123 (void)k;
124 if (ixType == amrex::IndexType::TheNodeType())
125 {
126 return Vector(AMREX_D_DECL(
127 geom.ProbLo()[0] + ((amrex::Real)(i)) * geom.CellSize()[0],
128 geom.ProbLo()[1] + ((amrex::Real)(j)) * geom.CellSize()[1],
129 geom.ProbLo()[2] + ((amrex::Real)(k)) * geom.CellSize()[2]));
130 }
131 else if (ixType == amrex::IndexType::TheCellType())
132 {
133 return Vector(AMREX_D_DECL(
134 geom.ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom.CellSize()[0],
135 geom.ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom.CellSize()[1],
136 geom.ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom.CellSize()[2]));
137 }
138 Util::Abort(INFO,"Unsupported index type");
139 return Set::Vector::Zero();
140}
141
143Vector Normal( AMREX_D_DECL(bool xmin,bool ymin, bool zmin),
144 AMREX_D_DECL(bool xmax,bool ymax, bool zmax))
145{
146 Set::Vector N = Set::Vector::Zero();
147 if (xmin) N(0) = -1.0;
148 else if (xmax) N(0) = 1.0;
149#if AMREX_SPACEDIM>1
150 if (ymin) N(1) = -1.0;
151 else if (ymax) N(1) = 1.0;
152#endif
153#if AMREX_SPACEDIM>2
154 if (zmin) N(2) = -1.0;
155 else if (zmax) N(2) = 1.0;
156#endif
157 return N;
158}
159
161Vector Size(const amrex::Geometry &geom)
162{
164 size(0) = geom.ProbHi()[0] - geom.ProbLo()[0];
165#if AMREX_SPACEDIM>1
166 size(1) = geom.ProbHi()[1] - geom.ProbLo()[1];
167#endif
168#if AMREX_SPACEDIM>2
169 size(2) = geom.ProbHi()[2] - geom.ProbLo()[2];
170#endif
171 return size;
172}
173
174
176Vector Volume(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
177{
178 (void)k;
179 if (ixType == amrex::IndexType::TheNodeType())
180 {
181 return Vector(AMREX_D_DECL(
182 geom.ProbLo()[0] + ((amrex::Real)(i)) * geom.CellSize()[0],
183 geom.ProbLo()[1] + ((amrex::Real)(j)) * geom.CellSize()[1],
184 geom.ProbLo()[2] + ((amrex::Real)(k)) * geom.CellSize()[2]));
185 }
186 else if (ixType == amrex::IndexType::TheCellType())
187 {
188 return Vector(AMREX_D_DECL(
189 geom.ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom.CellSize()[0],
190 geom.ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom.CellSize()[1],
191 geom.ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom.CellSize()[2]));
192 }
193 Util::Abort(INFO,"Unsupported index type");
194 return Set::Vector::Zero();
195}
196
198template<int dim,int sym> class Matrix4{};
199template<int dim, int sym>
200std::ostream&
201operator<< (std::ostream& os, const Matrix4<dim,sym>& b)
202{
204 bcopy.Print(os);
205 return os;
206}
207}
208#endif
#define INFO
Definition Util.H:20
AMREX_FORCE_INLINE void operator+=(const Quaternion &rhs)
Definition Base.H:62
friend Quaternion operator-(const Quaternion a, const Quaternion b)
Definition Base.H:100
friend Quaternion operator*(const Set::Scalar alpha, const Quaternion b)
Definition Base.H:78
Quaternion(const Eigen::Matrix3d &R)
Definition Base.H:50
friend Quaternion operator+(const Quaternion a, const Quaternion b)
Definition Base.H:92
AMREX_FORCE_INLINE void operator=(const Eigen::Quaterniond &rhs)
Definition Base.H:56
friend bool operator==(const Quaternion a, const Quaternion b)
Definition Base.H:108
Quaternion(Set::Scalar w, Set::Scalar x, Set::Scalar y, Set::Scalar z)
Definition Base.H:48
Quaternion(Eigen::Quaterniond &q)
Definition Base.H:52
A collection of data types and symmetry-reduced data structures.
Definition Base.H:18
Eigen::Matrix< int, AMREX_SPACEDIM, AMREX_SPACEDIM > iMatrix
Definition Base.H:25
AMREX_FORCE_INLINE Quaternion operator-(const Quaternion a, const Quaternion b)
Definition Base.H:100
static Scalar Garbage
Definition Base.H:118
Sym
Definition Base.H:197
@ None
Definition Base.H:197
@ MajorMinor
Definition Base.H:197
@ Full
Definition Base.H:197
@ Diagonal
Definition Base.H:197
@ Isotropic
Definition Base.H:197
@ Major
Definition Base.H:197
@ Minor
Definition Base.H:197
amrex::Real Scalar
Definition Base.H:19
Eigen::Matrix3d Matrix3d
Definition Base.H:24
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:176
Eigen::Matrix< amrex::Real, 1, AMREX_SPACEDIM > Covector
Definition Base.H:22
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:20
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:121
Eigen::Vector3d Vector3d
Definition Base.H:21
AMREX_FORCE_INLINE bool operator==(const Quaternion a, const Quaternion b)
Definition Base.H:108
AMREX_FORCE_INLINE Quaternion operator+(const Quaternion a, const Quaternion b)
Definition Base.H:92
AMREX_FORCE_INLINE Set::Matrix3d expand(const Set::Matrix &in)
Definition Base.H:34
AMREX_FORCE_INLINE Vector Size(const amrex::Geometry &geom)
Definition Base.H:161
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:143
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
Definition Base.H:23
AMREX_FORCE_INLINE Set::Matrix reduce(const Set::Matrix3d &in)
Definition Base.H:28
AMREX_FORCE_INLINE Quaternion operator*(const Set::Scalar alpha, const Quaternion b)
Definition Base.H:78
std::ostream & operator<<(std::ostream &os, const Matrix4< dim, sym > &b)
Definition Base.H:201
void Abort(const char *msg)
Definition Util.cpp:170