MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EnergyUnitTest.cpp File Reference

Go to the source code of this file.

Classes

class  EnergyUnitTest
 

Functions

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

Function Documentation

int main ( int argc  UNUSED,
char *argv[]  UNUSED 
)
Todo:
TW The inaccuracy of the calculation is much worse for the irreversible force model, as there is a jump in force at zero overlap; we should correct for that in the time stepping algorithm (i.e. find out what the mean force was over the duration of the timestep, not using a left Riemann sum.

Definition at line 71 of file EnergyUnitTest.cpp.

References BaseHandler< T >::copyAndAddObject(), ERROR, DPMBase::getElasticEnergy(), DPMBase::getKineticEnergy(), DPMBase::getTimeStep(), mathsFunc::isEqual(), logger, constants::pi, ParticleSpecies::setDensity(), Files::setName(), Files::setSaveCount(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), DPMBase::solve(), DPMBase::speciesHandler, and mathsFunc::square().

72 {
73  std::cout << "Test if the LinearViscoelasticReversibleAdhesiveInteraction conserves energy" << std::endl;
74  EnergyUnitTest energyUnitTest;
75  energyUnitTest.setName("ReversibleAdhesiveEnergyUnitTest");
77  species1.setDensity(6.0 / constants::pi);
78  species1.setStiffness(500);
79  species1.setAdhesionStiffness(100);
80  species1.setAdhesionForceMax(10);
81  //std::cout << "maxVelocity=" << species1.getMaximumVelocity(0.5, 1.0) << std::endl;
82  energyUnitTest.setTimeStep(0.002 * species1.getCollisionTime(1.0));
83  //std::cout << "timeStep=" << energyUnitTest.getTimeStep() << std::endl;
84  energyUnitTest.setSaveCount(3);
85  energyUnitTest.setTimeMax(0.4);
86  energyUnitTest.speciesHandler.copyAndAddObject(species1);
87  energyUnitTest.solve();
88  Mdouble lostEnergy = mathsFunc::square(0.7)-energyUnitTest.getElasticEnergy()-energyUnitTest.getKineticEnergy();
89  if (!mathsFunc::isEqual(lostEnergy, 0.0, 1e-6))
90  {
91  logger(ERROR, "energy loss is %, but should be %", lostEnergy, 0.0);
92  }
93 
94  std::cout << "Test if the LinearViscoelasticIrreversibleAdhesiveInteraction looses the right amount of energy" << std::endl;
95  EnergyUnitTest energyUnitTest2;
96  energyUnitTest2.setName("IrreversibleAdhesiveEnergyUnitTest");
98  species2.setDensity(6.0 / constants::pi);
99  species2.setStiffness(500);
100  species2.setAdhesionStiffness(100);
101  species2.setAdhesionForceMax(10);
102  std::cout << "maxVelocity=" << species2.getMaximumVelocity(0.5, 1.0) << std::endl;
103  //this test is 10 times more accurate than the previous one, as the error is so much bigger.
104  energyUnitTest2.setTimeStep(0.0002 * species2.getCollisionTime(1.0));
105  std::cout << "timeStep=" << energyUnitTest2.getTimeStep() << std::endl;
106  energyUnitTest2.setSaveCount(3);
107  energyUnitTest2.setTimeMax(0.2);
108  energyUnitTest2.speciesHandler.copyAndAddObject(species2);
109  energyUnitTest2.solve();
110  lostEnergy = mathsFunc::square(0.7)-energyUnitTest2.getElasticEnergy()-energyUnitTest2.getKineticEnergy();
118  if (!mathsFunc::isEqual(lostEnergy, 0.5, 1e-4))
119  {
120  logger(ERROR, "energy loss is %, but should be %", lostEnergy, 0.5);
121  }
122 
123  return 0;
124 }
void solve()
The work horse of the code.
Definition: DPMBase.cc:1895
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:179
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:26
T square(T val)
squares a number
Definition: ExtendedMath.h:91
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Definition: DPMBase.cc:552
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:149
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:268
const Mdouble pi
Definition: ExtendedMath.h:42
Mdouble getKineticEnergy() const
Returns the global kinetic energy stored in the system.
Definition: DPMBase.cc:563
void setDensity(Mdouble density)
Allows the density to be changed.
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
bool isEqual(Mdouble v1, Mdouble v2, double absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353
Contains material and contact force properties.
Definition: Interaction.h:35
Mdouble getTimeStep() const
Allows the time step dt to be accessed.
Definition: DPMBase.cc:368