MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
force_test_demo.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 "DPMBase.h"
27 #include "Particles/BaseParticle.h"
28 #include "Walls/InfiniteWall.h"
29 #include "Species/Species.h"
31 //#include "Interactions/SlidingFrictionInteraction.h"
32 //#include "Interactions/LinearViscoelasticInteraction.h"
33 
35 public:
36 
38  {
40  }
41 
42  virtual void setupInitialConditions()
43  {
44  static int count = -1;
45  count++;
46 
47  // only do this for the first time
48  if (!count) {
51  species->setDensity(2000.0);
52 
53  unsigned int nParticle = 2;
54  normal = Vec3D(-1.0,0.0,0.0);
55  tangent = Vec3D(0.0,1.0,0.0);
56 
57  BaseParticle P0;
58  for (unsigned int j=0; j< nParticle; j++){
59  P0.setRadius(random.getRandomNumber(0.0005,0.001));
61  //P0.getSpecies()->computeMass(P0&);
62 
63  }
64 
65  //set random relative velocity
68 
69  tc = random.getRandomNumber(0.0,1.0e-5);
70  en = random.getRandomNumber(0.5,1.0);
71 
72  setXMax(0.005);
73  setYMax(0.005);
74  setZMax(0.005);
75 
77  species->setCollisionTimeAndRestitutionCoefficient(tc,en,2.0*m12);
78  setTimeMax(2.0*tc);
79  setTimeStep(tc / 200);
80  setSaveCount(1);
81  }
82 
83  // do this for all solves
85  particleHandler.getObject(1)->setVelocity(Vec3D(0.0,0.0,0.0));
88 
93 
94  }
95 
98  }
99 
100  void getRelativeVelocityComponents(Mdouble& normalRelativeVelocity, Mdouble& tangentialRelativeVelocity) {
101  Vec3D relativeVelocity = getRelativeVelocity();
102  normalRelativeVelocity = relativeVelocity.X / normal.X;
103  tangentialRelativeVelocity = relativeVelocity.Y / tangent.Y;
104  }
105 
108  return species->getCollisionTime(mass);
109  }
110 
111 
117 };
118 
120 public:
121 
123  {
124  static int count = -1;
125  count++;
126 
127  // only do this for the first time
128  if (!count) {
131  species->setDensity(2000.0);
132 
133 
134  InfiniteWall w0;
135  w0.set(Vec3D(1, 0, 0), Vec3D(0.0025, 0, 0));
137 
138  BaseParticle P0;
140  setXMax(0.005);
141  setYMax(0.005);
142  setZMax(0.005);
143 
144  //set random masses
145 
148 
149  //set random relative velocity
150  normal = Vec3D(-1.0,0.0,0.0);
151  tangent = Vec3D(0.0,1.0,0.0);
154 
155  tc = random.getRandomNumber(0.0,1.0e-5);
156  en = random.getRandomNumber(0.5,1.0);
157  m12 = particleHandler.getObject(0)->getMass(); // wall counts as an infinite mass
158  species->setCollisionTimeAndRestitutionCoefficient(tc,en,2.0*m12);
159  setTimeMax(2.0*tc);
160  setTimeStep(tc / 200);
161  setSaveCount(1);
162  }
163 
164  // do this for all solves
167 
169  particleHandler.getObject(0)->setOrientation(Vec3D(0.0,0.0,0.0));
170  }
171 
174  }
175  void getRelativeVelocityComponents(Mdouble& normalRelativeVelocity, Mdouble& tangentialRelativeVelocity) {
176  Vec3D relativeVelocity = getRelativeVelocity();
177  normalRelativeVelocity = relativeVelocity.X / normal.X;
178  tangentialRelativeVelocity = relativeVelocity.Y / tangent.Y;
179  }
180 
181 };
182 
184 {
185  std::cout << std::endl << "testing particle-particle collisions ..." << std::endl << std::endl;
186 
188 
189  problem.random.setRandomSeed(5);
190 
191  problem.setupInitialConditions();
192  Mdouble normalRelativeVelocity, tangentialRelativeVelocity, analyticTangentialRelativeVelocity;
193 
194  std::cout << "5: without tangential forces" << std::endl;
195  problem.setName("force_test5");
196  problem.solve();
197  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
198  std::cout << "tangentialRelativeVelocity: analytic=" << problem.initialTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
199  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
200 
201  //problem.setAppend_to_files(true);
202 
203  std::cout << "6: with Coulomb friction" << std::endl;
204  Mdouble mu = problem.random.getRandomNumber(0.0,1.0);
205  problem.species->setSlidingFrictionCoefficient(mu);
206  problem.species->setSlidingDissipation(1e20);
207  //problem.species->setSlidingStiffness(0.0);
208  problem.setName("force_test6");
209  problem.solve();
210  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
211  analyticTangentialRelativeVelocity = std::max(0.0,problem.initialTangentialRelativeVelocity + mu*3.5*(1+problem.en)*problem.initialNormalRelativeVelocity);
212  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
213  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
214 
215  std::cout << "7: with Coulomb friction, spring activated" << std::endl;
216  problem.species->setSlidingStiffness(1.0);
217  //problem.species->setSlidingDissipation(1);
218  problem.setName("force_test7");
219  problem.solve();
220  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
221  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
222 
223  std::cout << "8: with tangential viscous force" << std::endl;
224  Mdouble et = problem.random.getRandomNumber(-1.0,0.0);
225  problem.species->setSlidingFrictionCoefficient(1e20);
226  problem.species->setSlidingDissipation(-log(-et)/(2.0*problem.tc) /3.5 * 2.0 * problem.m12);
227  problem.species->setSlidingStiffness(0.0);
228  problem.setName("force_test8");
229  problem.solve();
230  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
231  analyticTangentialRelativeVelocity = problem.initialTangentialRelativeVelocity * exp(-2.0*3.5*problem.species->getSlidingDissipation()/(2.0*problem.m12) * problem.getCollisionTime(2.0*problem.m12));
232  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
233  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
234 
235  std::cout << "9: with tangential elastic force" << std::endl;
236  Mdouble et2 = problem.random.getRandomNumber(0.0,1.0);
237  problem.species->setSlidingFrictionCoefficient(1e20);
238  problem.species->setSlidingDissipation(0.0);
239  problem.species->setSlidingStiffness(problem.species->getStiffness()/3.5*mathsFunc::square(acos(-et2)/constants::pi));
240  problem.setName("force_test9");
241  problem.solve();
242  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
243  analyticTangentialRelativeVelocity = problem.initialTangentialRelativeVelocity * cos(sqrt(problem.species->getSlidingStiffness()/problem.m12*3.5)* problem.getCollisionTime(2.0*problem.m12));
244  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
245  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
246 
247 }
248 
250 {
251  std::cout << std::endl << "testing wall-particle collisions ..." << std::endl << std::endl;
252 
253  srand(5);
254 
255  wall_particle_collision problem;
256  problem.setupInitialConditions();
257 
258  Mdouble normalRelativeVelocity, tangentialRelativeVelocity, analyticTangentialRelativeVelocity;
259 
260  //problem.setAppend_to_files(true);
261 
262  std::cout << "0: without tangential forces" << std::endl;
263  problem.setName("force_test0");
264  problem.solve();
265 
266  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
267  std::cout << "tangentialRelativeVelocity: analytic=" << problem.initialTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
268  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
269 
270  std::cout << "1: with Coulomb friction" << std::endl;
271  Mdouble mu = problem.random.getRandomNumber(0.0,1.0);
272  problem.species->setSlidingFrictionCoefficient(mu);
273  problem.species->setSlidingDissipation(1e20);
274  problem.species->setSlidingStiffness(0.0);
275  problem.setName("force_test1");
276  problem.solve();
277  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
278  analyticTangentialRelativeVelocity = std::max(0.0,problem.initialTangentialRelativeVelocity + mu*3.5*(1+problem.en)*problem.initialNormalRelativeVelocity);
279  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
280  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
281 
282  std::cout << "2: with Coulomb friction, spring activated" << std::endl;
283  problem.species->setSlidingStiffness(1.0);
284  problem.setName("force_test2");
285  problem.solve();
286  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
287  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
288 
289  std::cout << "3: with tangential viscous force" << std::endl;
290  Mdouble et = problem.random.getRandomNumber(-1.0,0.0);
291  problem.species->setSlidingFrictionCoefficient(1e20);
292  problem.species->setSlidingDissipation(-log(-et)/(2.0*problem.tc) /3.5 * 2.0 * problem.m12);
293  problem.species->setSlidingStiffness(0.0);
294  problem.setName("force_test3");
295  problem.solve();
296  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
297  analyticTangentialRelativeVelocity = problem.initialTangentialRelativeVelocity * exp(-2.0*3.5*problem.species->getSlidingDissipation()/(2.0*problem.m12) * problem.getCollisionTime(2.0*problem.m12));
298  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
299  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
300 
301  std::cout << "4: with tangential elastic force" << std::endl;
302  Mdouble et2 = problem.random.getRandomNumber(0.0,1.0);
303  problem.species->setSlidingFrictionCoefficient(1e20);
304  problem.species->setSlidingDissipation(0.0);
305  problem.species->setSlidingStiffness(problem.species->getStiffness()/3.5*mathsFunc::square(acos(-et2)/constants::pi));
306  problem.setName("force_test4");
307  problem.solve();
308  problem.getRelativeVelocityComponents(normalRelativeVelocity, tangentialRelativeVelocity);
309  analyticTangentialRelativeVelocity = problem.initialTangentialRelativeVelocity * cos(sqrt(problem.species->getSlidingStiffness()/problem.m12*3.5)* problem.getCollisionTime(2.0*problem.m12));
310  std::cout << "tangentialRelativeVelocity: analytic=" << analyticTangentialRelativeVelocity << ", simulation=" << tangentialRelativeVelocity << std::endl;
311  std::cout << "normalRelativeVelocity: analytic:" << -problem.en*problem.initialNormalRelativeVelocity << ", simulation=" << normalRelativeVelocity << std::endl;
312 }
313 
314 
315 
316 int main(int argc UNUSED, char *argv[] UNUSED) {
317 
318  std::cout << std::endl << "note: analytic values are only asymptotically correct as delta->0" << std::endl;
321 
322  return 0;
323 }
324 
void particle_particle_test()
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
Mdouble X
the vector components
Definition: Vector.h:52
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 setOrientation(const Vec3D &orientation)
Sets the orientation of this BaseInteractable.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void getRelativeVelocityComponents(Mdouble &normalRelativeVelocity, Mdouble &tangentialRelativeVelocity)
double Mdouble
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
virtual void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
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
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 setYMax(Mdouble newYMax)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMax...
Definition: DPMBase.cc:324
void wall_particle_test()
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
Mdouble getMass() const
Returns the particle's mass_.
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
int main(int argc UNUSED, char *argv[] UNUSED)
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
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
Definition: Vector.cc:268
Mdouble getRadius() const
Returns the particle's radius_.
void getRelativeVelocityComponents(Mdouble &normalRelativeVelocity, Mdouble &tangentialRelativeVelocity)
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
Mdouble Y
Definition: Vector.h:52
virtual void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setRandomSeed(unsigned long int new_seed)
This is the seed for the random number generator. (note the call to seed_LFG is only required really ...
Definition: RNG.cc:46
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:883
RNG random
This is a random generator, often used for setting up the initial conditions etc...
Definition: DPMBase.h:873
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void set(Vec3D normal, Vec3D point)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
Definition: InfiniteWall.cc:70
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
LinearViscoelasticSlidingFrictionSpecies * species
Contains material and contact force properties.
Definition: Interaction.h:35
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Mdouble getCollisionTime(Mdouble mass)
Calculates collision time for two copies of a particle of species 0.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Mdouble getRandomNumber(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:69