ElasticSuperQuadricUnitTest.cpp File Reference

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

Takes an oblique collision of elastic superellipsoids and checks whether the collision

  • conserves momentum
  • conserves kinetic+potential energy
19 {
21  problem.setName("ElasticSuperQuadricUnitTest");
22  problem.setDomain({-1,-1,-1},{1,1,1});
23  problem.setSaveCount(NEVER);
24  problem.dataFile.setSaveCount(10);
25 
26  auto s = problem.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies());
27  s->setStiffness(2e5);
28  s->setDensity(6.0/constants::pi);
29 
31  p.setSpecies(s);
32  p.setAxes(.5,.5,.5);
33  p.setExponents(.5,.9);
34  p.setPosition({.1,0,.5});
35  p.setVelocity({0,0,-.5});
36  auto p0 = problem.particleHandler.copyAndAddObject(p);
37 
38  p.setPosition(-p.getPosition());
39  p.setVelocity(-p.getVelocity());
40  //p.rotate({0,constants::pi,0});
41  auto p1 = problem.particleHandler.copyAndAddObject(p);
42 
43  problem.setTimeMax(1e-0);
44  problem.setTimeStep(1e-4);
45 
46  const Vec3D momentum0 = problem.particleHandler.getMomentum();
47  const Vec3D angularMomentum0 = problem.particleHandler.getAngularMomentum();
48  const Mdouble kineticEnergy0 = problem.particleHandler.getKineticEnergy()
49  +problem.particleHandler.getRotationalEnergy();
50 
51  // comment the next to lines to turn on file output
52  problem.setSuperquadricParticlesWriteVTK(true);
53  problem.setFileType(FileType::NO_FILE);
54  problem.solve();
55 
56  const Vec3D momentum1 = problem.particleHandler.getMomentum();
57  const Vec3D angularMomentum1 = problem.particleHandler.getAngularMomentum();
58  const Mdouble kineticEnergy1 = problem.particleHandler.getKineticEnergy()
59  +problem.particleHandler.getRotationalEnergy();
60 
61  // Check conservation properties
62  helpers::check(momentum0-momentum1,{0,0,0},1e-10*momentum0.getLength(),
63  "Conservation of momentum");
64  helpers::check(angularMomentum0-angularMomentum1,{0,0,0},1e-10*angularMomentum0.getLength(),
65  "Con. of angular momentum");
66  helpers::check(kineticEnergy0-kineticEnergy1,0,1e-4*kineticEnergy0,
67  "Con. of kinetic energy ");
68  // Note, energy conservation is not very good; it does not decay quickly with time step
69 
70  return 0;
71 }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
const unsigned NEVER
Definition: File.h:13
@ NO_FILE
file will not be created/read
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:11
Vector3f p0
Definition: MatrixBase_all.cpp:2
Vector3f p1
Definition: MatrixBase_all.cpp:2
float * p
Definition: Tutorial_Map_using.cpp:9
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:16
Definition: SuperQuadricParticle.h:36
Definition: Kernel/Math/Vector.h:30
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:350
RealScalar s
Definition: level1_cplx_impl.h:130
const Mdouble pi
Definition: ExtendedMath.h:23
void check(double real, double ideal, double error, std::string errorMessage)
Definition: TestHelpers.cc:16
Constructor for SteadyAxisymAdvectionDiffusion problem
Definition: steady_axisym_advection_diffusion.cc:213

References helpers::check(), e(), Vec3D::getLength(), NEVER, NO_FILE, p, p0, p1, constants::pi, problem, and s.