MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
1Particle4WallsRestartUnitTest.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 
26 #include <Logger.h>
27 #include "DPMBase.h"
28 #include "Math/Helpers.h"
29 
35 int main(int argc UNUSED, char *argv[] UNUSED)
36 {
37  helpers::writeToFile("1Particle4WallsRestartUnitTest.ini",
38  "1 0 0 0 0 .96 1 .96\n"
39  "0.48 0 0.48 0 0 0 0.5 0 0 0 0 0 0 0\n"
40  );
41 
42  helpers::writeToFile("1Particle4WallsRestartUnitTest.restart",
43  "restart_version 1.0 name 1Particle4WallsRestartUnitTest_restart\n"
44  "dataFile name 1Particle4WallsRestartUnitTest_restart.data fileType ONE_FILE saveCount 5 counter 0 nextSavedTimeStep 0\n"
45  "fStatFile name 1Particle4WallsRestartUnitTest_restart.fstat fileType ONE_FILE saveCount 5 counter 0 nextSavedTimeStep 0\n"
46  "eneFile name 1Particle4WallsRestartUnitTest_restart.ene fileType ONE_FILE saveCount 5 counter 0 nextSavedTimeStep 0\n"
47  "restartFile name 1Particle4WallsRestartUnitTest_restart.restart fileType ONE_FILE saveCount 5 counter 0 nextSavedTimeStep 0\n"
48  "statFile name 1Particle4WallsRestartUnitTest_restart.stat fileType ONE_FILE saveCount 5 counter 0 nextSavedTimeStep 0\n"
49  "xMin 0 xMax 1 yMin 0 yMax 1 zMin 0 zMax 1\n"
50  "timeStep 1e-04 time 0 ntimeSteps 0 timeMax 0.01\n"
51  "systemDimensions 3 particleDimensions 3 gravity 0 0 0\n"
52  "Species 1\n"
53  "LinearViscoelasticSlidingFrictionSpecies id 0 density 1.9098593 stiffness 200000 dissipation 0 slidingStiffness 57142.857 slidingDissipation 0 frictionCoefficient 0.5 frictionCoefficientStatic 0.5\n"
54  "Walls 4\n"
55  "InfiniteWall id 0 indSpecies 0 position 0 0 0 orientation 0 0 0 1 velocity 0 0 0 angularVelocity 0 0 0 0 force 0 0 0 torque 0 0 0 normal -1 0 0 factor 1\n"
56  "InfiniteWall id 1 indSpecies 0 position 0.96 0 0 orientation 0 0 0 1 velocity 0 0 0 angularVelocity 0 0 0 0 force 0 0 0 torque 0 0 0 normal 1 0 0 factor 1\n"
57  "InfiniteWall id 2 indSpecies 0 position 0 0 0 orientation 0 0 0 1 velocity 0 0 0 angularVelocity 0 0 0 0 force 0 0 0 torque 0 0 0 normal 0 0 -1 factor 1\n"
58  "InfiniteWall id 3 indSpecies 0 position 0 0 0.96 orientation 0 0 0 1 velocity 0 0 0 angularVelocity 0 0 0 0 force 0 0 0 torque 0 0 0 normal 0 0 1 factor 1\n"
59  "Boundaries 0\n"
60  "Particles 1\n"
61  "BaseParticle id 0 indSpecies 0 position 0.48 0 0.48 orientation 0 0 0 1 velocity 0 0 0 angularVelocity 0 60 0 0 force 0 0 0 torque 0 0 0 radius 0.5 invMass 1 invInertia 10\n"
62  "Interactions 4\n"
63  "LinearViscoelasticSlidingFrictionInteraction particleWallIds 0 0 timeStamp 0 force 0 0 0 torque 0 0 0 slidingSpring 0 0 0\n"
64  "LinearViscoelasticSlidingFrictionInteraction particleWallIds 0 1 timeStamp 0 force 0 0 0 torque 0 0 0 slidingSpring 0 0 0\n"
65  "LinearViscoelasticSlidingFrictionInteraction particleWallIds 0 2 timeStamp 0 force 0 0 0 torque 0 0 0 slidingSpring 0 0 0\n"
66  "LinearViscoelasticSlidingFrictionInteraction particleWallIds 0 3 timeStamp 0 force 0 0 0 torque 0 0 0 slidingSpring 0 0 0\n"
67  );
68 
69  DPMBase problem;
70  problem.setName("1Particle4WallsRestartUnitTest");
71  problem.readRestartFile();
72  //problem.readDataFile("1Particle4WallsRestartUnitTest.ini");
73  problem.setAppend(false);
74  //problem.write(std::cout,true);
75  problem.solve();
76  //problem.write(std::cout,true);
77  problem.writeRestartFile();
78 
79  BaseParticle* p = problem.particleHandler.getObject(0);
80  if (!p->getAngularVelocity().isEqualTo(Vec3D(0.0,17.7251802668803,0.0), 1e-7)) logger(FATAL, "First particles has the wrong angular velocity it is %, while is should be %.",p->getAngularVelocity(),Vec3D(0.0,17.7251802668803,0.0));
81  if (!p->getVelocity().isEqualTo(Vec3D(0.0,0.0,0.0) , 1e-7)) logger(FATAL, "First particle has the wrong velocity, it is %, while it should be %",p->getVelocity(),0.0);
82 
83  //Now check the rotational energy in the system; it should loose some rotational energy in the first loop due to
84  //sliding, then conserve energy as no tangential dissipation is used.
85  //gnuplot:
86  // p '1Particle4WallsRestartUnitTest_restart.ene' u 1:4 w l t 'rotational energy', '1Particle4WallsRestartUnitTest_restart.ene' u 1:($3+$4+$5-160) w l t 'total energy - normal elastic energy'
87 
88 }
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: Helpers.cc:411
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
int main(int argc UNUSED, char *argv[] UNUSED)
In this file, 1 Particle and 4 Walls are loaded from files "1Particle4Walls.ini" and "1Particle4Walls...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void setAppend(bool newAppendFlag)
Allows to set the append option.
Definition: DPMBase.cc:544
bool isEqualTo(const Vec3D &other, const double tol) const
Checks if the length this Vec3D is equal the length of other with a certain tolerance.
Definition: Vector.cc:390
int readRestartFile()
Reads all the particle data corresponding to the current saved time step. Which is what the restart f...
Definition: DPMBase.cc:1375
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:149
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:415
#define UNUSED
Definition: GeneralDefine.h:37
LL< Log::FATAL > FATAL
Fatal log level.
Definition: Logger.cc:25
virtual void writeRestartFile()
Stores all the particle data for current save time step. Calls the write function.
Definition: DPMBase.cc:1365
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45