QuaternionUnitTest.cpp File Reference

Functions

void test1 ()
 
void test2 ()
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc  ,
char **  argv 
)
125  {
126  test1();
127  test2();
128  return 0;
129 }
void test2()
Definition: QuaternionUnitTest.cpp:65
void test1()
Definition: QuaternionUnitTest.cpp:9

References test1(), and test2().

◆ test1()

void test1 ( )
Todo:
shouldn't this be default?
9  {
10  logger(INFO, "Test 1:\n"
11  "We apply a torque T around the z-axis to a motionless\n"
12  "particle of inertia I for a time t using a time step dt.\n"
13  "The result is a final angular velocity omega=T/I*t\n"
14  "and rotation angle alpha=T/I*t^2/2.\n"
15  "\n"
16  "The input/output values should be:\n"
17  " T = 0.1*pi*(0 0 1) Nm\n"
18  " I = 0.1 kg m^2\n"
19  " t = 1 s\n"
20  " dt = 1e-5 s\n"
21  " omega=pi*(0 0 1) rad/s\n"
22  " alpha = pi/2*(0 0 1) rad\n");
23 
24  //compute mass (requires species and handler to be set)
25  DPMBase D;
26  LinearViscoelasticSpecies* S = D.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies());
27  BaseParticle* P = D.particleHandler.copyAndAddObject(SphericalParticle(S));
28  D.setDimension(3);
29  S->setDensity(6.0 / constants::pi);
30  P->setRadius(0.5);
31  S->computeMass(P);
32 
33  //std::cout << "P " << *P << std::endl;
34  P->setForce({1, 0, 0});
35  P->setTorque(0.1 * constants::pi * Vec3D(0, 0, 1));
36  Mdouble timeMax = 1.0;
37  Mdouble timeStep = 1e-5;
38  for (Mdouble time = 0; time < timeMax; time += timeStep)
39  {
40  P->accelerate(P->getForce() * P->getInvMass() * timeStep);
41  P->move(P->getVelocity() * timeStep);
42  P->angularAccelerate(
43  P->getOrientation().rotateInverseInertiaTensor(P->getInvInertia()) * P->getTorque() * timeStep);
44  P->rotate(P->getAngularVelocity() * timeStep);
45  }
46 
47  logger(INFO, "Results:\n"
48  " omega= %\n"
49  " alpha= %", P->getAngularVelocity(), P->getOrientation().getEuler());
50 
51  // std::cout << P->getAngularVelocity() - Vec3D(0,0,pi) << std::endl;
52  // std::cout << P->getOrientation().getEuler() - Vec3D(0,0,pi/2) << std::endl;
53 
54  //check results (with numerical error values added))
55  if (!mathsFunc::isEqual(P->getAngularVelocity(), Vec3D(0, 0, pi + 3.14159e-05), 1e-10))
56  {
57  logger(ERROR, "angular velocity is %, but should be %", P->getAngularVelocity(), pi / 2);
58  }
59  if (!mathsFunc::isEqual(P->getOrientation().getEuler(), {0, 0, pi / 2 + 4.71241e-05}, 1e-10))
60  {
61  logger(ERROR, "orientation is %, but should be %", P->getOrientation().getEuler().Z, pi / 2);
62  }
63 }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
dominoes D
Definition: Domino.cpp:55
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:11
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:32
Definition: BaseParticle.h:33
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:56
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:16
Definition: Kernel/Math/Vector.h:30
#define INFO(i)
Definition: mumps_solver.h:54
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
const Mdouble pi
Definition: ExtendedMath.h:23
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
Definition: ExtendedMath.cc:230
@ S
Definition: quadtree.h:62

References D, e(), ERROR, INFO, mathsFunc::isEqual(), logger, Global_Physical_Variables::P, constants::pi, and oomph::QuadTreeNames::S.

