MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MercuryBase.h
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 #ifndef MERCURYBASE_H
27 #define MERCURYBASE_H
28 
29 #include <ostream>
30 #include <iostream>
31 #include <stdlib.h>
32 
33 #include "DPMBase.h"
34 #include "HGrid.h"
35 
46 {
48 };
49 
50 inline std::ostream & operator<<(std::ostream & os, HGridMethod h)
51 {
52  if (h==BOTTOMUP)
53  return os << "BOTTOMUP";
54  else
55  return os << "TOPDOWN";
56 }
57 
58 inline std::istream & operator>>(std::istream & is, HGridMethod& h)
59 {
60  std::string s;
61  is >> s;
62  if (s=="BOTTOMUP")
63  h=BOTTOMUP;
64  else if (s=="TOPDOWN")
65  h=TOPDOWN;
66  else
67  {
68  logger(ERROR, "HGridMethod could not be read: %", s);
69  }
70  return is;
71 }
72 
86 {
88 };
89 
90 inline std::ostream & operator<<(std::ostream & os, HGridDistribution h)
91 {
92  if (h==OLDHGRID)
93  return os << "OLDHGRID";
94  else if (h==LINEAR)
95  return os << "LINEAR";
96  else if (h==EXPONENTIAL)
97  return os << "EXPONENTIAL";
98  else
99  return os << "USER";
100 }
101 
102 inline std::istream & operator>>(std::istream & is, HGridDistribution& h)
103 {
104  std::string s;
105  is >> s;
106  if (s=="OLDHGRID")
107  h=OLDHGRID;
108  else if (s=="LINEAR")
109  h=LINEAR;
110  else if (s=="EXPONENTIAL")
111  h=EXPONENTIAL;
112  else if (s=="USER")
113  h=USER;
114  else {
115  std::cerr << "HGridMethod could not be read: " << s << std::endl;
116  exit(-1);
117  }
118  return is;
119 }
120 
127 class MercuryBase : public virtual DPMBase
128 {
129 public:
133  MercuryBase();
134 
138  ~MercuryBase();
139 
143  MercuryBase(const MercuryBase& mercuryBase);
144 
148  void constructor();
149 
154  void hGridActionsBeforeTimeLoop() override;
155 
160  void hGridActionsBeforeTimeStep() override;
161 
165  void read(std::istream& is) override;
166 
170  void write(std::ostream& os, bool writeAllParticles = true) const override;
171 
176 
181 
185  void setHGridUpdateEachTimeStep(bool updateEachTimeStep);
186 
190  bool getHGridUpdateEachTimeStep() const override;
191 
195  void setHGridMaxLevels(unsigned int HGridMaxLevels);
196 
200  unsigned int getHGridMaxLevels() const;
201 
205  HGridMethod getHGridMethod() const;
206 
210  void setHGridMethod(HGridMethod hGridMethod);
211 
216 
220  void setHGridDistribution(HGridDistribution hGridDistribution);
221 
226 
230  void setHGridCellOverSizeRatio(Mdouble cellOverSizeRatio);
231 
235  bool hGridNeedsRebuilding();
236 
240  virtual unsigned int getHGridTargetNumberOfBuckets() const;
241 
246 
251 
255  bool checkParticleForInteraction(const BaseParticle& P) override;
256  bool checkParticleForInteractionLocal(const BaseParticle& P) override;
257 
261  virtual Mdouble userHGridCellSize(unsigned int level);
262 
263 protected:
264 
268  void hGridRebuild();
269 
273  void hGridInsertParticle(BaseParticle* obj) override;
274 
279  void broadPhase(BaseParticle* i) override;
280 
286  virtual void hGridFindOneSidedContacts(BaseParticle* obj) = 0;
287 
292  virtual bool hGridHasParticleContacts(const BaseParticle* obj)=0;
293 
298  void hGridUpdateMove(BaseParticle * iP, Mdouble move) override;
299 
303  void hGridActionsBeforeIntegration() override;
304 
308  void hGridActionsAfterIntegration() override;
309 
313  HGrid* getHGrid();
314 
318  const HGrid* getHGrid() const;
319 
323  bool readNextArgument(int& i, int argc, char *argv[]) override;
324 
325 public:
329  void hGridInfo() const;
330 
331 private:
336 
348 
354 
362 
368 
376 
382 
395  unsigned int hGridMaxLevels_;
404 };
405 
406 #endif
std::ostream & operator<<(std::ostream &os, HGridMethod h)
Definition: MercuryBase.h:50
virtual void hGridFindOneSidedContacts(BaseParticle *obj)=0
This is a purely virtual function that checks if an object is in the grid, this code is dimension dep...
bool checkParticleForInteraction(const BaseParticle &P) override
Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle.
Definition: MercuryBase.cc:609
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:65
bool hGridNeedsRebuilding()
Gets if the HGrid needs rebuilding before anything else happens.
Definition: MercuryBase.cc:520
Mdouble totalCurrentMaxRelativeDisplacement_
After each time step, this Mdouble is increased by 2*currentMaxRelativeDisplacement_.
Definition: MercuryBase.h:367
Mdouble getHGridCellOverSizeRatio() const
Gets the ratio of the smallest cell over the smallest particle.
Definition: MercuryBase.cc:477
std::istream & operator>>(std::istream &is, HGridMethod &h)
Definition: MercuryBase.h:58
HGrid * grid
A pointer to the HGrid associated with this MercuryBase.
Definition: MercuryBase.h:335
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble getHGridCurrentMaxRelativeDisplacement() const
Returns hGridCurrentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:154
virtual unsigned int getHGridTargetNumberOfBuckets() const
Gets the desired number of buckets, which is the maximum of the number of particles and 10...
Definition: MercuryBase.cc:558
void setHGridUpdateEachTimeStep(bool updateEachTimeStep)
Sets whether or not the HGrid must be updated every time step.
Definition: MercuryBase.cc:172
virtual Mdouble getHGridTargetMinInteractionRadius() const
Gets the desired size of the smallest cells of the HGrid.
Definition: MercuryBase.cc:575
HGridDistribution hGridDistribution_
Indicator for the distribution of the sizes of the cells of different levels of the HGrid...
Definition: MercuryBase.h:353
double Mdouble
unsigned int hGridMaxLevels_
Unsigned integer that indicates the maximum number of levels of the HGrid.
Definition: MercuryBase.h:395
HGridMethod getHGridMethod() const
Gets whether the HGrid in this MercuryBase is BOTTOMUP or TOPDOWN.
Definition: MercuryBase.cc:439
void hGridUpdateMove(BaseParticle *iP, Mdouble move) override
Computes the relative displacement of the given BaseParticle and updates the currentMaxRelativeDispla...
Definition: MercuryBase.cc:367
Mdouble hGridCellOverSizeRatio_
The maximum ratio between the size of the cells and the BaseParticle they contain.
Definition: MercuryBase.h:403
unsigned int getHGridMaxLevels() const
Gets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:512
void hGridActionsBeforeTimeStep() override
Performs all necessary actions before a time-step, like updating the particles and resetting all the ...
Definition: MercuryBase.cc:324
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:51
void hGridInfo() const
Writes the info of the HGrid to the screen in a nice format.
Definition: MercuryBase.cc:691
virtual Mdouble getHGridTargetMaxInteractionRadius() const
Gets the desired size of the largest cells of the HGrid.
Definition: MercuryBase.cc:591
HGridMethod
Enum class that indicates how particles in different levels (cross level checking) of the HGrid are c...
Definition: MercuryBase.h:45
void setHGridMethod(HGridMethod hGridMethod)
Sets the HGridMethod to either BOTTOMUP or TOPDOWN.
Definition: MercuryBase.cc:447
HGridMethod hGridMethod_
Indicator of which way the interactions between different levels are tested.
Definition: MercuryBase.h:347
This is the base class for both Mercury2D and Mercury3D. Note the actually abstract grid is defined i...
Definition: MercuryBase.h:127
Mdouble getHGridTotalCurrentMaxRelativeDisplacement() const
Returns hGridTotalCurrentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:163
void hGridActionsAfterIntegration() override
Sets the totalCurrentMaxRelativeDisplacement_ as 2*currentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:381
void write(std::ostream &os, bool writeAllParticles=true) const override
Writes the MercuryBase to an output stream, for example a restart file.
Definition: MercuryBase.cc:132
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:41
bool readNextArgument(int &i, int argc, char *argv[]) override
Reads the next command line argument.
Definition: MercuryBase.cc:419
void hGridInsertParticle(BaseParticle *obj) override
Inserts a single Particle to current grid.
Definition: MercuryBase.cc:297
~MercuryBase()
This is the default destructor.
Definition: MercuryBase.cc:40
bool checkParticleForInteractionLocal(const BaseParticle &P) override
Definition: MercuryBase.cc:658
void setHGridCellOverSizeRatio(Mdouble cellOverSizeRatio)
Sets the ratio of the smallest cell over the smallest particle.
Definition: MercuryBase.cc:487
HGridDistribution
Enum that indicates what the ratio of the size of the cells in different levels is.
Definition: MercuryBase.h:85
bool updateEachTimeStep_
Boolean which indicates whether or not the cell in which a particle is must be updated every timestep...
Definition: MercuryBase.h:381
void setHGridMaxLevels(unsigned int HGridMaxLevels)
Sets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:500
void hGridActionsBeforeTimeLoop() override
This sets up the broad phase information, has to be done at this stage because it requires the partic...
Definition: MercuryBase.cc:95
MercuryBase()
This is the default constructor. It sets sensible defaults.
Definition: MercuryBase.cc:34
void hGridRebuild()
This sets up the parameters required for the contact model.
Definition: MercuryBase.cc:201
virtual bool hGridHasParticleContacts(const BaseParticle *obj)=0
Purely virtual function that checks if the given particle has a possible contact with any other BaseP...
HGridDistribution getHGridDistribution() const
Gets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:455
void constructor()
This is the actual constructor, it is called do both constructors above.
Definition: MercuryBase.cc:80
bool gridNeedsUpdate_
Boolean that indicates whether or not the grid needs to be updated.
Definition: MercuryBase.h:375
void read(std::istream &is) override
Reads the MercuryBase from an input stream, for example a restart file.
Definition: MercuryBase.cc:105
bool getHGridUpdateEachTimeStep() const override
Gets whether or not the HGrid is updated every time step.
Definition: MercuryBase.cc:180
void broadPhase(BaseParticle *i) override
This checks particles in the HGRID to see if for closer enough for possible contact.
Definition: MercuryBase.cc:314
virtual Mdouble userHGridCellSize(unsigned int level)
Virtual function that enables inheriting classes to implement a function to let the user set the cell...
Definition: MercuryBase.cc:406
void setHGridDistribution(HGridDistribution hGridDistribution)
Sets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:464
HGrid * getHGrid()
Gets the HGrid used by this problem.
Definition: MercuryBase.cc:389
Mdouble currentMaxRelativeDisplacement_
Mdouble that denotes the maximum of the displacement of a particle divided by the cell size of the le...
Definition: MercuryBase.h:361
void hGridActionsBeforeIntegration() override
Resets the currentMaxRelativeDisplacement_ to 0.
Definition: MercuryBase.cc:376