MercuryBase.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, 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 <iostream>
30 
31 #include "DPMBase.h"
32 #include "HGrid.h"
33 
44 {
46 };
47 
48 inline std::ostream& operator<<(std::ostream& os, HGridMethod h)
49 {
50  if (h == BOTTOMUP)
51  return os << "BOTTOMUP";
52  else
53  return os << "TOPDOWN";
54 }
55 
56 inline std::istream& operator>>(std::istream& is, HGridMethod& h)
57 {
58  std::string s;
59  is >> s;
60  if (s == "BOTTOMUP")
61  h = BOTTOMUP;
62  else if (s == "TOPDOWN")
63  h = TOPDOWN;
64  else
65  {
66  logger(ERROR, "HGridMethod could not be read: %", s);
67  }
68  return is;
69 }
70 
84 {
86 };
87 
88 inline std::ostream& operator<<(std::ostream& os, HGridDistribution h)
89 {
90  if (h == OLDHGRID)
91  return os << "OLDHGRID";
92  else if (h == LINEAR)
93  return os << "LINEAR";
94  else if (h == EXPONENTIAL)
95  return os << "EXPONENTIAL";
96  else
97  return os << "USER";
98 }
99 
100 inline std::istream& operator>>(std::istream& is, HGridDistribution& h)
101 {
102  std::string s;
103  is >> s;
104  if (s == "OLDHGRID")
105  h = OLDHGRID;
106  else if (s == "LINEAR")
107  h = LINEAR;
108  else if (s == "EXPONENTIAL")
109  h = EXPONENTIAL;
110  else if (s == "USER")
111  h = USER;
112  else
113  {
114  logger(ERROR,"HGridDistribution could not be read: %",s);
115  }
116  return is;
117 }
118 
125 class MercuryBase : public virtual DPMBase
126 {
127 public:
131  MercuryBase();
132 
136  ~MercuryBase() override;
137 
141  MercuryBase(const MercuryBase& mercuryBase);
142 
146  void constructor();
147 
152  void hGridActionsBeforeTimeLoop() override;
153 
158  void hGridActionsBeforeTimeStep() override;
159 
163  void read(std::istream& is, ReadOptions opt = ReadOptions::ReadAll) override;
164 
168  void write(std::ostream& os, bool writeAllParticles = true) const override;
169 
174 
179 
183  void setHGridUpdateEachTimeStep(bool updateEachTimeStep);
184 
188  bool getHGridUpdateEachTimeStep() const final;
189 
193  void setHGridMaxLevels(unsigned int HGridMaxLevels);
194 
198  unsigned int getHGridMaxLevels() const;
199 
205  { return hGridMethod_; }
206 
211  void setHGridMethod(HGridMethod hGridMethod);
212 
217 
221  void setHGridDistribution(HGridDistribution hGridDistribution);
222 
227 
231  void setHGridCellOverSizeRatio(Mdouble cellOverSizeRatio);
232 
236  bool hGridNeedsRebuilding();
237 
241  virtual unsigned int getHGridTargetNumberOfBuckets() const;
242 
247 
252 
256  bool checkParticleForInteraction(const BaseParticle& P) final;
257 
262 
266  virtual Mdouble userHGridCellSize(unsigned int level);
267 
271  virtual std::vector<BaseParticle*> hGridFindParticleContacts(const BaseParticle* obj)=0;
272 
273 protected:
274 
278  void hGridRebuild();
279 
283  void hGridInsertParticle(BaseParticle* obj) final;
284 
289  virtual bool hGridHasParticleContacts(const BaseParticle* obj)=0;
290 
295  void hGridUpdateMove(BaseParticle* iP, Mdouble move) final;
296 
300  void hGridActionsBeforeIntegration() override;
301 
305  void hGridActionsAfterIntegration() override;
306 
312  { return grid; }
313 
318  const HGrid* getHGrid() const
319  { return grid; }
320 
324  bool readNextArgument(int& i, int argc, char* argv[]) override;
325 
326 public:
330  void hGridInfo(std::ostream& os = std::cout) const;
331 
332 private:
337 
349 
355 
363 
369 
377 
383 
396  unsigned int hGridMaxLevels_;
405 };
406 
407 #endif
double Mdouble
Definition: GeneralDefine.h:34
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:53
std::istream & operator>>(std::istream &is, HGridMethod &h)
Definition: MercuryBase.h:56
HGridDistribution
Enum that indicates what the ratio of the size of the cells in different levels is.
Definition: MercuryBase.h:84
@ OLDHGRID
Definition: MercuryBase.h:85
@ EXPONENTIAL
Definition: MercuryBase.h:85
@ LINEAR
Definition: MercuryBase.h:85
@ USER
Definition: MercuryBase.h:85
HGridMethod
Enum class that indicates how particles in different levels (cross level checking) of the HGrid are c...
Definition: MercuryBase.h:44
@ BOTTOMUP
Definition: MercuryBase.h:45
@ TOPDOWN
Definition: MercuryBase.h:45
std::ostream & operator<<(std::ostream &os, HGridMethod h)
Definition: MercuryBase.h:48
Definition: BaseParticle.h:54
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:77
ReadOptions
Definition: DPMBase.h:254
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:43
This is the base class for both Mercury2D and Mercury3D. Note the actually abstract grid is defined i...
Definition: MercuryBase.h:126
virtual Mdouble getHGridTargetMinInteractionRadius() const
Gets the desired size of the smallest cells of the HGrid.
Definition: MercuryBase.cc:558
bool hGridNeedsRebuilding()
Gets if the HGrid needs rebuilding before anything else happens.
Definition: MercuryBase.cc:496
unsigned int getHGridMaxLevels() const
Gets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:488
Mdouble currentMaxRelativeDisplacement_
Mdouble that denotes the maximum of the displacement of a particle divided by the cell size of the le...
Definition: MercuryBase.h:362
Mdouble getHGridTotalCurrentMaxRelativeDisplacement() const
Returns hGridTotalCurrentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:167
HGrid * grid
A pointer to the HGrid associated with this MercuryBase.
Definition: MercuryBase.h:336
void hGridInfo(std::ostream &os=std::cout) const
Writes the info of the HGrid to the screen in a nice format.
Definition: MercuryBase.cc:655
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:389
void hGridUpdateMove(BaseParticle *iP, Mdouble move) final
Computes the relative displacement of the given BaseParticle and updates the currentMaxRelativeDispla...
Definition: MercuryBase.cc:359
Mdouble hGridCellOverSizeRatio_
The maximum ratio between the size of the cells and the BaseParticle they contain.
Definition: MercuryBase.h:404
HGridDistribution hGridDistribution_
Indicator for the distribution of the sizes of the cells of different levels of the HGrid....
Definition: MercuryBase.h:354
unsigned int hGridMaxLevels_
Unsigned integer that indicates the maximum number of levels of the HGrid.
Definition: MercuryBase.h:396
const HGrid * getHGrid() const
Gets the HGrid used by this problem, const version.
Definition: MercuryBase.h:318
void setHGridDistribution(HGridDistribution hGridDistribution)
Sets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:440
bool readNextArgument(int &i, int argc, char *argv[]) override
Reads the next command line argument.
Definition: MercuryBase.cc:402
void setHGridUpdateEachTimeStep(bool updateEachTimeStep)
Sets whether or not the HGrid must be updated every time step.
Definition: MercuryBase.cc:176
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:622
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:94
MercuryBase()
This is the default constructor. It sets sensible defaults.
Definition: MercuryBase.cc:31
void write(std::ostream &os, bool writeAllParticles=true) const override
Writes all data into a restart file.
Definition: MercuryBase.cc:147
HGridMethod getHGridMethod() const
Gets whether the HGrid in this MercuryBase is BOTTOMUP or TOPDOWN.
Definition: MercuryBase.h:204
void hGridActionsAfterIntegration() override
This function has to be called before integrateBeforeForceComputation.
Definition: MercuryBase.cc:379
Mdouble getHGridCurrentMaxRelativeDisplacement() const
Returns hGridCurrentMaxRelativeDisplacement_.
Definition: MercuryBase.cc:158
HGrid * getHGrid()
Gets the HGrid used by this problem.
Definition: MercuryBase.h:311
bool gridNeedsUpdate_
Boolean that indicates whether or not the grid needs to be updated.
Definition: MercuryBase.h:376
void setHGridMaxLevels(unsigned int HGridMaxLevels)
Sets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:476
void hGridActionsBeforeIntegration() override
Resets the currentMaxRelativeDisplacement_ to 0.
Definition: MercuryBase.cc:371
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:540
bool checkParticleForInteraction(const BaseParticle &P) final
Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle.
Definition: MercuryBase.cc:594
bool getHGridUpdateEachTimeStep() const final
Gets whether or not the HGrid is updated every time step.
Definition: MercuryBase.cc:184
HGridDistribution getHGridDistribution() const
Gets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:431
Mdouble totalCurrentMaxRelativeDisplacement_
After each time step, this Mdouble is increased by 2*currentMaxRelativeDisplacement_.
Definition: MercuryBase.h:368
void hGridInsertParticle(BaseParticle *obj) final
Inserts a single Particle to current grid.
Definition: MercuryBase.cc:311
bool updateEachTimeStep_
Boolean which indicates whether or not the cell in which a particle is must be updated every time ste...
Definition: MercuryBase.h:382
~MercuryBase() override
This is the default destructor.
Definition: MercuryBase.cc:37
void constructor()
This is the actual constructor, it is called do both constructors above.
Definition: MercuryBase.cc:77
void hGridActionsBeforeTimeStep() override
Performs all necessary actions before a time-step, like updating the particles and resetting all the ...
Definition: MercuryBase.cc:323
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:463
void hGridRebuild()
This sets up the parameters required for the contact model.
Definition: MercuryBase.cc:204
virtual Mdouble getHGridTargetMaxInteractionRadius() const
Gets the desired size of the largest cells of the HGrid.
Definition: MercuryBase.cc:574
void setHGridMethod(HGridMethod hGridMethod)
Sets the HGridMethod to either BOTTOMUP or TOPDOWN.
Definition: MercuryBase.cc:423
HGridMethod hGridMethod_
Indicator of which way the interactions between different levels are tested.
Definition: MercuryBase.h:348
Mdouble getHGridCellOverSizeRatio() const
Gets the ratio of the smallest cell over the smallest particle.
Definition: MercuryBase.cc:453
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:104
virtual std::vector< BaseParticle * > hGridFindParticleContacts(const BaseParticle *obj)=0
Purely virtual function that returns all particles that have a contact with a given particle.
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51