Referenced by oomph::QTaylorHoodSpaceTimeElement< DIM >::dptest_eulerian(), oomph::QTaylorHoodMixedOrderSpaceTimeElement< DIM >::dptest_eulerian(), main(), oomph::QTaylorHoodSpaceTimeElement< DIM >::ptest_nst(), and oomph::QTaylorHoodMixedOrderSpaceTimeElement< DIM >::ptest_nst().

◆ test2()

void test2 ( )
Todo:
shouldn't this be default?
66 {
67  logger(INFO, "Test 2:\n"
68  "We apply a torque T around the z-axis to a motionless\n"
69  "particle of inertia I for a time t using a time step dt.\n"
70  "The result is a final angular velocity omega=inv(I)*T*t\n"
71  "and rotation angle alpha=inv(I)*T*t^2/2.\n"
72  "\n"
73  "The input/output values should be:\n"
74  " T = 0.1*pi*(0 0 1) Nm\n"
75  " I = 0.1*(2 0 0;0 2 0;0 0 1) kg m^2\n"
76  " t = 1 s\n"
77  " dt = 1e-5 s\n"
78  " omega=pi*(0 0 1) rad/s\n"
79  " alpha = pi/2*(0 0 1) rad\n");
80 
81  //compute mass (requires species and handler to be set)
82  DPMBase D;
83  LinearViscoelasticSpecies* S = D.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies());
84  BaseParticle* P = D.particleHandler.copyAndAddObject(SphericalParticle(S));
85  D.setDimension(3);
86  S->setDensity(6.0 / constants::pi);
87  P->setRadius(0.5);
88  S->computeMass(P);
89  P->setInertia(MatrixSymmetric3D(2, 1, 0,
90  2, 0,
91  1) * 0.1);
92 
93  //std::cout << "P " << *P << std::endl;
94  P->setForce({1, 0, 0});
95  P->setTorque(0.1 * constants::pi * Vec3D(0, 0, 1));
96  Mdouble timeMax = 1.0;
97  Mdouble timeStep = 1e-5;
98  for (Mdouble time = 0; time < timeMax; time += timeStep)
99  {
100  P->accelerate(P->getForce() * P->getInvMass() * timeStep);
101  P->move(P->getVelocity() * timeStep);
102  P->angularAccelerate(
103  P->getOrientation().rotateInverseInertiaTensor(P->getInvInertia()) * P->getTorque() * timeStep);
104  P->rotate(P->getAngularVelocity() * timeStep);
105  }
106 
107  logger(INFO, "Results:\n"
108  " omega= %\n"
109  " alpha= %", P->getAngularVelocity(), P->getOrientation().getEuler());
110 
111  // std::cout << P->getAngularVelocity() - Vec3D(0,0,pi) << std::endl;
112  // std::cout << P->getOrientation().getEuler() - Vec3D(0,0,pi/2) << std::endl;
113 
114  //check results (with numerical error values added))
115  if (!mathsFunc::isEqual(P->getAngularVelocity(), Vec3D(0, 0, pi + 3.14159e-05), 1e-10))
116  {
117  logger(ERROR, "angular velocity is %, but should be %", P->getAngularVelocity(), pi / 2);
118  }
119  if (!mathsFunc::isEqual(P->getOrientation().getEuler(), {0, 0, pi / 2 + 4.71241e-05}, 1e-10))
120  {
121  logger(ERROR, "orientation is %, but should be %", P->getOrientation().getEuler().Z, pi / 2);
122  }
123 }
Implementation of a 3D symmetric matrix.
Definition: MatrixSymmetric.h:16

References D, e(), ERROR, INFO, mathsFunc::isEqual(), logger, Global_Physical_Variables::P, constants::pi, and oomph::QuadTreeNames::S.

Referenced by oomph::QTaylorHoodSpaceTimeElement< DIM >::dptest_eulerian(), oomph::QTaylorHoodMixedOrderSpaceTimeElement< DIM >::dptest_eulerian(), EIGEN_DECLARE_TEST(), main(), oomph::QTaylorHoodSpaceTimeElement< DIM >::ptest_nst(), and oomph::QTaylorHoodMixedOrderSpaceTimeElement< DIM >::ptest_nst().