MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CGHandler Class Reference

Container that stores all CG objects. More...

#include <CGHandler.h>

+ Inheritance diagram for CGHandler:

Public Member Functions

 CGHandler ()=default
 Default constructor, creates an empty CGHandler. More...
 
 CGHandler (const CGHandler &BH)
 Copy constructor, copies the CGHandler and all BaseCGPoint's it contains. More...
 
CGHandleroperator= (const CGHandler &rhs)
 Assignment operator that copies the pointer to the DPMBase and all objects. More...
 
 ~CGHandler () final=default
 Destructor, destructs the CGHandler and all BaseCGPoint's it contains. More...
 
void addObject (BaseCG *cg) final
 
std::string getName () const final
 
void readAndAddObject (std::istream &is) final
 Reads objects into the CGHandler from an istream (currently not implemented). More...
 
void write (std::ostream &os) const
 Writes objects into the CGHandler to an ostream (currently not implemented). More...
 
void initialise ()
 Contains the code executed before the first time step. More...
 
void evaluate ()
 Contains the code executed at each time step. More...
 
void finish ()
 Contains the code executed after the last time step. More...
 
void restart (std::string name)
 loads restart file, before evaluateDataFiles is run More...
 
void restartAndEvaluateRestartFiles (const std::string &name)
 
void restartAndEvaluateDataFiles (const std::string &name, bool evaluateFStatFiles=true)
 
bool evaluateDataFiles (bool evaluateFStatFiles=true)
 does the same as StatisticsVector::statistics_from_fstat_and_data: loads a restart file (if existing), then several data files, and fstat files (if existing) More...
 
bool evaluateRestartFiles ()
 
void computeContactPoints ()
 
Mdouble getTimeMin ()
 
Mdouble getTimeMax ()
 
void setInitialFileCounter (unsigned initialFileCounter)
 
unsigned getInitialFileCounter () const
 
- Public Member Functions inherited from BaseHandler< BaseCG >
 BaseHandler ()
 Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null pointer. More...
 
 BaseHandler (const BaseHandler< BaseCG > &BH)
 Constructor that copies the objects of the given handler into itself and sets other variables to 0/nullptr. More...
 
virtual ~BaseHandler ()
 Destructor, it destructs the BaseHandler and all Object it contains. More...
 
void copyContentsFromOtherHandler (const BaseHandler< BaseCG > &BH)
 Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handler (container) to the other. More...
 
std::enable_if
<!std::is_pointer< U >::value,
U * >::type 
copyAndAddObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
std::enable_if
< std::is_pointer< U >::value,
U >::type 
copyAndAddObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. More...
 
