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_GpuComplex.H"
11#include "AMReX_IndexType.H"
12#include <eigen3/Eigen/Core>
13#include <eigen3/Eigen/Geometry>
14#include <eigen3/Eigen/SVD>
15#include <AMReX_REAL.H>
16
17namespace Set
18{
19using Scalar = amrex::Real;
20using Complex = amrex::GpuComplex<Scalar>;
21using Vector = Eigen::Matrix<amrex::Real,AMREX_SPACEDIM,1>;
22using Vector3d = Eigen::Vector3d;
23using Covector = Eigen::Matrix<amrex::Real,1,AMREX_SPACEDIM>;
24using Matrix = Eigen::Matrix<amrex::Real,AMREX_SPACEDIM,AMREX_SPACEDIM>;
25using Matrix3d = Eigen::Matrix3d;
26using iMatrix = Eigen::Matrix<int,AMREX_SPACEDIM,AMREX_SPACEDIM>;
27
30{
31 return in.block<AMREX_SPACEDIM,AMREX_SPACEDIM>(0,0);
32}
33
36{
37 Set::Matrix3d ret = Set::Matrix3d::Zero();
38 ret.block<AMREX_SPACEDIM,AMREX_SPACEDIM>(0,0) = in;
39 return ret;
40}
41
42//using Quaternion = Eigen::Quaterniond;
43
44class Quaternion : public Eigen::Quaterniond
45{
46public:
48 : Eigen::Quaterniond() {}
50 : Eigen::Quaterniond(w,x,y,z) {}
51 Quaternion(const Eigen::Matrix3d &R)
52 : Eigen::Quaterniond(R) {}
53 Quaternion(Eigen::Quaterniond &q)
54 : Eigen::Quaterniond(q.w(),q.x(),q.y(),q.z()) {}
55
57 void operator = (const Eigen::Quaterniond &rhs)
58 {
59 w() = rhs.w(); x() = rhs.x(); y() = rhs.y(); z() = rhs.z();
60 }
61
64 {
65 w() += rhs.w(); x() += rhs.x(); y() += rhs.y(); z() += rhs.z();
66 }
67 // AMREX_FORCE_INLINE
68 // void operator * (const Set::Scalar alpha)
69 // {
70 // w += alpha; x *= alpha; y *= alpha; z *= alpha;
71 // }
72 friend Quaternion operator * (const Set::Scalar alpha, const Quaternion b);
73 friend Quaternion operator * (const Quaternion b,const Set::Scalar alpha);
74 friend Quaternion operator + (const Quaternion a, const Quaternion b);
75 friend Quaternion operator - (const Quaternion a, const Quaternion b);
76 friend bool operator == (const Quaternion a, const Quaternion b);
77};
80{
82 ret.w() = b.w()*alpha; ret.x() = b.x()*alpha; ret.y() = b.y()*alpha; ret.z() = b.z()*alpha;
83 return ret;
84}
87{
89 ret.w() = b.w()*alpha; ret.x() = b.x()*alpha; ret.y() = b.y()*alpha; ret.z() = b.z()*alpha;
90 return ret;
91}
94{
96 ret.w() = a.w()+b.w(); ret.x() = a.x()+b.x(); ret.y() = a.y()+b.y(); ret.z() = a.z()+b.z();
97 return ret;
98}
99
102{
104 ret.w() = a.w()-b.w(); ret.x() = a.x()-b.x(); ret.y() = a.y()-b.y(); ret.z() = a.z()-b.z();
105 return ret;
106}
107
110{
111 if (fabs((a.w() - b.w())/(a.w()+a.w())) > 1E-8) return false;
112 if (fabs((a.x() - b.x())/(a.x()+a.x())) > 1E-8) return false;
113 if (fabs((a.y() - b.y())/(a.y()+a.y())) > 1E-8) return false;
114 if (fabs((a.z() - b.z())/(a.z()+a.z())) > 1E-8) return false;
115 return true;
116}
117
118
120
122Vector Position(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
123{
124 (void)k;
125 if (ixType == amrex::IndexType::TheNodeType())
126 {
127 return Vector(AMREX_D_DECL(
128 geom.ProbLo()[0] + ((amrex::Real)(i)) * geom.CellSize()[0],
129 geom.ProbLo()[1] + ((amrex::Real)(j)) * geom.CellSize()[1],
130 geom.ProbLo()[2] + ((amrex::Real)(k)) * geom.CellSize()[2]));
131 }
132 else if (ixType == amrex::IndexType::TheCellType())
133 {
134 return Vector(AMREX_D_DECL(
135 geom.ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom.CellSize()[0],
136 geom.ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom.CellSize()[1],
137 geom.ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom.CellSize()[2]));
138 }
139 return Set::Vector::Zero();
140}
141
144Vector Position(const int &i, const int &j, const int &k,
145 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> &prob_lo,
146 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> &cell_size,
147 const amrex::IndexType &ixType)
148{
149 (void)k;
150 const amrex::Real offset =
151 ixType == amrex::IndexType::TheNodeType() ? 0.0 : 0.5;
152 return Vector(AMREX_D_DECL(
153 prob_lo[0] + (amrex::Real(i) + offset) * cell_size[0],
154 prob_lo[1] + (amrex::Real(j) + offset) * cell_size[1],
155 prob_lo[2] + (amrex::Real(k) + offset) * cell_size[2]));
156}
157
159Vector Normal( AMREX_D_DECL(bool xmin,bool ymin, bool zmin),
160 AMREX_D_DECL(bool xmax,bool ymax, bool zmax))
161{
162 Set::Vector N = Set::Vector::Zero();
163 if (xmin) N(0) = -1.0;
164 else if (xmax) N(0) = 1.0;
165#if AMREX_SPACEDIM>1
166 if (ymin) N(1) = -1.0;
167 else if (ymax) N(1) = 1.0;
168#endif
169#if AMREX_SPACEDIM>2
170 if (zmin) N(2) = -1.0;
171 else if (zmax) N(2) = 1.0;
172#endif
173 return N;
174}
175
177Vector Size(const amrex::Geometry &geom)
178{
180 size(0) = geom.ProbHi()[0] - geom.ProbLo()[0];
181#if AMREX_SPACEDIM>1
182 size(1) = geom.ProbHi()[1] - geom.ProbLo()[1];
183#endif
184#if AMREX_SPACEDIM>2
185 size(2) = geom.ProbHi()[2] - geom.ProbLo()[2];
186#endif
187 return size;
188}
189
190
192Vector Volume(const int &i, const int &j, const int &k, const amrex::Geometry &geom, const amrex::IndexType &ixType)
193{
194 (void)k;
195 if (ixType == amrex::IndexType::TheNodeType())
196 {
197 return Vector(AMREX_D_DECL(
198 geom.ProbLo()[0] + ((amrex::Real)(i)) * geom.CellSize()[0],
199 geom.ProbLo()[1] + ((amrex::Real)(j)) * geom.CellSize()[1],
200 geom.ProbLo()[2] + ((amrex::Real)(k)) * geom.CellSize()[2]));
201 }
202 else if (ixType == amrex::IndexType::TheCellType())
203 {
204 return Vector(AMREX_D_DECL(
205 geom.ProbLo()[0] + ((amrex::Real)(i) + 0.5) * geom.CellSize()[0],
206 geom.ProbLo()[1] + ((amrex::Real)(j) + 0.5) * geom.CellSize()[1],
207 geom.ProbLo()[2] + ((amrex::Real)(k) + 0.5) * geom.CellSize()[2]));
208 }
209 return Set::Vector::Zero();
210}
211
212}
213#endif
AMREX_FORCE_INLINE void operator+=(const Quaternion &rhs)
Definition Base.H:63
friend Quaternion operator-(const Quaternion a, const Quaternion b)
Definition Base.H:101
friend Quaternion operator*(const Set::Scalar alpha, const Quaternion b)
Definition Base.H:79
Quaternion(const Eigen::Matrix3d &R)
Definition Base.H:51
friend Quaternion operator+(const Quaternion a, const Quaternion b)
Definition Base.H:93
AMREX_FORCE_INLINE void operator=(const Eigen::Quaterniond &rhs)
Definition Base.H:57
friend bool operator==(const Quaternion a, const Quaternion b)
Definition Base.H:109
Quaternion(Set::Scalar w, Set::Scalar x, Set::Scalar y, Set::Scalar z)
Definition Base.H:49
Quaternion(Eigen::Quaterniond &q)
Definition Base.H:53
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:26
AMREX_FORCE_INLINE Quaternion operator-(const Quaternion a, const Quaternion b)
Definition Base.H:101
static Scalar Garbage
Definition Base.H:119
amrex::Real Scalar
Definition Base.H:19
amrex::GpuComplex< Scalar > Complex
Definition Base.H:20
Eigen::Matrix3d Matrix3d
Definition Base.H:25
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:192
Eigen::Matrix< amrex::Real, 1, AMREX_SPACEDIM > Covector
Definition Base.H:23
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, 1 > Vector
Definition Base.H:21
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:122
Eigen::Vector3d Vector3d
Definition Base.H:22
AMREX_FORCE_INLINE bool operator==(const Quaternion a, const Quaternion b)
Definition Base.H:109
AMREX_FORCE_INLINE Quaternion operator+(const Quaternion a, const Quaternion b)
Definition Base.H:93
AMREX_FORCE_INLINE Set::Matrix3d expand(const Set::Matrix &in)
Definition Base.H:35
AMREX_FORCE_INLINE Vector Size(const amrex::Geometry &geom)
Definition Base.H:177
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:159
Eigen::Matrix< amrex::Real, AMREX_SPACEDIM, AMREX_SPACEDIM > Matrix
Definition Base.H:24
AMREX_FORCE_INLINE Set::Matrix reduce(const Set::Matrix3d &in)
Definition Base.H:29
AMREX_FORCE_INLINE Quaternion operator*(const Set::Scalar alpha, const Quaternion b)
Definition Base.H:79