MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SpeciesUnitTest.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 "Mercury3D.h"
27 #include "Particles/BaseParticle.h"
28 #include <iostream>
29 #include <cmath>
31 
32 class SpeciesTest : public Mercury3D
33 {
34 public:
35  virtual void printTime() const
36  {
37  }
38 
40  {
41  auto species0 = new LinearViscoelasticSpecies;
42  speciesHandler.addObject(species0);
43  species0->setDensity(6. / constants::pi);
44 
45  double tc = 1e-2, r = 0.4, m = 1;
46  //sets k and dissipation_ based on the collision time and restitution coefficient for a collision with effective mass m
47  //species0->setStiffnessAndDissipation(helpers::computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(tc, r, m));
48  //setCollisionTimeAndRestitutionCoefficient(tc,r, 1.0,1.0);
49  species0->setCollisionTimeAndRestitutionCoefficient(tc, r, m);
50 
51  setSaveCount(50);
53  setTimeStep(tc / 50.);
54  setTimeMax(3.0);
55  setXMax(10);
56  setYMax(10);
57  setZMax(1);
58  setZMin(-1);
59  setGravity(Vec3D(0, 0, 0));
60 
61  auto species1 = speciesHandler.copyAndAddObject(species0);
62 
63  BaseParticle P0, P1, P2, P3, P4, P5;
64  //Small particles are species 0 and large particles are species two
65  //Collison small - small
66  P0.setRadius(.5);
67  P0.setIndSpecies(0);
68  P0.setPosition(Vec3D(0.0, 0.0, 0.0));
69  P0.setVelocity(Vec3D(1.0, 0.0, 0.0));
70 
71  P1.setRadius(.5);
72  P1.setIndSpecies(0);
73  P1.setPosition(Vec3D(2.5, 0.0, 0.0));
74  P1.setVelocity(Vec3D(0.0, 0.0, 0.0));
75 
76  //Collision small - large
77  P2.setRadius(.5);
78  P2.setIndSpecies(0);
79  P2.setPosition(Vec3D(0.0, 0.0, 2.0));
80  P2.setVelocity(Vec3D(1.0, 0.0, 0.0));
81 
82  P3.setRadius(1.0);
83  P3.setIndSpecies(1);
84  P3.setPosition(Vec3D(2.5, 0.0, 2.0));
85  P3.setVelocity(Vec3D(0.0, 0.0, 0.0));
86 
87  //Collision large - large
88  P4.setRadius(1.0);
89  P4.setIndSpecies(1);
90  P4.setPosition(Vec3D(0.0, 0.0, 4.0));
91  P4.setVelocity(Vec3D(1.0, 0.0, 0.0));
92 
93  P5.setRadius(1.0);
94  P5.setIndSpecies(1);
95  P5.setPosition(Vec3D(2.5, 0.0, 4.0));
96  P5.setVelocity(Vec3D(0.0, 0.0, 0.0));
97 
104 
105  species1->setCollisionTimeAndRestitutionCoefficient(tc, r, 8.0, 8.0);
106  speciesHandler.getMixedObject(species0, species1)->setCollisionTimeAndRestitutionCoefficient(tc, r, 1.0, 8.0);
107 
108  }
109 
111  {
112  for (unsigned int i = 0; i < 5; i += 2)
113  {
115  std::cout << "Cofficient of resutions for collision " << round(i / 2.0) + 1 << " is : " << r << std::endl;
116  if (std::abs(r-0.4)>1e-2)
117  {
118  std::cerr << "Wrong restitution" << std::endl;
119  exit(-1);
120  }
121  }
122  }
123 
124 };
125 
126 int main(int argc UNUSED, char *argv[] UNUSED)
127 {
128  std::cout << "Species test problem " << std::endl;
129  std::cout << "---------------------" << std::endl;
130  std::cout << std::endl;
131  std::cout << "This problem set k and gamma for different for different size particles such that the coefficent of restitution is the same" << std::endl;
132  std::cout << "Note for each collision this value should be 0.4" << std::endl;
133  std::cout << "Also this code demostrates how to use different species in the code" << std::endl;
134  SpeciesTest problem;
135  problem.setName("SpeciesUnitTest");
136 
137  problem.solve();
138 }
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
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 actionsAfterSolve()
A virtual function which allows to define operations to be executed after the solve().
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 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) ...
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 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
virtual void addObject(ParticleSpecies *const S)
Adds a new ParticleSpecies to the SpeciesHandler.
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:35
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
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
MERCURY_DEPRECATED void setIndSpecies(unsigned int indSpecies)
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
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
U::MixedSpeciesType * getMixedObject(const U *S, const U *T)
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
virtual void printTime() const
Displays the current simulation time onto your screen for example.
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
int main(int argc UNUSED, char *argv[] UNUSED)