EnergyUnitTest.cpp File Reference

Classes

class  EnergyUnitTest
 

Functions

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

Function Documentation

◆ main()

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 time step, not using a left Riemann sum.
72 {
73  logger(INFO, "Test if the LinearViscoelasticReversibleAdhesiveInteraction conserves energy");
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  logger(INFO, "Test if the LinearViscoelasticIrreversibleAdhesiveInteraction looses the right amount of energy\n",
96  EnergyUnitTest energyUnitTest2;
97  energyUnitTest2.setName("IrreversibleAdhesiveEnergyUnitTest");
99  species2.setDensity(6.0 / constants::pi);
100  species2.setStiffness(500);
101  species2.setAdhesionStiffness(100);
102  species2.setAdhesionForceMax(10);
103  logger(INFO, "maxVelocity=%\n", species2.getMaximumVelocity(0.5, 1.0), Flusher::NO_FLUSH);
104  //this test is 10 times more accurate than the previous one, as the error is so much bigger.
105  energyUnitTest2.setTimeStep(0.0002 * species2.getCollisionTime(1.0));
106  logger(INFO, "timeStep=%\n", energyUnitTest2.getTimeStep());
107  energyUnitTest2.setSaveCount(3);
108  energyUnitTest2.setTimeMax(0.2);
109  energyUnitTest2.speciesHandler.copyAndAddObject(species2);
110  energyUnitTest2.solve();
111  lostEnergy = mathsFunc::square(0.7)-energyUnitTest2.getElasticEnergy()-energyUnitTest2.getKineticEnergy();
119  if (!mathsFunc::isEqual(lostEnergy, 0.5, 1e-4))
120  {
121  logger(ERROR, "energy loss is %, but should be %", lostEnergy, 0.5);
122  }
123 
124  return 0;
125 }
double Mdouble
Definition: GeneralDefine.h:34
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
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:53
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
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 setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1250
Mdouble getKineticEnergy() const
Returns the global kinetic energy stored in the system.
Definition: DPMBase.cc:1544
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
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Definition: DPMBase.cc:1530
Definition: EnergyUnitTest.cpp:39
void setDensity(Mdouble density)
Definition: ParticleSpecies.cc:108
Contains material and contact force properties.
Definition: Species.h:35
const Mdouble pi
Definition: ExtendedMath.h:45
T square(const T val)
squares a number
Definition: ExtendedMath.h:106
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
Definition: ExtendedMath.cc:251

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