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 addObject (BaseCG *object)
 Adds a new Object to the BaseHandler. 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)
 
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 toString (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).

Constructor & Destructor Documentation

◆ CGHandler() [1/2]

CGHandler::CGHandler ( )
default

Default constructor, creates an empty CGHandler.

◆ CGHandler() [2/2]

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.
35  : BaseHandler(ch)
36 {
37  setDPMBase(ch.getDPMBase());
38  //copyContentsFromOtherHandler(ch);
39 }
BaseHandler()
Default BaseHandler constructor, it creates an empty BaseHandler and assigns DPMBase_ to a null point...
Definition: BaseHandler.h:335
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
Definition: BaseHandler.h:718
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
Definition: BaseHandler.h:725

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

◆ ~CGHandler()

CGHandler::~CGHandler ( )
finaldefault

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

Member Function Documentation

◆ addObject()

void CGHandler::addObject ( BaseCG cg)
final
Parameters
[in]cgA pointer to the CG object that has to be added to the handler.
65 {
66  //Puts the cg object in the list
68  //set the CGHandler pointer
69  cg->setHandler(this);
70 }
void setHandler(CGHandler *handler)
Sets handler_, the pointer to the CGHandler.
Definition: BaseCG.cc:73
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
Definition: BaseHandler.h:431

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

◆ computeContactPoints()

void CGHandler::computeContactPoints ( )
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
Logger< CG_LOGLEVEL > cgLogger("MercuryCG")
@ WARN
Stores information about interactions between two interactable objects; often particles but could be ...
Definition: BaseInteraction.h:60
Definition: BaseParticle.h:54
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:348
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:48
Vec3D getNormal() const
Access function for normal.
Definition: InfiniteWall.cc:213
Definition: Vector.h:51
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
Definition: Vector.cc:76
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:320
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51

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

Referenced by evaluateRestartFiles(), and main().

◆ evaluate()

void CGHandler::evaluate ( )

Contains the code executed at each time step.

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 };
Base class of all CG objects, needed to store the various CG objects in the CGHandler.
Definition: BaseCG.h:57
Mdouble getTimeMax() const
Returns timeMax_, the upper limit of the temporal domain.
Definition: BaseCG.cc:181
File statFile
File class to handle the output into a .stat file.
Definition: BaseCG.h:376
virtual void evaluate()=0
Called after a given number of time steps (statFile::saveCount_) to evaluate the CG fields.
Mdouble getTimeMin() const
Returns timeMin_, the lower limit of the temporal domain.
Definition: BaseCG.cc:176
bool saveCurrentTimeStep(unsigned int ntimeSteps)
determined if this time step has to be written; if so, opens the output file
Definition: File.cc:312
void setLastSavedTimeStep(unsigned int lastSavedTimeStep)
Sets File::nextSavedTimeStep_.
Definition: File.cc:302

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

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