std::enable_if
<!std::is_pointer< U >::value,
U * >::type 
copyAndAddGhostObject (const U &object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
std::enable_if
< std::is_pointer< U >::value,
U >::type 
copyAndAddGhostObject (const U object)
 Creates a copy of a Object and adds it to the BaseHandler. This is one locally for inserting mpi particles, they avoid the global check if the particle can actually be inserted, because the mpi domain already knows that is the case. More...
 
virtual void addExistingObject (BaseCG *O)
 Adds an existing object to the BaseHandler without changing the id of the object. More...
 
virtual void addGhostObject (BaseCG *O)
 Adds a new Object to the BaseHandler. called by the to avoid increasing the id. More...
 
void removeIf (const std::function< bool(BaseCG *)> cond)
 
virtual void removeObject (unsigned const int index)
 Removes an Object from the BaseHandler. More...
 
void removeLastObject ()
 Removes the last Object from the BaseHandler. More...
 
virtual void clear ()
 Empties the whole BaseHandler by removing all Objects and setting all other variables to 0. More...
 
void read (std::istream &is)
 Reads all objects from restart data. More...
 
BaseCGgetObjectById (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
std::vector< BaseCG * > getObjectsById (const unsigned int id)
 Gets a vector of pointers to the objects with the specific id. More...
 
BaseCGgetObject (const unsigned int id)
 Gets a pointer to the Object at the specified index in the BaseHandler. More...
 
const BaseCGgetObject (const unsigned int id) const
 Gets a constant pointer to the Object at the specified index in the BaseHandler. More...
 
BaseCGgetLastObject ()
 Gets a pointer to the last Object in this BaseHandler. More...
 
const BaseCGgetLastObject () const
 Gets a constant pointer to the last Object in this BaseHandler. More...
 
virtual unsigned int getNumberOfObjects () const
 Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) More...
 
unsigned int getSize () const
 Gets the size of the particleHandler (including mpi and periodic particles) More...
 
unsigned int getStorageCapacity () const
 Gets the storage capacity of this BaseHandler. More...
 
void setStorageCapacity (const unsigned int N)
 Sets the storage capacity of this BaseHandler. More...
 
void resize (const unsigned int N, const BaseCG &obj)
 Resizes the container to contain N elements. More...
 
const std::vector< BaseCG * >
::const_iterator 
begin () const
 Gets the begin of the const_iterator over all Object in this BaseHandler. More...
 
const std::vector< BaseCG * >
::iterator 
begin ()
 Gets the begin of the iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseCG * >
::const_iterator 
end () const
 Gets the end of the const_iterator over all BaseBoundary in this BaseHandler. More...
 
const std::vector< BaseCG * >
::iterator 
end ()
 Gets the end of the iterator over all BaseBoundary in this BaseHandler. More...
 
void setDPMBase (DPMBase *DPMBase)
 Sets the problem that is solved using this handler. More...
 
void setId (BaseCG *object, unsigned int id)
 This function sets the id and ensures that nextId is a bigger value than id. More...
 
void increaseId ()
 
unsigned int getNextId ()
 
void setNextId (unsigned int id)
 
DPMBasegetDPMBase ()
 Gets the problem that is solved using this handler. More...
 
DPMBasegetDPMBase () const
 Gets the problem that is solved using this handler and does not change the class. More...
 
virtual void writeVTK () const
 now empty function for writing VTK files. More...
 
unsigned getNextGroupId ()
 Should be called each time you assign a groupId. Returns the value of nextGroupId_ and increases nextGroupId_ by one. More...
 

Public Attributes

unsigned initialFileCounter = 0
 

Additional Inherited Members

- Protected Attributes inherited from BaseHandler< BaseCG >
std::vector< BaseCG * > objects_
 The actual list of Object pointers. More...
 

Detailed Description

Container that stores all CG objects.

Todo:

get function that by default can distinguish species, but also density

make tests

change output format

command line arguments

make more readable definitions

read (a) restart, (b) data/fstat files

add speed by using the mesh

introduce standardDev

add 2D support

do we need to store the BaseObject::index_ anymore?

Can Interaction inherit directly from BaseInteraction?

make Files::statFile_, ... public, like the handlers; remove get functions for File's and handlers.

take out dependence on DPMBase::statFile (i.e. the savecount)

TW note, to keep the code working on Windows:

  • std::exit requires correct header cstdlib,
  • don't use to_string (thanks to Silvia for debugging)

The CGHandler stores all CG objects. Its member functions initialise, evaluate, and finish are called by the DPMBase before, during and after the time loop, respectively, and call the member functions initialise, evaluate, and finish of each CG object.

See also: MercuryCG: Post-processing discrete particle data using the coarse-graining formulation (in development).

Definition at line 64 of file CGHandler.h.

Constructor & Destructor Documentation

CGHandler::CGHandler ( )
default

Default constructor, creates an empty CGHandler.

CGHandler::CGHandler ( const CGHandler ch)

Copy constructor, copies the CGHandler and all BaseCGPoint's it contains.

Parameters
[in]chThe CGHandler that has to be copied.

Definition at line 34 of file CGHandler.cc.

References BaseHandler< T >::getDPMBase(), and BaseHandler< BaseCG >::setDPMBase().

35  : BaseHandler(ch)
36 {
37  setDPMBase(ch.getDPMBase());
38  //copyContentsFromOtherHandler(ch);
39 }
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
BaseHandler()
Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null point...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
CGHandler::~CGHandler ( )
finaldefault

Destructor, destructs the CGHandler and all BaseCGPoint's it contains.

Member Function Documentation

void CGHandler::addObject ( BaseCG cg)
finalvirtual
Parameters
[in]cgA pointer to the CG object that has to be added to the handler.

Reimplemented from BaseHandler< BaseCG >.

Definition at line 64 of file CGHandler.cc.

References BaseHandler< T >::addObject(), and BaseCG::setHandler().

65 {
66  //Puts the cg object in the list
68  //set the CGHandler pointer
69  cg->setHandler(this);
70 }
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:72
void CGHandler::computeContactPoints ( )

Definition at line 194 of file CGHandler.cc.

References cgLogger, Vec3D::dot(), BaseHandler< BaseCG >::getDPMBase(), Vec3D::getLength(), InfiniteWall::getNormal(), BaseParticle::getRadius(), constants::i, and WARN.

Referenced by evaluateRestartFiles(), and main().

195 {
196  //recompute contact point (necessary for old restart files)
197  for (BaseInteraction* const c : getDPMBase()->interactionHandler)
198  {
199  if (c->getContactPoint().isNaN())
200  {
201  const Vec3D& p = c->getP()->getPosition();
202  const Vec3D& i = c->getI()->getPosition();
203  const BaseParticle* const PParticle = dynamic_cast<BaseParticle*>(c->getP());
204  const BaseParticle* const IParticle = dynamic_cast<BaseParticle*>(c->getI());
205  if (IParticle != nullptr)
206  {
207  const Vec3D branchVector = p - i;
208  const Mdouble distance = branchVector.getLength();
209  c->setNormal(branchVector / distance);
210  c->setOverlap(PParticle->getRadius() + IParticle->getRadius() - distance);
211  c->setDistance(distance);
212  c->setContactPoint(p - (PParticle->getRadius() - 0.5 * c->getOverlap()) * c->getNormal());
213  }
214  else
215  {
216  const InfiniteWall* const IWall = dynamic_cast<InfiniteWall*>(c->getI());
217  if (IWall != nullptr)
218  {
219  const Mdouble dist = Vec3D::dot(i - p, IWall->getNormal());
220  const Mdouble r = dynamic_cast<BaseParticle*>(c->getP())->getRadius();
221  const Vec3D branch = (0.5 * (dist + r)) * IWall->getNormal();
222  c->setNormal(-IWall->getNormal());
223  c->setContactPoint(p + branch);
224  }
225  else
226  {
227  const Vec3D IP = p - i;
228  const Mdouble distance = Vec3D::getLength(IP);
229  c->setNormal(IP / distance);
230  c->setContactPoint(i);
231  }
232  }
233  //logger(INFO,"c%",c->getContactPoint());
234  static bool firstTime = true;
235  if (firstTime)
236  {
237  cgLogger(WARN,
238  "recomputing contact point, as contact point information is not available\n"
239  "Contact point is placed assuming spherical particles\n"
240  "Complex walls, non-spherical particles, periodic walls can create errors");
241  firstTime = false;
242  }
243  }
244  }
245 }
double Mdouble
Definition: GeneralDefine.h:34
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Vec3D getNormal() const
Access function for normal.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
Stores information about interactions between two interactable objects; often particles but could be ...
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:320
This is a class defining walls.
Definition: InfiniteWall.h:47
Logger< CG_LOGLEVEL > cgLogger("MercuryCG")
Definition: Vector.h:49
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
void CGHandler::evaluate ( )

Contains the code executed at each time step.

Definition at line 97 of file CGHandler.cc.

References BaseCG::evaluate(), BaseHandler< BaseCG >::getDPMBase(), DPMBase::getTime(), BaseCG::getTimeMax(), BaseCG::getTimeMin(), File::saveCurrentTimeStep(), File::setLastSavedTimeStep(), and BaseCG::statFile.

Referenced by evaluateDataFiles(), evaluateRestartFiles(), and DPMBase::writeOutputFiles().

98 {
99  //evaluate all CG objects in the handler
100  for (BaseCG* it : *this)
101  {
102  //if we are below timeMax and the next time step should be written
103  if (it->getTimeMin() <= getDPMBase()->getTime() && it->getTimeMax() > getDPMBase()->getTime()
104  && it->statFile.saveCurrentTimeStep(getDPMBase()->getNumberOfTimeSteps()))
105  {
106  //logger(INFO,"evaluate %, nt=%",it->statFile.getName(), getDPMBase()->getNumberOfTimeSteps());
107  it->statFile.setLastSavedTimeStep(getDPMBase()->getNumberOfTimeSteps());
108  it->evaluate();
109  }
110  }
111 };
virtual void evaluate()=0
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields...
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:180
bool saveCurrentTimeStep(unsigned int ntimeSteps)
determined if this time step has to be written; if so, opens the output file
Definition: File.cc:313
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:303
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:369
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:797
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:56
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:175
bool CGHandler::evaluateDataFiles ( bool  evaluateFStatFiles = true)

does the same as StatisticsVector::statistics_from_fstat_and_data: loads a restart file (if existing), then several data files, and fstat files (if existing)

Todo:
use ignore if time is out of bounds

Definition at line 315 of file CGHandler.cc.

References cgLogger, File::close(), DPMBase::dataFile, ERROR, evaluate(), finish(), DPMBase::fStatFile, BaseHandler< BaseCG >::getDPMBase(), File::getFullName(), DPMBase::getNumberOfDomains(), BaseHandler< T >::getNumberOfObjects(), MPIContainer::getNumberOfProcessors(), MPIContainer::getProcessorID(), BaseHandler< T >::getSize(), DPMBase::getTime(), getTimeMax(), getTimeMin(), INFO, initialFileCounter, initialise(), MPIContainer::Instance(), DPMBase::interactionHandler, logger, DPMBase::particleHandler, DPMBase::readNextDataFile(), DPMBase::readNextFStatFile(), and File::setCounter().

Referenced by restartAndEvaluateDataFiles().

316 {
317 
318 #ifdef MERCURY_USE_MPI
319  //Make sure that the number of processors is equal to the number of processors used for the run
320  MPIContainer& communicator = MPIContainer::Instance();
321  std::vector<unsigned> numberOfDomains = this->getDPMBase()->getNumberOfDomains();
322  int numberOfRequiredProcessors = numberOfDomains[0]*numberOfDomains[1]*numberOfDomains[2];
323  if(!(numberOfRequiredProcessors == communicator.getNumberOfProcessors()))
324  {
325  if (communicator.getProcessorID() == 0)
326  {
327  logger(ERROR,"Please re-run the program with % cores",numberOfRequiredProcessors);
328  }
329  else
330  {
331  std::exit(-1);
332  }
333  }
334 #endif
335  // reset counters so reading begins with the first data/fstat file
336  DPMBase* const dpm = getDPMBase();
337  //dpm->interactionHandler.clear();
340 
341  initialise();
342 
343  // return false if no data file can be read
345  if (!dpm->readNextDataFile()) return false;
346 
347  //define and check time limits
348  const Mdouble timeMin = getTimeMin();
349  const Mdouble timeMax = getTimeMax();
350  if (dpm->getTime() > timeMax)
351  {
352  logger(ERROR, "Time stamp of initial data file (%) is beyond the maximum cg time (tMax=%)", dpm->getTime(),
353  timeMax);
354  }
355  else
356  while (dpm->getTime() < timeMin)
357  {
358  if (evaluateFStatFiles) dpm->readNextFStatFile();
359  cgLogger(INFO, "Skipped %, t = %, because time is below tMin = %", dpm->dataFile.getFullName(),
360  dpm->getTime(), timeMin);
361  dpm->readNextDataFile();
362  }
363 
364  // read data file
365  do
366  {
367  if (evaluateFStatFiles) dpm->readNextFStatFile();
368 
369  cgLogger(INFO, "Read %, t=%, Np=%, Nc=%", dpm->dataFile.getFullName(), dpm->getTime(),
371 
372  evaluate();
373  } while (dpm->readNextDataFile() && getDPMBase()->getTime() <= timeMax);
374  cgLogger(INFO, "Finished reading from %", dpm->dataFile.getFullName());
375 
376  finish();
377  dpm->dataFile.close();
378  return true;
379 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
void finish()
Contains the code executed after the last time step.
Definition: CGHandler.cc:113
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:72
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getTimeMin()
Definition: CGHandler.cc:381
void readNextFStatFile()
Reads the next fstat file.
Definition: DPMBase.cc:2754
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:232
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:171
unsigned initialFileCounter
Definition: CGHandler.h:149
void evaluate()
Contains the code executed at each time step.
Definition: CGHandler.cc:97
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
void initialise()
Contains the code executed before the first time step.
Definition: CGHandler.cc:90
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:408
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1370
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: DPMBase.h:1375
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1329
bool readNextDataFile(unsigned int format=0)
Reads the next data file with default format=0. However, one can modify the format based on whether t...
Definition: DPMBase.cc:2575
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
Definition: BaseHandler.h:648
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1359
std::vector< unsigned > getNumberOfDomains()
returns the number of domains
Definition: DPMBase.cc:5025
Mdouble getTimeMax()
Definition: CGHandler.cc:391
Logger< CG_LOGLEVEL > cgLogger("MercuryCG")
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:797
bool CGHandler::evaluateRestartFiles ( )

Definition at line 247 of file CGHandler.cc.

References cgLogger, BaseHandler< T >::clear(), ParticleHandler::clear(), File::close(), computeContactPoints(), DPMBase::dataFile, ERROR, evaluate(), finish(), BaseHandler< BaseCG >::getDPMBase(), File::getFullName(), DPMBase::getNumberOfDomains(), BaseHandler< T >::getNumberOfObjects(), MPIContainer::getNumberOfProcessors(), MPIContainer::getProcessorID(), BaseHandler< T >::getSize(), DPMBase::getTime(), getTimeMax(), getTimeMin(), INFO, initialise(), MPIContainer::Instance(), DPMBase::interactionHandler, logger, DPMBase::particleHandler, DPMBase::readRestartFile(), DPMBase::restartFile, and DPMBase::wallHandler.

Referenced by restartAndEvaluateRestartFiles().

248 {
249 
250 #ifdef MERCURY_USE_MPI
251  //Make sure that the number of processors is equal to the number of processors used for the run
252  MPIContainer& communicator = MPIContainer::Instance();
253  std::vector<unsigned> numberOfDomains = this->getDPMBase()->getNumberOfDomains();
254  int numberOfRequiredProcessors = numberOfDomains[0]*numberOfDomains[1]*numberOfDomains[2];
255  if(!(numberOfRequiredProcessors == communicator.getNumberOfProcessors()))
256  {
257  if (communicator.getProcessorID() == 0)
258  {
259  logger(ERROR,"Please re-run the program with % cores",numberOfRequiredProcessors);
260  }
261  else
262  {
263  std::exit(-1);
264  }
265  }
266 #endif
267  // reset counters so reading begins with the first data/fstat file
268  DPMBase* const dpm = getDPMBase();
269 
270  //define and check time limits
271  Mdouble timeMin = getTimeMin();
272  Mdouble timeMax = getTimeMax();
273  if (getDPMBase()->getTime() > timeMax)
274  {
275  logger(ERROR, "initial restart file (t=%) is beyond the maximum cg time (tMax=%)", dpm->getTime(), timeMax);
276  }
277  else
278  while (getDPMBase()->getTime() < timeMin)
279  {
280  cgLogger(INFO, "Skipped %, t = %, because time is below tMin = %", dpm->restartFile.getFullName(),
281  dpm->getTime(), timeMin);
282  //the particle and wall handler is cleared here, because BaseSpecies doesn't delete particles belonging to it
283  dpm->particleHandler.clear();
284  dpm->wallHandler.clear();
285  dpm->readRestartFile();
286  }
287 
288  //call initialise to set up mesh, stat files, etc
289  initialise();
290 
291  // evaluate restart files, starting with the one already read (since interactions where not read)
292  while (dpm->readRestartFile() && getDPMBase()->getTime() < timeMax)
293  {
294  cgLogger(INFO, "Read %, t=%, Np=%, Nc=%", dpm->restartFile.getFullName(), dpm->getTime(),
296 
297  //recompute contact point (necessary for old restart files)
299 
300  evaluate();
301 
302  //the particle and wall handler is cleared here, because BaseSpecies doesn't delete particles belonging to it
303  dpm->particleHandler.clear();
304  dpm->wallHandler.clear();
305 
306  //continue if the next restart file can be read and the max time has not been reached
307  }
308  cgLogger(INFO, "Finished reading from %", dpm->dataFile.getFullName());
309 
310  finish();
311  dpm->dataFile.close();
312  return true;
313 }
This class contains all information and functions required for communication between processors...
Definition: MpiContainer.h:125
void finish()
Contains the code executed after the last time step.
Definition: CGHandler.cc:113
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:130
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:72
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
Mdouble getTimeMin()
Definition: CGHandler.cc:381
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:171
void evaluate()
Contains the code executed at each time step.
Definition: CGHandler.cc:97
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
void initialise()
Contains the code executed before the first time step.
Definition: CGHandler.cc:90
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:408
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1370
void computeContactPoints()
Definition: CGHandler.cc:194
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1329
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
Definition: BaseHandler.h:648
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1359
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1339
std::vector< unsigned > getNumberOfDomains()
returns the number of domains
Definition: DPMBase.cc:5025
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1385
Mdouble getTimeMax()
Definition: CGHandler.cc:391
Logger< CG_LOGLEVEL > cgLogger("MercuryCG")
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
bool readRestartFile(ReadOptions opt=ReadOptions::ReadAll)
Reads all the particle data corresponding to a given, existing . restart file (for more details regar...
Definition: DPMBase.cc:2896
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:797
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:528
void CGHandler::finish ( )

Contains the code executed after the last time step.

Definition at line 113 of file CGHandler.cc.

References BaseCG::finish(), NEVER, File::setLastSavedTimeStep(), and BaseCG::statFile.

Referenced by evaluateDataFiles(), evaluateRestartFiles(), and DPMBase::finishStatistics().

114 {
115  //enforce that data gets written
116  for (BaseCG* it : *this)
117  {
119  }
120  //evaluate all CG objects in the handler
121  //evaluate();
122  //finish all CG objects in the handler
123  for (BaseCG* it : *this)
124  it->finish();
125 }
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:303
const unsigned NEVER
Definition: File.h:35
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:369
virtual void finish()=0
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile...
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:56
unsigned CGHandler::getInitialFileCounter ( ) const
inline

Definition at line 145 of file CGHandler.h.

References initialFileCounter.

145  {
146  return initialFileCounter;
147  }
unsigned initialFileCounter
Definition: CGHandler.h:149
std::string CGHandler::getName ( ) const
finalvirtual
Returns
a string containing the name.

Implements BaseHandler< BaseCG >.

Definition at line 75 of file CGHandler.cc.

76 {
77  return "CGHandler";
78 }
Mdouble CGHandler::getTimeMax ( )

Definition at line 391 of file CGHandler.cc.

References BaseCG::getTimeMax(), and constants::inf.

Referenced by evaluateDataFiles(), and evaluateRestartFiles().

392 {
393  Mdouble time = -constants::inf;
394  for (BaseCG* it : *this)
395  {
396  time = std::max(time, it->getTimeMax());
397  }
398  return time;
399 }
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:180
double Mdouble
Definition: GeneralDefine.h:34
const Mdouble inf
Definition: GeneralDefine.h:44
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:56
Mdouble CGHandler::getTimeMin ( )

Definition at line 381 of file CGHandler.cc.

References BaseCG::getTimeMin(), and constants::inf.

Referenced by evaluateDataFiles(), and evaluateRestartFiles().

382 {
383  Mdouble time = constants::inf;
384  for (BaseCG* it : *this)
385  {
386  time = std::min(time, it->getTimeMin());
387  }
388  return time;
389 }
double Mdouble
Definition: GeneralDefine.h:34
const Mdouble inf
Definition: GeneralDefine.h:44
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:56
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:175
void CGHandler::initialise ( )

Contains the code executed before the first time step.

Definition at line 90 of file CGHandler.cc.

References BaseCG::initialise().

Referenced by evaluateDataFiles(), evaluateRestartFiles(), and DPMBase::initialiseStatistics().

91 {
92  //initialise all CG objects in the handler
93  for (BaseCG* it : *this)
94  it->initialise();
95 };
virtual void initialise()=0
Called at the beginning of the DPM simulation to initialise the cg evaluation and to open the statFil...
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:56
CGHandler & CGHandler::operator= ( const CGHandler rhs)

Assignment operator that copies the pointer to the DPMBase and all objects.

Parameters
[in]rhsThe WallHandler on the right hand side of the assignment.

This is not a copy assignment operator! It only copies the pointer to the DPMBase and the BaseWall in objects_, it sets the other data members to 0 or nullptr.

Definition at line 47 of file CGHandler.cc.

References BaseHandler< BaseCG >::clear(), BaseHandler< BaseCG >::copyContentsFromOtherHandler(), BaseHandler< T >::getDPMBase(), and BaseHandler< BaseCG >::setDPMBase().

48 {
49  if (this != &rhs)
50  {
51  clear();
52  setDPMBase(rhs.getDPMBase());
54  }
55  return *this;
56 #ifdef DEBUG_CONSTRUCTOR
57  std::cerr << "CGHandler::operator =(const CGHandler&) finished" << std::endl;
58 #endif
59 }
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void copyContentsFromOtherHandler(const BaseHandler< BaseCG > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
void CGHandler::readAndAddObject ( std::istream &  is)
finalvirtual

Reads objects into the CGHandler from an istream (currently not implemented).

Implements BaseHandler< BaseCG >.

Definition at line 80 of file CGHandler.cc.

81 {
82 
83 }
void CGHandler::restart ( std::string  name)

loads restart file, before evaluateDataFiles is run

Definition at line 127 of file CGHandler.cc.

References cgLogger, BaseHandler< T >::copyAndAddObject(), DPMBase::dataFile, File::decreaseCounter(), ERROR, BaseHandler< BaseCG >::getDPMBase(), File::getFullName(), File::getName(), BaseHandler< T >::getNumberOfObjects(), BaseHandler< T >::getSize(), DPMBase::getTime(), INFO, DPMBase::interactionHandler, logger, DPMBase::particleHandler, DPMBase::ReadNoInteractions, DPMBase::readRestartFile(), DPMBase::restartFile, DPMBase::setDomain(), File::setName(), DPMBase::setName(), DPMBase::speciesHandler, and WARN.

Referenced by restartAndEvaluateDataFiles(), and restartAndEvaluateRestartFiles().

128 {
129  DPMBase* dpm = getDPMBase();
130 
131  // determines if the variable name contains the name of a restart file, or a problem name
132  // (in which case the restart file is assumed to be name.restart)
133  std::string::size_type endName = name.find(".restart");
134  if (endName == std::string::npos)
135  {
136  dpm->setName(name);
137  }
138  else
139  {
140  dpm->setName(name.substr(0, endName));
141  dpm->restartFile.setName(name);
142  }
143 
144  // read restart file
145  cgLogger(INFO, "Reading %", dpm->restartFile.getFullName());
146 
148  {
149  if (dpm->speciesHandler.getNumberOfObjects() == 0)
150  {
152  }
153  std::ifstream data(dpm->dataFile.getName());
154  if (data.is_open())
155  {
156  Mdouble N = 0, t = 0;
157  Vec3D min, max;
158  data >> N >> t >> min >> max;
159  data.close();
160  dpm->setDomain(min, max);
161  logger(INFO, "Reading domain size from %: min %, max % ", dpm->dataFile.getName(), min, max);
162  }
163  else
164  {
165  logger(ERROR, "Data file could not be opened");
166  }
167  //adding 10 walls by default
168 // while (dpm->wallHandler.getNumberOfObjects()<10) {
169 // dpm->wallHandler.copyAndAddObject(InfiniteWall(dpm->speciesHandler.getLastObject()));
170 // }
171  //what to do if restart file could not be loaded
172  cgLogger(WARN, "Using default dpm setup as % does not exist", dpm->restartFile.getName());
173  }
174  else
175  {
176  cgLogger(INFO, "Successfully restarted from %, t=%, Np=%, Nc=%", dpm->restartFile.getFullName(), dpm->getTime(),
179  }
180 }
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:72
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
double Mdouble
Definition: GeneralDefine.h:34
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:171
void setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1059
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1370
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1329
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
virtual unsigned int getNumberOfObjects() const
Gets the number of real Object in this BaseHandler. (i.e. no mpi or periodic particles) ...
Definition: BaseHandler.h:648
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1319
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1359
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:412
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1385
void decreaseCounter()
Definition: File.h:150
Logger< CG_LOGLEVEL > cgLogger("MercuryCG")
Definition: Vector.h:49
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:199
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
bool readRestartFile(ReadOptions opt=ReadOptions::ReadAll)
Reads all the particle data corresponding to a given, existing . restart file (for more details regar...
Definition: DPMBase.cc:2896
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:797
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
Definition: File.cc:166
void CGHandler::restartAndEvaluateDataFiles ( const std::string &  name,
bool  evaluateFStatFiles = true 
)

Definition at line 188 of file CGHandler.cc.

References evaluateDataFiles(), and restart().

189 {
190  restart(name);
191  evaluateDataFiles(evaluateFStatFiles);
192 }
bool evaluateDataFiles(bool evaluateFStatFiles=true)
does the same as StatisticsVector::statistics_from_fstat_and_data: loads a restart file (if existing)...
Definition: CGHandler.cc:315
void restart(std::string name)
loads restart file, before evaluateDataFiles is run
Definition: CGHandler.cc:127
void CGHandler::restartAndEvaluateRestartFiles ( const std::string &  name)

Definition at line 182 of file CGHandler.cc.

References evaluateRestartFiles(), and restart().

183 {
184  restart(name);
186 }
void restart(std::string name)
loads restart file, before evaluateDataFiles is run
Definition: CGHandler.cc:127
bool evaluateRestartFiles()
Definition: CGHandler.cc:247
void CGHandler::setInitialFileCounter ( unsigned  initialFileCounter)
inline

Definition at line 141 of file CGHandler.h.

References initialFileCounter.

141  {
142  this->initialFileCounter = initialFileCounter;
143  }
unsigned initialFileCounter
Definition: CGHandler.h:149
void CGHandler::write ( std::ostream &  os) const

Writes objects into the CGHandler to an ostream (currently not implemented).

Definition at line 85 of file CGHandler.cc.

86 {
87 
88 }

Member Data Documentation

unsigned CGHandler::initialFileCounter = 0

Definition at line 149 of file CGHandler.h.

Referenced by evaluateDataFiles(), getInitialFileCounter(), and setInitialFileCounter().


The documentation for this class was generated from the following files: