MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EnergyUnitTest.cpp
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
28 #include "DPMBase.h"
29 #include "Logger.h"
31 
38 class EnergyUnitTest : public DPMBase
39 {
40 public:
41 
43  {
45  //to see the behaviour of elastic and kinetic energy, comment the line above and plot in gnuplot
46  //p 'ReversibleAdhesiveEnergyUnitTest.ene' u 1:3 w lp, 'ReversibleAdhesiveEnergyUnitTest.ene' u 1:5 w lp, 'ReversibleAdhesiveEnergyUnitTest.ene' u 1:($3+$5) w lp
47  //p 'IrreversibleAdhesiveEnergyUnitTest.ene' u 1:3 w lp, 'IrreversibleAdhesiveEnergyUnitTest.ene' u 1:5 w lp, 'IrreversibleAdhesiveEnergyUnitTest.ene' u 1:($3+$5) w lp
48  setDimension(3);
49 
50  setGravity({0.0, 0.0, 0.0});
51 
52  setXMax(1.0);
53  setYMax(0.5);
54  setZMax(0.5);
55  setXMin(-1.0);
56  setYMin(-0.5);
57  setZMin(-0.5);
58 
60  BaseParticle P;
61  P.setRadius(0.5);
62  P.setPosition({-0.551, 0.0, 0.0});
63  P.setVelocity({0.7, 0.0, 0.0});
65  P.setPosition({0.551, 0.0, 0.0});
66  P.setVelocity({-0.7, 0.0, 0.0});
68  }
69 };
70 
71 int main(int argc UNUSED, char *argv[] UNUSED)
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 setXMax(Mdouble newXMax)
If the length of the problem domain in x-direction is XMax - XMin, this method sets XMax...
Definition: DPMBase.cc:309
void solve()
The work horse of the code.
Definition: DPMBase.cc:1895
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:61
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:179
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setYMin(Mdouble newYMin)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMin...
Definition: DPMBase.cc:280
double Mdouble
void setZMax(Mdouble newZMax)
If the length of the problem domain in z-direction is XMax - XMin, this method sets ZMax...
Definition: DPMBase.cc:338
void setDimension(unsigned int newDim)
Sets the system and particle dimension.
Definition: DPMBase.cc:445
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:169
void setGravity(Vec3D newGravity)
Allows to modify the gravity vector.
Definition: DPMBase.cc:431
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:26
T square(T val)
squares a number
Definition: ExtendedMath.h:91
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
void setYMax(Mdouble newYMax)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMax...
Definition: DPMBase.cc:324
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Definition: DPMBase.cc:552
file will not be created/read
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
void setXMin(Mdouble newXMin)
If the length of the problem domain in x-direction is XMax - XMin, this method sets XMin...
Definition: DPMBase.cc:266
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
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.
#define UNUSED
Definition: GeneralDefine.h:37
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
void setZMin(Mdouble newZMin)
If the length of the problem domain in z-direction is ZMax - ZMin, this method sets ZMin...
Definition: DPMBase.cc:295
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 setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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
int main(int argc UNUSED, char *argv[] UNUSED)