◆ evaluateDataFiles()

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
316 {
317 
318 #ifdef MERCURYDPM_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 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ INFO
@ ERROR
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
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
unsigned initialFileCounter
Definition: CGHandler.h:149
void evaluate()
Contains the code executed at each time step.
Definition: CGHandler.cc:97
void finish()
Contains the code executed after the last time step.
Definition: CGHandler.cc:113
Mdouble getTimeMin()
Definition: CGHandler.cc:381
Mdouble getTimeMax()
Definition: CGHandler.cc:391
void initialise()
Contains the code executed before the first time step.
Definition: CGHandler.cc:90
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:77
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: DPMBase.h:1483
std::vector< unsigned > getNumberOfDomains()
returns the number of domains
Definition: DPMBase.cc:5280
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:808
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1478
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:2691
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1467
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
void readNextFStatFile()
Reads the next fstat file.
Definition: DPMBase.cc:2869
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter,...
Definition: File.cc:170
void close()
Closes the file by calling fstream_.close()
Definition: File.cc:407
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:231
This class contains all information and functions required for communication between processors.
Definition: MpiContainer.h:130
std::size_t getNumberOfProcessors() const
Get the total number of processors participating in this simulation.
Definition: MpiContainer.cc:104
static MPIContainer & Instance()
fetch the instance to be used for communication
Definition: MpiContainer.h:134
std::size_t getProcessorID()
Reduces a scalar on all processors to one scalar on a target processor.
Definition: MpiContainer.cc:113

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 commandLineCG(), and restartAndEvaluateDataFiles().

◆ evaluateRestartFiles()

bool CGHandler::evaluateRestartFiles ( )
248 {
249 
250 #ifdef MERCURYDPM_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 }
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition: BaseHandler.h:528
void computeContactPoints()
Definition: CGHandler.cc:194
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1447
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1493
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:3006
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
Definition: ParticleHandler.cc:977

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 commandLineCG(), and restartAndEvaluateRestartFiles().

◆ finish()

void CGHandler::finish ( )

Contains the code executed after the last time step.

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 }
const unsigned NEVER
Definition: File.h:35
virtual void finish()=0
Called at the end of the DPM simulation to finish the cg evaluation and to close the statFile.

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

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

◆ getInitialFileCounter()

unsigned CGHandler::getInitialFileCounter ( ) const
inline
145  {
146  return initialFileCounter;
147  }

References initialFileCounter.

◆ getName()

std::string CGHandler::getName ( ) const
finalvirtual
Returns
a string containing the name.

Implements BaseHandler< BaseCG >.

76 {
77  return "CGHandler";
78 }

◆ getTimeMax()

Mdouble CGHandler::getTimeMax ( )
392 {
393  Mdouble time = -constants::inf;
394  for (BaseCG* it : *this)
395  {
396  time = std::max(time, it->getTimeMax());
397  }
398  return time;
399 }
const Mdouble inf
Definition: GeneralDefine.h:44

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

Referenced by evaluateDataFiles(), and evaluateRestartFiles().

◆ getTimeMin()

Mdouble CGHandler::getTimeMin ( )
382 {
383  Mdouble time = constants::inf;
384  for (BaseCG* it : *this)
385  {
386  time = std::min(time, it->getTimeMin());
387  }
388  return time;
389 }

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

Referenced by evaluateDataFiles(), and evaluateRestartFiles().

◆ initialise()

void CGHandler::initialise ( )

Contains the code executed before the first time step.

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...

References BaseCG::initialise().

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

◆ operator=()

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.

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 copyContentsFromOtherHandler(const BaseHandler< BaseCG > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Definition: BaseHandler.h:367

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

◆ readAndAddObject()

void CGHandler::readAndAddObject ( std::istream &  is)
finalvirtual

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

Implements BaseHandler< BaseCG >.

81 {
82 
83 }

◆ restart()

void CGHandler::restart ( std::string  name)

loads restart file, before evaluateDataFiles is run

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, "No density is specified, thus density is assumed to be 1. Provide % file if you want to specify the density.", dpm->restartFile.getName());
173  }
174  else
175  {
176  cgLogger(INFO, "Successfully restarted from %, t=%, Np=%, Nc=%", dpm->restartFile.getFullName(), dpm->getTime(),
179  }
180 }
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:33
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
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1427
void setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1098
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
Definition: File.cc:165
void decreaseCounter()
Definition: File.h:150
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:198
std::string name
Definition: MercuryProb.h:48

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, units::name, DPMBase::particleHandler, DPMBase::ReadNoInteractions, DPMBase::readRestartFile(), DPMBase::restartFile, DPMBase::setDomain(), DPMBase::setName(), File::setName(), DPMBase::speciesHandler, and WARN.

Referenced by commandLineCG(), restartAndEvaluateDataFiles(), and restartAndEvaluateRestartFiles().

◆ restartAndEvaluateDataFiles()

void CGHandler::restartAndEvaluateDataFiles ( const std::string &  name,
bool  evaluateFStatFiles = true 
)
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

References evaluateDataFiles(), units::name, and restart().

Referenced by main().

◆ restartAndEvaluateRestartFiles()

void CGHandler::restartAndEvaluateRestartFiles ( const std::string &  name)
183 {
184  restart(name);
186 }
bool evaluateRestartFiles()
Definition: CGHandler.cc:247

References evaluateRestartFiles(), units::name, and restart().

◆ setInitialFileCounter()

void CGHandler::setInitialFileCounter ( unsigned  initialFileCounter)
inline
141  {
143  }

References initialFileCounter.

Referenced by commandLineCG().

◆ write()

void CGHandler::write ( std::ostream &  os) const

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

86 {
87 
88 }

Member Data Documentation

◆ initialFileCounter

unsigned CGHandler::initialFileCounter = 0

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