MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlasticForceUnitTest.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 <iostream>
29 #include <vector>
31 #include <Logger.h>
32 
33 
36 public:
37 
39  {
41  }
42 
44  {
45  setXMax(3.0);
46  setYMax(2.0);
47  setZMax(2.0);
48  setGravity(Vec3D(0.0,0.0,0.0));
50 
51  double depth = 0.05;
52  double deltamax = (species->getUnloadingStiffnessMax()/(species->getUnloadingStiffnessMax()-species->getLoadingStiffness()))*depth*((2*0.5*0.5)/(0.5+0.5));
53  double relVelocity=sqrt(species->getLoadingStiffness()*(chi*deltamax)*(chi*deltamax)*2);
54 
56 
57  BaseParticle P0,P1;
58  P0.setPosition(Vec3D( 1.0,1.0,1.0));
59  P0.setVelocity(Vec3D(relVelocity/2.0,0.0,0.0));
60  P0.setRadius(0.5);
61  P1.setPosition(Vec3D( 2.0,1.0,1.0));
62  P1.setVelocity(Vec3D(-relVelocity/2.0,0.0,0.0));
63  P1.setRadius(0.5);
64 
67 
68  double mass=1.0;
69  setTimeStep(species->computeTimeStep(mass)*2.0);
70  setTimeMax(getTimeStep()*100.0);
72  setSaveCount(1);
73  }
74 
75  void set_chi(double new_){chi=new_;}
76  double get_chi() {return chi;}
77 
78  double chi;
80 };
81 
82 int main(int argc UNUSED, char *argv[] UNUSED)
83 {
84  PlasticForceUnitTest PlasticForceUnitTestProblem;
85  double k1=100.0;
86  PlasticForceUnitTestProblem.species->setPlasticParameters(k1, 5.0*k1, k1, 0.05);
87  PlasticForceUnitTestProblem.species->setDissipation(0);
88  PlasticForceUnitTestProblem.setParticleDimensions(3);
89  PlasticForceUnitTestProblem.setSystemDimensions(3);
90 
91  logger(INFO,"Testing particle particles collision for elastic plastic forces. \n"
92  "This will be done for serveral values of scaled relative velocity chi");
93 
94  //PlasticForceUnitTestProblem.restartFile.getFstream().precision(20);
95 
96  //Set up constant data that will be used
97  const std::vector<double> chi = {0.34, 0.69, 1.1, 1.37};
98  const std::vector<Vec3D> leftFinalVecloity = {
99  Vec3D(-0.032721738352012,0.0,0.0),
100  Vec3D(-0.0138683231953154,0.0,0.0),
101  Vec3D(-0.0204655358555405,0.0,0.0),
102  Vec3D(-0.163049415300304,0.0,0.0)};
103  const std::vector<Vec3D> leftFinalPosition = {
104  Vec3D(0.995546292935715,1.0,1.0),
105  Vec3D(1.00695193269955,1.0,1.0),
106  Vec3D(1.00840467123501,1.0,1.0),
107  Vec3D(0.969386085767181,1.0,1.0)};
108 
109  //Loop over all test cases
110  for (int i=0; i<4; i++)
111  {
112  logger(INFO, "Running for chi=%",chi[i]);
113  PlasticForceUnitTestProblem.set_chi(chi[i]);
114  std::stringstream ss("");
115  ss << "PlasticForceUnitTest" << PlasticForceUnitTestProblem.get_chi();
116  PlasticForceUnitTestProblem.setName(ss.str().c_str());
117  PlasticForceUnitTestProblem.solve();
118  PlasticForceUnitTestProblem.writeRestartFile();
119 
120  //Now check the particles are in the right place for each of the 4 cases
121  auto pIt = PlasticForceUnitTestProblem.particleHandler.begin();
122  if (!(*pIt)->getPosition().isEqualTo(leftFinalPosition[i], 1e-10))
123  logger(FATAL,"Left particle is in the wrong position. It is at % and should be %",(*pIt)->getPosition(),leftFinalPosition[i]);
124  if (!(*pIt)->getVelocity().isEqualTo(leftFinalVecloity[i] , 1e-10))
125  logger(FATAL,"Left particle has the wrong velocity. It is at % and should be %",(*pIt)->getVelocity(),leftFinalVecloity[i]);
126  }
127 
128  //to display use
129  //gnuplot> plot 'plastic/collinear1.1.fstat' u 7:9 w lp
130 }
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
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")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:28
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 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 setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:453
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
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
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
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
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 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
Species< LinearPlasticViscoelasticNormalSpecies > LinearPlasticViscoelasticSpecies
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
all data will be written into/ read from a single file called name_
void setDensity(Mdouble density)
Allows the density to be changed.
#define UNUSED
Definition: GeneralDefine.h:37
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
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
This code tests our plastic force model, as published in Luding 2008.
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
int main(int argc UNUSED, char *argv[] UNUSED)
virtual void writeRestartFile()
Stores all the particle data for current save time step. Calls the write function.
Definition: DPMBase.cc:1365
Contains material and contact force properties.
Definition: Interaction.h:35
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
LinearPlasticViscoelasticSpecies * species
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...