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.
51 {
52  logger(INFO, "Test if the LinearViscoelasticReversibleAdhesiveInteraction conserves energy");
53  EnergyUnitTest energyUnitTest;
54  energyUnitTest.setName("ReversibleAdhesiveEnergyUnitTest");
56  species1.setDensity(6.0 / constants::pi);
57  species1.setStiffness(500);
58  species1.setAdhesionStiffness(100);
59  species1.setAdhesionForceMax(10);
60  //std::cout << "maxVelocity=" << species1.getMaximumVelocity(0.5, 1.0) << std::endl;
61  energyUnitTest.setTimeStep(0.002 * species1.getCollisionTime(1.0));
62  //std::cout << "timeStep=" << energyUnitTest.getTimeStep() << std::endl;
63  energyUnitTest.setSaveCount(3);
64  energyUnitTest.setTimeMax(0.4);
65  energyUnitTest.speciesHandler.copyAndAddObject(species1);
66  energyUnitTest.solve();
67  Mdouble lostEnergy = mathsFunc::square(0.7) - energyUnitTest.getElasticEnergy() - energyUnitTest.getKineticEnergy();
68  if (!mathsFunc::isEqual(lostEnergy, 0.0, 1e-6))
69  {
70  logger(ERROR, "energy loss is %, but should be %", lostEnergy, 0.0);
71  }
72 
73  logger(INFO, "Test if the LinearViscoelasticIrreversibleAdhesiveInteraction looses the right amount of energy\n",
75  EnergyUnitTest energyUnitTest2;
76  energyUnitTest2.setName("IrreversibleAdhesiveEnergyUnitTest");
78  species2.setDensity(6.0 / constants::pi);
79  species2.setStiffness(500);
80  species2.setAdhesionStiffness(100);
81  species2.setAdhesionForceMax(10);
82  logger(INFO, "maxVelocity=%\n", species2.getMaximumVelocity(0.5, 1.0), Flusher::NO_FLUSH);
83  //this test is 10 times more accurate than the previous one, as the error is so much bigger.
84  energyUnitTest2.setTimeStep(0.0002 * species2.getCollisionTime(1.0));
85  logger(INFO, "timeStep=%\n", energyUnitTest2.getTimeStep());
86  energyUnitTest2.setSaveCount(3);
87  energyUnitTest2.setTimeMax(0.2);
88  energyUnitTest2.speciesHandler.copyAndAddObject(species2);
89  energyUnitTest2.solve();
90  lostEnergy = mathsFunc::square(0.7)-energyUnitTest2.getElasticEnergy()-energyUnitTest2.getKineticEnergy();
98  if (!mathsFunc::isEqual(lostEnergy, 0.5, 1e-4))
99  {
100  logger(ERROR, "energy loss is %, but should be %", lostEnergy, 0.5);
101  }
102 
103  return 0;
104 }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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
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:360
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:386
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:400
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1241
Mdouble getKineticEnergy() const
Returns the global kinetic energy stored in the system.
Definition: DPMBase.cc:1535
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1225
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:864
void solve()
The work horse of the code.
Definition: DPMBase.cc:4334
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Definition: DPMBase.cc:1521
Definition: EnergyUnitTest.cpp:18
void setDensity(Mdouble density)
Definition: ParticleSpecies.cc:88
Contains material and contact force properties.
Definition: Species.h:14
#define INFO(i)
Definition: mumps_solver.h:54
const Mdouble pi
Definition: ExtendedMath.h:23
T square(const T val)
squares a number
Definition: ExtendedMath.h:86
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

References BaseHandler< T >::copyAndAddObject(), e(), 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().