MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MovingWallUnitTest.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 <cmath>
27 #include <iostream>
28 #include <iomanip>
29 
30 #include <Logger.h>
31 #include "DPMBase.h"
32 #include "Particles/BaseParticle.h"
34 #include "Walls/InfiniteWall.h"
35 
40 class MovingWall : public DPMBase
41 {
42 public:
43 
45  {
49  }
50 
52  {
54  setXMax(2);
55  setYMax(2);
56  setZMax(2);
59  setGravity(Vec3D(0.0, 0.0, 0.0));
60  species->setCollisionTimeAndRestitutionCoefficient(0.01, 1.0, 1.0);
61  setTimeStep(0.0002);
62  setTimeMax(1.0);
64 
65  //set particles
66  particle->setRadius(0.5);
67  particle->setPosition(Vec3D(1.0, 1.0, 1.0));
68  particle->setVelocity(Vec3D(0.0, 0.0, -1.0));
69 
70  //set walls
71  wall->setNormal(Vec3D(0.0, 0.0, -1.0));
72 
73  }
74 
75 protected:
79 };
80 
83 {
85  {
87  particle->setVelocity(Vec3D(0.0, 0.0, -2.0));
88  wall->setPosition(Vec3D(0.0, 0.0, 0.0));
89  wall->setVelocity(Vec3D(0.0, 0.0, 0.0));
90  }
91 };
92 
94 {
96  {
98  wall->setPosition(Vec3D(0.0, 0.0, 0.0));
99  wall->setVelocity(Vec3D(0.0, 0.0, 1.0));
100  }
101 };
102 
104 {
106  {
108  wall->setPrescribedPosition([] (double time)
109  {
110  return Vec3D(0.0,0.0,time);
111  });
112  }
113 };
114 
116 {
118  {
120  wall->setPosition(Vec3D(0.0, 0.0, 0.0));
121  wall->setPrescribedVelocity([] (double time UNUSED)
122  {
123  return Vec3D(0.0,0.0,1);
124  });
125 
126  }
127 };
128 
130 {
132  {
134  wall->setPrescribedPosition([] (double time)
135  {
136  return Vec3D(0.0,0.0,time);
137  });
138  wall->setPrescribedVelocity([] (double time UNUSED)
139  {
140  return Vec3D(0.0,0.0,1);
141  });
142  }
143 };
144 
146 {
147 public:
149  {
151  setGravity(Vec3D(0,0,-1));
152  species->setCollisionTimeAndRestitutionCoefficient(0.01, 0.5, 1);
153  species->setSlidingFrictionCoefficient(0.5);
154  species->setSlidingStiffness(species->getStiffness() * 2.0 / 7.0);
155  species->setSlidingDissipation(species->getDissipation());
157  particle->setVelocity(Vec3D(0.0, 0.0, 0.0));
158  }
159 };
160 
163 {
165  {
167  particle->setVelocity(Vec3D(-1.0, 0.0, 0.0));
168  wall->setPosition(Vec3D(0.0, 0.0, 0.0));
169  wall->setVelocity(Vec3D(0.0, 0.0, 0.0));
170  }
171 };
172 
174 {
176  {
178  wall->setPosition(Vec3D(0.0, 0.0, 0.0));
179  wall->setVelocity(Vec3D(1.0, 0.0, 0.0));
180  }
181 };
182 
184 {
186  {
188  wall->setPrescribedPosition([] (double time)
189  {
190  return Vec3D(time,0.0,0.0);
191  });
192  }
193 };
194 
196 {
198  {
200  wall->setPosition(Vec3D(0.0, 0.0, 0.0));
201  wall->setPrescribedVelocity([] (double time UNUSED)
202  {
203  return Vec3D(1.0,0.0,0.0);
204  });
205 
206  }
207 };
208 
210 {
212  {
214  wall->setPrescribedPosition([] (double time)
215  {
216  return Vec3D(time,0.0,0.0);
217  });
218  wall->setPrescribedVelocity([] (double time UNUSED)
219  {
220  return Vec3D(1.0,0.0,0.0);
221  });
222  }
223 };
224 
225 void compareParticles(BaseParticle* Ptest, BaseParticle* Pref, double absError, Vec3D positionDifference, Vec3D velocityDifference, Vec3D orientationDifference, Vec3D AngularVelocityDifference)
226 {
227  if (!mathsFunc::isEqual(Ptest->getPosition(), Pref->getPosition() + positionDifference, absError))
228  {
229  logger(FATAL, "The particle has the wrong position. It is %, however is should be %, the difference is %", Ptest->getPosition(), Pref->getPosition() + positionDifference, Ptest->getPosition() - Pref->getPosition() - positionDifference);
230  }
231  if (!mathsFunc::isEqual(Ptest->getVelocity(), Pref->getVelocity() + velocityDifference, absError))
232  {
233  logger(FATAL, "The particle has the wrong velocity. It is %, however is should be %, the difference is %", Ptest->getVelocity(), Pref->getVelocity() + velocityDifference, Ptest->getVelocity() - Pref->getVelocity() - velocityDifference);
234  }
235  if (!mathsFunc::isEqual(Ptest->getOrientation(), Pref->getOrientation() + orientationDifference, absError))
236  {
237  logger(FATAL, "The particle has the wrong orientation. It is %, however is should be %, the difference is %", Ptest->getOrientation(), Pref->getOrientation() + orientationDifference, Ptest->getOrientation() - Pref->getOrientation() - orientationDifference);
238  }
239  if (!mathsFunc::isEqual(Ptest->getAngularVelocity(), Pref->getAngularVelocity() + AngularVelocityDifference, absError))
240  {
241  logger(FATAL, "The particle has the wrong angular velocity. It is %, however is should be %, the difference is %", Ptest->getAngularVelocity(), Pref->getAngularVelocity() + AngularVelocityDifference, Ptest->getAngularVelocity() - Pref->getAngularVelocity() - AngularVelocityDifference);
242  }
243 }
244 
245 int main(int argc UNUSED, char *argv[] UNUSED)
246 {
247 
248  {
249  MovingWallReference problem0;
250  problem0.setName("MovingWallUnitTest_Normal_Reference");
251  problem0.solve();
253  problem1.setName("MovingWallUnitTest_Normal_SimpleIntegration");
254  problem1.solve();
256  problem2.setName("MovingWallUnitTest_Normal_PrescribedPosition");
257  problem2.solve();
259  problem3.setName("MovingWallUnitTest_Normal_PrescribedVelocity");
260  problem3.solve();
262  problem4.setName("MovingWallUnitTest_Normal_PrescribedPositionPrescribedVelocity");
263  problem4.solve();
264 
265  Vec3D positionDifference = Vec3D(0.0, 0.0, problem0.getTime());
266  Vec3D velocityDifference = Vec3D(0.0, 0.0, 1.0);
267  Vec3D orientationDifference = Vec3D(0.0, 0.0, 0.0);
268  Vec3D angularVelocityDifference = Vec3D(0.0, 0.0, 0.0);
269  compareParticles(problem1.particleHandler.getLastObject(), problem0.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
270  compareParticles(problem2.particleHandler.getLastObject(), problem0.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
271  compareParticles(problem3.particleHandler.getLastObject(), problem0.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
272  compareParticles(problem4.particleHandler.getLastObject(), problem0.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
273  }
274  {
276  problem5.setName("MovingWallUnitTest_Tangential_Reference");
277  problem5.solve();
279  problem6.setName("MovingWallUnitTest_Tangential_SimpleIntegration");
280  problem6.solve();
282  problem7.setName("MovingWallUnitTest_Tangential_PrescribedPosition");
283  problem7.solve();
285  problem8.setName("MovingWallUnitTest_Tangential_PrescribedVelocity");
286  problem8.solve();
288  problem9.setName("MovingWallUnitTest_Tangential_PrescribedPositionPrescribedVelocity");
289  problem9.solve();
290 
291  Vec3D positionDifference = Vec3D(problem5.getTime(), 0.0, 0.0);
292  Vec3D velocityDifference = Vec3D(1.0, 0.0, 0.0);
293  Vec3D orientationDifference = Vec3D(0.0, 0.0, 0.0);
294  Vec3D angularVelocityDifference = Vec3D(0.0, 0.0, 0.0);
295  compareParticles(problem6.particleHandler.getLastObject(), problem5.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
296  compareParticles(problem7.particleHandler.getLastObject(), problem5.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
297  compareParticles(problem8.particleHandler.getLastObject(), problem5.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
298  compareParticles(problem9.particleHandler.getLastObject(), problem5.particleHandler.getLastObject(), 1e-10, positionDifference, velocityDifference, orientationDifference, angularVelocityDifference);
299  }
300 
301  /*
302  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWall.data MovingWallUnitTest_Normal_PrescribedPosition.data
303  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWall.data MovingWallUnitTest_Normal_PrescribedVelocity.data
304  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWall.data MovingWallUnitTest_Normal_PrescribedPositionPrescribedVelocity.data
305  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWall.data MovingWallUnitTest_Normal_SimpleIntegration.data
306  diff ../../../Source/Drivers/UnitTests/SelfTestData/noMovingWall.data MovingWallUnitTest_Normal_Reference.data
307 
308  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWallTangential.data MovingWallUnitTest_Tangential_PrescribedPosition.data
309  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWallTangential.data MovingWallUnitTest_Tangential_PrescribedVelocity.data
310  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWallTangential.data MovingWallUnitTest_Tangential_PrescribedPositionPrescribedVelocity.data
311  diff ../../../Source/Drivers/UnitTests/SelfTestData/movingWallTangential.data MovingWallUnitTest_Tangential_SimpleIntegration.data
312  diff ../../../Source/Drivers/UnitTests/SelfTestData/noMovingWallTangential.data MovingWallUnitTest_Tangential_Reference.data
313  */
314 
315 
316  return 0;
317 }
BaseParticle * particle
void compareParticles(BaseParticle *Ptest, BaseParticle *Pref, double absError, Vec3D positionDifference, Vec3D velocityDifference, Vec3D orientationDifference, Vec3D AngularVelocityDifference)
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
LinearViscoelasticSlidingFrictionSpecies * species
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 setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setPrescribedPosition(std::function< Vec3D(double)> prescribedPosition)
Allows the position of an infinite mass interactable to be prescribed.
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
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:453
Species< LinearViscoelasticNormalSpecies, SlidingFrictionSpecies > LinearViscoelasticSlidingFrictionSpecies
void setGravity(Vec3D newGravity)
Allows to modify the gravity vector.
Definition: DPMBase.cc:431
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 Vec3D & getOrientation() const
Returns the orientation of this BaseInteractable.
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
In the reference case the particle just moves two times as fast.
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
InfiniteWall * wall
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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
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
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setPrescribedVelocity(std::function< Vec3D(double)> prescribedVelocity)
Allows the velocity of an infinite mass interactable to be prescribed.
void setDensity(Mdouble density)
Allows the density to be changed.
This tests if moving the wall works with CWall::move(Vec3D velocity,Vec3D dt).
#define UNUSED
Definition: GeneralDefine.h:37
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
LL< Log::FATAL > FATAL
Fatal log level.
Definition: Logger.cc:25
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
Mdouble getRadius() const
Returns the particle's radius_.
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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 setNormal(const Vec3D normal)
Changes the normal of the InfiniteWall.
Definition: InfiniteWall.cc:79
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:883
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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 ...
In the reference case the particle just moves two times as fast.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353
This is a class defining walls.
Definition: InfiniteWall.h:43
Contains material and contact force properties.
Definition: Interaction.h:35
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition: BaseHandler.h:452
int main(int argc UNUSED, char *argv[] UNUSED)
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Mdouble getTimeStep() const
Allows the time step dt to be accessed.
Definition: DPMBase.cc:368
unsigned int getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(unsigned int numberOfSaves, Mdouble timeMax, Mdouble timestep)
Returns the correct saveCount if the total number of saves, the final time and the time step is known...
Definition: Helpers.cc:343
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:158
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:194
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...