MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtremeOverlapWithWallsUnitTest.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 #include "DPMBase.h"
26 #include "Particles/BaseParticle.h"
27 #include "Walls/InfiniteWall.h"
28 #include <iostream>
30 #include <Logger.h>
31 
57 public:
58 
60  {
61  Mdouble r0=0.004, r1=0.001;
62 
63  setZMax(2.0*(r0+r1));
64  setZMin(0.0);
65  setYMax(r0);
66  setYMin(-r0);
67  setXMax(r0);
68  setXMin(-r0);
69 
70  InfiniteWall w0;
71  w0.set(Vec3D(0,0,-1), Vec3D(0,0,0));
73  w0.set(Vec3D(0,0,1), Vec3D(0,0,getZMax()));
74  //should be set to 0.005*sin(2*pi*t/0.02))
75  //w0.setVelocity(Vec3D(0.0,0.0,-constants::pi/2.0));
76  w0.setPrescribedPosition([this] (double time)
77  {
78  return Vec3D(0.0,0.0,getZMax() - 0.005 * std::sin(time * 2.0 * constants::pi/0.02));
79  });
81 
82  BaseParticle p0;
83  p0.setPosition(Vec3D(0,0,r0));
84  p0.setVelocity(Vec3D(0.0,0.0,0.0));
85  p0.setRadius(r0);
87  p0.setPosition(Vec3D(0,0,r0+r0+r1));
88  p0.setVelocity(Vec3D(0.0,0.0,0.0));
89  p0.setRadius(r1);
91  }
92 
93 // void printTime() const
94 // {
95 // if (interactionHandler.getNumberOfObjects()>1)
96 // std::cout
97 // << getTime() << " "
98 // << particleHandler.getObject(0)->getPosition().Z << " "
99 // << particleHandler.getObject(1)->getPosition().Z << " "
100 // << interactionHandler.getObject(1)->getContactPoint().Z <<std::endl;
101 // }
102 
103 };
104 
105 int main(int argc, char *argv[])
106 {
108  ExtremeOverlapWithWallsUnitTest OverlapProblem;
109  auto species = OverlapProblem.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies());
110  species->setDensity(2000);
111  species->setStiffness(1e5);
112  species->setDissipation(1e-2);
113  OverlapProblem.setName("ExtremeOverlapWithWallsUnitTest");
114  OverlapProblem.setFileType(FileType::NO_FILE);
115  OverlapProblem.dataFile.setFileType(FileType::ONE_FILE);
116  OverlapProblem.setSaveCount(1000);
117  OverlapProblem.setDimension(3);
118  OverlapProblem.setTimeStep(1e-7);
119  OverlapProblem.setTimeMax(0.01);
120  // OverlapProblem.dataFile.getFstream().precision(10);
121  OverlapProblem.solve(argc,argv);
122 
123  Vec3D position = OverlapProblem.particleHandler.getObject(0)->getPosition();
124  Vec3D positionToCompare = Vec3D(0, -0.0004900098000491, 0.004008957617341);
125  if (!position.isEqualTo(positionToCompare, 1e-10))
126  logger(FATAL,"Large particle is in the wrong position. It is at % and should be %",position,positionToCompare);
127  else
128  std::cout << "Test passed" << std::endl;
129  position = OverlapProblem.particleHandler.getObject(1)->getPosition();
130  positionToCompare = Vec3D(0, -0.0004900098000491, 0.009004578797915);
131  //std::cout.precision(13); std::cout << position << std::endl;
132  if (!position.isEqualTo(positionToCompare, 1e-10))
133  logger(FATAL,"Large particle is in the wrong position. It is at % and should be %",position,positionToCompare);
134  else
135  std::cout << "Test passed" << std::endl;
136 
137  return 0;
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
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 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 getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax...
Definition: DPMBase.cc:259
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 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 setDimension(unsigned int newDim)
Sets the system and particle dimension.
Definition: DPMBase.cc:445
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:169
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.
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
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
all data will be written into/ read from a single file called name_
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:415
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
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
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
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition: File.cc:209
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:883
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
int main(int argc, char *argv[])
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
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Compresses 2 particles (vertically) until they have an extreme overlap.