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
40 {
41  Mercury3D problem;
42  problem.setName("ElasticSuperQuadricUnitTest");
43  problem.setDomain({-1,-1,-1},{1,1,1});
44  problem.setSaveCount(NEVER);
45  problem.dataFile.setSaveCount(10);
46 
48  s->setStiffness(2e5);
49  s->setDensity(6.0/constants::pi);
50 
52  p.setSpecies(s);
53  p.setAxes(.5,.5,.5);
54  p.setExponents(.5,.9);
55  p.setPosition({.1,0,.5});
56  p.setVelocity({0,0,-.5});
57  auto p0 = problem.particleHandler.copyAndAddObject(p);
58 
59  p.setPosition(-p.getPosition());
60  p.setVelocity(-p.getVelocity());
61  //p.rotate({0,constants::pi,0});
62  auto p1 = problem.particleHandler.copyAndAddObject(p);
63 
64  problem.setTimeMax(1e-0);
65  problem.setTimeStep(1e-4);
66 
67  const Vec3D momentum0 = problem.particleHandler.getMomentum();
68  const Vec3D angularMomentum0 = problem.particleHandler.getAngularMomentum();
69  const Mdouble kineticEnergy0 = problem.particleHandler.getKineticEnergy()
71 
72  // comment the next to lines to turn on file output
75  problem.solve();
76 
77  const Vec3D momentum1 = problem.particleHandler.getMomentum();
78  const Vec3D angularMomentum1 = problem.particleHandler.getAngularMomentum();
79  const Mdouble kineticEnergy1 = problem.particleHandler.getKineticEnergy()
81 
82  // Check conservation properties
83  helpers::check(momentum0-momentum1,{0,0,0},1e-10*momentum0.getLength(),
84  "Conservation of momentum");
85  helpers::check(angularMomentum0-angularMomentum1,{0,0,0},1e-10*angularMomentum0.getLength(),
86  "Con. of angular momentum");
87  helpers::check(kineticEnergy0-kineticEnergy1,0,1e-4*kineticEnergy0,
88  "Con. of kinetic energy ");
89  // Note, energy conservation is not very good; it does not decay quickly with time step
90 
91  return 0;
92 }
const unsigned NEVER
Definition: File.h:35
@ NO_FILE
file will not be created/read
double Mdouble
Definition: GeneralDefine.h:34
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:33
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Definition: BaseInteractable.cc:329
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Definition: BaseInteractable.cc:350
virtual void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Definition: BaseInteractable.h:239
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
void setSpecies(const ParticleSpecies *species)
Definition: BaseParticle.cc:818
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:408
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1427
void setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1098
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1478
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:459
void setSuperquadricParticlesWriteVTK(bool writeSuperquadricParticlesVTK)
Definition: DPMBase.cc:956
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1234
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:873
void solve()
The work horse of the code.
Definition: DPMBase.cc:4270
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
Definition: File.cc:273
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:37
Mdouble getRotationalEnergy() const
Definition: ParticleHandler.cc:586
Vec3D getMomentum() const
Definition: ParticleHandler.cc:666
Vec3D getAngularMomentum() const
Definition: ParticleHandler.cc:675
Mdouble getKineticEnergy() const
Definition: ParticleHandler.cc:557
Definition: SuperQuadricParticle.h:57
void setExponents(const Mdouble &eps1, const Mdouble &eps2) override
Set the exponents to eps1 and eps2 for this superquadric. We use the super-ellipsoid definition state...
Definition: SuperQuadricParticle.cc:169
void setAxes(const Mdouble &a1, const Mdouble &a2, const Mdouble &a3)
Set the axes-lengths to a1, a2 and a3 for this superquadric. We use the super-ellipsoid definition st...
Definition: SuperQuadricParticle.cc:164
Definition: Vector.h:51
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
const Mdouble pi
Definition: ExtendedMath.h:45
void check(double real, double ideal, double error, std::string errorMessage)
Definition: TestHelpers.cc:37

References helpers::check(), BaseHandler< T >::copyAndAddObject(), DPMBase::dataFile, ParticleHandler::getAngularMomentum(), ParticleHandler::getKineticEnergy(), Vec3D::getLength(), ParticleHandler::getMomentum(), BaseInteractable::getPosition(), ParticleHandler::getRotationalEnergy(), BaseInteractable::getVelocity(), NEVER, NO_FILE, DPMBase::particleHandler, constants::pi, SuperQuadricParticle::setAxes(), DPMBase::setDomain(), SuperQuadricParticle::setExponents(), DPMBase::setFileType(), DPMBase::setName(), BaseInteractable::setPosition(), DPMBase::setSaveCount(), File::setSaveCount(), BaseParticle::setSpecies(), DPMBase::setSuperquadricParticlesWriteVTK(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), BaseInteractable::setVelocity(), DPMBase::solve(), and DPMBase::speciesHandler.