MercuryBase.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MERCURYBASE_H
6 #define MERCURYBASE_H
7 
8 #include <iostream>
9 
10 #include "DPMBase.h"
11 #include "HGrid.h"
12 
23 {
25 };
26 
27 inline std::ostream& operator<<(std::ostream& os, HGridMethod h)
28 {
29  if (h == BOTTOMUP)
30  return os << "BOTTOMUP";
31  else
32  return os << "TOPDOWN";
33 }
34 
35 inline std::istream& operator>>(std::istream& is, HGridMethod& h)
36 {
37  std::string s;
38  is >> s;
39  if (s == "BOTTOMUP")
40  h = BOTTOMUP;
41  else if (s == "TOPDOWN")
42  h = TOPDOWN;
43  else
44  {
45  logger(ERROR, "HGridMethod could not be read: %", s);
46  }
47  return is;
48 }
49 
63 {
65 };
66 
67 inline std::ostream& operator<<(std::ostream& os, HGridDistribution h)
68 {
69  if (h == OLDHGRID)
70  return os << "OLDHGRID";
71  else if (h == LINEAR)
72  return os << "LINEAR";
73  else if (h == EXPONENTIAL)
74  return os << "EXPONENTIAL";
75  else
76  return os << "USER";
77 }
78 
79 inline std::istream& operator>>(std::istream& is, HGridDistribution& h)
80 {
81  std::string s;
82  is >> s;
83  if (s == "OLDHGRID")
84  h = OLDHGRID;
85  else if (s == "LINEAR")
86  h = LINEAR;
87  else if (s == "EXPONENTIAL")
88  h = EXPONENTIAL;
89  else if (s == "USER")
90  h = USER;
91  else
92  {
93  logger(ERROR,"HGridDistribution could not be read: %",s);
94  }
95  return is;
96 }
97 
104 class MercuryBase : public virtual DPMBase
105 {
106 public:
110  MercuryBase();
111 
115  ~MercuryBase() override;
116 
120  MercuryBase(const MercuryBase& mercuryBase);
121 
125  void constructor();
126 
131  void hGridActionsBeforeTimeLoop() override;
132 
137  void hGridActionsBeforeTimeStep() override;
138 
142  void read(std::istream& is, ReadOptions opt = ReadOptions::ReadAll) override;
143 
147  void write(std::ostream& os, bool writeAllParticles = true) const override;
148 
153 
158 
162  void setHGridUpdateEachTimeStep(bool updateEachTimeStep);
163 
167  bool getHGridUpdateEachTimeStep() const final;
168 
172  void setHGridMaxLevels(unsigned int HGridMaxLevels);
173 
177  unsigned int getHGridMaxLevels() const;
178 
184  { return hGridMethod_; }
185 
190  void setHGridMethod(HGridMethod hGridMethod);
191 
196 
200  void setHGridDistribution(HGridDistribution hGridDistribution);
201 
206 
210  void setHGridCellOverSizeRatio(Mdouble cellOverSizeRatio);
211 
215  bool hGridNeedsRebuilding();
216 
220  virtual unsigned int getHGridTargetNumberOfBuckets() const;
221 
226 
231 
235  bool checkParticleForInteraction(const BaseParticle& P) final;
236 
241 
245  virtual Mdouble userHGridCellSize(unsigned int level);
246 
250  virtual std::vector<BaseParticle*> hGridFindParticleContacts(const BaseParticle* obj)=0;
251 
252 protected:
253 
257  void hGridRebuild();
258 
262  void hGridInsertParticle(BaseParticle* obj) final;
263 
268  virtual bool hGridHasParticleContacts(const BaseParticle* obj)=0;
269 
274  void hGridUpdateMove(BaseParticle* iP, Mdouble move) final;
275 
279  void hGridActionsBeforeIntegration() override;
280 
284  void hGridActionsAfterIntegration() override;
285 
291  { return grid; }
292 
297  const HGrid* getHGrid() const
298  { return grid; }
299 
303  bool readNextArgument(int& i, int argc, char* argv[]) override;
304 
305 public:
309  void hGridInfo(std::ostream& os = std::cout) const;
310 
311 private:
316 
328 
334 
342 
348 
356 
362 
375  unsigned int hGridMaxLevels_;
384 };
385 
386 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:32
std::istream & operator>>(std::istream &is, HGridMethod &h)
Definition: MercuryBase.h:35
HGridDistribution
Enum that indicates what the ratio of the size of the cells in different levels is.
Definition: MercuryBase.h:63
@ OLDHGRID
Definition: MercuryBase.h:64
@ EXPONENTIAL
Definition: MercuryBase.h:64
@ LINEAR
Definition: MercuryBase.h:64
@ USER
Definition: MercuryBase.h:64
HGridMethod
Enum class that indicates how particles in different levels (cross level checking) of the HGrid are c...
Definition: MercuryBase.h:23
@ BOTTOMUP
Definition: MercuryBase.h:24
@ TOPDOWN
Definition: MercuryBase.h:24
Definition: BaseParticle.h:33
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:56
ReadOptions
Definition: DPMBase.h:233
std::ostream & operator<<(std::ostream &s, const DenseBase< Derived > &m)
Definition: IO.h:222
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:22
This is the base class for both Mercury2D and Mercury3D. Note the actually abstract grid is defined i...
Definition: MercuryBase.h:105
virtual Mdouble getHGridTargetMinInteractionRadius() const
Gets the desired size of the smallest cells of the HGrid.
Definition: MercuryBase.cc:537
bool hGridNeedsRebuilding()
Gets if the HGrid needs rebuilding before anything else happens.
Definition: MercuryBase.cc:475
unsigned int getHGridMaxLevels() const
Gets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:467
Mdouble currentMaxRelativeDisplacement_
Mdouble that denotes the maximum of the displacement of a particle divided by the cell size of the le...
Definition: MercuryBase.h:341
Mdouble getHGridTotalCurrentMaxRelativeDisplacement() const
Returns hGridTotalCurrentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:146
HGrid * grid
A pointer to the HGrid associated with this MercuryBase.
Definition: MercuryBase.h:315
void hGridInfo(std::ostream &os=std::cout) const
Writes the info of the HGrid to the screen in a nice format.
Definition: MercuryBase.cc:634
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:368
void hGridUpdateMove(BaseParticle *iP, Mdouble move) final
Computes the relative displacement of the given BaseParticle and updates the currentMaxRelativeDispla...
Definition: MercuryBase.cc:338
Mdouble hGridCellOverSizeRatio_
The maximum ratio between the size of the cells and the BaseParticle they contain.
Definition: MercuryBase.h:383
HGridDistribution hGridDistribution_
Indicator for the distribution of the sizes of the cells of different levels of the HGrid....
Definition: MercuryBase.h:333
unsigned int hGridMaxLevels_
Unsigned integer that indicates the maximum number of levels of the HGrid.
Definition: MercuryBase.h:375
const HGrid * getHGrid() const
Gets the HGrid used by this problem, const version.
Definition: MercuryBase.h:297
void setHGridDistribution(HGridDistribution hGridDistribution)
Sets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:419
bool readNextArgument(int &i, int argc, char *argv[]) override
Reads the next command line argument.
Definition: MercuryBase.cc:381
void setHGridUpdateEachTimeStep(bool updateEachTimeStep)
Sets whether or not the HGrid must be updated every time step.
Definition: MercuryBase.cc:155
bool checkParticleForInteractionLocal(const BaseParticle &P) final
Checks if the given BaseParticle has an interaction with a BaseWall or other BaseParticles in a local...
Definition: MercuryBase.cc:601
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:73
MercuryBase()
This is the default constructor. It sets sensible defaults.
Definition: MercuryBase.cc:10
void write(std::ostream &os, bool writeAllParticles=true) const override
Writes all data into a restart file.
Definition: MercuryBase.cc:126
HGridMethod getHGridMethod() const
Gets whether the HGrid in this MercuryBase is BOTTOMUP or TOPDOWN.
Definition: MercuryBase.h:183
void hGridActionsAfterIntegration() override
This function has to be called before integrateBeforeForceComputation.
Definition: MercuryBase.cc:358
Mdouble getHGridCurrentMaxRelativeDisplacement() const
Returns hGridCurrentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:137
HGrid * getHGrid()
Gets the HGrid used by this problem.
Definition: MercuryBase.h:290
bool gridNeedsUpdate_
Boolean that indicates whether or not the grid needs to be updated.
Definition: MercuryBase.h:355
void setHGridMaxLevels(unsigned int HGridMaxLevels)
Sets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:455
void hGridActionsBeforeIntegration() override
Resets the currentMaxRelativeDisplacement_ to 0.
Definition: MercuryBase.cc:350
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:519
bool checkParticleForInteraction(const BaseParticle &P) final
Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle.
Definition: MercuryBase.cc:573
bool getHGridUpdateEachTimeStep() const final
Gets whether or not the HGrid is updated every time step.
Definition: MercuryBase.cc:163
HGridDistribution getHGridDistribution() const
Gets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:410
Mdouble totalCurrentMaxRelativeDisplacement_
After each time step, this Mdouble is increased by 2*currentMaxRelativeDisplacement_.
Definition: MercuryBase.h:347
void hGridInsertParticle(BaseParticle *obj) final
Inserts a single Particle to current grid.
Definition: MercuryBase.cc:290
bool updateEachTimeStep_
Boolean which indicates whether or not the cell in which a particle is must be updated every time ste...
Definition: MercuryBase.h:361
~MercuryBase() override
This is the default destructor.
Definition: MercuryBase.cc:16
void constructor()
This is the actual constructor, it is called do both constructors above.
Definition: MercuryBase.cc:56
void hGridActionsBeforeTimeStep() override
Performs all necessary actions before a time-step, like updating the particles and resetting all the ...
Definition: MercuryBase.cc:302
virtual bool hGridHasParticleContacts(const BaseParticle *obj)=0
Purely virtual function that checks if the given particle has a possible contact with any other BaseP...
void setHGridCellOverSizeRatio(Mdouble cellOverSizeRatio)
Sets the ratio of the smallest cell over the smallest particle.
Definition: MercuryBase.cc:442
void hGridRebuild()
This sets up the parameters required for the contact model.
Definition: MercuryBase.cc:183
virtual Mdouble getHGridTargetMaxInteractionRadius() const
Gets the desired size of the largest cells of the HGrid.
Definition: MercuryBase.cc:553
void setHGridMethod(HGridMethod hGridMethod)
Sets the HGridMethod to either BOTTOMUP or TOPDOWN.
Definition: MercuryBase.cc:402
HGridMethod hGridMethod_
Indicator of which way the interactions between different levels are tested.
Definition: MercuryBase.h:327
Mdouble getHGridCellOverSizeRatio() const
Gets the ratio of the smallest cell over the smallest particle.
Definition: MercuryBase.cc:432
void read(std::istream &is, ReadOptions opt=ReadOptions::ReadAll) override
Reads the MercuryBase from an input stream, for example a restart file.
Definition: MercuryBase.cc:83
virtual std::vector< BaseParticle * > hGridFindParticleContacts(const BaseParticle *obj)=0
Purely virtual function that returns all particles that have a contact with a given particle.
RealScalar s
Definition: level1_cplx_impl.h:130
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286