MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PeriodicWallsWithSlidingFrictionUnitTest.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.
27 #include "Mercury3D.h"
29 #include "Particles/BaseParticle.h"
30 #include <Logger.h>
31 
36 
38 {
40  {
42  species->setDensity(constants::pi / 6.0);
43 
44  double stiffness = 1e5;
46  species->setDensity(2500);
47  species->setStiffness(stiffness);
48  species->setSlidingStiffness(2.0 / 7.0 * stiffness);
49  species->setSlidingFrictionCoefficient(0.5);
50  species->setRollingStiffness(2.0 / 5.0 * stiffness);
51  species->setRollingFrictionCoefficient(0.5);
52  species->setTorsionStiffness(2.0 / 5.0 * stiffness);
53  species->setTorsionFrictionCoefficient(0.5);
54 
55  setGravity(Vec3D(0.0, 0.0, 0.0));
56  setTimeMax(8e-2);
57  setTimeStep(2.0e-4);
59 
60  setXMin(0.0);
61  setYMin(0.0);
62  setXMax(1.0);
63  setYMax(1.0);
64 
66  b0.set(Vec3D(1, 0, 0), getXMin(), getXMax());
68  b0.set(Vec3D(0, 1, 0), getYMin(), getYMax());
70 
71  BaseParticle P0, P1, P2, P3, P4, P5, P6, P7;
72 
73  //Particle to be removed
74  P0.setPosition(Vec3D(0.1, 0.1, 0.0));
75  P1.setPosition(Vec3D(0.3, 0.3, 0.0));
76  //Contacts starts normal becomes periodic
77  P2.setPosition(Vec3D(0.6, 0.041, 0.0));
78  P2.setAngularVelocity(Vec3D(0.3, 0.6, 0.9));
79  P3.setPosition(Vec3D(0.4, 0.001, 0.0));
80  //Normal case
81  P4.setPosition(Vec3D(0.6, 0.82, 0.0));
82  P4.setAngularVelocity(Vec3D(0.3, 0.6, 0.9));
83  P5.setPosition(Vec3D(0.4, 0.78, 0.0));
84  //Contact starts periodic becomes normal and periodic again
85  P6.setPosition(Vec3D(0.02, 0.42, 0.0));
86  P6.setAngularVelocity(Vec3D(0.3, 0.6, 0.9));
87  P7.setPosition(Vec3D(0.82, 0.38, 0.0));
88 
89  P0.setVelocity(Vec3D(0.0, 0.0, 0.0));
90  P1.setVelocity(Vec3D(0.0, 0.0, 0.0));
91  P2.setVelocity(Vec3D(-1.0, 0.0, 0.0));
92  P3.setVelocity(Vec3D(1.0, 0.0, 0.0));
93  P4.setVelocity(Vec3D(-1.0, 0.0, 0.0));
94  P5.setVelocity(Vec3D(1.0, 0.0, 0.0));
95  P6.setVelocity(Vec3D(-1.0, 0.0, 0.0));
96  P7.setVelocity(Vec3D(1.0, 0.0, 0.0));
97 
98  P0.setRadius(0.1);
99  P1.setRadius(0.1);
100  P2.setRadius(0.1);
101  P3.setRadius(0.1);
102  P4.setRadius(0.1);
103  P5.setRadius(0.1);
104  P6.setRadius(0.1);
105  P7.setRadius(0.1);
106 
115  }
116 
117 protected:
118 
120  {
121  static bool FirstParticleRemoved = false;
122  static bool SecondParticlRemoved = false;
123  if (getTime() > 3.5e-2 && FirstParticleRemoved == false)
124  {
125  logger(VERBOSE, "Just before removing first particle");
126  for (auto it = interactionHandler.begin(); it != interactionHandler.end(); ++it)
127  {
128  logger(VERBOSE, "Interaction between particle (id=% index=%) and particle (id=% index=%) delta=%)", (*it)->getP()->getId(), (*it)->getP()->getIndex(), (*it)->getI()->getId(), (*it)->getI()->getIndex(), (*it)->getTimeStamp());
129  }
130 
131  FirstParticleRemoved = true;
133 
134  logger(VERBOSE, "Just after removing first particle");
135  for (auto it = interactionHandler.begin(); it != interactionHandler.end(); ++it)
136  {
137  logger(VERBOSE, "Interaction between particle (id=% index=%) and particle (id=% index=%) delta=%)", (*it)->getP()->getId(), (*it)->getP()->getIndex(), (*it)->getI()->getId(), (*it)->getI()->getIndex(), (*it)->getTimeStamp());
138  }
139  logger(VERBOSE, "What should have happened:");
140  logger(VERBOSE, "First the particle (id=1,index=1) is removed");
141  logger(VERBOSE, "This causes the particle (id=7,index=7) to move to (id=7,index=1)");
142  logger(VERBOSE, "So the tangential spring witch was between particle (id=7,index=1) and (id=6,index=6) should be move to the last particle and reversed");
143  }
144 
145  if (getTime() > 4.5e-2 && SecondParticlRemoved == false)
146  {
147  logger(VERBOSE, "Just before removing second particle");
148  for (auto it = interactionHandler.begin(); it != interactionHandler.end(); ++it)
149  {
150  logger(VERBOSE, "Interaction between particle (id=% index=%) and particle (id=% index=%) delta=%)", (*it)->getP()->getId(), (*it)->getP()->getIndex(), (*it)->getI()->getId(), (*it)->getI()->getIndex(), (*it)->getTimeStamp());
151  }
152 
153  SecondParticlRemoved = true;
155 
156  logger(VERBOSE, "Just after removing second particle");
157  //TW: here this code seems to create a segmentation fault on my Mac
158  for (auto it = interactionHandler.begin(); it != interactionHandler.end(); ++it)
159  {
160  logger(VERBOSE, "Interaction between particle (id=% index=%) and particle (id=% index=%) delta=%)", (*it)->getP()->getId(), (*it)->getP()->getIndex(), (*it)->getI()->getId(), (*it)->getI()->getIndex(), (*it)->getTimeStamp());
161  }
162  logger(VERBOSE, "What should have happened:");
163  logger(VERBOSE, "First the particle (id=0,index=0) is removed");
164  logger(VERBOSE, "This causes the particle (id=6,index=6) to move to (id=0,index=0)");
165  logger(VERBOSE, "So the tangential spring between particle (id=6,index=6) and (id=7,index=1) should be move to the last particle and reversed");
166  }
167  }
168 
169  void printTime() const
170  {
171  }
172 };
173 
174 int main(int argc UNUSED, char *argv[] UNUSED)
175 {
177  PeriodicWallsWithSlidingFrictionUnitTest periodicWallsWithSlidingFrictionUnitTest;
178  periodicWallsWithSlidingFrictionUnitTest.solve();
179 
180  periodicWallsWithSlidingFrictionUnitTest.setName("PeriodicWallsWithSlidingFrictionUnitTest");
181 
182  BaseParticle* PNormal;
183  BaseParticle* PCase1;
184  BaseParticle* PCase2;
185  Vec3D shift;
186  PNormal = periodicWallsWithSlidingFrictionUnitTest.particleHandler.getObject(4);
187  PCase1 = periodicWallsWithSlidingFrictionUnitTest.particleHandler.getObject(0);
188  PCase2 = periodicWallsWithSlidingFrictionUnitTest.particleHandler.getObject(2);
189 
190  shift = Vec3D(-0.58, -0.4, 0.0);
191  if (!PCase1->getPosition().isEqualTo(PNormal->getPosition() + shift, 1e-10))
192  {
193  logger(FATAL, "E0 The particle is in the wrong position. It is %, however is should be %", PCase1->getPosition(), PNormal->getPosition() + shift);
194  }
195  if (!PCase1->getVelocity().isEqualTo(PNormal->getVelocity(), 1e-10))
196  {
197  logger(FATAL, "E1 The particle has the wrong velocity. It is %, however is should be %", PCase1->getVelocity(), PNormal->getVelocity());
198  }
199 
200  shift = Vec3D(0.0, -0.779, 0.0);
201  if (!PCase2->getPosition().isEqualTo(PNormal->getPosition() + shift, 1e-10))
202  {
203  logger(FATAL, "E2 The particle is in the wrong position. It is %, however is should be %", PCase2->getPosition(), PNormal->getPosition() + shift);
204  }
205  if (!PCase2->getVelocity().isEqualTo(PNormal->getVelocity(), 1e-10))
206  {
207  logger(FATAL, "E3 The particle has the wrong velocity. It is %, however is should be %", PCase2->getVelocity(), PNormal->getVelocity());
208  }
209 
210  PNormal = periodicWallsWithSlidingFrictionUnitTest.particleHandler.getObject(5);
211  PCase1 = periodicWallsWithSlidingFrictionUnitTest.particleHandler.getObject(1);
212  PCase2 = periodicWallsWithSlidingFrictionUnitTest.particleHandler.getObject(3);
213 
214  shift = Vec3D(1.0 - 0.58, -0.4, 0.0);
215  if (!PCase1->getPosition().isEqualTo(PNormal->getPosition() + shift, 1e-10))
216  {
217  std::cout << PNormal->getPosition() - PCase1->getPosition() << " " << PNormal->getPosition() + PCase1->getPosition() << std::endl;
218  logger(FATAL, "E4 The particle is in the wrong position. It is %, however is should be %", PCase1->getPosition(), PNormal->getPosition() + shift);
219  }
220  if (!PCase1->getVelocity().isEqualTo(PNormal->getVelocity(), 1e-10))
221  {
222  logger(FATAL, "E5 The particle has the wrong velocity. It is %, however is should be %", PCase1->getVelocity(), PNormal->getVelocity());
223  }
224 
225  shift = Vec3D(0.0, 1.0 - 0.779, 0.0);
226  if (!PCase2->getPosition().isEqualTo(PNormal->getPosition() + shift, 1e-10))
227  {
228  logger(FATAL, "E6 The particle is in the wrong position. It is %, however is should be %", PCase2->getPosition(), PNormal->getPosition() + shift);
229  }
230  if (!PCase2->getVelocity().isEqualTo(PNormal->getVelocity(), 1e-10))
231  {
232  logger(FATAL, "E7 The particle has the wrong velocity. It is %, however is should be %", PCase2->getVelocity(), PNormal->getVelocity());
233  }
234 }
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a periodic wall.
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
void actionsBeforeTimeStep()
A virtual function which allows to define operations to be executed before the new time step...
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
void printTime() const
Displays the current simulation time onto your screen for example.
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
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin...
Definition: DPMBase.cc:224
int main(int argc UNUSED, char *argv[] UNUSED)
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin...
Definition: DPMBase.cc:238
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:494
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
Definition: DPMBase.cc:474
Species< LinearViscoelasticNormalSpecies, FrictionSpecies > LinearViscoelasticFrictionSpecies
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
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
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:482
Defines a pair of periodic walls. Inherits from BaseBoundary.
Mdouble getXMax() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax...
Definition: DPMBase.cc:231
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
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
BoundaryHandler boundaryHandler
An object of the class BoundaryHandler which concerns insertion and deletion of particles into or fro...
Definition: DPMBase.h:888
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:35
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
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
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:893
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax...
Definition: DPMBase.cc:245
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:158
virtual void removeObject(unsigned const int id)
Removes a BaseParticle from the ParticleHandler.
This test is a UnitTest for: Periodic Particles in combination with HGrid Tangential Springs over per...